607783b36b3ad64b557909b1eb9674d05ce4a304
[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 = -1;
33   public static final int AGE_oldest        = -2;
34   public static final int AGE_summary       = -3;
35
36
37   public AllocationSite(int allocationDepth, TypeDescriptor type) {
38     assert allocationDepth >= 1;
39
40     this.allocationDepth = allocationDepth;
41     this.type            = type;
42
43     ithOldest = new Vector<Integer>(allocationDepth);
44     id        = generateUniqueAllocationSiteID();
45   }
46
47   static public Integer generateUniqueAllocationSiteID() {
48     ++uniqueIDcount;
49     return new Integer(uniqueIDcount);
50   }
51
52
53   public int getAllocationDepth() {
54     return allocationDepth;
55   }
56
57   public void setIthOldest(int i, Integer id) {
58     assert i  >= 0;
59     assert i  <  allocationDepth;
60     assert id != null;
61
62     ithOldest.add(i, id);
63   }
64
65   public Integer getIthOldest(int i) {
66     assert i >= 0;
67     assert i <  allocationDepth;
68
69     return ithOldest.get(i);
70   }
71
72   public Integer getOldest() {
73     return ithOldest.get(allocationDepth - 1);
74   }
75
76   public void setSummary(Integer id) {
77     assert id != null;
78     summary = id;
79   }
80
81   public Integer getSummary() {
82     return summary;
83   }
84
85   public TypeDescriptor getType() {
86     return type;
87   }
88
89   public int getAge(Integer id) {
90     if( id.equals(summary) ) {
91       return AGE_summary;
92     }
93
94     if( id.equals(getOldest() ) ) {
95       return AGE_oldest;
96     }
97
98     for( int i = 0; i < allocationDepth - 1; ++i ) {
99       if( id.equals(ithOldest.get(i) ) ) {
100         return i;
101       }
102     }
103
104     return AGE_notInThisSite;
105   }
106
107   public String toString() {
108     return "allocSite" + id;
109   }
110 }