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 TypeDescriptor type;
32 public static final int AGE_notInThisSite = 100;
33 public static final int AGE_in_I = 101;
34 public static final int AGE_oldest = 102;
35 public static final int AGE_summary = 103;
37 public static final int SHADOWAGE_notInThisSite = -100;
38 public static final int SHADOWAGE_in_I = -101;
39 public static final int SHADOWAGE_oldest = -102;
40 public static final int SHADOWAGE_summary = -103;
43 public AllocationSite(int allocationDepth, TypeDescriptor type) {
44 assert allocationDepth >= 2;
46 this.allocationDepth = allocationDepth;
49 ithOldest = new Vector<Integer>(allocationDepth);
50 id = generateUniqueAllocationSiteID();
53 static public Integer generateUniqueAllocationSiteID() {
55 return new Integer(uniqueIDcount);
59 public int getAllocationDepth() {
60 return allocationDepth;
63 public void setIthOldest(int i, Integer id) {
65 assert i < allocationDepth;
71 public Integer getIthOldest(int i) {
73 assert i < allocationDepth;
75 return ithOldest.get(i);
78 public Integer getIthOldestShadow(int i) {
80 assert i < allocationDepth;
82 return -ithOldest.get(i);
85 public Integer getOldest() {
86 return ithOldest.get(allocationDepth - 1);
89 public Integer getOldestShadow() {
90 return -ithOldest.get(allocationDepth - 1);
93 public void setSummary(Integer id) {
98 public Integer getSummary() {
102 public Integer getSummaryShadow() {
106 public TypeDescriptor getType() {
110 public int getAgeCategory(Integer id) {
112 if( id.equals(summary) ) {
116 if( id.equals(getOldest() ) ) {
120 for( int i = 0; i < allocationDepth - 1; ++i ) {
121 if( id.equals(ithOldest.get(i) ) ) {
126 return AGE_notInThisSite;
129 public Integer getAge(Integer id) {
130 for( int i = 0; i < allocationDepth - 1; ++i ) {
131 if( id.equals(ithOldest.get(i) ) ) {
132 return new Integer(i);
139 public int getShadowAgeCategory(Integer id) {
140 if( id.equals(-summary) ) {
141 return SHADOWAGE_summary;
144 if( id.equals(getOldestShadow() ) ) {
145 return SHADOWAGE_oldest;
148 for( int i = 0; i < allocationDepth - 1; ++i ) {
149 if( id.equals(getIthOldestShadow(i) ) ) {
150 return SHADOWAGE_in_I;
154 return SHADOWAGE_notInThisSite;
157 public Integer getShadowAge(Integer id) {
158 for( int i = 0; i < allocationDepth - 1; ++i ) {
159 if( id.equals(getIthOldestShadow(i) ) ) {
160 return new Integer(-i);
167 public String toString() {
168 return "allocSite" + id;
171 public String toStringVerbose() {
172 return "allocSite" + id + " "+type.toPrettyString();