6d7e3b5f5d050f6f130993d377bc7fe1fbd16b1a
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / AllocationSite.java
1 package Analysis.OwnershipAnalysis;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6
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.
13
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.
21
22 public class AllocationSite {
23
24   static private int uniqueIDcount = 0;
25
26   protected Integer id;
27   protected int allocationDepth;
28   protected Vector<Integer> ithOldest;
29   protected Integer summary;
30   protected TypeDescriptor type;
31
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;
36
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;
41
42
43   public AllocationSite(int allocationDepth, TypeDescriptor type) {
44     assert allocationDepth >= 2;
45
46     this.allocationDepth = allocationDepth;
47     this.type            = type;
48
49     ithOldest = new Vector<Integer>(allocationDepth);
50     id        = generateUniqueAllocationSiteID();
51   }
52
53   static public Integer generateUniqueAllocationSiteID() {
54     ++uniqueIDcount;
55     return new Integer(uniqueIDcount);
56   }
57
58
59   public int getAllocationDepth() {
60     return allocationDepth;
61   }
62
63   public void setIthOldest(int i, Integer id) {
64     assert i  >= 0;
65     assert i  <  allocationDepth;
66     assert id != null;
67
68     ithOldest.add(i, id);
69   }
70
71   public Integer getIthOldest(int i) {
72     assert i >= 0;
73     assert i <  allocationDepth;
74
75     return ithOldest.get(i);
76   }
77
78   public Integer getIthOldestShadow(int i) {
79     assert i >= 0;
80     assert i <  allocationDepth;
81
82     return -ithOldest.get(i);
83   }
84
85   public Integer getOldest() {
86     return ithOldest.get(allocationDepth - 1);
87   }
88
89   public Integer getOldestShadow() {
90     return -ithOldest.get(allocationDepth - 1);
91   }
92
93   public void setSummary(Integer id) {
94     assert id != null;
95     summary = id;
96   }
97
98   public Integer getSummary() {
99     return summary;
100   }
101
102   public Integer getSummaryShadow() {
103     return -summary;
104   }
105
106   public TypeDescriptor getType() {
107     return type;
108   }
109
110   public int getAgeCategory(Integer id) {
111
112     if( id.equals(summary) ) {
113       return AGE_summary;
114     }
115
116     if( id.equals(getOldest() ) ) {
117       return AGE_oldest;
118     }
119
120     for( int i = 0; i < allocationDepth - 1; ++i ) {
121       if( id.equals(ithOldest.get(i) ) ) {
122         return AGE_in_I;
123       }
124     }
125
126     return AGE_notInThisSite;
127   }
128
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);
133       }
134     }
135
136     return null;
137   }
138
139   public int getShadowAgeCategory(Integer id) {
140     if( id.equals(-summary) ) {
141       return SHADOWAGE_summary;
142     }
143
144     if( id.equals(getOldestShadow() ) ) {
145       return SHADOWAGE_oldest;
146     }
147
148     for( int i = 0; i < allocationDepth - 1; ++i ) {
149       if( id.equals(getIthOldestShadow(i) ) ) {
150         return SHADOWAGE_in_I;
151       }
152     }
153
154     return SHADOWAGE_notInThisSite;
155   }
156
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);
161       }
162     }
163
164     return null;
165   }
166
167   public String toString() {
168     return "allocSite" + id;
169   }
170
171   public String toStringVerbose() {
172     return "allocSite" + id + " "+type.toPrettyString();
173   }
174 }