7829ea112c8f33870fa902c8b961149e0f661806
[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 FlatNew flatNew;
31   protected boolean forceAnalyze;
32
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;
37
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;
42
43
44   public AllocationSite(int allocationDepth, FlatNew flatNew, boolean forceAnalyze) {
45     assert allocationDepth >= 1;
46
47     this.allocationDepth = allocationDepth;
48     this.flatNew         = flatNew;
49     this.forceAnalyze    = forceAnalyze;
50
51     ithOldest = new Vector<Integer>(allocationDepth);
52     id        = generateUniqueAllocationSiteID();
53   }
54
55   static public Integer generateUniqueAllocationSiteID() {
56     ++uniqueIDcount;
57     return new Integer(uniqueIDcount);
58   }
59
60
61   public boolean doForceAnalyze() {
62     return forceAnalyze;
63   }
64
65
66   public int getAllocationDepth() {
67     return allocationDepth;
68   }
69
70   public void setIthOldest(int i, Integer id) {
71     assert i  >= 0;
72     assert i  <  allocationDepth;
73     assert id != null;
74
75     ithOldest.add(i, id);
76   }
77
78   public Integer getIthOldest(int i) {
79     assert i >= 0;
80     assert i <  allocationDepth;
81
82     return ithOldest.get(i);
83   }
84
85   public Integer getIthOldestShadow(int i) {
86     assert i >= 0;
87     assert i <  allocationDepth;
88
89     return -ithOldest.get(i);
90   }
91
92   public Integer getOldest() {
93     return ithOldest.get(allocationDepth - 1);
94   }
95
96   public Integer getOldestShadow() {
97     return -ithOldest.get(allocationDepth - 1);
98   }
99
100   public void setSummary(Integer id) {
101     assert id != null;
102     summary = id;
103   }
104
105   public Integer getSummary() {
106     return summary;
107   }
108
109   public Integer getSummaryShadow() {
110     return -summary;
111   }
112
113   public FlatNew getFlatNew() {
114     return flatNew;
115   }
116
117   public TypeDescriptor getType() {
118     return flatNew.getType();
119   }
120
121   public int getAgeCategory(Integer id) {
122
123     if( id.equals(summary) ) {
124       return AGE_summary;
125     }
126
127     if( id.equals(getOldest() ) ) {
128       return AGE_oldest;
129     }
130
131     for( int i = 0; i < allocationDepth - 1; ++i ) {
132       if( id.equals(ithOldest.get(i) ) ) {
133         return AGE_in_I;
134       }
135     }
136
137     return AGE_notInThisSite;
138   }
139
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);
144       }
145     }
146
147     return null;
148   }
149
150   public int getShadowAgeCategory(Integer id) {
151     if( id.equals(-summary) ) {
152       return SHADOWAGE_summary;
153     }
154
155     if( id.equals(getOldestShadow() ) ) {
156       return SHADOWAGE_oldest;
157     }
158
159     for( int i = 0; i < allocationDepth - 1; ++i ) {
160       if( id.equals(getIthOldestShadow(i) ) ) {
161         return SHADOWAGE_in_I;
162       }
163     }
164
165     return SHADOWAGE_notInThisSite;
166   }
167
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);
172       }
173     }
174
175     return null;
176   }
177
178   public String toString() {
179     return "allocSite" + id;
180   }
181
182   public String toStringVerbose() {
183     return "allocSite" + id + " "+flatNew.getType().toPrettyString();
184   }
185 }