1 package Analysis.Disjoint;
9 //////////////////////////////////////////////
11 // SMFEState is part of a
12 // (S)tate (M)achine (F)or (E)ffects.
14 // StateMachineForEffects describes an intial
15 // state and the effect transtions a DFJ
16 // traverser should make from the current state
17 // when searching for possible runtime conflicts.
19 //////////////////////////////////////////////
21 public class SMFEState {
23 // #####################
24 // ## NOTE NOTE NOTE!!!!
25 // #####################
26 // When every state corresponds to exactly one
27 // FlatNode (whereDefined attribute) then we can
28 // use the FlatNode's id as an ID. BUT BUT BUT, if
29 // we merge nodes together in the future for
30 // optimizations and whatnot, we need an alternate
31 // system of unique IDs
33 // uniquely identifies this state
35 protected int iHashCode;
37 // all possible effects in this state
38 protected Set<Effect> effects;
40 //TODO Jim! get me the list of conflicts!
41 protected Set<Effect> conflicts;
43 // the given effect allows a transition to a
45 protected Hashtable< Effect, Set<SMFEState> > e2states;
47 // useful for knowing when a state can be inlined during
49 protected int refCount;
51 protected FlatNode whereDefined;
53 public SMFEState(FlatNode fnWhereDefined, int id) {
55 this.iHashCode = fnWhereDefined.hashCode();
56 this.whereDefined=fnWhereDefined;
58 effects = new HashSet<Effect>();
59 conflicts = new HashSet<Effect>();
60 e2states = new Hashtable< Effect, Set<SMFEState> >();
64 public void addEffect(Effect e) {
68 // the given effect allows the transition to the new state
69 public void addTransition(Effect effect,
73 Set<SMFEState> states = e2states.get(effect);
74 if( states == null ) {
75 states = new HashSet<SMFEState>();
76 e2states.put(effect, states);
78 if (!states.contains(stateTo)) {
89 // once you get your hands on an SMFEState in the
90 // RuntimeConflictResolver side of things, this is how you
91 // find out what effects are possible in this state
92 public Set<Effect> getEffectsAllowed() {
96 public void addConflict(Effect e) {
100 public Set<Effect> getConflicts() {
104 public Set<Effect> getTransitionEffects() {
105 return this.e2states.keySet();
108 // some subset of the above effects may transition to
110 public Set<SMFEState> transitionsTo(Effect e) {
111 Set<SMFEState> statesOut = e2states.get(e);
112 if( statesOut == null ) {
113 statesOut = new HashSet<SMFEState>();
118 // some subset of the above effects may transition to
120 public Set<SMFEState> transitionsTo() {
121 Set<SMFEState> statesOut = new HashSet<SMFEState>();
122 for(Map.Entry<Effect, Set<SMFEState>> entry : e2states.entrySet()) {
123 statesOut.addAll(entry.getValue());
128 public int getRefCount() {
133 public boolean equals(Object o) {
138 if( !(o instanceof SMFEState) ) {
142 SMFEState state = (SMFEState) o;
144 return id == state.id;
147 public int hashCode() {
152 public String toStringDOT() {
154 // first create the state as a node in DOT graph
155 String s = " "+id+"[shape=box,";
156 if (conflicts.size()>0 ) {
161 if( effects.size() >= 1 ) {
163 Iterator<Effect> eItr = effects.iterator();
164 while( eItr.hasNext() ) {
165 Effect e = eItr.next();
166 if (conflicts.contains(e)) {
167 s += "["+e.toString()+"]";
171 if( eItr.hasNext() ) {
179 // then each transition is an edge
180 Iterator<Effect> eItr = e2states.keySet().iterator();
181 while( eItr.hasNext() ) {
182 Effect e = eItr.next();
183 Set<SMFEState> states = e2states.get(e);
185 Iterator<SMFEState> sItr = states.iterator();
186 while( sItr.hasNext() ) {
187 SMFEState state = sItr.next();
191 "[label=\""+e+", RC="+refCount+"\"";
192 if (conflicts.contains(e))