changes.
[IRC.git] / Robust / src / Analysis / OoOJava / ConflictNode.java
1 package Analysis.OoOJava;
2
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.Set;
7
8 import Analysis.Disjoint.Alloc;
9 import Analysis.Disjoint.AllocSite;
10 import Analysis.Disjoint.Effect;
11 import Analysis.Disjoint.Taint;
12 import IR.ClassDescriptor;
13 import IR.Flat.FlatNew;
14 import IR.Flat.FlatNode;
15 import IR.Flat.FlatSESEEnterNode;
16 import IR.Flat.TempDescriptor;
17
18 public class ConflictNode {
19
20   protected HashSet<ConflictEdge> edgeSet;
21   protected HashSet<Alloc> allocSet;
22   protected HashSet<Taint> taintSet;
23
24   protected Hashtable<Alloc, Set<Effect>> alloc2readEffectSet;
25   protected Hashtable<Alloc, Set<Effect>> alloc2writeEffectSet;
26   protected Hashtable<Alloc, Set<Effect>> alloc2strongUpdateEffectSet;
27
28   protected int nodeType;
29   protected String id;
30   protected FlatNode stallSite;
31   protected TempDescriptor var;
32   protected FlatSESEEnterNode fsen;
33   protected boolean toBePruned = false;
34
35   protected ClassDescriptor cd;
36
37   public boolean isTobePruned() {
38     return toBePruned;
39   }
40
41   public void setToBePruned(boolean toBePruned) {
42     this.toBePruned = toBePruned;
43   }
44
45   public static final int FINE_READ = 0;
46   public static final int FINE_WRITE = 1;
47   public static final int PARENT_READ = 2;
48   public static final int PARENT_WRITE = 3;
49   public static final int COARSE = 4;
50   public static final int PARENT_COARSE = 5;
51   public static final int SCC = 6;
52
53   public static final int INVAR = 0;
54   public static final int STALLSITE = 1;
55
56   public ConflictNode(String id, int nodeType, TempDescriptor var, FlatNode stallSite,
57                       ClassDescriptor cd) {
58     this(id, var, nodeType);
59     this.stallSite = stallSite;
60     this.cd = cd;
61   }
62
63   public ConflictNode(String id, int nodeType, TempDescriptor var, FlatSESEEnterNode fsen) {
64     this(id, var, nodeType);
65     this.fsen = fsen;
66   }
67
68   public ConflictNode(String id, TempDescriptor var, int nodeType) {
69     edgeSet = new HashSet<ConflictEdge>();
70     // redundant views of access root's
71     // allocation sites for efficient retrieval
72     allocSet = new HashSet<Alloc>();
73     taintSet = new HashSet<Taint>();
74
75     alloc2readEffectSet = new Hashtable<Alloc, Set<Effect>>();
76     alloc2writeEffectSet = new Hashtable<Alloc, Set<Effect>>();
77     alloc2strongUpdateEffectSet = new Hashtable<Alloc, Set<Effect>>();
78
79     this.id = id;
80     this.nodeType = nodeType;
81     this.var = var;
82   }
83
84   public void addTaint(Taint t) {
85     taintSet.add(t);
86   }
87
88   public Taint getTaint(Alloc as) {
89     for (Iterator iterator = taintSet.iterator(); iterator.hasNext(); ) {
90       Taint t = (Taint) iterator.next();
91       if (t.getAllocSite().equals(as)) {
92         return t;
93       }
94     }
95     return null;
96   }
97
98   public void addEffect(Alloc as, Effect e) {
99     if (e.getType() == Effect.read) {
100       addReadEffect(as, e);
101     } else if (e.getType() == Effect.write) {
102       addWriteEffect(as, e);
103     } else {
104       addStrongUpdateEffect(as, e);
105     }
106   }
107
108   public void addReadEffect(Alloc as, Effect e) {
109     allocSet.add(as);
110     Set<Effect> effectSet = alloc2readEffectSet.get(as);
111     if (effectSet == null) {
112       effectSet = new HashSet<Effect>();
113     }
114     effectSet.add(e);
115
116     alloc2readEffectSet.put(as, effectSet);
117   }
118
119   public void addWriteEffect(Alloc as, Effect e) {
120     allocSet.add(as);
121     Set<Effect> effectSet = alloc2writeEffectSet.get(as);
122     if (effectSet == null) {
123       effectSet = new HashSet<Effect>();
124     }
125     effectSet.add(e);
126
127     alloc2writeEffectSet.put(as, effectSet);
128   }
129
130   public void addStrongUpdateEffect(Alloc as, Effect e) {
131     allocSet.add(as);
132     Set<Effect> effectSet = alloc2strongUpdateEffectSet.get(as);
133     if (effectSet == null) {
134       effectSet = new HashSet<Effect>();
135     }
136     effectSet.add(e);
137
138     alloc2strongUpdateEffectSet.put(as, effectSet);
139   }
140
141   public Hashtable<Alloc, Set<Effect>> getReadEffectSet() {
142     return alloc2readEffectSet;
143   }
144
145   public Hashtable<Alloc, Set<Effect>> getWriteEffectSet() {
146     return alloc2writeEffectSet;
147   }
148
149   public Hashtable<Alloc, Set<Effect>> getStrongUpdateEffectSet() {
150     return alloc2strongUpdateEffectSet;
151   }
152
153   public boolean isInVarNode() {
154     if (nodeType == ConflictNode.INVAR) {
155       return true;
156     }
157     return false;
158   }
159
160   public boolean isStallSiteNode() {
161     return !isInVarNode();
162   }
163
164   public Set<FlatNew> getFlatNewSet() {
165     Set<FlatNew> fnSet = new HashSet<FlatNew>();
166     for (Iterator iterator = allocSet.iterator(); iterator.hasNext(); ) {
167       Alloc as = (Alloc) iterator.next();
168       FlatNew fn = as.getFlatNew();
169       fnSet.add(fn);
170     }
171     return fnSet;
172   }
173
174   public TempDescriptor getVar() {
175     return var;
176   }
177
178   public Set<ConflictEdge> getEdgeSet() {
179     return edgeSet;
180   }
181
182   public void addEdge(ConflictEdge edge) {
183     edgeSet.add(edge);
184   }
185
186   public String getID() {
187     return id;
188   }
189
190   public FlatNode getStallSiteFlatNode() {
191     return stallSite;
192   }
193
194   public int getSESEIdentifier() {
195     return fsen.getIdentifier();
196   }
197
198   public boolean equals(Object o) {
199
200     if (o == null) {
201       return false;
202     }
203
204     if (!(o instanceof ConflictNode)) {
205       return false;
206     }
207
208     ConflictNode in = (ConflictNode) o;
209
210     if (id.equals(in.id)) {
211       return true;
212     } else {
213       return false;
214     }
215
216   }
217
218   public String toStringAllEffects() {
219
220     String str = "";
221
222     if (!alloc2readEffectSet.isEmpty()) {
223       str += "read effect= " + alloc2readEffectSet.toString() + "\n";
224     }
225
226     if (!alloc2writeEffectSet.isEmpty()) {
227       str += "write effect = " + alloc2writeEffectSet.toString() + "\n";
228     }
229
230     if (!alloc2strongUpdateEffectSet.isEmpty()) {
231       str += "SU effect = " + alloc2strongUpdateEffectSet.toString() + "\n";
232     }
233
234     return str;
235   }
236
237   public String toString() {
238     return id;
239   }
240
241   public boolean IsValidToPrune() {
242
243     for (Iterator iterator = edgeSet.iterator(); iterator.hasNext(); ) {
244       ConflictEdge edge = (ConflictEdge) iterator.next();
245
246       if (edge.getVertexU() == edge.getVertexV()) {
247         // self-conflict, need to generate traverser
248         return false;
249       } else {
250
251         if (edge.getVertexU() == this) {
252           if (edge.getVertexV().isInVarNode()) {
253             // has a conflict with invar, need to generate traverser
254             return false;
255           }
256         } else {
257           if (edge.getVertexU().isInVarNode()) {
258             // has a conflict with invar, need to generate traverser
259             return false;
260           }
261         }
262       }
263     }
264     return true;
265   }
266
267   public String getSourceFileName() {
268     return cd.getSourceFileName();
269   }
270
271 }