From d56003c3fd803f9a559d749fb4d57512201a0393 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 18 Oct 2010 03:59:39 +0000 Subject: [PATCH] changes --- .../Analysis/OoOJava/SESEWaitingQueue.java | 93 ++++++++------ Robust/src/IR/Flat/BuildCode.java | 114 +++++++++--------- Robust/src/IR/Flat/FlatSESEEnterNode.java | 26 ++-- .../src/IR/Flat/RuntimeConflictResolver.java | 47 ++++++-- 4 files changed, 157 insertions(+), 123 deletions(-) diff --git a/Robust/src/Analysis/OoOJava/SESEWaitingQueue.java b/Robust/src/Analysis/OoOJava/SESEWaitingQueue.java index 215fc97b..300888b5 100644 --- a/Robust/src/Analysis/OoOJava/SESEWaitingQueue.java +++ b/Robust/src/Analysis/OoOJava/SESEWaitingQueue.java @@ -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>mapWaitingElement; - private HashMapmapType; + private HashMap>tmp2WaitingElement; + private HashMap>mapWaitingElement; + private HashMapmapType; + + public SESEWaitingQueue(){ + mapWaitingElement=new HashMap>(); + tmp2WaitingElement=new HashMap>(); + mapType=new HashMap(); + } - public SESEWaitingQueue(){ - mapWaitingElement=new HashMap>(); - mapType=new HashMap(); - } + 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 set){ - mapWaitingElement.put(new Integer(queueID), set); - } - - public Set getWaitingElementSet(int queueID){ - return mapWaitingElement.get(new Integer(queueID)); - } + public void setWaitingElementSet(int queueID, Set set) { + mapWaitingElement.put(new Integer(queueID), set); + for(Iterator wit=set.iterator();wit.hasNext();) { + WaitingElement we=wit.next(); + TempDescriptor tmp=we.getTempDesc(); + if (!tmp2WaitingElement.containsKey(tmp)) + tmp2WaitingElement.put(tmp, new HashSet()); + tmp2WaitingElement.get(tmp).add(we); + } + } + + public Set getWaitingElementSet(TempDescriptor tmp) { + return tmp2WaitingElement.get(tmp); + } + + public Set getWaitingElementSet(int queueID){ + return mapWaitingElement.get(new Integer(queueID)); + } - public Set getQueueIDSet(){ - return mapWaitingElement.keySet(); - } + public Set getQueueIDSet(){ + return mapWaitingElement.keySet(); + } - public int getWaitingElementSize(){ - int size=0; - Set 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 keySet=mapWaitingElement.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + Integer key = (Integer) iterator.next(); + size+=mapWaitingElement.get(key).size(); + } + return size; + } } diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 1dff0ddb..97f2eb30 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -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 inset=fsen.getInVarVector(); - int incount=0; - + Vector inset=fsen.getInVarsForDynamicCoarseConflictResolution(); for(int i=0; inumRunningChildren));"); } - // 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 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 invars=fsen.getInVarsForDynamicCoarseConflictResolution(); + for(int i=0;i weset=seseWaitingQueue.getWaitingElementSet(td); + int numqueues=weset.size(); + output.println(" seseToIssue->rcrRecords["+i+"]="+numqueues+";"); + output.println(" dispCount=0;"); + for(Iterator 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, diff --git a/Robust/src/IR/Flat/FlatSESEEnterNode.java b/Robust/src/IR/Flat/FlatSESEEnterNode.java index d75e137e..90731b34 100644 --- a/Robust/src/IR/Flat/FlatSESEEnterNode.java +++ b/Robust/src/IR/Flat/FlatSESEEnterNode.java @@ -37,7 +37,7 @@ public class FlatSESEEnterNode extends FlatNode { protected Set children; - protected Vector inVars; + protected Set inVars; protected Set outVars; protected Set 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 inVarsForDynamicCoarseConflictResolution; + protected Vector 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(); - inVars = new Vector(); + inVars = new HashSet(); outVars = new HashSet(); needStaticNameInCode = new HashSet(); staticInVarSrcs = new HashSet(); @@ -93,7 +93,7 @@ public class FlatSESEEnterNode extends FlatNode { dynamicInVars = new HashSet(); dynamicVars = new HashSet(); - inVarsForDynamicCoarseConflictResolution = new HashSet(); + inVarsForDynamicCoarseConflictResolution = new Vector(); staticInVar2src = new Hashtable(); @@ -178,22 +178,14 @@ public class FlatSESEEnterNode extends FlatNode { } public void addInVarSet( Set s ) { - for(Iterator sit=s.iterator();sit.hasNext();) { - TempDescriptor tmp=sit.next(); - if (!inVars.contains(tmp)) - inVars.add(tmp); - } + inVars.addAll(s); } public void addOutVarSet( Set s ) { outVars.addAll( s ); } - public Collection getInVarSet() { - return inVars; - } - - public Vector getInVarVector() { + public Set getInVarSet() { return inVars; } @@ -408,14 +400,14 @@ public class FlatSESEEnterNode extends FlatNode { return numDepRecs; } - public Set getInVarsForDynamicCoarseConflictResolution() { + public Vector 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 ) { diff --git a/Robust/src/IR/Flat/RuntimeConflictResolver.java b/Robust/src/IR/Flat/RuntimeConflictResolver.java index 87c118f5..af403d97 100644 --- a/Robust/src/IR/Flat/RuntimeConflictResolver.java +++ b/Robust/src/IR/Flat/RuntimeConflictResolver.java @@ -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 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 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 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 invars=fsen.getInVarsForDynamicCoarseConflictResolution(); + for(int i=0;i"+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) { -- 2.34.1