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;
38 // all possible effects in this state
39 protected Set<Effect> effects;
41 // the given effect allows a transition to a
43 protected Hashtable< Effect, Set<SMFEState> > e2states;
45 // useful for knowing when a state can be inlined during
47 protected int refCount;
51 public SMFEState( FlatNode fnWhereDefined ) {
53 this.id = fnWhereDefined.nodeid;
54 this.iHashCode = fnWhereDefined.hashCode();
56 effects = new HashSet<Effect>();
57 e2states = new Hashtable< Effect, Set<SMFEState> >();
61 public void addEffect( Effect e ) {
65 // the given effect allows the transition to the new state
66 public void addTransition( Effect effect,
70 Set<SMFEState> states = e2states.get( effect );
71 if( states == null ) {
72 states = new HashSet<SMFEState>();
73 e2states.put( effect, states );
75 states.add( stateTo );
85 // once you get your hands on an SMFEState in the
86 // RuntimeConflictResolver side of things, this is how you
87 // find out what effects are possible in this state
88 public Set<Effect> getEffectsAllowed() {
92 // some subset of the above effects may transition to
94 public Set<SMFEState> transitionsTo( Effect e ) {
95 Set<SMFEState> statesOut = e2states.get( e );
96 if( statesOut == null ) {
97 statesOut = new HashSet<SMFEState>();
102 public int getRefCount() {
107 public boolean equals( Object o ) {
112 if( !(o instanceof SMFEState) ) {
116 SMFEState state = (SMFEState) o;
118 return id == state.id;
121 public int hashCode() {
126 public String toStringDOT() {
128 // first create the state as a node in DOT graph
129 String s = " "+id+"[shape=box,label=\"";
131 if( effects.size() == 1 ) {
132 s += effects.iterator().next().toString();
134 } else if( effects.size() > 1 ) {
136 Iterator<Effect> eItr = effects.iterator();
137 while( eItr.hasNext() ) {
138 Effect e = eItr.next();
141 if( eItr.hasNext() ) {
149 // then each transition is an edge
150 Iterator<Effect> eItr = e2states.keySet().iterator();
151 while( eItr.hasNext() ) {
152 Effect e = eItr.next();
153 Set<SMFEState> states = e2states.get( e );
155 Iterator<SMFEState> sItr = states.iterator();
156 while( sItr.hasNext() ) {
157 SMFEState state = sItr.next();
161 "[label=\""+e+"\"];";