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;
44 public AllocationSite(int allocationDepth, FlatNew flatNew, String disjointId) {
45 assert allocationDepth >= 1;
47 this.allocationDepth = allocationDepth;
48 this.flatNew = flatNew;
49 this.disjointId = disjointId;
51 ithOldest = new Vector<Integer>(allocationDepth);
52 id = generateUniqueAllocationSiteID();
55 static public Integer generateUniqueAllocationSiteID() {
57 return new Integer(uniqueIDcount);
61 public String getDisjointId() {
66 public int getAllocationDepth() {
67 return allocationDepth;
70 public void setIthOldest(int i, Integer id) {
72 assert i < allocationDepth;
78 public Integer getIthOldest(int i) {
80 assert i < allocationDepth;
82 return ithOldest.get(i);
85 public Integer getIthOldestShadow(int i) {
87 assert i < allocationDepth;
89 return -ithOldest.get(i);
92 public Integer getOldest() {
93 return ithOldest.get(allocationDepth - 1);
96 public Integer getOldestShadow() {
97 return -ithOldest.get(allocationDepth - 1);
100 public void setSummary(Integer id) {
105 public Integer getSummary() {
109 public Integer getSummaryShadow() {
113 public FlatNew getFlatNew() {
117 public TypeDescriptor getType() {
118 return flatNew.getType();
121 public int getAgeCategory(Integer id) {
123 if( id.equals(summary) ) {
127 if( id.equals(getOldest() ) ) {
131 for( int i = 0; i < allocationDepth - 1; ++i ) {
132 if( id.equals(ithOldest.get(i) ) ) {
137 return AGE_notInThisSite;
140 public Integer getAge(Integer id) {
141 for( int i = 0; i < allocationDepth - 1; ++i ) {
142 if( id.equals(ithOldest.get(i) ) ) {
143 return new Integer(i);
150 public int getShadowAgeCategory(Integer id) {
151 if( id.equals(-summary) ) {
152 return SHADOWAGE_summary;
155 if( id.equals(getOldestShadow() ) ) {
156 return SHADOWAGE_oldest;
159 for( int i = 0; i < allocationDepth - 1; ++i ) {
160 if( id.equals(getIthOldestShadow(i) ) ) {
161 return SHADOWAGE_in_I;
165 return SHADOWAGE_notInThisSite;
168 public Integer getShadowAge(Integer id) {
169 for( int i = 0; i < allocationDepth - 1; ++i ) {
170 if( id.equals(getIthOldestShadow(i) ) ) {
171 return new Integer(-i);
178 public String toString() {
179 if( disjointId == null ) {
180 return "allocSite" + id;
182 return "allocSite "+disjointId+" ("+id+")";
185 public String toStringVerbose() {
186 if( disjointId == null ) {
187 return "allocSite" + id + " "+flatNew.getType().toPrettyString();
189 return "allocSite "+disjointId+" ("+id+") "+flatNew.getType().toPrettyString();
192 public String toStringForDOT() {
193 if( disjointId != null ) {
194 return "disjoint "+disjointId+"\\n"+toString()+"\\n"+getType().toPrettyString();
196 return toString()+"\\n"+getType().toPrettyString();