beb1b65e8098819c62c85accc1d2ede166d12a09
[IRC.git] / Robust / src / Analysis / MLP / StallSite.java
1 package Analysis.MLP;
2
3 import java.util.HashSet;
4 import java.util.Iterator;
5
6 import Analysis.OwnershipAnalysis.AllocationSite;
7 import Analysis.OwnershipAnalysis.HeapRegionNode;
8 import Analysis.OwnershipAnalysis.ReachabilitySet;
9
10 public class StallSite {
11
12         public static final Integer READ_EFFECT = new Integer(1);
13         public static final Integer WRITE_EFFECT = new Integer(2);
14
15         private HashSet<Effect> effectSet;
16         private HashSet<HeapRegionNode> hrnSet;
17         private HashSet<AllocationSite> allocationSiteSet;
18         private ReachabilitySet rechabilitySet;
19
20         public StallSite() {
21                 effectSet = new HashSet<Effect>();
22                 hrnSet = new HashSet<HeapRegionNode>();
23                 rechabilitySet = new ReachabilitySet();
24                 allocationSiteSet=new HashSet<AllocationSite>();
25         }
26         
27         public StallSite(HashSet<HeapRegionNode> hrnSet){
28                 this();
29                 setHeapRegionNodeSet(hrnSet);
30                 for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
31                         HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next();
32                         setAllocationSite(heapRegionNode.getAllocationSite());
33                 }
34         }
35
36         public StallSite(HashSet<Effect> effectSet, HashSet<HeapRegionNode> hrnSet,
37                         ReachabilitySet rechabilitySet) {
38                 this.effectSet = effectSet;
39                 this.hrnSet = hrnSet;
40                 this.rechabilitySet = rechabilitySet;
41         }
42         
43         public void setAllocationSite(AllocationSite allocationSite){
44                 if(allocationSite!=null){
45                         allocationSiteSet.add(allocationSite);
46                 }
47         }
48         
49         public void setHeapRegionNodeSet(HashSet<HeapRegionNode> newSet){
50                 hrnSet.addAll(newSet);
51         }
52         
53         public HashSet<AllocationSite> getAllocationSiteSet(){
54                 return allocationSiteSet;
55         }
56
57         public void addEffect(String type, String field, Integer effect) {
58                 Effect e = new Effect(type, field, effect);
59                 effectSet.add(e);
60         }
61
62         public HashSet<Effect> getEffectSet() {
63                 return effectSet;
64         }
65
66         public HashSet<HeapRegionNode> getHRNSet() {
67                 return hrnSet;
68         }
69
70         public ReachabilitySet getReachabilitySet() {
71                 return rechabilitySet;
72         }
73
74         public boolean equals(Object o) {
75
76                 if (o == null) {
77                         return false;
78                 }
79
80                 if (!(o instanceof StallSite)) {
81                         return false;
82                 }
83
84                 StallSite in = (StallSite) o;
85
86                 if (effectSet.equals(in.getEffectSet())
87                                 && hrnSet.equals(in.getHRNSet())
88                                 && rechabilitySet.equals(in.getReachabilitySet())) {
89                         return true;
90                 } else {
91                         return false;
92                 }
93
94         }
95
96         public String toString() {
97                 return "StallSite [effectSet=" + effectSet + ", hrnIDSet=" + hrnSet
98                                 + ", rechabilitySet=" + rechabilitySet + "]";
99         }
100         
101 }
102
103 class Effect {
104
105         private String field;
106         private String type;
107         private Integer effect;
108
109         public Effect(String type, String field, Integer effect) {
110                 this.type = type;
111                 this.field = field;
112                 this.effect = effect;
113         }
114
115         public String getField() {
116                 return field;
117         }
118
119         public String getType() {
120                 return type;
121         }
122
123         public Integer getEffect() {
124                 return effect;
125         }
126
127         public boolean equals(Object o) {
128
129                 if (o == null) {
130                         return false;
131                 }
132
133                 if (!(o instanceof StallSite)) {
134                         return false;
135                 }
136
137                 Effect in = (Effect) o;
138
139                 if (type.equals(in.getType()) && field.equals(in.getField())
140                                 && effect.equals(in.getEffect())) {
141                         return true;
142                 } else {
143                         return false;
144                 }
145
146         }
147
148 }