1 package Analysis.Disjoint;
8 import Analysis.OoOJava.*;
12 //////////////////////////////////////////////
14 // BuildStateMachines builds a state machine
15 // for every task/stall site and variable pair
17 // StateMachineForEffects describes an intial
18 // state and the effect transtions a DFJ
19 // traverser should make from the current state
20 // when searching for possible runtime conflicts.
22 //////////////////////////////////////////////
24 public class BuildStateMachines {
26 // map a task or stall site (both a FlatNode) to a variable
27 // and then finally to a state machine
29 Hashtable< FlatNode, Hashtable<TempDescriptor, StateMachineForEffects> >
32 // remember all the FlatNode/TempDescriptor pairs that have a state machines
33 // for easy retrieval of all machines
34 protected Set<Pair> allMachineNamePairs;
37 public BuildStateMachines() {
39 Hashtable< FlatNode, Hashtable<TempDescriptor, StateMachineForEffects> >();
41 allMachineNamePairs = new HashSet<Pair>();
45 public StateMachineForEffects getStateMachine( FlatNode fn,
46 TempDescriptor var ) {
48 Hashtable<TempDescriptor, StateMachineForEffects> var2smfe = fn2var2smfe.get( fn );
49 if( var2smfe == null ) {
50 var2smfe = new Hashtable<TempDescriptor, StateMachineForEffects>();
51 fn2var2smfe.put( fn, var2smfe );
54 StateMachineForEffects smfe = var2smfe.get( var );
56 smfe = new StateMachineForEffects( fn );
57 var2smfe.put( var, smfe );
59 allMachineNamePairs.add( new Pair( fn, var ) );
66 public Set<Pair> getAllMachineNames() {
67 return allMachineNamePairs;
71 public void addToStateMachine( Taint t,
73 FlatNode currentProgramPoint ) {
75 FlatNode taskOrStallSite;
76 if( t.isStallSiteTaint() ) {
77 taskOrStallSite = t.getStallSite();
79 taskOrStallSite = t.getSESE();
82 TempDescriptor var = t.getVar();
84 StateMachineForEffects smfe = getStateMachine( taskOrStallSite, var );
86 FlatNode whereDefined = t.getWhereDefined();
88 smfe.addEffect( whereDefined, e );
90 // reads of pointers make a transition
91 if( e.getType() == Effect.read &&
92 e.getField().getType().isPtr() ) {
94 smfe.addTransition( whereDefined,
101 public void writeStateMachines() {
103 Iterator<FlatNode> fnItr = fn2var2smfe.keySet().iterator();
104 while( fnItr.hasNext() ) {
105 FlatNode fn = fnItr.next();
107 Hashtable<TempDescriptor, StateMachineForEffects>
108 var2smfe = fn2var2smfe.get( fn );
110 Iterator<TempDescriptor> varItr = var2smfe.keySet().iterator();
111 while( varItr.hasNext() ) {
112 TempDescriptor var = varItr.next();
114 StateMachineForEffects smfe = var2smfe.get( var );
116 smfe.writeAsDOT( "statemachine_"+fn.toString()+var.toString() );