1 package Analysis.Disjoint;
10 //////////////////////////////////////////////
12 // StateMachineForEffects describes an intial
13 // state and the effect transtions a DFJ
14 // traverser should make from the current state
15 // when searching for possible runtime conflicts.
17 //////////////////////////////////////////////
19 public class StateMachineForEffects {
20 public final static FlatNode startNode=new FlatNop();
21 protected HashMap<Pair<Alloc, FieldDescriptor>, Integer> effectsMap;
23 // states in the machine are uniquely identified
24 // by a flat node (program point)
25 protected Hashtable<FlatNode, SMFEState> fn2state;
27 //TODO Jim! Jim! Give me the weakly connected group number here!
28 protected Hashtable<FlatNode, Integer> fn2weaklyConnectedGroupID;
30 protected SMFEState initialState;
31 protected FlatNode fn;
34 public StateMachineForEffects( FlatNode fnInitial ) {
35 fn2state = new Hashtable<FlatNode, SMFEState>();
36 effectsMap = new HashMap<Pair<Alloc, FieldDescriptor>, Integer>();
37 initialState = getState( startNode );
41 public Set<SMFEState> getStates() {
42 HashSet<SMFEState> set=new HashSet<SMFEState>();
43 set.addAll(fn2state.values());
47 public FlatNode getStallorSESE() {
51 public int getEffects(Alloc affectedNode, FieldDescriptor fd) {
52 Integer type=effectsMap.get(new Pair<Alloc, FieldDescriptor>(affectedNode, fd));
56 return type.intValue();
59 public void addEffect( FlatNode fnState,
63 SMFEState state = getState( fnState );
65 Pair<Alloc, FieldDescriptor> p=new Pair<Alloc, FieldDescriptor>(e.getAffectedAllocSite(), e.getField());
67 if (!effectsMap.containsKey(p))
68 effectsMap.put(p, new Integer(type));
70 effectsMap.put(p, new Integer(type|effectsMap.get(p).intValue()));
73 public void addTransition( FlatNode fnFrom,
79 assert fn2state.containsKey( fnFrom );
80 SMFEState stateFrom = getState( fnFrom );
81 SMFEState stateTo = getState( fnTo );
83 stateFrom.addTransition( e, stateTo );
86 public SMFEState getInitialState() {
91 protected SMFEState getState( FlatNode fn ) {
92 SMFEState state = fn2state.get( fn );
94 state = new SMFEState( fn ,id++ );
95 fn2state.put( fn, state );
100 public Integer getWeaklyConnectedGroupID(FlatNode fn) {
101 //TODO stubby stubby!
105 public void writeAsDOT( String graphName ) {
106 graphName = graphName.replaceAll( "[\\W]", "" );
110 new BufferedWriter( new FileWriter( graphName+".dot" ) );
112 bw.write( "digraph "+graphName+" {\n" );
114 Iterator<FlatNode> fnItr = fn2state.keySet().iterator();
115 while( fnItr.hasNext() ) {
116 SMFEState state = fn2state.get( fnItr.next() );
117 bw.write( state.toStringDOT()+"\n" );
123 } catch( IOException e ) {
124 throw new Error( "Error writing out DOT graph "+graphName );