1 package Analysis.OoOJava;
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
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;
18 public class ConflictNode {
20 protected HashSet<ConflictEdge> edgeSet;
21 protected HashSet<Alloc> allocSet;
22 protected HashSet<Taint> taintSet;
24 protected Hashtable<Alloc, Set<Effect>> alloc2readEffectSet;
25 protected Hashtable<Alloc, Set<Effect>> alloc2writeEffectSet;
26 protected Hashtable<Alloc, Set<Effect>> alloc2strongUpdateEffectSet;
28 protected int nodeType;
30 protected FlatNode stallSite;
31 protected TempDescriptor var;
32 protected FlatSESEEnterNode fsen;
33 protected boolean toBePruned = false;
35 protected ClassDescriptor cd;
37 public boolean isTobePruned() {
41 public void setToBePruned(boolean toBePruned) {
42 this.toBePruned = toBePruned;
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;
53 public static final int INVAR = 0;
54 public static final int STALLSITE = 1;
56 public ConflictNode(String id, int nodeType, TempDescriptor var, FlatNode stallSite,
58 this(id, var, nodeType);
59 this.stallSite = stallSite;
63 public ConflictNode(String id, int nodeType, TempDescriptor var, FlatSESEEnterNode fsen) {
64 this(id, var, nodeType);
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>();
75 alloc2readEffectSet = new Hashtable<Alloc, Set<Effect>>();
76 alloc2writeEffectSet = new Hashtable<Alloc, Set<Effect>>();
77 alloc2strongUpdateEffectSet = new Hashtable<Alloc, Set<Effect>>();
80 this.nodeType = nodeType;
84 public void addTaint(Taint t) {
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)) {
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);
104 addStrongUpdateEffect(as, e);
108 public void addReadEffect(Alloc as, Effect e) {
110 Set<Effect> effectSet = alloc2readEffectSet.get(as);
111 if (effectSet == null) {
112 effectSet = new HashSet<Effect>();
116 alloc2readEffectSet.put(as, effectSet);
119 public void addWriteEffect(Alloc as, Effect e) {
121 Set<Effect> effectSet = alloc2writeEffectSet.get(as);
122 if (effectSet == null) {
123 effectSet = new HashSet<Effect>();
127 alloc2writeEffectSet.put(as, effectSet);
130 public void addStrongUpdateEffect(Alloc as, Effect e) {
132 Set<Effect> effectSet = alloc2strongUpdateEffectSet.get(as);
133 if (effectSet == null) {
134 effectSet = new HashSet<Effect>();
138 alloc2strongUpdateEffectSet.put(as, effectSet);
141 public Hashtable<Alloc, Set<Effect>> getReadEffectSet() {
142 return alloc2readEffectSet;
145 public Hashtable<Alloc, Set<Effect>> getWriteEffectSet() {
146 return alloc2writeEffectSet;
149 public Hashtable<Alloc, Set<Effect>> getStrongUpdateEffectSet() {
150 return alloc2strongUpdateEffectSet;
153 public boolean isInVarNode() {
154 if (nodeType == ConflictNode.INVAR) {
160 public boolean isStallSiteNode() {
161 return !isInVarNode();
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();
174 public TempDescriptor getVar() {
178 public Set<ConflictEdge> getEdgeSet() {
182 public void addEdge(ConflictEdge edge) {
186 public String getID() {
190 public FlatNode getStallSiteFlatNode() {
194 public int getSESEIdentifier() {
195 return fsen.getIdentifier();
198 public boolean equals(Object o) {
204 if (!(o instanceof ConflictNode)) {
208 ConflictNode in = (ConflictNode) o;
210 if (id.equals(in.id)) {
218 public String toStringAllEffects() {
222 if (!alloc2readEffectSet.isEmpty()) {
223 str += "read effect= " + alloc2readEffectSet.toString() + "\n";
226 if (!alloc2writeEffectSet.isEmpty()) {
227 str += "write effect = " + alloc2writeEffectSet.toString() + "\n";
230 if (!alloc2strongUpdateEffectSet.isEmpty()) {
231 str += "SU effect = " + alloc2strongUpdateEffectSet.toString() + "\n";
237 public String toString() {
241 public boolean IsValidToPrune() {
243 for (Iterator iterator = edgeSet.iterator(); iterator.hasNext(); ) {
244 ConflictEdge edge = (ConflictEdge) iterator.next();
246 if (edge.getVertexU() == edge.getVertexV()) {
247 // self-conflict, need to generate traverser
251 if (edge.getVertexU() == this) {
252 if (edge.getVertexV().isInVarNode()) {
253 // has a conflict with invar, need to generate traverser
257 if (edge.getVertexU().isInVarNode()) {
258 // has a conflict with invar, need to generate traverser
267 public String getSourceFileName() {
268 return cd.getSourceFileName();