From: stephey Date: Fri, 13 Aug 2010 00:28:09 +0000 (+0000) Subject: Temporarily integrates Runtime Conflict Resolution into buildCode and runtime with... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fca720e2d9cfe7ee2fee7e544c4e364a930845ea;p=IRC.git Temporarily integrates Runtime Conflict Resolution into buildCode and runtime with -rcr flag --- diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index ee5e3c9d..8e3aa8c9 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -6,6 +6,7 @@ import IR.Tree.DNFFlagAtom; import IR.Tree.TagExpressionList; import IR.Tree.OffsetNode; import IR.*; + import java.util.*; import java.io.*; @@ -23,6 +24,7 @@ import Analysis.Locality.DCWrapper; import Analysis.Locality.DelayComputation; import Analysis.Locality.BranchAnalysis; import Analysis.CallGraph.CallGraph; +import Analysis.Disjoint.AllocSite; import Analysis.Disjoint.Effect; import Analysis.Disjoint.ReachGraph; import Analysis.Disjoint.Taint; @@ -80,6 +82,7 @@ public class BuildCode { "sprintf(errmsg, \"MLP error at %s:%d\", __FILE__, __LINE__); "+ "perror(errmsg); exit(-1); }"; boolean nonSESEpass=true; + RuntimeConflictResolver rcr = null; WriteBarrier wb; DiscoverConflicts dc; DiscoverConflicts recorddc; @@ -218,6 +221,10 @@ public class BuildCode { // Output the C class declarations // These could mutually reference each other + + + outclassdefs.println("#ifndef __CLASSDEF_H_"); + outclassdefs.println("#define __CLASSDEF_H_"); outputClassDeclarations(outclassdefs); // Output function prototypes and structures for parameters @@ -226,6 +233,7 @@ public class BuildCode { ClassDescriptor cn=(ClassDescriptor)it.next(); generateCallStructs(cn, outclassdefs, outstructs, outmethodheader); } + outclassdefs.println("#endif"); outclassdefs.close(); if (state.TASK) { @@ -255,30 +263,48 @@ public class BuildCode { }else{ seseit=oooa.getAllSESEs().iterator(); } + + //TODO signal the object that will report errors + if(state.RCR) { + try { + rcr = new RuntimeConflictResolver(PREFIX); + } + catch (FileNotFoundException e) { + System.out.println("Runtime Conflict Resolver could not create output file."); + } + } + while(seseit.hasNext()){ FlatSESEEnterNode fsen = seseit.next(); initializeSESE( fsen ); - /* - if(state.RCR){ - if(!fsen.getIsCallerSESEplaceholder() && fsen.getParent()!=null){ - - FlatMethod fm=fsen.getfmEnclosing(); - - //reach graph - ReachGraph rg=oooa.getDisjointAnalysis().getReachGraph(fm.getMethod()); - - //get effect set - Hashtable> effects=oooa.getDisjointAnalysis().getEffectsAnalysis().get(fsen); - - //get conflict set - Analysis.OoOJava.ConflictGraph conflictGraph=oooa.getConflictGraph(fsen.getParent()); - Hashtable> conflicts=conflictGraph.getConflictEffectSet(fsen); + if(state.RCR && rcr != null){ + Analysis.OoOJava.ConflictGraph conflictGraph; + Hashtable> conflicts; + if(!fsen.getIsCallerSESEplaceholder() && fsen.getParent()!=null && + (conflictGraph = oooa.getConflictGraph(fsen.getParent())) != null && + (conflicts = conflictGraph.getConflictEffectSet(fsen)) != null){ + + FlatMethod fm=fsen.getfmEnclosing(); + + //reach graph + ReachGraph rg=oooa.getDisjointAnalysis().getReachGraph(fm.getMethod()); + + //TODO remove this later + rg.writeGraph("RCRDEBUG"); + + //get effect set + Hashtable> effects=oooa.getDisjointAnalysis().getEffectsAnalysis().get(fsen); + + rcr.traverse(fsen, effects, conflicts, rg); + } } } - */ - } + if(rcr != null) { + rcr.close(); + System.out.println("Runtime Conflict Resolver Done."); + } } /* Build the actual methods */ @@ -546,6 +572,10 @@ public class BuildCode { outmethod.println("#include "); outmethod.println("#include \"mlp_runtime.h\""); outmethod.println("#include \"psemaphore.h\""); + + if( state.RCR) { + outmethod.println("#include \"RuntimeConflictResolver.h\""); + } } if (state.COREPROF) { outmethod.println("#include \"coreprof.h\""); @@ -2960,6 +2990,7 @@ public class BuildCode { WaitingElement waitingElement = (WaitingElement) iterator.next(); if( waitingElement.getStatus() >= ConflictNode.COARSE ){ + // HERE! a parent might conflict with a child output.println(" rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", seseCaller);"); }else{ output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", seseCaller, (void*)&___locals___."+ waitingElement.getDynID() + ");"); @@ -3830,6 +3861,32 @@ 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; + } + } + + //TODO fix this workaround later by invoking it only once in the lifetime of the program + output.println(" initializeStructsRCR();"); + + 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{ output .println(" ADDRENTRYTOBUF(parentCommon->memoryQueueArray[" diff --git a/Robust/src/IR/Flat/FlatSESEEnterNode.java b/Robust/src/IR/Flat/FlatSESEEnterNode.java index 52985ab5..086b1b76 100644 --- a/Robust/src/IR/Flat/FlatSESEEnterNode.java +++ b/Robust/src/IR/Flat/FlatSESEEnterNode.java @@ -47,6 +47,10 @@ public class FlatSESEEnterNode extends FlatNode { private SESEEffectsSet seseEffectsSet; + // 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; // scope info for this SESE protected FlatMethod fmEnclosing; @@ -82,6 +86,8 @@ public class FlatSESEEnterNode extends FlatNode { dynamicInVars = new HashSet(); dynamicVars = new HashSet(); + inVarsForDynamicCoarseConflictResolution = new HashSet(); + staticInVar2src = new Hashtable(); seseEffectsSet = new SESEEffectsSet(); @@ -383,4 +389,12 @@ public class FlatSESEEnterNode extends FlatNode { public int getNumDepRecs() { return numDepRecs; } + + public Set getInVarsForDynamicCoarseConflictResolution() { + return inVarsForDynamicCoarseConflictResolution; + } + + public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) { + inVarsForDynamicCoarseConflictResolution.add(inVar); + } } diff --git a/Robust/src/IR/Flat/RuntimeConflictResolver.java b/Robust/src/IR/Flat/RuntimeConflictResolver.java index 9b0444e9..ac96c72b 100644 --- a/Robust/src/IR/Flat/RuntimeConflictResolver.java +++ b/Robust/src/IR/Flat/RuntimeConflictResolver.java @@ -9,7 +9,9 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Set; import Analysis.Disjoint.*; +import IR.TypeDescriptor; +//TODO fix inaccuracy problem and take advantage of the refEdges //TODO make it so that methods with no conflicts get no output. //TODO Make more efficient by only using ONE hashtable. @@ -76,13 +78,21 @@ public class RuntimeConflictResolver { if (inVars.size() == 0) return; - // For every inVariable, generate unique method + // For every non-primative variable, generate unique method + // Special Note: The Criteria for executing printCMethod in this loop should match + // exactly the criteria in buildcode.java to invoke the generated C method(s). for (TempDescriptor invar : inVars) { + TypeDescriptor type = invar.getType(); + if(type == null || type.isPrimitive()) { + continue; + } + Hashtable created = new Hashtable(); createTree(rblock, invar, effects, conflicts, rg, created); if (!created.isEmpty()) { - printCMethod(created, invar.getSymbol(), rblock.getSESErecordName()); + rblock.addInVarForDynamicCoarseConflictResolution(invar); + printCMethod(created, invar.getSafeSymbol(), rblock.getPrettyIdentifier()); } } } @@ -121,8 +131,7 @@ public class RuntimeConflictResolver { RefEdge edge = possibleEdges.next(); assert edge != null; - // always assumed to be a conflict on the root variables. - ConcreteRuntimeObjNode singleRoot = new ConcreteRuntimeObjNode(edge.getDst(), true, true); + ConcreteRuntimeObjNode singleRoot = new ConcreteRuntimeObjNode(edge.getDst(), false, true); AllocSite rootKey = singleRoot.allocSite; if (!created.containsKey(rootKey)) { @@ -132,13 +141,64 @@ public class RuntimeConflictResolver { } } + private Hashtable generateEffectsLookupTable(FlatSESEEnterNode rblock, + VariableNode var, Hashtable> effects, + Hashtable> conflicts) { + // we search effects since conflicts is only a subset of effects + Taint taint = getProperTaint(rblock, var, effects); + assert taint != null; + + Set localEffects = effects.get(taint); + Set localConflicts = conflicts.get(taint); + + if (localEffects == null || localEffects.isEmpty() || localConflicts == null || localConflicts.isEmpty()) + return null; + + // Debug Code for manually checking effects + // System.out.println("For Taint " + taint); + // System.out.println("Effects"); + // for(Effect e: localEffects) + // { + // System.out.println(e); + // } + // + // System.out.println("Conflicts"); + // for(Effect e: localConflicts) + // { + // System.out.println(e); + // } + + Hashtable lookupTable = new Hashtable(); + + for (Effect e : localEffects) { + boolean conflict = localConflicts.contains(e); + AllocSite key = e.getAffectedAllocSite(); + EffectsGroup myEffects = lookupTable.get(key); + + if(myEffects == null) { + myEffects = new EffectsGroup(); + lookupTable.put(key, myEffects); + } + + if(e.getField().getType().isPrimitive()) { + if(conflict) { + myEffects.addPrimative(e); + } + } + else { + myEffects.addObj(e, conflict); + } + } + + return lookupTable; + } + // Plan is to add stuff to the tree depth-first sort of way. That way, we can // propagate up conflicts private void createHelper(ConcreteRuntimeObjNode curr, Iterator edges, Hashtable created, Hashtable table) { assert table != null; - AllocSite parentKey = curr.allocSite; EffectsGroup currEffects = table.get(parentKey); @@ -165,10 +225,9 @@ public class RuntimeConflictResolver { } else { child = created.get(childKey); - child.myObjConflict = effect.conflict || child.myObjConflict; } - curr.addObjChild(field, child); + curr.addObjChild(field, child, effect.conflict); if (effect.conflict) { propogateObjConflictFlag(child); @@ -188,58 +247,6 @@ public class RuntimeConflictResolver { } } - private Hashtable generateEffectsLookupTable(FlatSESEEnterNode rblock, - VariableNode var, Hashtable> effects, - Hashtable> conflicts) { - // we search effects since conflicts is only a subset of effects - Taint taint = getProperTaint(rblock, var, effects); - assert taint != null; - - Set localEffects = effects.get(taint); - Set localConflicts = conflicts.get(taint); - - if (localEffects == null || localEffects.isEmpty() || localConflicts == null || localConflicts.isEmpty()) - return null; - -// Debug Code for manually checking effects -// System.out.println("For Taint " + taint); -// System.out.println("Effects"); -// for(Effect e: localEffects) -// { -// System.out.println(e); -// } -// -// System.out.println("Conflicts"); -// for(Effect e: localConflicts) -// { -// System.out.println(e); -// } - - Hashtable lookupTable = new Hashtable(); - - for (Effect e : localEffects) { - boolean conflict = localConflicts.contains(e); - AllocSite key = e.getAffectedAllocSite(); - EffectsGroup myEffects = lookupTable.get(key); - - if(myEffects == null) { - myEffects = new EffectsGroup(); - lookupTable.put(key, myEffects); - } - - if(e.getField().getType().isPrimitive()) { - if(conflict) { - myEffects.addPrimative(e); - } - } - else { - myEffects.addObj(e, conflict); - } - } - - return lookupTable; - } - // This will propagate the conflict up the data structure. private void propogateObjConflictFlag(ConcreteRuntimeObjNode in) { ConcreteRuntimeObjNode node = in; @@ -282,12 +289,15 @@ public class RuntimeConflictResolver { // note that primitive in-set variables do not generate effects, so we can assume // that inVar is an object + //Note: remember to change getTraverserInvocation if you change the line below String methodName = "void traverse___" + inVar.replaceAll(" ", "") + rBlock.replaceAll(" ", "") + "___(void * InVar)"; cFile.append(methodName + " {\n"); headerFile.append(methodName + ";\n"); + cFile.append("printf(\"The traverser ran for " + methodName + "\\n\");\n"); + //Casts the ptr to a genericObjectSTruct so we can get to the ptr->allocsite field. cFile.append("struct genericObjectStruct * ptr = (struct genericObjectStruct *) InVar; if(InVar != NULL) { " + queryAndAddHashTableInC + "ptr); do { "); @@ -311,6 +321,11 @@ public class RuntimeConflictResolver { cFile.flush(); } + + public String getTraverserInvocation(TempDescriptor invar, String varString, FlatSESEEnterNode sese) { + return "traverse___" + invar.getSafeSymbol().replaceAll(" ", "") + + sese.getPrettyIdentifier().replaceAll(" ", "") + "___("+varString+");"; + } /* * addChecker creates a case statement for every object that is either an inset variable @@ -327,7 +342,7 @@ public class RuntimeConflictResolver { //Specific Primitives test for invars if(node.isInsetVar && node.hasPrimativeConflicts()) - handlePrimitiveConflict(prefix, node.primativeFields); + handlePrimitiveConflict(prefix, node.primativeFields, node.allocSite); // TODO orientation //Casts C pointer; depth is used to create unique "myPtr" name @@ -346,11 +361,11 @@ public class RuntimeConflictResolver { + ref.allocSite + ") { "); // Prints out conflicts of child - if (ref.child.myObjConflict) + if (ref.conflict) handleObjConflict(childPtr, node.allocSite); if(ref.child.hasPrimativeConflicts()) - handlePrimitiveConflict(childPtr, ref.child.primativeFields); + handlePrimitiveConflict(childPtr, ref.child.primativeFields, ref.child.allocSite); if (ref.child.decendantsConflict()) { // Checks if we have visited the child before @@ -378,8 +393,8 @@ public class RuntimeConflictResolver { cFile.append("printf(\"Conflict detected with %p from parent with allocation site %u\\n\"," + childPtr + "," + allocSite.hashCodeSpecific() + ");"); } - private void handlePrimitiveConflict(String ptr, ArrayList conflicts) { - cFile.append("printf(\"Primitive Conflict detected with %p\\n\", "+ptr+"); "); + private void handlePrimitiveConflict(String ptr, ArrayList conflicts, AllocSite allocSite) { + cFile.append("printf(\"Primitive Conflict detected with %p with alloc site %u\\n\", "+ptr+", "+allocSite.hashCodeSpecific()+"); "); } private Taint getProperTaint(FlatSESEEnterNode rblock, VariableNode var, @@ -473,12 +488,14 @@ public class RuntimeConflictResolver { private class ObjRef { String field; int allocSite; + boolean conflict; ConcreteRuntimeObjNode child; - public ObjRef(String fieldname, ConcreteRuntimeObjNode ref) { + public ObjRef(String fieldname, ConcreteRuntimeObjNode ref, boolean con) { field = fieldname; allocSite = ref.getAllocationSite(); child = ref; + conflict = con; } } @@ -488,7 +505,6 @@ public class RuntimeConflictResolver { ArrayList parents; HashSet conflictingParents; ConcreteRuntimeObjNode lastReferencer; - boolean myObjConflict; boolean decendantsPrimConflict; boolean decendantsObjConflict; boolean isInsetVar; @@ -502,7 +518,6 @@ public class RuntimeConflictResolver { lastReferencer = null; allocSite = me.getAllocSite(); original = me; - myObjConflict = conflict; isInsetVar = isInVar; decendantsPrimConflict = false; decendantsObjConflict = false; @@ -533,23 +548,23 @@ public class RuntimeConflictResolver { } public boolean hasConflicts() { - return (primativeFields != null) || myObjConflict; + return (primativeFields != null) || !conflictingParents.isEmpty(); } public boolean decendantsConflict() { return decendantsPrimConflict || decendantsObjConflict; } - public void addObjChild(String field, ConcreteRuntimeObjNode child) { + public void addObjChild(String field, ConcreteRuntimeObjNode child, boolean conflict) { child.lastReferencer = this; - ObjRef ref = new ObjRef(field, child); + ObjRef ref = new ObjRef(field, child, conflict); objectRefs.add(ref); child.parents.add(this); } public String toString() { - return "AllocSite=" + getAllocationSite() + " myConflict=" + myObjConflict + + return "AllocSite=" + getAllocationSite() + " myConflict=" + !conflictingParents.isEmpty() + " decCon="+decendantsObjConflict+ " NumOfParents=" + parents.size()+ " NumOfConParents=" + getNumOfReachableParents() + " ObjectChildren=" + objectRefs.size(); } diff --git a/Robust/src/buildscript b/Robust/src/buildscript index d503c662..4b898e7d 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -151,6 +151,7 @@ NOJAVA=false CHECKFLAG=false RECOVERFLAG=false MLP_ON=false +RCR=false MLPDEBUG=false MULTICOREFLAG=false RAWFLAG=false @@ -511,6 +512,9 @@ shift elif [[ $1 = '-rcr' ]] then JAVAOPTS="$JAVAOPTS -rcr" +RCR=true +EXTRAOPTIONS="$EXTRAOPTIONS -I$ROBUSTROOT/Runtime/oooJava" + elif [[ $1 = '-coreprof' ]] then @@ -1073,6 +1077,11 @@ then FILES="$FILES $ROBUSTROOT/Runtime/coreprof/coreprof.c" fi +if $RCR +then +FILES="$FILES $tmpbuilddirectory/RuntimeConflictResolver.c $ROBUSTROOT/Runtime/oooJava/hashRCR.c $ROBUSTROOT/Runtime/oooJava/Queue_RCR.c" +fi + if $MLP_ON then FILES="$FILES $ROBUSTROOT/Runtime/mlp_runtime.c"