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 {
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 String getDisjointAnalysisId() {
112 public int getAllocationDepth() {
113 return allocationDepth;
116 public void setIthOldest( int i, Integer id ) {
118 assert i < allocationDepth;
121 ithOldest.add( i, id );
124 public Integer getIthOldest( int i ) {
126 assert i < allocationDepth;
128 return ithOldest.get( i );
131 public Integer getIthOldestShadow( int i ) {
133 assert i < allocationDepth;
135 return -ithOldest.get( i );
138 public Integer getOldest() {
139 return ithOldest.get( allocationDepth - 1 );
142 public Integer getOldestShadow() {
143 return -ithOldest.get( allocationDepth - 1 );
146 public void setSummary( Integer id ) {
151 public Integer getSummary() {
155 public Integer getSummaryShadow() {
159 public FlatNew getFlatNew() {
163 public TypeDescriptor getType() {
164 return flatNew.getType();
167 public boolean isFlagged() {
171 public int getAgeCategory( Integer id ) {
173 if( id.equals( summary ) ) {
177 if( id.equals( getOldest() ) ) {
181 for( int i = 0; i < allocationDepth - 1; ++i ) {
182 if( id.equals( ithOldest.get( i ) ) ) {
187 return AGE_notInThisSite;
190 public Integer getAge( Integer id ) {
191 for( int i = 0; i < allocationDepth; ++i ) {
192 if( id.equals( ithOldest.get( i ) ) ) {
193 return new Integer( i );
200 public int getShadowAgeCategory( Integer id ) {
201 if( id.equals( -summary ) ) {
202 return SHADOWAGE_summary;
205 if( id.equals( getOldestShadow() ) ) {
206 return SHADOWAGE_oldest;
209 for( int i = 0; i < allocationDepth - 1; ++i ) {
210 if( id.equals( getIthOldestShadow( i ) ) ) {
211 return SHADOWAGE_in_I;
215 return SHADOWAGE_notInThisSite;
218 public Integer getShadowAge( Integer id ) {
219 for( int i = 0; i < allocationDepth - 1; ++i ) {
220 if( id.equals( getIthOldestShadow( i ) ) ) {
221 return new Integer( -i );
228 public Integer getShadowIDfromID( Integer id ) {
229 int ageCat = getAgeCategory( id );
237 case AGE_notInThisSite:
239 System.out.println( toStringWithIDs() );
240 throw new Error( "ID "+id+" not from this site." );
244 public String toString() {
245 if( disjointId == null ) {
246 return "allocSite"+id;
248 return "allocSite "+disjointId+" ("+id+")";
251 public String toStringBrief() {
252 return id.toString();
255 public String toStringVerbose() {
256 if( disjointId == null ) {
257 return "allocSite"+id+" "+
258 flatNew.getType().toPrettyString();
260 return "allocSite "+disjointId+" ("+id+") "+
261 flatNew.getType().toPrettyString();
264 public String toStringForDOT() {
265 if( disjointId != null ) {
266 return "disjoint "+disjointId+"\\n"+toString()+
267 "\\n"+getType().toPrettyString();
270 "\\n"+getType().toPrettyString();
274 public String toStringWithIDs() {
275 String s = "allocSite"+id+" ";
276 for( int i = 0; i < ithOldest.size(); ++i ) {
277 s += i+"("+ithOldest.get( i )+") ";
279 s += "summary("+summary+")";
283 public boolean equalsSpecific( Object o ) {
288 if( !(o instanceof AllocSite) ) {
292 AllocSite as = (AllocSite) o;
294 return this.id == as.id;
297 public int hashCodeSpecific() {