1 package Analysis.Disjoint;
7 // allocation sites are independent of any particular
8 // reachability graph, unlike most of the other elements
9 // of the reachability 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.
14 // So two different reachability 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 AllocSite
19 // object associated with the FlatNew node that gives
20 // the graphs the identifiers in question.
22 // note that an allocsite extends Canonical because they
23 // are Canonical, but specifically so an AllocSite can
24 // be an operand to a CanonicalOp
26 public class AllocSite extends Canonical implements Alloc {
28 static protected int uniqueIDcount = 0;
30 public static final int AGE_notInThisSite = 100;
31 public static final int AGE_in_I = 101;
32 public static final int AGE_oldest = 102;
33 public static final int AGE_summary = 103;
35 public static final int SHADOWAGE_notInThisSite = -100;
36 public static final int SHADOWAGE_in_I = -101;
37 public static final int SHADOWAGE_oldest = -102;
38 public static final int SHADOWAGE_summary = -103;
41 protected int allocationDepth;
42 protected Vector<Integer> ithOldest;
43 protected Integer summary;
44 protected FlatNew flatNew;
45 protected String disjointId;
46 protected boolean isFlagged;
49 public static AllocSite factory(int allocationDepth,
54 AllocSite out = new AllocSite(allocationDepth,
58 out = (AllocSite) Canonical.makeCanonical(out);
63 protected AllocSite(int allocationDepth,
69 assert allocationDepth >= 1;
71 this.allocationDepth = allocationDepth;
72 this.flatNew = flatNew;
73 this.disjointId = disjointId;
75 // mark this allocation site as being flagged
76 // for the analysis if
77 // 1) we have a non-null disjointID (a named flagged site)
79 // 2) the type is a class with Bamboo-parameter flags
81 // 3) a client wants to programmatically flag this site,
82 // such as the OoOJava method effects analysis
83 this.isFlagged = false;
85 if( disjointId != null ) {
86 this.isFlagged = true;
88 } else if( flatNew.getType().isClass() &&
89 flatNew.getType().getClassDesc().hasFlags()
91 this.isFlagged = true;
93 } else if( markAsFlagged ) {
94 this.isFlagged = true;
98 ithOldest = new Vector<Integer>(allocationDepth);
99 id = generateUniqueAllocSiteID();
102 static public Integer generateUniqueAllocSiteID() {
104 return new Integer(uniqueIDcount);
107 public int getUniqueAllocSiteID() {
111 public String getDisjointAnalysisId() {
116 public int getAllocationDepth() {
117 return allocationDepth;
120 public void setIthOldest(int i, Integer id) {
122 assert i < allocationDepth;
125 ithOldest.add(i, id);
128 public Integer getIthOldest(int i) {
130 assert i < allocationDepth;
132 return ithOldest.get(i);
135 public Integer getIthOldestShadow(int i) {
137 assert i < allocationDepth;
139 return -ithOldest.get(i);
142 public Integer getOldest() {
143 return ithOldest.get(allocationDepth - 1);
146 public Integer getOldestShadow() {
147 return -ithOldest.get(allocationDepth - 1);
150 public void setSummary(Integer id) {
155 public Integer getSummary() {
159 public Integer getSummaryShadow() {
163 public FlatNew getFlatNew() {
167 public TypeDescriptor getType() {
168 return flatNew.getType();
171 public boolean isFlagged() {
175 public int getAgeCategory(Integer id) {
177 if( id.equals(summary) ) {
181 if( id.equals(getOldest() ) ) {
185 for( int i = 0; i < allocationDepth - 1; ++i ) {
186 if( id.equals(ithOldest.get(i) ) ) {
191 return AGE_notInThisSite;
194 public Integer getAge(Integer id) {
195 for( int i = 0; i < allocationDepth; ++i ) {
196 if( id.equals(ithOldest.get(i) ) ) {
197 return new Integer(i);
204 public int getShadowAgeCategory(Integer id) {
205 if( id.equals(-summary) ) {
206 return SHADOWAGE_summary;
209 if( id.equals(getOldestShadow() ) ) {
210 return SHADOWAGE_oldest;
213 for( int i = 0; i < allocationDepth - 1; ++i ) {
214 if( id.equals(getIthOldestShadow(i) ) ) {
215 return SHADOWAGE_in_I;
219 return SHADOWAGE_notInThisSite;
222 public Integer getShadowAge(Integer id) {
223 for( int i = 0; i < allocationDepth - 1; ++i ) {
224 if( id.equals(getIthOldestShadow(i) ) ) {
225 return new Integer(-i);
232 public Integer getShadowIDfromID(Integer id) {
233 int ageCat = getAgeCategory(id);
241 case AGE_notInThisSite:
243 System.out.println(toStringWithIDs() );
244 throw new Error("ID "+id+" not from this site.");
248 public String toString() {
249 if( disjointId == null ) {
250 return "allocSite"+id;
252 return "allocSite "+disjointId+" ("+id+")";
255 public String toStringBrief() {
256 return id.toString();
259 public String toStringVerbose() {
260 if( disjointId == null ) {
261 return "allocSite"+id+" "+
262 flatNew.getType().toPrettyString();
264 return "allocSite "+disjointId+" ("+id+") "+
265 flatNew.getType().toPrettyString();
268 public String toStringForDOT() {
270 if( disjointId != null ) {
271 s += "disjoint "+disjointId+"\\n";
273 s += toString()+"\\n";
275 // jjenista -- too lazy to make this a compiler option right now
276 // But here's the rub: getting the source file and line number of
277 // each allocation site in the graph is awesome except it blows up
278 // the size of the image dramatically: only turn it on when you
281 //String filename = DisjointAnalysis.fn2filename.get( flatNew );
282 //if( filename != null ) {
283 // s += DisjointAnalysis.fn2filename.get( flatNew )+":"+
284 // flatNew.getNumLine()+"\\n";
287 return s + getType().toPrettyString();
290 public String toStringWithIDs() {
291 return "allocSite"+id+" "+toStringJustIDs();
294 public String toStringJustIDs() {
296 for( int i = 0; i < ithOldest.size(); ++i ) {
297 s += i+"("+ithOldest.get(i)+") ";
299 s += "summary("+summary+")";
303 public boolean equalsSpecific(Object o) {
308 if( !(o instanceof AllocSite) ) {
312 AllocSite as = (AllocSite) o;
314 return this.id == as.id;
317 public int hashCodeSpecific() {
318 return id.hashCode();