pull in class files that already exist in library
[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
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, FlatNew flatNew) {
44     assert allocationDepth >= 1;
45
46     this.allocationDepth = allocationDepth;
47     this.flatNew         = flatNew;
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 FlatNew getFlatNew() {
107     return flatNew;
108   }
109
110   public TypeDescriptor getType() {
111     return flatNew.getType();
112   }
113
114   public int getAgeCategory(Integer id) {
115
116     if( id.equals(summary) ) {
117       return AGE_summary;
118     }
119
120     if( id.equals(getOldest() ) ) {
121       return AGE_oldest;
122     }
123
124     for( int i = 0; i < allocationDepth - 1; ++i ) {
125       if( id.equals(ithOldest.get(i) ) ) {
126         return AGE_in_I;
127       }
128     }
129
130     return AGE_notInThisSite;
131   }
132
133   public Integer getAge(Integer id) {
134     for( int i = 0; i < allocationDepth - 1; ++i ) {
135       if( id.equals(ithOldest.get(i) ) ) {
136         return new Integer(i);
137       }
138     }
139
140     return null;
141   }
142
143   public int getShadowAgeCategory(Integer id) {
144     if( id.equals(-summary) ) {
145       return SHADOWAGE_summary;
146     }
147
148     if( id.equals(getOldestShadow() ) ) {
149       return SHADOWAGE_oldest;
150     }
151
152     for( int i = 0; i < allocationDepth - 1; ++i ) {
153       if( id.equals(getIthOldestShadow(i) ) ) {
154         return SHADOWAGE_in_I;
155       }
156     }
157
158     return SHADOWAGE_notInThisSite;
159   }
160
161   public Integer getShadowAge(Integer id) {
162     for( int i = 0; i < allocationDepth - 1; ++i ) {
163       if( id.equals(getIthOldestShadow(i) ) ) {
164         return new Integer(-i);
165       }
166     }
167
168     return null;
169   }
170
171   public String toString() {
172     return "allocSite" + id;
173   }
174
175   public String toStringVerbose() {
176     return "allocSite" + id + " "+flatNew.getType().toPrettyString();
177   }
178 }