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 //TODO: Jim! Also give me a list of "inset alloc sites"
44 //as in for every state, give me starting allocation sites
45 //Useful for determining which allocs within a state need its own case statement
46 //Basically allocs that have transitions TO them.
47 protected Set<Alloc> startingAllocs;
49 // the given effect allows a transition to a
51 protected Hashtable< Effect, Set<SMFEState> > e2states;
53 // useful for knowing when a state can be inlined during
55 protected int refCount;
59 public SMFEState( FlatNode fnWhereDefined ) {
61 this.id = fnWhereDefined.nodeid;
62 this.iHashCode = fnWhereDefined.hashCode();
64 effects = new HashSet<Effect>();
65 conflicts = new HashSet<Effect>();
66 e2states = new Hashtable< Effect, Set<SMFEState> >();
70 public void addEffect( Effect e ) {
74 // the given effect allows the transition to the new state
75 public void addTransition( Effect effect,
79 Set<SMFEState> states = e2states.get( effect );
80 if( states == null ) {
81 states = new HashSet<SMFEState>();
82 e2states.put( effect, states );
84 states.add( stateTo );
94 // once you get your hands on an SMFEState in the
95 // RuntimeConflictResolver side of things, this is how you
96 // find out what effects are possible in this state
97 public Set<Effect> getEffectsAllowed() {
101 public Set<Effect> getConflicts() {
102 //TODO JIM! Fix this when have a chance!
103 conflicts.addAll(effects);
104 return this.conflicts;
107 public Set<Alloc> getStartingAllocs() {
108 return startingAllocs;
111 public Set<Effect> getTransistionEffects() {
112 return this.e2states.keySet();
115 // some subset of the above effects may transition to
117 public Set<SMFEState> transitionsTo( Effect e ) {
118 Set<SMFEState> statesOut = e2states.get( e );
119 if( statesOut == null ) {
120 statesOut = new HashSet<SMFEState>();
125 public int getRefCount() {
130 public boolean equals( Object o ) {
135 if( !(o instanceof SMFEState) ) {
139 SMFEState state = (SMFEState) o;
141 return id == state.id;
144 public int hashCode() {
149 public String toStringDOT() {
151 // first create the state as a node in DOT graph
152 String s = " "+id+"[shape=box,label=\"";
154 if( effects.size() == 1 ) {
155 s += effects.iterator().next().toString();
157 } else if( effects.size() > 1 ) {
159 Iterator<Effect> eItr = effects.iterator();
160 while( eItr.hasNext() ) {
161 Effect e = eItr.next();
164 if( eItr.hasNext() ) {
172 // then each transition is an edge
173 Iterator<Effect> eItr = e2states.keySet().iterator();
174 while( eItr.hasNext() ) {
175 Effect e = eItr.next();
176 Set<SMFEState> states = e2states.get( e );
178 Iterator<SMFEState> sItr = states.iterator();
179 while( sItr.hasNext() ) {
180 SMFEState state = sItr.next();
184 "[label=\""+e+"\"];";