changes
authorbdemsky <bdemsky>
Mon, 18 Oct 2010 03:59:39 +0000 (03:59 +0000)
committerbdemsky <bdemsky>
Mon, 18 Oct 2010 03:59:39 +0000 (03:59 +0000)
Robust/src/Analysis/OoOJava/SESEWaitingQueue.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/FlatSESEEnterNode.java
Robust/src/IR/Flat/RuntimeConflictResolver.java

index 215fc97b65d70e60e55d1e91cff9a5729d2cbd92..300888b5b3a2beb9115fccbdff0e45f43e49a753 100644 (file)
@@ -2,52 +2,67 @@ package Analysis.OoOJava;
 
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.HashSet;
 import java.util.Set;
+import IR.Flat.TempDescriptor;
 
 public class SESEWaitingQueue {
-       public static final int NORMAL= 0; // enqueue all stuff.
-       public static final int EXCEPTION= 1; // dynamically decide whether a waiting element is enqueued or not.
+  public static final int NORMAL= 0; // enqueue all stuff.
+  public static final int EXCEPTION= 1; // dynamically decide whether a waiting element is enqueued or not.
        
-       private HashMap<Integer, Set<WaitingElement>>mapWaitingElement;
-       private HashMap<Integer, Integer>mapType;
+  private HashMap<TempDescriptor, Set<WaitingElement>>tmp2WaitingElement;
+  private HashMap<Integer, Set<WaitingElement>>mapWaitingElement;
+  private HashMap<Integer, Integer>mapType;
+  
+  public SESEWaitingQueue(){
+    mapWaitingElement=new HashMap<Integer, Set<WaitingElement>>();
+    tmp2WaitingElement=new HashMap<TempDescriptor, Set<WaitingElement>>();
+    mapType=new HashMap<Integer, Integer>();
+  }
        
-       public SESEWaitingQueue(){
-               mapWaitingElement=new HashMap<Integer, Set<WaitingElement>>();
-               mapType=new HashMap<Integer, Integer>();
-       }
+  public void setType(int queueID, int type){
+    mapType.put(new Integer(queueID), new Integer(type));
+  }
        
-       public void setType(int queueID, int type){
-               mapType.put(new Integer(queueID), new Integer(type));
-       }
+  public int getType(int queueID){
+    Integer type=mapType.get(new Integer(queueID));
+    if(type==null){
+      return SESEWaitingQueue.NORMAL;
+    } else {
+      return type.intValue();
+    }
+  }
        
-       public int getType(int queueID){
-               Integer type=mapType.get(new Integer(queueID));
-               if(type==null){
-                       return SESEWaitingQueue.NORMAL;
-               }else{
-                       return type.intValue();
-               }
-       }
-       
-       public void setWaitingElementSet(int queueID, Set<WaitingElement> set){
-               mapWaitingElement.put(new Integer(queueID), set);
-       }
-       
-       public Set<WaitingElement> getWaitingElementSet(int queueID){
-               return mapWaitingElement.get(new Integer(queueID));
-       }
+  public void setWaitingElementSet(int queueID, Set<WaitingElement> set) {
+    mapWaitingElement.put(new Integer(queueID), set);
+    for(Iterator<WaitingElement> wit=set.iterator();wit.hasNext();) {
+      WaitingElement we=wit.next();
+      TempDescriptor tmp=we.getTempDesc();
+      if (!tmp2WaitingElement.containsKey(tmp))
+       tmp2WaitingElement.put(tmp, new HashSet<WaitingElement>());
+      tmp2WaitingElement.get(tmp).add(we);
+    }
+  }
+
+  public Set<WaitingElement> getWaitingElementSet(TempDescriptor tmp) {
+    return tmp2WaitingElement.get(tmp);
+  }
+  
+  public Set<WaitingElement> getWaitingElementSet(int queueID){
+    return mapWaitingElement.get(new Integer(queueID));
+  }
        
-       public Set<Integer> getQueueIDSet(){
-               return mapWaitingElement.keySet();
-       }
+  public Set<Integer> getQueueIDSet(){
+    return mapWaitingElement.keySet();
+  }
        
-       public int getWaitingElementSize(){
-               int size=0;
-               Set<Integer> keySet=mapWaitingElement.keySet();
-               for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
-                       Integer key = (Integer) iterator.next();
-                       size+=mapWaitingElement.get(key).size();
-               }
-               return size;
-       }
+  public int getWaitingElementSize(){
+    int size=0;
+    Set<Integer> keySet=mapWaitingElement.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      Integer key = (Integer) iterator.next();
+      size+=mapWaitingElement.get(key).size();
+    }
+    return size;
+  }
 }
