Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / AllocationSite.java
1 package Analysis.OwnershipAnalysis;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6
7 // allocation sites are independent of any particular
8 // ownership graph, unlike most of the other elements
9 // of the ownership analysis.  An allocation site is
10 // simply a collection of heap region identifiers that
11 // are associated with a single allocation site in the
12 // program under analysis.
13
14 // So two different ownership graphs may incorporate
15 // nodes that represent the memory from one allocation
16 // site.  In this case there are two different sets of
17 // HeapRegionNode objects, but they have the same
18 // node identifiers, and there is one AllocationSite
19 // object associated with the FlatNew node that gives
20 // the graphs the identifiers in question.
21
22 public class AllocationSite {
23
24   static private int uniqueIDcount = 0;
25
26   protected Integer id;
27   protected int allocationDepth;
28   protected Vector<Integer> ithOldest;
29   protected Integer summary;
30   protected FlatNew flatNew;
31   protected String disjointId;
32
33   public static final int AGE_notInThisSite = 100;
34   public static final int AGE_in_I          = 101;
35   public static final int AGE_oldest        = 102;
36   public static final int AGE_summary       = 103;
37
38   public static final int SHADOWAGE_notInThisSite = -100;
39   public static final int SHADOWAGE_in_I          = -101;
40   public static final int SHADOWAGE_oldest        = -102;
41   public static final int SHADOWAGE_summary       = -103;
42
43   private boolean flag=false;
44
45
46   public AllocationSite(int allocationDepth, FlatNew flatNew, String disjointId) {
47     assert allocationDepth >= 1;
48
49     this.allocationDepth = allocationDepth;
50     this.flatNew         = flatNew;
51     this.disjointId      = disjointId;
52
53     ithOldest = new Vector<Integer>(allocationDepth);
54     id        = generateUniqueAllocationSiteID();
55   }
56
57   static public Integer generateUniqueAllocationSiteID() {
58     ++uniqueIDcount;
59     return new Integer(uniqueIDcount);
60   }
61
62
63   public String getDisjointId() {
64     return disjointId;
65   }
66
67
68   public int getAllocationDepth() {
69     return allocationDepth;
70   }
71
72   public void setIthOldest(int i, Integer id) {
73     assert i  >= 0;
74     assert i  <  allocationDepth;
75     assert id != null;
76
77     ithOldest.add(i, id);
78   }
79
80   public Integer getIthOldest(int i) {
81     assert i >= 0;
82     assert i <  allocationDepth;
83
84     return ithOldest.get(i);
85   }
86
87   public Integer getIthOldestShadow(int i) {
88     assert i >= 0;
89     assert i <  allocationDepth;
90
91     return -ithOldest.get(i);
92   }
93
94   public Integer getOldest() {
95     return ithOldest.get(allocationDepth - 1);
96   }
97
98   public Integer getOldestShadow() {
99     return -ithOldest.get(allocationDepth - 1);
100   }
101
102   public void setSummary(Integer id) {
103     assert id != null;
104     summary = id;
105   }
106
107   public Integer getSummary() {
108     return summary;
109   }
110
111   public Integer getSummaryShadow() {
112     return -summary;
113   }
114
115   public FlatNew getFlatNew() {
116     return flatNew;
117   }
118
119   public TypeDescriptor getType() {
120     return flatNew.getType();
121   }
122
123   public int getAgeCategory(Integer id) {
124
125     if( id.equals(summary) ) {
126       return AGE_summary;
127     }
128
129     if( id.equals(getOldest() ) ) {
130       return AGE_oldest;
131     }
132
133     for( int i = 0; i < allocationDepth - 1; ++i ) {
134       if( id.equals(ithOldest.get(i) ) ) {
135         return AGE_in_I;
136       }
137     }
138
139     return AGE_notInThisSite;
140   }
141
142   public Integer getAge(Integer id) {
143     for( int i = 0; i < allocationDepth - 1; ++i ) {
144       if( id.equals(ithOldest.get(i) ) ) {
145         return new Integer(i);
146       }
147     }
148
149     return null;
150   }
151
152   public int getShadowAgeCategory(Integer id) {
153     if( id.equals(-summary) ) {
154       return SHADOWAGE_summary;
155     }
156
157     if( id.equals(getOldestShadow() ) ) {
158       return SHADOWAGE_oldest;
159     }
160
161     for( int i = 0; i < allocationDepth - 1; ++i ) {
162       if( id.equals(getIthOldestShadow(i) ) ) {
163         return SHADOWAGE_in_I;
164       }
165     }
166
167     return SHADOWAGE_notInThisSite;
168   }
169
170   public Integer getShadowAge(Integer id) {
171     for( int i = 0; i < allocationDepth - 1; ++i ) {
172       if( id.equals(getIthOldestShadow(i) ) ) {
173         return new Integer(-i);
174       }
175     }
176
177     return null;
178   }
179
180   public String toString() {
181     if( disjointId == null ) {
182       return "allocSite" + id;
183     }
184     return "allocSite "+disjointId+" ("+id+")";
185   }
186
187   public String toStringVerbose() {
188     if( disjointId == null ) {
189       return "allocSite" + id + " "+flatNew.getType().toPrettyString();
190     }
191     return "allocSite "+disjointId+" ("+id+") "+flatNew.getType().toPrettyString();
192   }
193
194   public String toStringForDOT() {
195     if( disjointId != null ) {
196       return "disjoint "+disjointId+"\\n"+toString()+"\\n"+getType().toPrettyString();
197     } else {
198       return toString()+"\\n"+getType().toPrettyString();
199     }
200   }
201
202   public void setFlag(boolean flag) {
203     this.flag=flag;
204   }
205
206   public boolean getFlag() {
207     return flag;
208   }
209
210   public int getID() {
211     return id;
212   }
213 }