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.Flat.FlatNew;
13 import IR.Flat.FlatNode;
14 import IR.Flat.FlatSESEEnterNode;
15 import IR.Flat.TempDescriptor;
17 public class ConflictNode {
19 protected HashSet<ConflictEdge> edgeSet;
20 protected HashSet<Alloc> allocSet;
21 protected HashSet<Taint> taintSet;
23 protected Hashtable<Alloc, Set<Effect>> alloc2readEffectSet;
24 protected Hashtable<Alloc, Set<Effect>> alloc2writeEffectSet;
25 protected Hashtable<Alloc, Set<Effect>> alloc2strongUpdateEffectSet;
27 protected int nodeType;
29 protected FlatNode stallSite;
30 protected TempDescriptor var;
31 protected FlatSESEEnterNode fsen;
33 public static final int FINE_READ = 0;
34 public static final int FINE_WRITE = 1;
35 public static final int PARENT_READ = 2;
36 public static final int PARENT_WRITE = 3;
37 public static final int COARSE = 4;
38 public static final int PARENT_COARSE = 5;
39 public static final int SCC = 6;
41 public static final int INVAR = 0;
42 public static final int STALLSITE = 1;
44 public ConflictNode(String id, int nodeType, TempDescriptor var, FlatNode stallSite) {
45 this(id, var, nodeType);
46 this.stallSite = stallSite;
49 public ConflictNode(String id, int nodeType, TempDescriptor var, FlatSESEEnterNode fsen) {
50 this(id, var, nodeType);
54 public ConflictNode(String id, TempDescriptor var, int nodeType) {
55 edgeSet = new HashSet<ConflictEdge>();
56 // redundant views of access root's
57 // allocation sites for efficient retrieval
58 allocSet = new HashSet<Alloc>();
59 taintSet = new HashSet<Taint>();
61 alloc2readEffectSet = new Hashtable<Alloc, Set<Effect>>();
62 alloc2writeEffectSet = new Hashtable<Alloc, Set<Effect>>();
63 alloc2strongUpdateEffectSet = new Hashtable<Alloc, Set<Effect>>();
66 this.nodeType = nodeType;
70 public void addTaint(Taint t) {
74 public Taint getTaint(Alloc as) {
75 for (Iterator iterator = taintSet.iterator(); iterator.hasNext();) {
76 Taint t = (Taint) iterator.next();
77 if (t.getAllocSite().equals(as)) {
84 public void addEffect(Alloc as, Effect e) {
85 if (e.getType() == Effect.read) {
87 } else if (e.getType() == Effect.write) {
88 addWriteEffect(as, e);
90 addStrongUpdateEffect(as, e);
94 public void addReadEffect(Alloc as, Effect e) {
96 Set<Effect> effectSet = alloc2readEffectSet.get(as);
97 if (effectSet == null) {
98 effectSet = new HashSet<Effect>();
102 alloc2readEffectSet.put(as, effectSet);
105 public void addWriteEffect(Alloc as, Effect e) {
107 Set<Effect> effectSet = alloc2writeEffectSet.get(as);
108 if (effectSet == null) {
109 effectSet = new HashSet<Effect>();
113 alloc2writeEffectSet.put(as, effectSet);
116 public void addStrongUpdateEffect(Alloc as, Effect e) {
118 Set<Effect> effectSet = alloc2strongUpdateEffectSet.get(as);
119 if (effectSet == null) {
120 effectSet = new HashSet<Effect>();
124 alloc2strongUpdateEffectSet.put(as, effectSet);
127 public Hashtable<Alloc, Set<Effect>> getReadEffectSet() {
128 return alloc2readEffectSet;
131 public Hashtable<Alloc, Set<Effect>> getWriteEffectSet() {
132 return alloc2writeEffectSet;
135 public Hashtable<Alloc, Set<Effect>> getStrongUpdateEffectSet() {
136 return alloc2strongUpdateEffectSet;
139 public boolean isInVarNode() {
140 if (nodeType == ConflictNode.INVAR) {
146 public boolean isStallSiteNode() {
147 return !isInVarNode();
150 public Set<FlatNew> getFlatNewSet() {
151 Set<FlatNew> fnSet = new HashSet<FlatNew>();
152 for (Iterator iterator = allocSet.iterator(); iterator.hasNext();) {
153 Alloc as = (Alloc) iterator.next();
154 FlatNew fn = as.getFlatNew();
160 public TempDescriptor getVar() {
164 public Set<ConflictEdge> getEdgeSet() {
168 public void addEdge(ConflictEdge edge) {
172 public String getID() {
176 public FlatNode getStallSiteFlatNode() {
180 public int getSESEIdentifier() {
181 return fsen.getIdentifier();
184 public boolean equals(Object o) {
190 if (!(o instanceof ConflictNode)) {
194 ConflictNode in = (ConflictNode) o;
196 if (id.equals(in.id)) {
204 public String toStringAllEffects() {
208 if (!alloc2readEffectSet.isEmpty()) {
209 str += "read effect= " + alloc2readEffectSet.toString() + "\n";
212 if (!alloc2writeEffectSet.isEmpty()) {
213 str += "write effect = " + alloc2writeEffectSet.toString() + "\n";
216 if (!alloc2strongUpdateEffectSet.isEmpty()) {
217 str += "SU effect = " + alloc2strongUpdateEffectSet.toString() + "\n";
223 public String toString() {
227 public boolean IsValidToPrune() {
229 for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
230 ConflictEdge edge = (ConflictEdge) iterator.next();
232 if (edge.getVertexU() == edge.getVertexV()) {
233 // self-conflict, need to generate traverser
237 if (edge.getVertexU() == this) {
238 if (edge.getVertexV().isInVarNode()) {
239 // has a conflict with invar, need to generate traverser
243 if (edge.getVertexU().isInVarNode()) {
244 // has a conflict with invar, need to generate traverser