1 package Analysis.OwnershipAnalysis;
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.
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.
22 public class AllocationSite {
24 static private int uniqueIDcount = 0;
27 protected int allocationDepth;
28 protected Vector<Integer> ithOldest;
29 protected Integer summary;
30 protected FlatNew flatNew;
31 protected String disjointId;
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;
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;
43 private boolean flag=false;
46 public AllocationSite(int allocationDepth, FlatNew flatNew, String disjointId) {
47 assert allocationDepth >= 1;
49 this.allocationDepth = allocationDepth;
50 this.flatNew = flatNew;
51 this.disjointId = disjointId;
53 ithOldest = new Vector<Integer>(allocationDepth);
54 id = generateUniqueAllocationSiteID();
57 static public Integer generateUniqueAllocationSiteID() {
59 return new Integer(uniqueIDcount);
63 public String getDisjointId() {
68 public int getAllocationDepth() {
69 return allocationDepth;
72 public void setIthOldest(int i, Integer id) {
74 assert i < allocationDepth;
80 public Integer getIthOldest(int i) {
82 assert i < allocationDepth;
84 return ithOldest.get(i);
87 public Integer getIthOldestShadow(int i) {
89 assert i < allocationDepth;
91 return -ithOldest.get(i);
94 public Integer getOldest() {
95 return ithOldest.get(allocationDepth - 1);
98 public Integer getOldestShadow() {
99 return -ithOldest.get(allocationDepth - 1);
102 public void setSummary(Integer id) {
107 public Integer getSummary() {
111 public Integer getSummaryShadow() {
115 public FlatNew getFlatNew() {
119 public TypeDescriptor getType() {
120 return flatNew.getType();
123 public int getAgeCategory(Integer id) {
125 if( id.equals(summary) ) {
129 if( id.equals(getOldest() ) ) {
133 for( int i = 0; i < allocationDepth - 1; ++i ) {
134 if( id.equals(ithOldest.get(i) ) ) {
139 return AGE_notInThisSite;
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);
152 public int getShadowAgeCategory(Integer id) {
153 if( id.equals(-summary) ) {
154 return SHADOWAGE_summary;
157 if( id.equals(getOldestShadow() ) ) {
158 return SHADOWAGE_oldest;
161 for( int i = 0; i < allocationDepth - 1; ++i ) {
162 if( id.equals(getIthOldestShadow(i) ) ) {
163 return SHADOWAGE_in_I;
167 return SHADOWAGE_notInThisSite;
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);
180 public String toString() {
181 if( disjointId == null ) {
182 return "allocSite" + id;
184 return "allocSite "+disjointId+" ("+id+")";
187 public String toStringVerbose() {
188 if( disjointId == null ) {
189 return "allocSite" + id + " "+flatNew.getType().toPrettyString();
191 return "allocSite "+disjointId+" ("+id+") "+flatNew.getType().toPrettyString();
194 public String toStringForDOT() {
195 if( disjointId != null ) {
196 return "disjoint "+disjointId+"\\n"+toString()+"\\n"+getType().toPrettyString();
198 return toString()+"\\n"+getType().toPrettyString();
202 public void setFlag(boolean flag) {
206 public boolean getFlag() {