more code for state machines in dfj traversers
authorjjenista <jjenista>
Sat, 5 Mar 2011 00:02:19 +0000 (00:02 +0000)
committerjjenista <jjenista>
Sat, 5 Mar 2011 00:02:19 +0000 (00:02 +0000)
Robust/src/Analysis/Disjoint/BuildStateMachines.java [new file with mode: 0644]
Robust/src/Analysis/Disjoint/DisjointAnalysis.java
Robust/src/Analysis/Disjoint/EffectsAnalysis.java
Robust/src/Analysis/Disjoint/SMFEState.java
Robust/src/Analysis/Disjoint/StateMachineForEffects.java

diff --git a/Robust/src/Analysis/Disjoint/BuildStateMachines.java b/Robust/src/Analysis/Disjoint/BuildStateMachines.java
new file mode 100644 (file)
index 0000000..e0d6e2e
--- /dev/null
@@ -0,0 +1,80 @@
+package Analysis.Disjoint;
+
+import java.util.*;
+import java.io.*;
+
+import IR.*;
+import IR.Flat.*;
+
+//////////////////////////////////////////////
+//
+//  BuildStateMachines builds a state machine
+//  for every task/stall site and variable pair
+//
+//  StateMachineForEffects describes an intial
+//  state and the effect transtions a DFJ
+//  traverser should make from the current state
+//  when searching for possible runtime conflicts.
+//
+//////////////////////////////////////////////
+
+public class BuildStateMachines {
+
+  protected 
+    Hashtable< FlatNode, Hashtable<TempDescriptor, StateMachineForEffects> >
+    fn2var2smfe;
+
+  public BuildStateMachines() {
+    fn2var2smfe = new
+      Hashtable< FlatNode, Hashtable<TempDescriptor, StateMachineForEffects> >();
+  }
+
+  protected StateMachineForEffects getStateMachine( FlatNode       fn,
+                                                    TempDescriptor var ) {
+
+    Hashtable<TempDescriptor, StateMachineForEffects> var2smfe = fn2var2smfe.get( fn );
+    if( var2smfe == null ) {
+      var2smfe = new Hashtable<TempDescriptor, StateMachineForEffects>();
+      fn2var2smfe.put( fn, var2smfe );
+    }
+    
+    StateMachineForEffects smfe = var2smfe.get( var );
+    if( smfe == null ) {
+      smfe = new StateMachineForEffects( fn );
+      var2smfe.put( var, smfe );
+    }
+
+    return smfe;
+  }
+
+
+
+  public void addToStateMachine( Taint t, 
+                                 Effect e, 
+                                 FlatNode currentProgramPoint ) {
+    
+    FlatNode taskOrStallSite;
+    if( t.isStallSiteTaint() ) {
+      taskOrStallSite = t.getStallSite();
+    } else {
+      taskOrStallSite = t.getSESE();
+    }
+
+    TempDescriptor var = t.getVar();
+
+    StateMachineForEffects smfe = getStateMachine( taskOrStallSite, var );
+
+    FlatNode whereDefined = t.getWhereDefined();
+
+    smfe.addEffect( whereDefined, e );
+
+    // reads of pointers make a transition
+    if( e.getType() == Effect.read &&
+        e.getField().getType().isPtr() ) {
+      
+      smfe.addTransition( whereDefined, 
+                          currentProgramPoint,
+                          e );
+    }
+  }
+}
index 81ea411e1f5ae2b2279f5361c3a87705ca2cbdc4..de09d5ec219607d241a04ab9050441357f7091f4 100644 (file)
@@ -390,6 +390,8 @@ public class DisjointAnalysis {
 
   protected boolean doEffectsAnalysis = false;
   protected EffectsAnalysis effectsAnalysis;
+  protected BuildStateMachines buildStateMachines;
+
   
   // data structure for public interface
   private Hashtable< Descriptor, HashSet<AllocSite> > 
@@ -662,6 +664,10 @@ public class DisjointAnalysis {
       effectsAnalysis   = new EffectsAnalysis();
     }
 
+    if( state.RCR ) {
+      buildStateMachines = new BuildStateMachines();
+    }
+
     this.allocationDepth         = state.DISJOINTALLOCDEPTH;
     this.releaseMode             = state.DISJOINTRELEASEMODE;
     this.determinismDesired      = state.DISJOINTDETERMINISM;
@@ -690,7 +696,6 @@ public class DisjointAnalysis {
     ReachGraph.typeUtil        = typeUtil;
     ReachGraph.state           = state;
 
-
     ReachGraph.debugCallSiteVisitStartCapture
       = state.DISJOINTDEBUGCALLVISITTOSTART;
 
@@ -703,6 +708,11 @@ public class DisjointAnalysis {
     ReachGraph.debugCallSiteVisitCounter 
       = 0; // count visits from 1, is incremented before first visit
     
+
+    EffectsAnalysis.state              = state;
+    EffectsAnalysis.buildStateMachines = buildStateMachines;
+
+
     if( suppressOutput ) {
       System.out.println( "* Running disjoint reachability analysis with output suppressed! *" );
     }
@@ -1246,7 +1256,7 @@ public class DisjointAnalysis {
       // after transfer, use updated graph to
       // do effects analysis
       if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
-        effectsAnalysis.analyzeFlatFieldNode( rg, rhs, fld );          
+        effectsAnalysis.analyzeFlatFieldNode( rg, rhs, fld, fn );          
       }
       break;
 
@@ -1287,7 +1297,7 @@ public class DisjointAnalysis {
 
       // use transformed graph to do effects analysis
       if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
-        effectsAnalysis.analyzeFlatSetFieldNode( rg, lhs, fld, strongUpdate );          
+        effectsAnalysis.analyzeFlatSetFieldNode( rg, lhs, fld, fn, strongUpdate );          
       }
       break;
 
@@ -1326,7 +1336,7 @@ public class DisjointAnalysis {
 
       // use transformed graph to do effects analysis
       if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
-        effectsAnalysis.analyzeFlatFieldNode( rg, rhs, fdElement );                    
+        effectsAnalysis.analyzeFlatFieldNode( rg, rhs, fdElement, fn );                    
       }        
       break;
 
@@ -1373,7 +1383,7 @@ public class DisjointAnalysis {
 
       // use transformed graph to do effects analysis
       if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
-        effectsAnalysis.analyzeFlatSetFieldNode( rg, lhs, fdElement,
+        effectsAnalysis.analyzeFlatSetFieldNode( rg, lhs, fdElement, fn,
                                                  false );          
       }
       break;
index 221f23ae6730a5610377aa2c1eb3dfd8aaf2125b..bb1331164151c6e445264beeaf860ef365a6c620 100644 (file)
@@ -4,12 +4,8 @@ import java.util.*;
 import java.util.Map.Entry;
 import java.io.*;
 
-import IR.FieldDescriptor;
-import IR.Flat.FlatCall;
-import IR.Flat.FlatMethod;
-import IR.Flat.FlatNode;
-import IR.Flat.TempDescriptor;
-import IR.Flat.FlatSESEEnterNode;
+import IR.*;
+import IR.Flat.*;
 
 /////////////////////////////////////////////
 // 
@@ -39,6 +35,9 @@ public class EffectsAnalysis {
   private Hashtable<FlatSESEEnterNode, Hashtable<Taint, Set<Effect>> > sese2te;
   private Hashtable<FlatNode,          Hashtable<Taint, Set<Effect>> > stallSite2te;
 
+  public static State              state;
+  public static BuildStateMachines buildStateMachines;
+
 
   public EffectsAnalysis() {
     taint2effects = new Hashtable<Taint, Set<Effect>>();
@@ -59,12 +58,16 @@ public class EffectsAnalysis {
     return taint2effects.entrySet().iterator();
   }
 
-  protected void add(Taint t, Effect e) {
+  protected void add(Taint t, Effect e, FlatNode currentProgramPoint) {
 
     Taint tNoPreds = Canonical.changePredsTo( t,
                                               ReachGraph.predsEmpty
                                               );
 
+    if( state.RCR ) {
+      buildStateMachines.addToStateMachine( t, e, currentProgramPoint );
+    }
+
     // add to the global bag
     Set<Effect> effectSet = taint2effects.get(tNoPreds);
     if (effectSet == null) {
@@ -121,7 +124,7 @@ public class EffectsAnalysis {
 
 
 
-  public void analyzeFlatFieldNode(ReachGraph rg, TempDescriptor rhs, FieldDescriptor fld) {
+  public void analyzeFlatFieldNode(ReachGraph rg, TempDescriptor rhs, FieldDescriptor fld, FlatNode currentProgramPoint) {
 
     VariableNode vn = rg.td2vn.get(rhs);
     if( vn == null ) {
@@ -136,12 +139,12 @@ public class EffectsAnalysis {
 
       for (Iterator<Taint> taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) {
         Taint taint = taintSetIter.next();        
-        add(taint, effect);
+        add(taint, effect, currentProgramPoint);
       }
     }
   }
 
-  public void analyzeFlatSetFieldNode(ReachGraph rg, TempDescriptor lhs, FieldDescriptor fld, boolean strongUpdate) {
+  public void analyzeFlatSetFieldNode(ReachGraph rg, TempDescriptor lhs, FieldDescriptor fld, FlatNode currentProgramPoint, boolean strongUpdate) {
 
     VariableNode vn = rg.td2vn.get(lhs);
     if( vn == null ) {
@@ -161,10 +164,10 @@ public class EffectsAnalysis {
 
       for (Iterator<Taint> taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) {
         Taint taint = taintSetIter.next();
-        add( taint, effect );
+        add( taint, effect, currentProgramPoint );
 
         if (strongUpdate) {
-          add( taint, effectSU );
+          add( taint, effectSU, currentProgramPoint );
         }
       }
     }
index f427cd99a3c0d2b182cfac0bd28096b23f8f8ecb..fee844d0130721af9eb67d827d9269a1fbb885b5 100644 (file)
@@ -102,14 +102,19 @@ public class SMFEState {
     s += "\"];";
 
     // then each transition is an edge
-    Iterator<Effect> eItr = e2states.entrySet().iterator();
+    Iterator<Effect> eItr = e2states.keySet().iterator();
     while( eItr.hasNext() ) {
-      Effect    e     = eItr.next();
-      SMFEState state = e2states.get( e );
+      Effect         e      = eItr.next();
+      Set<SMFEState> states = e2states.get( e );
 
-      s += "\n  "+
-        id.nodeid+" -> "+state.id.nodeid+
-        "[label=\""+e+"\"];"
+      Iterator<SMFEState> sItr = states.iterator();
+      while( sItr.hasNext() ) {
+        SMFEState state = sItr.next();
+
+        s += "\n  "+
+          id.nodeid+" -> "+state.id.nodeid+
+          "[label=\""+e+"\"];";
+      }
     }
 
     return s;
index 0becddb895c4adbe510738009d1c414d7164f45c..69abb040be0d67e722f4ad8e1f640b84ce61eafa 100644 (file)
@@ -30,6 +30,14 @@ public class StateMachineForEffects {
     initialState = getState( fnInitial );
   }
 
+  public void addEffect( FlatNode fnState,
+                         Effect e ) {
+
+    assert fn2state.containsKey( fnState );
+    SMFEState state = getState( fnState );
+    state.addEffect( e );
+  }
+
   public void addTransition( FlatNode fnFrom,
                              FlatNode fnTo,
                              Effect e ) {
@@ -49,7 +57,7 @@ public class StateMachineForEffects {
   protected SMFEState getState( FlatNode fn ) {
     SMFEState state = fn2state.get( fn );
     if( state == null ) {
-      state = new SMFEState();
+      state = new SMFEState( fn );
     }
     return state;
   }
@@ -65,7 +73,7 @@ public class StateMachineForEffects {
 
       bw.write( "digraph "+graphName+" {\n" );
 
-      Iterator<Effect> fnItr = fn2state.entrySet().iterator();
+      Iterator<FlatNode> fnItr = fn2state.keySet().iterator();
       while( fnItr.hasNext() ) {
         SMFEState state = fn2state.get( fnItr.next() );
         bw.write( state.toStringDOT()+"\n" );