1 package Analysis.Pointer;
3 import Analysis.Disjoint.Alloc;
8 public class AllocFactory {
9 public static AllocSiteNode dummySite=new AllocSiteNode(-1, null);
10 public static AllocNode dummyNode=new AllocNode(-1, null, false, dummySite);
12 public static class AllocNode {
18 public AllocNode(int allocsite, FlatNew node, boolean summary) {
19 this.allocsite=allocsite;
24 public AllocNode(int allocsite, FlatNew node, boolean summary, AllocSiteNode as) {
25 this.allocsite=allocsite;
31 public AllocSiteNode getAllocSite() {
35 public TypeDescriptor getType() {
36 return node.getType();
39 public FlatNew getFlatNew() {
43 public int getUniqueAllocSiteID() {
47 public boolean isSummary() {
51 public int hashCode() {
52 return allocsite<<1^(summary?0:1);
55 public boolean equals(Object o) {
56 if (o instanceof AllocNode) {
57 AllocNode an=(AllocNode)o;
58 return (allocsite==an.allocsite)&&(summary==an.summary);
63 public String toString() {
67 public String getID() {
69 return "SUM"+allocsite;
71 return "SING"+allocsite;
75 public static class AllocSiteNode implements Alloc {
79 public AllocSiteNode(int allocsite, FlatNew node) {
80 this.allocsite=allocsite;
84 public TypeDescriptor getType() {
85 return node.getType();
88 public FlatNew getFlatNew() {
92 public int getUniqueAllocSiteID() {
96 public int hashCode() {
100 public boolean equals(Object o) {
101 if (o instanceof AllocSiteNode) {
102 AllocSiteNode an=(AllocSiteNode)o;
103 return (allocsite==an.allocsite);
108 public String toStringBrief() {
112 public String toString() {
116 public String getID() {
117 return "N"+allocsite;
121 public AllocFactory(State state, TypeUtil typeUtil) {
122 allocMap=new HashMap<FlatNew, Integer>();
123 allocNodeMap=new HashMap<AllocNode, AllocNode>();
124 allocSiteMap=new HashMap<AllocSiteNode, AllocSiteNode>();
125 this.typeUtil=typeUtil;
126 ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.StringClass);
127 TypeDescriptor stringtd=new TypeDescriptor(stringcd);
128 TypeDescriptor stringarraytd=stringtd.makeArray(state);
129 StringArray=new AllocNode(0, new FlatNew(stringarraytd, null, false), false);
130 StringArray.as=getAllocSite(StringArray);
131 Strings=new AllocNode(1, new FlatNew(stringtd, null, false), true);
132 Strings.as=getAllocSite(Strings);
135 public int getSiteNumber(FlatNew node) {
136 if (allocMap.containsKey(node))
137 return allocMap.get(node);
138 int index=siteCounter++;
139 allocMap.put(node, index);
143 public AllocNode getAllocNode(FlatNew node, boolean isSummary) {
144 int site=getSiteNumber(node);
145 AllocNode key=new AllocNode(site, node, isSummary);
146 if (!allocNodeMap.containsKey(key)) {
147 allocNodeMap.put(key, key);
148 key.as=getAllocSite(key);
151 return allocNodeMap.get(key);
154 public AllocNode getAllocNode(AllocNode node, boolean isSummary) {
155 int site=node.allocsite;
156 AllocNode key=new AllocNode(site, node.node, isSummary);
157 if (!allocNodeMap.containsKey(key)) {
158 allocNodeMap.put(key, key);
159 key.as=getAllocSite(key);
162 return allocNodeMap.get(key);
165 public AllocSiteNode getAllocSite(AllocNode node) {
166 AllocSiteNode as=new AllocSiteNode(node.allocsite, node.node);
167 if (!allocSiteMap.containsKey(as)) {
168 allocSiteMap.put(as, as);
171 return allocSiteMap.get(as);
174 HashMap<AllocNode, AllocNode> allocNodeMap;
175 HashMap<AllocSiteNode, AllocSiteNode> allocSiteMap;
176 HashMap<FlatNew, Integer> allocMap;
180 public AllocNode StringArray;
181 public AllocNode Strings;