index 1dff0ddbbc3aba112fe7d8ea51aa760d6db59854..97f2eb30c877f828a0851c1ad3341bd99fde4ab3 100644 (file)
@@ -273,7 +273,7 @@ public class BuildCode {
       //TODO signal the object that will report errors
       if(state.RCR) {
         try {
-          rcr = new RuntimeConflictResolver(PREFIX);
+          rcr = new RuntimeConflictResolver(PREFIX, oooa);
           rcr.setGlobalEffects(oooa.getDisjointAnalysis().getEffectsAnalysis().getAllEffects());
         } catch (FileNotFoundException e) {
           System.out.println("Runtime Conflict Resolver could not create output file.");
@@ -2138,21 +2138,15 @@ public class BuildCode {
     // used in the following code, but let's just leave the working
     // implementation unless there is actually a problem...
 
-    Vector<TempDescriptor> inset=fsen.getInVarVector();
-    int incount=0;
-
+    Vector<TempDescriptor> inset=fsen.getInVarsForDynamicCoarseConflictResolution();
     for(int i=0; i<inset.size();i++) {
       TempDescriptor temp=inset.get(i);
-      TypeDescriptor type=temp.getType();
-      if(type.isPtr()) {
-       incount++;
-       if (temp.getType().isNull())
-         outputStructs.println("  void * "+temp.getSafeSymbol()+
-                               ";  /* in-or-out-set obj in gl */");
-       else
-         outputStructs.println("  struct "+temp.getType().getSafeSymbol()+" * "+
-                               temp.getSafeSymbol()+"; /* in-or-out-set obj in gl */");
-      }
+      if (temp.getType().isNull())
+       outputStructs.println("  void * "+temp.getSafeSymbol()+
+                             ";  /* in-or-out-set obj in gl */");
+      else
+       outputStructs.println("  struct "+temp.getType().getSafeSymbol()+" * "+
+                             temp.getSafeSymbol()+"; /* in-or-out-set obj in gl */");
     }
 
     for(int i=0; i<objectparams.numPointers(); i++) {
@@ -2206,7 +2200,7 @@ public class BuildCode {
     }
 
     if (state.RCR) {
-      outputStructs.println("struct rcrRecord rcrRecords["+incount+"]");
+      outputStructs.println("struct rcrRecord rcrRecords["+inset.size()+"];");
     }
     
     if( fsen.getFirstDepRecField() != null ) {
@@ -3689,8 +3683,7 @@ public class BuildCode {
   public void generateFlatSESEEnterNode( FlatMethod fm,  
                                         LocalityBinding lb, 
                                         FlatSESEEnterNode fsen, 
-                                        PrintWriter output 
-                                      ) {
+                                        PrintWriter output) {
     // if MLP flag is off, okay that SESE nodes are in IR graph, 
     // just skip over them and code generates exactly the same
     if( !(state.MLP || state.OOOJAVA) ) {
@@ -3724,7 +3717,6 @@ public class BuildCode {
       output.println("     atomic_inc(&(runningSESE->numRunningChildren));");
     }
 
-
     // allocate the space for this record
     output.println( "#ifndef OOO_DISABLE_TASKMEMPOOL" );
 
@@ -3755,8 +3747,6 @@ public class BuildCode {
     output.println( "#endif // OOO_DISABLE_TASKMEMPOOL" );
 
 
-
-
     // set up the SESE in-set and out-set objects, which look
     // like a garbage list
     output.println("     struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(seseToIssue))[1]);");
@@ -3780,7 +3770,7 @@ public class BuildCode {
     }
     
     if (state.RCR) {
-      output.println("    seseToIssumer->common.offsetToParamRecords=(INTPTR)sizeof("+fsen.getSESErecordName()+") - (INTPTR) & ((("+fsen.getSESErecordName()+"*)0)->rcrRecords);");
+      output.println("    seseToIssue->common.offsetToParamRecords=(INTPTR)sizeof("+fsen.getSESErecordName()+") - (INTPTR) & ((("+fsen.getSESErecordName()+"*)0)->rcrRecords);");
     }
 
     // fill in common data
@@ -3949,16 +3939,6 @@ public class BuildCode {
         output.println("     }");
       }
 
-      if (state.RCR) {
-
-       
-      }
-
-      if(state.RCR) {
-       //TODO BCD
-       //clear out the parameter records
-
-      }
 
 
       if( state.COREPROF ) {
@@ -3970,8 +3950,9 @@ public class BuildCode {
 
       ////////////////
       // count up memory conflict dependencies,
-      // eom
-      if(state.OOOJAVA){
+      if(state.RCR) {
+       dispatchMEMRC(fm, lb, fsen, output);
+      } else if(state.OOOJAVA){
         FlatSESEEnterNode parent = fsen.getParent();
         Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(parent);
         if (graph != null && graph.hasConflictEdge()) {
@@ -4053,30 +4034,7 @@ public class BuildCode {
                                  + "],rentry)==NOTREADY) {");
                   output.println("          localCount++;");
                   output.println("       }");
-                  
-                  // Trying to execute the dynamic coarse grain conflict strategy...
-                  if(state.RCR && rcr != null) {
-                    boolean useParentContext = false;
-
-                    if( (state.MLP &&fsen != mlpa.getMainSESE()) || 
-                        (state.OOOJAVA &&fsen != oooa.getMainSESE())) {
-                      assert fsen.getParent() != null;
-                      if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
-                        useParentContext = true;
-                      }
-                    }
-                    
-                    for (TempDescriptor invar : fsen.getInVarsForDynamicCoarseConflictResolution()) {                      
-                      String varString;
-                      if( useParentContext ) {
-                        varString = generateTemp( fsen.getParent().getfmBogus(), invar, null );
-                      } else {
-                        varString = generateTemp( fsen.getfmEnclosing(),         invar, null );
-                      }
-                      output.println("       "+rcr.getTraverserInvocation(invar, varString, fsen));
-                    }
-                  }
-                }else{
+               } else {
                   output.println("       ADDRENTRYTOBUF(runningSESE->memoryQueueArray[" + waitingElement.getQueueID() + "],rentry);");
                 }
               }
@@ -4245,6 +4203,48 @@ public class BuildCode {
     
   }
 
+  void dispatchMEMRC(FlatMethod fm,  LocalityBinding lb, FlatSESEEnterNode fsen, PrintWriter output) {
+    FlatSESEEnterNode parent = fsen.getParent();
+    Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(parent);
+    if (graph != null && graph.hasConflictEdge()) {
+      Set<Analysis.OoOJava.SESELock> seseLockSet = oooa.getLockMappings(graph);
+      Analysis.OoOJava.SESEWaitingQueue seseWaitingQueue=graph.getWaitingElementSetBySESEID(fsen.getIdentifier(), seseLockSet);
+      if(seseWaitingQueue.getWaitingElementSize()>0) {
+       output.println("     {");
+       output.println("       REntry* rentry=NULL;");
+       output.println("       INTPTR* pointer=NULL;");
+       output.println("       seseToIssue->common.rentryIdx=0;");
+       output.println("       int dispCount;");
+       Vector<TempDescriptor> invars=fsen.getInVarsForDynamicCoarseConflictResolution();
+       for(int i=0;i<invars.size();i++) {
+         TempDescriptor td=invars.get(i);
+         Set<Analysis.OoOJava.WaitingElement> weset=seseWaitingQueue.getWaitingElementSet(td);
+         int numqueues=weset.size();
+         output.println("      seseToIssue->rcrRecords["+i+"]="+numqueues+";");
+         output.println("      dispCount=0;");
+         for(Iterator<Analysis.OoOJava.WaitingElement> wtit=weset.iterator();wtit.hasNext();) {
+           Analysis.OoOJava.WaitingElement waitingElement=wtit.next();
+           int queueID=waitingElement.getQueueID();
+           assert(waitingElement.getStatus()>=ConflictNode.COARSE);
+           output.println("       rentry=mlpCreateREntry(" + waitingElement.getStatus() + ", &(seseToIssue->common));");
+           output.println("       seseToIssue->common.rentryArray[seseToIssue->common.rentryIdx++]=rentry;");
+           output.println("       if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],rentry)==READY) {");
+           output.println("          dispCount++;");
+           output.println("       }");
+         }
+         output.println("     if(!dispCount || !atomic_sub_and_test(dispCount,&(seseToIssue->rcrRecords["+i+"])))");
+         output.println("       localCount++;");
+         if (fsen.getDynamicInVarSet().contains(td)) {
+           // dynamic in-var case
+           //output.println("       pointer=seseToIssue->" + waitingElement.getDynID()+ "_srcSESE+seseToIssue->"+ waitingElement.getDynID()+ "_srcOffset;");
+           //output.println("       rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", &(seseToIssue->common),  pointer );");
+         }
+       }
+       output.println("    }");
+      }
+    }
+  }
+
   public void generateFlatSESEExitNode( FlatMethod fm,  
                                        LocalityBinding lb, 
                                        FlatSESEExitNode fsexn, 
index d75e137ebe13d5e36f0a871824f55aebc24e1afa..90731b3431d1cb10c251af3f2d089cdecb38f6b8 100644 (file)
@@ -37,7 +37,7 @@ public class FlatSESEEnterNode extends FlatNode {
 
   protected Set<FlatSESEEnterNode> children;
 
-  protected Vector<TempDescriptor> inVars;
+  protected Set<TempDescriptor> inVars;
   protected Set<TempDescriptor> outVars;
 
   protected Set<SESEandAgePair> needStaticNameInCode;
@@ -57,7 +57,7 @@ public class FlatSESEEnterNode extends FlatNode {
   // a subset of the in-set variables that shouuld be traversed during
   // the dynamic coarse grained conflict strategy, remember them here so
   // buildcode can be dumb and just gen the traversals
-  protected Set<TempDescriptor> inVarsForDynamicCoarseConflictResolution;
+  protected Vector<TempDescriptor> inVarsForDynamicCoarseConflictResolution;
 
   // scope info for this SESE
   protected FlatMethod       fmEnclosing;
@@ -84,7 +84,7 @@ public class FlatSESEEnterNode extends FlatNode {
     oldestAgeToTrack     = new Integer( 0 );
 
     children             = new HashSet<FlatSESEEnterNode>();
-    inVars               = new Vector<TempDescriptor>();
+    inVars               = new HashSet<TempDescriptor>();
     outVars              = new HashSet<TempDescriptor>();
     needStaticNameInCode = new HashSet<SESEandAgePair>();
     staticInVarSrcs      = new HashSet<SESEandAgePair>();
@@ -93,7 +93,7 @@ public class FlatSESEEnterNode extends FlatNode {
     dynamicInVars        = new HashSet<TempDescriptor>();
     dynamicVars          = new HashSet<TempDescriptor>();
 
-    inVarsForDynamicCoarseConflictResolution = new HashSet<TempDescriptor>();
+    inVarsForDynamicCoarseConflictResolution = new Vector<TempDescriptor>();
     
     staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
     
@@ -178,22 +178,14 @@ public class FlatSESEEnterNode extends FlatNode {
   }
 
   public void addInVarSet( Set<TempDescriptor> s ) {
-    for(Iterator<TempDescriptor> sit=s.iterator();sit.hasNext();) {
-      TempDescriptor tmp=sit.next();
-      if (!inVars.contains(tmp))
-       inVars.add(tmp);
-    }
+    inVars.addAll(s);
   }
 
   public void addOutVarSet( Set<TempDescriptor> s ) {
     outVars.addAll( s );
   }
 
-  public Collection<TempDescriptor> getInVarSet() {
-    return inVars;
-  }
-
-  public Vector<TempDescriptor> getInVarVector() {
+  public Set<TempDescriptor> getInVarSet() {
     return inVars;
   }
 
@@ -408,14 +400,14 @@ public class FlatSESEEnterNode extends FlatNode {
     return numDepRecs;
   }
   
-  public Set<TempDescriptor> getInVarsForDynamicCoarseConflictResolution() {
+  public Vector<TempDescriptor> getInVarsForDynamicCoarseConflictResolution() {
     return inVarsForDynamicCoarseConflictResolution;
   }
   
   public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) {
-    inVarsForDynamicCoarseConflictResolution.add(inVar);
+    if (!inVarsForDynamicCoarseConflictResolution.contains(inVar))
+      inVarsForDynamicCoarseConflictResolution.add(inVar);
   }
-
   
   public void setIsLeafSESE( boolean isLeaf ) {
     if( isLeaf ) {
index 87c118f5f18adf7c96380ac78c66baba3430f1ce..af403d97bb0d156d086e1292be7db3ad4d8be5ef 100644 (file)
@@ -8,8 +8,10 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.Vector;
 import Analysis.Disjoint.*;
 import IR.TypeDescriptor;
+import Analysis.OoOJava.OoOJavaAnalysis;
 
 /* An instance of this class manages all OoOJava coarse-grained runtime conflicts
  * by generating C-code to either rule out the conflict at runtime or resolve one.
@@ -64,11 +66,12 @@ public class RuntimeConflictResolver {
   private int weaklyConnectedHRCounter;
   private ArrayList<TaintAndInternalHeapStructure> pendingPrintout;
   private EffectsTable effectsLookupTable;
+  private OoOJavaAnalysis oooa;
 
-  public RuntimeConflictResolver(String buildir) 
-  throws FileNotFoundException {
+  public RuntimeConflictResolver(String buildir, OoOJavaAnalysis oooa) throws FileNotFoundException {
     String outputFile = buildir + "RuntimeConflictResolver";
-    
+    this.oooa=oooa;
+
     cFile = new PrintWriter(new File(outputFile + ".c"));
     headerFile = new PrintWriter(new File(outputFile + ".h"));
     
@@ -147,8 +150,7 @@ public class RuntimeConflictResolver {
     }
   }
 
-  private void traverseSESEBlock(FlatSESEEnterNode rblock,
-      ReachGraph rg) {
+  private void traverseSESEBlock(FlatSESEEnterNode rblock, ReachGraph rg) {
     Collection<TempDescriptor> inVars = rblock.getInVarSet();
     
     if (inVars.size() == 0)
@@ -184,8 +186,7 @@ public class RuntimeConflictResolver {
       
       //This will add the taint to the printout, there will be NO duplicates (checked above)
       if(!created.isEmpty()) {
-        //TODO change invocation to new format
-        //rblock.addInVarForDynamicCoarseConflictResolution(invar);
+        rblock.addInVarForDynamicCoarseConflictResolution(invar);
         pendingPrintout.add(new TaintAndInternalHeapStructure(taint, created));
       }
     }
@@ -303,9 +304,35 @@ public class RuntimeConflictResolver {
     cFile.println("}");
   }
 
+  private void printMasterTraverserInvocation() {
+    headerFile.println("\nint traverse(SESECommon * record);");
+    cFile.println("\nint traverse(SESECommon * record) {");
+    cFile.println("  switch(record->classID) {");
+    
+    for(Iterator<FlatSESEEnterNode> seseit=oooa.getAllSESEs().iterator();seseit.hasNext();) {
+      FlatSESEEnterNode fsen=seseit.next();
+      cFile.println(    "    /* "+fsen.getPrettyIdentifier()+" */");
+      cFile.println(    "    case "+fsen.getIdentifier()+": {");
+      cFile.println(    "      "+fsen.getSESErecordName()+" * rec=("+fsen.getSESErecordName()+" *) record;");
+      Vector<TempDescriptor> invars=fsen.getInVarsForDynamicCoarseConflictResolution();
+      for(int i=0;i<invars.size();i++) {
+       TempDescriptor tmp=invars.get(i);
+       cFile.println("      " + this.getTraverserInvocation(tmp, "rec->"+tmp, fsen));
+      }
+      cFile.println(    "    }");
+      cFile.println(    "    break;");
+    }
+
+    cFile.println("    default:\n    printf(\"Invalid SESE ID was passed in.\\n\");\n    break;");
+    
+    cFile.println("  }");
+    cFile.println("}");
+  }
+
+
   //This will print the traverser invocation that takes in a traverserID and 
   //starting ptr
-  private void printMasterTraverserInvocation() {
+  private void printAltMasterTraverserInvocation() {
     headerFile.println("\nint traverse(void * startingPtr, int traverserID);");
     cFile.println("\nint traverse(void * startingPtr, int traverserID) {");
     cFile.println(" switch(traverserID) {");
@@ -652,13 +679,13 @@ public class RuntimeConflictResolver {
       assert heaprootNum != -1;
       int allocSiteID = connectedHRHash.get(taint).getWaitingQueueBucketNum(node);
       int traverserID = doneTaints.get(taint);
-      currCase.append("rcr_WRITEBINCASE(allHashStructures["+heaprootNum+"],"+prefix+","+traverserID+",NULL,NULL)");
+      currCase.append("    rcr_WRITEBINCASE(allHashStructures["+heaprootNum+"],"+prefix+","+traverserID+",NULL,NULL)");
     } else if (primConfRead||objConfRead) {
       int heaprootNum = connectedHRHash.get(taint).id;
       assert heaprootNum != -1;
       int allocSiteID = connectedHRHash.get(taint).getWaitingQueueBucketNum(node);
       int traverserID = doneTaints.get(taint);
-      currCase.append("rcr_READBINCASE(allHashStructures["+heaprootNum+"],"+prefix+","+traverserID+",NULL,NULL)");
+      currCase.append("    rcr_READBINCASE(allHashStructures["+heaprootNum+"],"+prefix+","+traverserID+",NULL,NULL)");
     }
 
     if(objConfRead) {