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 flag;
49 public AllocSite( int allocationDepth,
54 assert allocationDepth >= 1;
56 this.allocationDepth = allocationDepth;
57 this.flatNew = flatNew;
58 this.disjointId = disjointId;
61 ithOldest = new Vector<Integer>( allocationDepth );
62 id = generateUniqueAllocSiteID();
65 static public Integer generateUniqueAllocSiteID() {
67 return new Integer( uniqueIDcount );
70 public String getDisjointAnalysisId() {
75 public int getAllocationDepth() {
76 return allocationDepth;
79 public void setIthOldest( int i, Integer id ) {
81 assert i < allocationDepth;
84 ithOldest.add( i, id );
87 public Integer getIthOldest( int i ) {
89 assert i < allocationDepth;
91 return ithOldest.get( i );
94 public Integer getIthOldestShadow( int i ) {
96 assert i < allocationDepth;
98 return -ithOldest.get( i );
101 public Integer getOldest() {
102 return ithOldest.get( allocationDepth - 1 );
105 public Integer getOldestShadow() {
106 return -ithOldest.get( allocationDepth - 1 );
109 public void setSummary( Integer id ) {
114 public Integer getSummary() {
118 public Integer getSummaryShadow() {
122 public FlatNew getFlatNew() {
126 public TypeDescriptor getType() {
127 return flatNew.getType();
130 public int getAgeCategory( Integer id ) {
132 if( id.equals( summary ) ) {
136 if( id.equals( getOldest() ) ) {
140 for( int i = 0; i < allocationDepth - 1; ++i ) {
141 if( id.equals( ithOldest.get( i ) ) ) {
146 return AGE_notInThisSite;
149 public Integer getAge( Integer id ) {
150 for( int i = 0; i < allocationDepth; ++i ) {
151 if( id.equals( ithOldest.get( i ) ) ) {
152 return new Integer( i );
159 public int getShadowAgeCategory( Integer id ) {
160 if( id.equals( -summary ) ) {
161 return SHADOWAGE_summary;
164 if( id.equals( getOldestShadow() ) ) {
165 return SHADOWAGE_oldest;
168 for( int i = 0; i < allocationDepth - 1; ++i ) {
169 if( id.equals( getIthOldestShadow( i ) ) ) {
170 return SHADOWAGE_in_I;
174 return SHADOWAGE_notInThisSite;
177 public Integer getShadowAge( Integer id ) {
178 for( int i = 0; i < allocationDepth - 1; ++i ) {
179 if( id.equals( getIthOldestShadow( i ) ) ) {
180 return new Integer( -i );
187 public Integer getShadowIDfromID( Integer id ) {
188 int ageCat = getAgeCategory( id );
196 case AGE_notInThisSite:
198 System.out.println( toStringWithIDs() );
199 throw new Error( "ID "+id+" not from this site." );
203 public String toString() {
204 if( disjointId == null ) {
205 return "allocSite"+id;
207 return "allocSite "+disjointId+" ("+id+")";
210 public String toStringVerbose() {
211 if( disjointId == null ) {
212 return "allocSite"+id+" "+
213 flatNew.getType().toPrettyString();
215 return "allocSite "+disjointId+" ("+id+") "+
216 flatNew.getType().toPrettyString();
219 public String toStringForDOT() {
220 if( disjointId != null ) {
221 return "disjoint "+disjointId+"\\n"+toString()+
222 "\\n"+getType().toPrettyString();
225 "\\n"+getType().toPrettyString();
229 public String toStringWithIDs() {
230 String s = "allocSite"+id+" ";
231 for( int i = 0; i < ithOldest.size(); ++i ) {
232 s += i+"("+ithOldest.get( i )+") ";
234 s += "summary("+summary+")";
239 public int hashCodeSpecific() {
243 public void setFlag( boolean flag ) {
247 public boolean getFlag() {