import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
+import java.util.Vector;
+import Util.Tuple;
import Analysis.Disjoint.*;
+import Analysis.MLP.CodePlan;
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.
* Note: All computation is done upon closing the object. Steps 1-3 only input data
*/
public class RuntimeConflictResolver {
- public static final boolean javaDebug = false;
+ public static final boolean javaDebug = true;
public static final boolean cSideDebug = false;
private PrintWriter cFile;
//This keeps track of taints we've traversed to prevent printing duplicate traverse functions
//The Integer keeps track of the weakly connected group it's in (used in enumerateHeapRoots)
private Hashtable<Taint, Integer> doneTaints;
+ private Hashtable<Tuple, Integer> idMap=new Hashtable<Tuple,Integer>();
private Hashtable<Taint, Set<Effect>> globalEffects;
private Hashtable<Taint, Set<Effect>> globalConflicts;
private ArrayList<TraversalInfo> toTraverse;
+ public int currentID=1;
+
// initializing variables can be found in printHeader()
private static final String getAllocSiteInC = "->allocsite";
- private static final String queryVistedHashtable = "hashRCRInsert(";
+ private static final String queryVistedHashtable = "hashRCRInsert";
private static final String addToQueueInC = "enqueueRCRQueue(";
private static final String dequeueFromQueueInC = "dequeueRCRQueue()";
private static final String clearQueue = "resetRCRQueue()";
private static final String deallocVisitedHashTable = "hashRCRDelete()";
private static final String resetVisitedHashTable = "hashRCRreset()";
- //TODO find correct strings for these
- private static final String addCheckFromHashStructure = "checkFromHashStructure(";
- private static final String putWaitingQueueBlock = "putWaitingQueueBlock("; //lifting of blocks will be done by hashtable.
- private static final String putIntoAllocQueue = "putIntoWaitingQ(";
- private static final int noConflict = 0;
- private static final int conflictButTraverserCanContinue = 1;
- private static final int conflictButTraverserCannotContinue = 2;
- private static final int allocQueueIsNotEmpty = 0;
-
// Hashtable provides fast access to heaproot # lookups
private Hashtable<Taint, WeaklyConectedHRGroup> connectedHRHash;
private ArrayList<WeaklyConectedHRGroup> num2WeaklyConnectedHRGroup;
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"));
- cFile.append("#include \"" + hashAndQueueCFileDir + "hashRCR.h\"\n#include \""
- + hashAndQueueCFileDir + "Queue_RCR.h\"\n#include <stdlib.h>\n");
- cFile.append("#include \"classdefs.h\"\n");
- cFile.append("#include \"RuntimeConflictResolver.h\"\n");
- cFile.append("#include \"hashStructure.h\"\n");
+ cFile.println("#include \"" + hashAndQueueCFileDir + "hashRCR.h\"\n#include \""
+ + hashAndQueueCFileDir + "Queue_RCR.h\"\n#include <stdlib.h>");
+ cFile.println("#include \"classdefs.h\"");
+ cFile.println("#include \"structdefs.h\"");
+ cFile.println("#include \"mlp_runtime.h\"");
+ cFile.println("#include \"RuntimeConflictResolver.h\"");
+ cFile.println("#include \"hashStructure.h\"");
- headerFile.append("#ifndef __3_RCR_H_\n");
- headerFile.append("#define __3_RCR_H_\n");
+ headerFile.println("#ifndef __3_RCR_H_");
+ headerFile.println("#define __3_RCR_H_");
doneTaints = new Hashtable<Taint, Integer>();
connectedHRHash = new Hashtable<Taint, WeaklyConectedHRGroup>();
System.out.println("====================END LIST====================");
}
}
+
+ public void init() {
+ // Go through the SESE's
+ for (Iterator<FlatSESEEnterNode> seseit = oooa.getAllSESEs().iterator(); seseit.hasNext();) {
+ FlatSESEEnterNode fsen = seseit.next();
+ Analysis.OoOJava.ConflictGraph conflictGraph;
+ Hashtable<Taint, Set<Effect>> conflicts;
+ System.out.println("-------");
+ System.out.println(fsen);
+ System.out.println(fsen.getIsCallerSESEplaceholder());
+ System.out.println(fsen.getParent());
+
+ if (fsen.getParent() != null) {
+ conflictGraph = oooa.getConflictGraph(fsen.getParent());
+ System.out.println("CG=" + conflictGraph);
+ if (conflictGraph != null)
+ System.out.println("Conflicts=" + conflictGraph.getConflictEffectSet(fsen));
+ }
+
+ if (!fsen.getIsCallerSESEplaceholder() && fsen.getParent() != null
+ && (conflictGraph = oooa.getConflictGraph(fsen.getParent())) != null
+ && (conflicts = conflictGraph.getConflictEffectSet(fsen)) != null) {
+ FlatMethod fm = fsen.getfmEnclosing();
+ ReachGraph rg = oooa.getDisjointAnalysis().getReachGraph(fm.getMethod());
+ if (cSideDebug)
+ rg.writeGraph("RCR_RG_SESE_DEBUG");
+
+ addToTraverseToDoList(fsen, rg, conflicts);
+ }
+ }
+ // Go through the stall sites
+ for (Iterator<FlatNode> codeit = oooa.getNodesWithPlans().iterator(); codeit.hasNext();) {
+ FlatNode fn = codeit.next();
+ CodePlan cp = oooa.getCodePlan(fn);
+ FlatSESEEnterNode currentSESE = cp.getCurrentSESE();
+ Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(currentSESE);
+
+ if (graph != null) {
+ Set<Analysis.OoOJava.SESELock> seseLockSet = oooa.getLockMappings(graph);
+ Set<Analysis.OoOJava.WaitingElement> waitingElementSet =
+ graph.getStallSiteWaitingElementSet(fn, seseLockSet);
+
+ if (waitingElementSet.size() > 0) {
+ for (Iterator<Analysis.OoOJava.WaitingElement> iterator = waitingElementSet.iterator(); iterator.hasNext();) {
+ Analysis.OoOJava.WaitingElement waitingElement =
+ (Analysis.OoOJava.WaitingElement) iterator.next();
+
+ Analysis.OoOJava.ConflictGraph conflictGraph = graph;
+ Hashtable<Taint, Set<Effect>> conflicts;
+ ReachGraph rg = oooa.getDisjointAnalysis().getReachGraph(currentSESE.getmdEnclosing());
+ if (cSideDebug) {
+ rg.writeGraph("RCR_RG_STALLSITE_DEBUG");
+ }
+ if ((conflictGraph != null) && (conflicts = graph.getConflictEffectSet(fn)) != null
+ && (rg != null)) {
+ addToTraverseToDoList(fn, waitingElement.getTempDesc(), rg, conflicts);
+ }
+ }
+ }
+ }
+ }
+
+ buildEffectsLookupStructure();
+ runAllTraversals();
+ }
/*
* Basic Strategy:
* 5) Print c methods by walking internal representation
*/
- public void addToTraverseToDoList(FlatSESEEnterNode rblock, ReachGraph rg, Hashtable<Taint, Set<Effect>> conflicts) {
+ public void addToTraverseToDoList(FlatSESEEnterNode rblock, ReachGraph rg,
+ Hashtable<Taint, Set<Effect>> conflicts) {
//Add to todo list
toTraverse.add(new TraversalInfo(rblock, rg));
-
+
//Add to Global conflicts
for(Taint t: conflicts.keySet()) {
- if(globalConflicts.contains(t)) {
+ if(globalConflicts.containsKey(t)) {
globalConflicts.get(t).addAll(conflicts.get(t));
- }
- else {
+ } else {
globalConflicts.put(t, conflicts.get(t));
}
}
toTraverse.add(new TraversalInfo(fn, rg, tempDesc));
for(Taint t: conflicts.keySet()) {
- if(globalConflicts.contains(t)) {
+ if(globalConflicts.containsKey(t)) {
globalConflicts.get(t).addAll(conflicts.get(t));
- }
- else {
+ } else {
globalConflicts.put(t, conflicts.get(t));
}
}
}
- private void traverseSESEBlock(FlatSESEEnterNode rblock,
- ReachGraph rg) {
- Set<TempDescriptor> inVars = rblock.getInVarSet();
+ private void traverseSESEBlock(FlatSESEEnterNode rblock, ReachGraph rg) {
+ Collection<TempDescriptor> inVars = rblock.getInVarSet();
if (inVars.size() == 0)
return;
+ System.out.println("RBLOCK:"+rblock);
+ System.out.println("["+inVars+"]");
// For every non-primitive 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()) {
+ if(isReallyAPrimitive(type)) {
continue;
}
-
- //created stores nodes with specific alloc sites that have been traversed while building
- //internal data structure. It is later traversed sequentially to find inset variables and
+ System.out.println(invar);
+ //"created" stores nodes with specific alloc sites that have been traversed while building
+ //internal data structure. Created is later traversed sequentially to find inset variables and
//build output code.
- Hashtable<AllocSite, ConcreteRuntimeObjNode> created = new Hashtable<AllocSite, ConcreteRuntimeObjNode>();
+ //NOTE: Integer stores Allocation Site ID in hashtable
+ Hashtable<Integer, ConcreteRuntimeObjNode> created = new Hashtable<Integer, ConcreteRuntimeObjNode>();
VariableNode varNode = rg.getVariableNodeNoMutation(invar);
Taint taint = getProperTaintForFlatSESEEnterNode(rblock, varNode, globalEffects);
if (taint == null) {
printDebug(javaDebug, "Null FOR " +varNode.getTempDescriptor().getSafeSymbol() + rblock.toPrettyString());
- return;
+ continue;
}
//This is to prevent duplicate traversals from being generated
- if(doneTaints.containsKey(taint) && doneTaints.get(taint) != null)
+ if(doneTaints.containsKey(taint))
return;
doneTaints.put(taint, traverserIDCounter++);
//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);
+ for(Iterator<ConcreteRuntimeObjNode> it=created.values().iterator();it.hasNext();) {
+ ConcreteRuntimeObjNode obj=it.next();
+ if (obj.hasPrimitiveConflicts()||obj.decendantsConflict()) {
+ rblock.addInVarForDynamicCoarseConflictResolution(invar);
+ break;
+ }
+ }
+
pendingPrintout.add(new TaintAndInternalHeapStructure(taint, created));
}
}
}
-
- private void traverseStallSite(
- FlatNode enterNode,
- TempDescriptor invar,
- ReachGraph rg) {
+ //This extends a tempDescriptor's isPrimitive test by also excluding primitive arrays.
+ private boolean isReallyAPrimitive(TypeDescriptor type) {
+ return (type.isPrimitive() && !type.isArray());
+ }
+
+ private void traverseStallSite(FlatNode enterNode, TempDescriptor invar, ReachGraph rg) {
TypeDescriptor type = invar.getType();
- if(type == null || type.isPrimitive()) {
+ if(type == null || isReallyAPrimitive(type)) {
return;
}
- Hashtable<AllocSite, ConcreteRuntimeObjNode> created = new Hashtable<AllocSite, ConcreteRuntimeObjNode>();
+
+ Hashtable<Integer, ConcreteRuntimeObjNode> created = new Hashtable<Integer, ConcreteRuntimeObjNode>();
VariableNode varNode = rg.getVariableNodeNoMutation(invar);
Taint taint = getProperTaintForEnterNode(enterNode, varNode, globalEffects);
return;
}
- if(doneTaints.containsKey(taint) && doneTaints.get(taint) != null)
+ if(doneTaints.containsKey(taint))
return;
doneTaints.put(taint, traverserIDCounter++);
String flatname;
if(fn instanceof FlatSESEEnterNode) {
flatname = ((FlatSESEEnterNode) fn).getPrettyIdentifier();
- }
- else {
+ } else {
flatname = fn.toString();
}
- return "traverse___" + removeInvalidChars(invar.getSafeSymbol()) +
+ return "traverse___" + invar.getSafeSymbol() +
removeInvalidChars(flatname) + "___("+varString+");";
}
+
+ public int getTraverserID(TempDescriptor invar, FlatNode fn) {
+ Tuple t=new Tuple(invar, fn);
+ if (idMap.containsKey(t))
+ return idMap.get(t).intValue();
+ int value=currentID++;
+ idMap.put(t, new Integer(value));
+ return value;
+ }
public String removeInvalidChars(String in) {
StringBuilder s = new StringBuilder(in);
for(int i = 0; i < s.length(); i++) {
- if(s.charAt(i) == ' ' || s.charAt(i) == '.' || s.charAt(i) == '=') {
+ if(s.charAt(i) == ' ' || s.charAt(i) == '.' || s.charAt(i) == '='||s.charAt(i)=='['||s.charAt(i)==']') {
s.deleteCharAt(i);
i--;
}
}
public void close() {
- buildEffectsLookupStructure();
- runAllTraverserals();
-
//prints out all generated code
for(TaintAndInternalHeapStructure ths: pendingPrintout) {
printCMethod(ths.nodesInHeap, ths.t);
}
- //Prints out the master traverser Invocation that'll call all other traverser
+ //Prints out the master traverser Invocation that'll call all other traversers
//based on traverserID
printMasterTraverserInvocation();
+ printResumeTraverserInvocation();
//TODO this is only temporary, remove when thread local vars implemented.
createMasterHashTableArray();
// Adds Extra supporting methods
- cFile.append("void initializeStructsRCR() { " + mallocVisitedHashtable + "; " + clearQueue + "; }");
- cFile.append("void destroyRCR() { " + deallocVisitedHashTable + "; }\n");
+ cFile.println("void initializeStructsRCR() {\n " + mallocVisitedHashtable + ";\n " + clearQueue + ";\n}");
+ cFile.println("void destroyRCR() {\n " + deallocVisitedHashTable + ";\n}");
- headerFile.append("void initializeStructsRCR(); \nvoid destroyRCR(); \n");
- headerFile.append("#endif\n");
+ headerFile.println("void initializeStructsRCR();\nvoid destroyRCR();");
+ headerFile.println("#endif\n");
cFile.close();
headerFile.close();
}
//Builds Effects Table and runs the analysis on them to get weakly connected HRs
- //SPECIAL NOTE: Only runs after we've taken all the conflicts
+ //SPECIAL NOTE: Only runs after we've taken all the conflicts and effects
private void buildEffectsLookupStructure(){
effectsLookupTable = new EffectsTable(globalEffects, globalConflicts);
- effectsLookupTable.runAnaylsis();
+ effectsLookupTable.runAnalysis();
enumerateHeaproots();
}
- private void runAllTraverserals() {
+ private void runAllTraversals() {
for(TraversalInfo t: toTraverse) {
printDebug(javaDebug, "Running Traversal a traversal on " + t.f);
if(t.f instanceof FlatSESEEnterNode) {
traverseSESEBlock((FlatSESEEnterNode)t.f, t.rg);
- }
- else {
+ } else {
if(t.invar == null) {
System.out.println("RCR ERROR: Attempted to run a stall site traversal with NO INVAR");
- }
- else {
+ } else {
traverseStallSite(t.f, t.invar, t.rg);
}
}
//TODO: This is only temporary, remove when thread local variables are functional.
private void createMasterHashTableArray() {
- headerFile.append("void createAndFillMasterHashStructureArray();");
- cFile.append("void createAndFillMasterHashStructureArray() { " +
- "createMasterHashTableArray("+weaklyConnectedHRCounter + ");");
+ headerFile.println("void createAndFillMasterHashStructureArray();");
+ cFile.println("void createAndFillMasterHashStructureArray() {\n" +
+ " rcr_createMasterHashTableArray("+weaklyConnectedHRCounter + ");");
for(int i = 0; i < weaklyConnectedHRCounter; i++) {
- cFile.append("allHashStructures["+i+"] = (HashStructure *) createhashTable("+num2WeaklyConnectedHRGroup.get(i).connectedHRs.size()+");}");
+ cFile.println(" allHashStructures["+i+"] = (HashStructure *) rcr_createHashtable("+num2WeaklyConnectedHRGroup.get(i).connectedHRs.size()+");");
}
+ cFile.println("}");
}
- //This will print the traverser invocation that takes in a traverserID and
- //starting ptr
private void printMasterTraverserInvocation() {
- headerFile.println("\nint traverse(void * startingPtr, int traverserID);");
- cFile.println("\nint traverse(void * startingPtr, int traverserID) {" +
- "switch(traverserID) { ");
+ headerFile.println("\nint tasktraverse(SESEcommon * record);");
+ cFile.println("\nint tasktraverse(SESEcommon * record) {");
+ cFile.println(" if(!CAS(&record->rcrstatus,1,2)) return;");
+ 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+", rec", fsen));
+ }
+ cFile.println( " }");
+ cFile.println( " break;");
+ }
for(Taint t: doneTaints.keySet()) {
- cFile.println(" case " + doneTaints.get(t)+ ": ");
- if(t.isRBlockTaint()) {
- cFile.println(" " + this.getTraverserInvocation(t.getVar(), "startingPtr", t.getSESE()));
+ if (t.isStallSiteTaint()){
+ cFile.println( " case -" + getTraverserID(t.getVar(), t.getStallSite())+ ": {");
+ cFile.println( " SESEstall * rec=(SESEstall*) record;");
+ cFile.println( " " + this.getTraverserInvocation(t.getVar(), "rec->___obj___, rec", t.getStallSite())+";");
+ cFile.println( " }");
+ cFile.println(" break;");
}
- else if (t.isStallSiteTaint()){
- cFile.println(" " + this.getTraverserInvocation(t.getVar(), "startingPtr", t.getStallSite()));
+ }
+
+ cFile.println(" default:\n printf(\"Invalid SESE ID was passed in: %d.\\n\",record->classID);\n break;");
+
+ cFile.println(" }");
+ cFile.println("}");
+ }
+
+
+ //This will print the traverser invocation that takes in a traverserID and starting ptr
+ private void printResumeTraverserInvocation() {
+ headerFile.println("\nint traverse(void * startingPtr, SESEcommon * record, int traverserID);");
+ cFile.println("\nint traverse(void * startingPtr, SESEcommon *record, int traverserID) {");
+ cFile.println(" switch(traverserID) {");
+
+ for(Taint t: doneTaints.keySet()) {
+ cFile.println(" case " + doneTaints.get(t)+ ":");
+ if(t.isRBlockTaint()) {
+ cFile.println(" " + this.getTraverserInvocation(t.getVar(), "startingPtr, ("+t.getSESE().getSESErecordName()+" *)record", t.getSESE()));
+ } else if (t.isStallSiteTaint()){
+ cFile.println("/* " + this.getTraverserInvocation(t.getVar(), "startingPtr, record", t.getStallSite())+"*/");
} else {
System.out.println("RuntimeConflictResolver encountered a taint that is neither SESE nor stallsite: " + t);
}
+ cFile.println(" break;");
}
if(RuntimeConflictResolver.cSideDebug) {
- cFile.println(" default: printf(\"invalid traverser ID %u was passed in.\\n\", traverserID);\n break; ");
+ cFile.println(" default:\n printf(\"Invalid traverser ID %u was passed in.\\n\", traverserID);\n break;");
} else {
- cFile.println(" default: break; ");
+ cFile.println(" default:\n break;");
}
- cFile.println("}}");
+ cFile.println(" }");
+ cFile.println("}");
}
private void createConcreteGraph(
EffectsTable table,
- Hashtable<AllocSite, ConcreteRuntimeObjNode> created,
+ Hashtable<Integer, ConcreteRuntimeObjNode> created,
VariableNode varNode,
Taint t) {
if (table == null)
return;
- Iterator<RefEdge> possibleEdges = varNode.iteratorToReferencees();
+ Iterator<RefEdge> possibleEdges = varNode.iteratorToReferencees();
while (possibleEdges.hasNext()) {
RefEdge edge = possibleEdges.next();
assert edge != null;
ConcreteRuntimeObjNode singleRoot = new ConcreteRuntimeObjNode(edge.getDst(), true);
- AllocSite rootKey = singleRoot.allocSite;
+ int rootKey = singleRoot.allocSite.getUniqueAllocSiteID();
if (!created.containsKey(rootKey)) {
created.put(rootKey, singleRoot);
}
}
}
-
- //This code is the old way of generating an effects lookup table.
- //The new way is to instantiate an EffectsGroup
- @Deprecated
- private Hashtable<AllocSite, EffectsGroup> generateEffectsLookupTable(
- Taint taint, Hashtable<Taint,
- Set<Effect>> effects,
- Hashtable<Taint, Set<Effect>> conflicts) {
- if(taint == null)
- return null;
-
- Set<Effect> localEffects = effects.get(taint);
- Set<Effect> localConflicts = conflicts.get(taint);
-
- //Debug Code for manually checking effects
- if(javaDebug) {
- printEffectsAndConflictsSets(taint, localEffects, localConflicts);
- }
-
- if (localEffects == null || localEffects.isEmpty() || localConflicts == null || localConflicts.isEmpty())
- return null;
-
- Hashtable<AllocSite, EffectsGroup> lookupTable = new Hashtable<AllocSite, EffectsGroup>();
-
- 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.addObjEffect(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<RefEdge> edges,
- Hashtable<AllocSite, ConcreteRuntimeObjNode> created,
+ Hashtable<Integer, ConcreteRuntimeObjNode> created,
EffectsTable table,
Taint taint) {
assert table != null;
//If there are no effects, then there's no point in traversing this edge
if(effectsForGivenField != null) {
HeapRegionNode childHRN = edge.getDst();
- AllocSite childKey = childHRN.getAllocSite();
+ int childKey = childHRN.getAllocSite().getUniqueAllocSiteID();
boolean isNewChild = !created.containsKey(childKey);
ConcreteRuntimeObjNode child;
if(isNewChild) {
child = new ConcreteRuntimeObjNode(childHRN, false);
created.put(childKey, child);
- }
- else {
+ } else {
child = created.get(childKey);
}
curr.addObjChild(field, child, effectsForGivenField);
if (effectsForGivenField.hasConflict()) {
- child.hasPotentialToBeIncorrectDueToConflict = true;
- propogateObjConflict(curr, child);
+ child.hasPotentialToBeIncorrectDueToConflict |= effectsForGivenField.hasReadConflict;
+ propagateObjConflict(curr, child);
}
if(effectsForGivenField.hasReadEffect) {
//If isNewChild, flag propagation will be handled at recursive call
if(isNewChild) {
createHelper(child, childHRN.iteratorToReferencees(), created, table, taint);
- }
- else {
+ } else {
//This makes sure that all conflicts below the child is propagated up the referencers.
if(child.decendantsPrimConflict || child.hasPrimitiveConflicts()) {
- propogatePrimConflict(child, child.enqueueToWaitingQueueUponConflict);
+ propagatePrimConflict(child, child.enqueueToWaitingQueueUponConflict);
}
if(child.decendantsObjConflict) {
- propogateObjConflict(child, child.enqueueToWaitingQueueUponConflict);
+ propagateObjConflict(child, child.enqueueToWaitingQueueUponConflict);
}
}
}
}
//Handles primitives
- if(currEffects.hasPrimativeConflicts()) {
- curr.conflictingPrimitiveFields = currEffects.primativeConflictingFields;
+ curr.primitiveConflictingFields = currEffects.primitiveConflictingFields;
+ if(currEffects.hasPrimitiveConflicts()) {
//Reminder: primitive conflicts are abstracted to object.
- curr.hasPotentialToBeIncorrectDueToConflict = true;
- propogatePrimConflict(curr, curr);
+ propagatePrimConflict(curr, curr);
}
}
// This will propagate the conflict up the data structure.
- private void propogateObjConflict(ConcreteRuntimeObjNode curr, HashSet<ConcreteRuntimeObjNode> pointsOfAccess) {
+ private void propagateObjConflict(ConcreteRuntimeObjNode curr, HashSet<ConcreteRuntimeObjNode> pointsOfAccess) {
for(ConcreteRuntimeObjNode referencer: curr.parentsWithReadToNode) {
if(curr.parentsThatWillLeadToConflicts.add(referencer) || //case where referencee has never seen referncer
(pointsOfAccess != null && referencer.addPossibleWaitingQueueEnqueue(pointsOfAccess))) // case where referencer has never seen possible unresolved referencee below
{
referencer.decendantsObjConflict = true;
- propogateObjConflict(referencer, pointsOfAccess);
+ propagateObjConflict(referencer, pointsOfAccess);
}
}
}
- private void propogateObjConflict(ConcreteRuntimeObjNode curr, ConcreteRuntimeObjNode pointOfAccess) {
+ private void propagateObjConflict(ConcreteRuntimeObjNode curr, ConcreteRuntimeObjNode pointOfAccess) {
for(ConcreteRuntimeObjNode referencer: curr.parentsWithReadToNode) {
if(curr.parentsThatWillLeadToConflicts.add(referencer) || //case where referencee has never seen referncer
(pointOfAccess != null && referencer.addPossibleWaitingQueueEnqueue(pointOfAccess))) // case where referencer has never seen possible unresolved referencee below
{
referencer.decendantsObjConflict = true;
- propogateObjConflict(referencer, pointOfAccess);
+ propagateObjConflict(referencer, pointOfAccess);
}
}
}
- private void propogatePrimConflict(ConcreteRuntimeObjNode curr, HashSet<ConcreteRuntimeObjNode> pointsOfAccess) {
+ private void propagatePrimConflict(ConcreteRuntimeObjNode curr, HashSet<ConcreteRuntimeObjNode> pointsOfAccess) {
for(ConcreteRuntimeObjNode referencer: curr.parentsWithReadToNode) {
if(curr.parentsThatWillLeadToConflicts.add(referencer) || //same cases as above
(pointsOfAccess != null && referencer.addPossibleWaitingQueueEnqueue(pointsOfAccess)))
{
referencer.decendantsPrimConflict = true;
- propogatePrimConflict(referencer, pointsOfAccess);
+ propagatePrimConflict(referencer, pointsOfAccess);
}
}
}
- private void propogatePrimConflict(ConcreteRuntimeObjNode curr, ConcreteRuntimeObjNode pointOfAccess) {
+ private void propagatePrimConflict(ConcreteRuntimeObjNode curr, ConcreteRuntimeObjNode pointOfAccess) {
for(ConcreteRuntimeObjNode referencer: curr.parentsWithReadToNode) {
if(curr.parentsThatWillLeadToConflicts.add(referencer) || //same cases as above
(pointOfAccess != null && referencer.addPossibleWaitingQueueEnqueue(pointOfAccess)))
{
referencer.decendantsPrimConflict = true;
- propogatePrimConflict(referencer, pointOfAccess);
+ propagatePrimConflict(referencer, pointOfAccess);
}
}
}
-
-
/*
* This method generates a C method for every inset variable and rblock.
*
* signal a conflict within itself.
*/
- private void printCMethod(Hashtable<AllocSite, ConcreteRuntimeObjNode> created, Taint taint) {
- //This hash table keeps track of all the case statements generated. Although it may seem a bit much
- //for its purpose, I think it may come in handy later down the road to do it this way.
- //(i.e. what if we want to eliminate some cases? Or build filter for 1 case)
+ private void printCMethod(Hashtable<Integer, ConcreteRuntimeObjNode> created, Taint taint) {
String inVar = taint.getVar().getSafeSymbol();
String rBlock;
if(taint.isStallSiteTaint()) {
rBlock = taint.getStallSite().toString();
- }
- else if(taint.isRBlockTaint()) {
- rBlock = taint.getSESE().toPrettyString();
- }
- else {
+ } else if(taint.isRBlockTaint()) {
+ rBlock = taint.getSESE().getPrettyIdentifier();
+ } else {
System.out.println("RCR CRITICAL ERROR: TAINT IS NEITHER A STALLSITE NOR SESE! " + taint.toString());
return;
}
+ //This hash table keeps track of all the case statements generated.
Hashtable<AllocSite, StringBuilder> cases = new Hashtable<AllocSite, StringBuilder>();
//Generate C cases
for (ConcreteRuntimeObjNode node : created.values()) {
- if (!cases.containsKey(node.allocSite) && (
- //insetVariable case
- (node.isInsetVar && (node.decendantsConflict() || node.hasPrimitiveConflicts())) ||
- //non-inline-able code cases
- (node.getNumOfReachableParents() != 1 && node.decendantsConflict()) ||
- //Cases where resumes are possible
- (node.hasPotentialToBeIncorrectDueToConflict) && node.decendantsObjConflict)) {
-
- printDebug(javaDebug, node.allocSite + " qualified for case statement");
+ printDebug(javaDebug, "Considering " + node.allocSite + " for traversal");
+ if (!cases.containsKey(node.allocSite) && qualifiesForCaseStatement(node)) {
+ printDebug(javaDebug, "+\t" + node.allocSite + " qualified for case statement");
addChecker(taint, node, cases, null, "ptr", 0);
}
}
- //IMPORTANT: remember to change getTraverserInvocation if you change the line below
- String methodName = "void traverse___" + removeInvalidChars(inVar) +
- removeInvalidChars(rBlock) + "___(void * InVar)";
- cFile.append(methodName + " {\n");
- headerFile.append(methodName + ";\n");
+ String methodName;
+ int index=-1;
+
+ if (taint.isStallSiteTaint()) {
+ methodName= "void traverse___" + inVar + removeInvalidChars(rBlock) + "___(void * InVar, SESEstall *record)";
+ } else {
+ methodName= "void traverse___" + inVar + removeInvalidChars(rBlock) + "___(void * InVar, "+taint.getSESE().getSESErecordName() +" *record)";
+ FlatSESEEnterNode fsese=taint.getSESE();
+ TempDescriptor tmp=taint.getVar();
+ index=fsese.getInVarsForDynamicCoarseConflictResolution().indexOf(tmp);
+ }
+
+ cFile.println(methodName + " {");
+ headerFile.println(methodName + ";");
if(cSideDebug) {
- cFile.append("printf(\"The traverser ran for " + methodName + "\\n\");\n");
- }
+ cFile.println("printf(\"The traverser ran for " + methodName + "\\n\");");
+ }
+
if(cases.size() == 0) {
- cFile.append(" return; }");
- }
- else {
- //clears queue and hashtable that keeps track of where we've been.
- cFile.append(clearQueue + "; " + resetVisitedHashTable + "; \n");
+ cFile.println(" return;");
+ } else {
+ cFile.println(" int totalcount=RUNBIAS;\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) { " + queryVistedHashtable
- + "ptr); do { ");
+ if (taint.isStallSiteTaint()) {
+ cFile.println(" record->rcrRecords[0].count=RUNBIAS;\n");
+ } else {
+ cFile.println(" record->rcrRecords["+index+"].count=RUNBIAS;\n");
+ cFile.println(" record->rcrRecords["+index+"].index=0;\n");
+ }
- cFile.append("switch(ptr->allocsite) { ");
+ //clears queue and hashtable that keeps track of where we've been.
+ cFile.println(clearQueue + ";\n" + resetVisitedHashTable + ";");
+ //generic cast to ___Object___ to access ptr->allocsite field.
+ cFile.println("struct ___Object___ * ptr = (struct ___Object___ *) InVar;\nif (InVar != NULL) {\n " + queryVistedHashtable + "(ptr);\n do {");
+ if (taint.isRBlockTaint()) {
+ cFile.println(" if(unlikely(record->common.doneExecuting)) {");
+ cFile.println(" record->common.rcrstatus=0;");
+ cFile.println(" return;");
+ cFile.println(" }");
+ }
+ cFile.println(" switch(ptr->allocsite) {");
- for(AllocSite singleCase: cases.keySet())
+ for(AllocSite singleCase: cases.keySet()) {
cFile.append(cases.get(singleCase));
+ }
+
+ cFile.println(" default:\n break; ");
+ cFile.println(" }\n } while((ptr = " + dequeueFromQueueInC + ") != NULL);\n}");
- cFile.append(" default : break; ");
- cFile.append("}} while( (ptr = " + dequeueFromQueueInC + ") != NULL); }}");
+ if (taint.isStallSiteTaint()) {
+ //need to add this
+ cFile.println(" if(atomic_sub_and_test(RUNBIAS-totalcount,&(record->rcrRecords[0].count))) {");
+ cFile.println(" psem_give_tag(record->common.parentsStallSem, record->tag);");
+ cFile.println(" BARRIER();");
+ cFile.println(" record->common.rcrstatus=0;");
+ cFile.println("}");
+ } else {
+ cFile.println(" if(atomic_sub_and_test(RUNBIAS-totalcount,&(record->rcrRecords["+index+"].count))) {");
+ cFile.println(" int flag=LOCKXCHG32(&(record->rcrRecords["+index+"].flag),0);");
+ cFile.println(" if(flag) {");
+ //we have resolved a heap root...see if this was the last dependence
+ cFile.println(" if(atomic_sub_and_test(1, &(record->common.unresolvedDependencies))) workScheduleSubmit((void *)record);");
+ cFile.println(" }");
+ cFile.println(" }");
+ cFile.println(" record->common.rcrstatus=0;");
+ }
}
+ cFile.println("}");
cFile.flush();
}
/*
- * addChecker creates a case statement for every object that is either an inset variable
- * or has multiple referencers (incoming edges). Else it just prints the checker for that object
- * so that its processing can be pushed up to the referencer node.
+ * addChecker creates a case statement for every object that is an inset variable, has more
+ * than 1 parent && has conflicts, or where resumes are possible (from waiting queue).
+ * See .qualifiesForCaseStatement
*/
private void addChecker(Taint taint,
ConcreteRuntimeObjNode node,
String prefix,
int depth) {
StringBuilder currCase = possibleContinuingCase;
- // We don't need a case statement for things with either 1 incoming or 0 out
- // going edges, because they can be processed when checking the parent.
- if((node.isInsetVar && (node.decendantsConflict() || node.hasPrimitiveConflicts())) ||
- (node.getNumOfReachableParents() != 1 && node.decendantsConflict()) ||
- node.hasPotentialToBeIncorrectDueToConflict && node.decendantsObjConflict) {
+ if(qualifiesForCaseStatement(node)) {
assert prefix.equals("ptr") && !cases.containsKey(node.allocSite);
currCase = new StringBuilder();
cases.put(node.allocSite, currCase);
- currCase.append("case " + node.getAllocationSite() + ":\n { ");
+ currCase.append(" case " + node.getAllocationSite() + ": {\n");
}
//either currCase is continuing off a parent case or is its own.
assert currCase !=null;
- //Casts C pointer; depth is used to create unique "myPtr" name for when things are inlined
- String currPtr = "myPtr" + depth;
-
- String structType = node.original.getType().getSafeSymbol();
- currCase.append(" struct " + structType + " * "+currPtr+"= (struct "+ structType + " * ) " + prefix + "; ");
-
- //Primitives Test
- if(node.hasPrimitiveConflicts()) {
- //This will check hashstructure, if cannot continue, add all to waiting queue and break; s
- addCheckHashtableAndWaitingQ(currCase, taint, node, currPtr, depth);
- currCase.append(" break; } ");
+ boolean primConfRead=false;
+ boolean primConfWrite=false;
+ boolean objConfRead=false;
+ boolean objConfWrite=false;
+
+ //Direct Primitives Test
+ for(String field: node.primitiveConflictingFields.keySet()) {
+ CombinedObjEffects effect=node.primitiveConflictingFields.get(field);
+ primConfRead|=effect.hasReadConflict;
+ primConfWrite|=effect.hasWriteConflict;
+ }
+
+ //Direct Object Reference Test
+ for(String field: node.objectRefs.keySet()) {
+ for(ObjRef ref: node.objectRefs.get(field)) {
+ CombinedObjEffects effect=ref.myEffects;
+ objConfRead|=effect.hasReadConflict;
+ objConfWrite|=effect.hasWriteConflict;
+ }
+ }
+
+ int index=-1;
+ if (taint.isRBlockTaint()) {
+ FlatSESEEnterNode fsese=taint.getSESE();
+ TempDescriptor tmp=taint.getVar();
+ index=fsese.getInVarsForDynamicCoarseConflictResolution().indexOf(tmp);
}
-
- //Conflicts
- for (ObjRef ref : node.objectRefs) {
- // Will only process edge if there is some sort of conflict with the Child
- if (ref.hasConflictsDownThisPath()) {
- String childPtr = currPtr +"->___" + ref.field + "___";
- // Checks if the child exists and has allocsite matching the conflict
- currCase.append(" if(" + childPtr + " != NULL && " + childPtr + getAllocSiteInC + "=="
- + ref.allocSite + ") { ");
+ String strrcr=taint.isRBlockTaint()?"&record->rcrRecords["+index+"], ":"NULL, ";
+
+ //Do call if we need it.
+ if(primConfWrite||objConfWrite) {
+ int heaprootNum = connectedHRHash.get(taint).id;
+ assert heaprootNum != -1;
+ int allocSiteID = connectedHRHash.get(taint).getWaitingQueueBucketNum(node);
+ int traverserID = doneTaints.get(taint);
+ currCase.append(" int tmpkey"+depth+"=rcr_generateKey("+prefix+");\n");
+ if (objConfRead)
+ currCase.append(" int tmpvar"+depth+"=rcr_WTWRITEBINCASE(allHashStructures["+heaprootNum+"], tmpkey"+depth+", (SESEcommon *) record, "+strrcr+index+");\n");
+ else
+ currCase.append(" int tmpvar"+depth+"=rcr_WRITEBINCASE(allHashStructures["+heaprootNum+"], tmpkey"+depth+", (SESEcommon *) record, "+strrcr+index+");\n");
+ } 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(" int tmpkey"+depth+"=rcr_generateKey("+prefix+");\n");
+ if (objConfRead)
+ currCase.append(" int tmpvar"+depth+"=rcr_WTREADBINCASE(allHashStructures["+heaprootNum+"], tmpkey"+depth+", (SESEcommon *) record, "+strrcr+index+");\n");
+ else
+ currCase.append(" int tmpvar"+depth+"=rcr_READBINCASE(allHashStructures["+heaprootNum+"], tmpkey"+depth+", (SESEcommon *) record, "+strrcr+index+");\n");
+ }
+ if(primConfWrite||objConfWrite||primConfRead||objConfRead) {
+ currCase.append("if (!(tmpvar"+depth+"&READYMASK)) totalcount--;\n");
+ }
+
+ //Handle conflicts further down.
+ if(node.decendantsConflict()) {
+ int pdepth=depth+1;
+ currCase.append("{\n");
+
+ //Array Case
+ if(node.isArray() && node.decendantsConflict()) {
+ String childPtr = "((struct ___Object___ **)(((char *) &(((struct ArrayObject *)"+ prefix+")->___length___))+sizeof(int)))[i]";
+ String currPtr = "arrayElement" + pdepth;
- //Handles Direct Conflicts on child.
- if(ref.hasDirectObjConflict()) {
- //This method will touch the waiting queues if necessary.
- addCheckHashtableAndWaitingQ(currCase, taint, ref.child, childPtr, depth);
- //Else if we can continue continue.
- currCase.append(" } else { ");
- }
+ currCase.append("{\n int i;\n");
+ currCase.append(" struct ___Object___ * "+currPtr+";\n");
+ currCase.append(" for(i = 0; i<((struct ArrayObject *) " + prefix + " )->___length___; i++ ) {\n");
- //If there are no direct conflicts (determined by static + dynamic), finish check
- if (ref.child.decendantsConflict() || ref.child.hasPrimitiveConflicts()) {
- // Checks if we have visited the child before
- currCase.append(" if(" + queryVistedHashtable + childPtr + ")) { ");
- if (ref.child.getNumOfReachableParents() == 1 && !ref.child.isInsetVar) {
- addChecker(taint, ref.child, cases, currCase, childPtr, depth + 1);
- }
- else {
- currCase.append(" " + addToQueueInC + childPtr + "); ");
- }
+ //There should be only one field, hence we only take the first field in the keyset.
+ assert node.objectRefs.keySet().size() <= 1;
+ ObjRefList refsAtParticularField = node.objectRefs.get(node.objectRefs.keySet().iterator().next());
+ printObjRefSwitchStatement(taint,cases,pdepth,currCase,refsAtParticularField,childPtr,currPtr);
+ currCase.append(" }}\n");
+ } else {
+ //All other cases
+ String currPtr = "myPtr" + pdepth;
+ currCase.append(" struct ___Object___ * "+currPtr+";\n");
+ for(String field: node.objectRefs.keySet()) {
+ ObjRefList refsAtParticularField = node.objectRefs.get(field);
- currCase.append(" } ");
- }
- //one more brace for the opening if
- if(ref.hasDirectObjConflict()) {
- currCase.append(" } ");
- }
-
- currCase.append(" } ");
+ if(refsAtParticularField.hasConflicts()) {
+ String childPtr = "((struct "+node.original.getType().getSafeSymbol()+" *)"+prefix +")->___" + field + "___";
+ printObjRefSwitchStatement(taint, cases, depth, currCase, refsAtParticularField, childPtr, currPtr);
+ }
+ }
}
+
+ currCase.append("}\n"); //For particular top level case statement.
}
-
- if((node.isInsetVar && (node.decendantsConflict() || node.hasPrimitiveConflicts())) ||
- (node.getNumOfReachableParents() != 1 && node.decendantsConflict()) ||
- (node.hasPotentialToBeIncorrectDueToConflict && node.decendantsObjConflict)) {
- currCase.append(" } break; \n");
+ if(qualifiesForCaseStatement(node)) {
+ currCase.append(" }\n break;\n");
}
}
- //This method will touch the waiting queues if necessary.
- //IMPORTANT NOTE: This needs a closing } from the caller and the if is cannot continue
- private void addCheckHashtableAndWaitingQ(StringBuilder currCase, Taint t, ConcreteRuntimeObjNode node, String ptr, int depth) {
- Iterator<ConcreteRuntimeObjNode> it = node.enqueueToWaitingQueueUponConflict.iterator();
-
- currCase.append("int retval"+depth+" = "+ addCheckFromHashStructure + ptr + ");");
- currCase.append("if(retval"+depth+" == " + conflictButTraverserCannotContinue + " || ");
- checkWaitingQueue(currCase, t, node);
- currCase.append(") { \n");
- //If cannot continue, then add all the undetermined references that lead from this child, including self.
- //TODO need waitingQueue Side to automatically check the thing infront of it to prevent double adds.
- putIntoWaitingQueue(currCase, t, node, ptr);
-
- ConcreteRuntimeObjNode related;
- while(it.hasNext()) {
- related = it.next();
- //TODO maybe ptr won't even be needed since upon resume, the hashtable will remove obj.
- putIntoWaitingQueue(currCase, t, related, ptr);
+ private void printObjRefSwitchStatement(Taint taint, Hashtable<AllocSite, StringBuilder> cases,
+ int pDepth, StringBuilder currCase, ObjRefList refsAtParticularField, String childPtr,
+ String currPtr) {
+
+ currCase.append(" "+currPtr+"= (struct ___Object___ * ) " + childPtr + ";\n");
+ currCase.append(" if (" + currPtr + " != NULL) { \n");
+ currCase.append(" switch(" + currPtr + getAllocSiteInC + ") {\n");
+
+ for(ObjRef ref: refsAtParticularField) {
+ if(ref.child.decendantsConflict() || ref.child.hasPrimitiveConflicts()) {
+ currCase.append(" case "+ref.allocSite+":\n {\n");
+ //The hash insert is here because we don't want to enqueue things unless we know it conflicts.
+ currCase.append(" if (" + queryVistedHashtable +"("+ currPtr + ")) {\n");
+
+ //Either it's an in-lineable case or we're just handling primitive conflicts
+ if ((ref.child.getNumOfReachableParents() == 1 && !ref.child.isInsetVar) ||
+ (ref.child.hasPrimitiveConflicts() && !qualifiesForCaseStatement(ref.child)))
+ {
+ addChecker(taint, ref.child, cases, currCase, currPtr, pDepth + 1);
+ }
+ else {
+ //if we are going to insert something into the queue,
+ //we should be able to resume traverser from it.
+ assert qualifiesForCaseStatement(ref.child);
+ currCase.append(" " + addToQueueInC + childPtr + ");\n ");
+ }
+ currCase.append(" }\n"); //close for queryVistedHashtable
+
+ currCase.append("}\n"); //close for internal case statement
+ }
}
- }
-
- /*
- private void handleObjConflict(StringBuilder currCase, String childPtr, AllocSite allocSite, ObjRef ref) {
- currCase.append("printf(\"Conflict detected with %p from parent with allocation site %u\\n\"," + childPtr + "," + allocSite.getUniqueAllocSiteID() + ");");
+
+ currCase.append(" default:\n" +
+ " break;\n"+
+ " }}\n"); //internal switch.
}
- private void handlePrimitiveConflict(StringBuilder currCase, String ptr, ArrayList<String> conflicts, AllocSite allocSite) {
- currCase.append("printf(\"Primitive Conflict detected with %p with alloc site %u\\n\", "+ptr+", "+allocSite.getUniqueAllocSiteID()+"); ");
+ private boolean qualifiesForCaseStatement(ConcreteRuntimeObjNode node) {
+ return (
+ //insetVariable case
+ (node.isInsetVar && (node.decendantsConflict() || node.hasPrimitiveConflicts())) ||
+ //non-inline-able code cases
+ (node.getNumOfReachableParents() != 1 && node.decendantsConflict()) ||
+ //Cases where resumes are possible
+ (node.hasPotentialToBeIncorrectDueToConflict) && node.decendantsObjConflict);
}
- */
private Taint getProperTaintForFlatSESEEnterNode(FlatSESEEnterNode rblock, VariableNode var,
Hashtable<Taint, Set<Effect>> effects) {
}
return null;
}
-
- private void printEffectsAndConflictsSets(Taint taint, Set<Effect> localEffects,
- Set<Effect> localConflicts) {
- System.out.println("#### List of Effects/Conflicts ####");
- System.out.println("For Taint " + taint);
- System.out.println("Effects");
- if(localEffects != null) {
- for(Effect e: localEffects) {
- System.out.println(e);
- }
- }
- System.out.println("Conflicts");
- if(localConflicts != null) {
- for(Effect e: localConflicts) {
- System.out.println(e);
- }
- }
- }
private void printDebug(boolean guard, String debugStatements) {
if(guard)
System.out.println(debugStatements);
}
- //TODO finish this once waitingQueue side is figured out
- private void putIntoWaitingQueue(StringBuilder sb, Taint taint, ConcreteRuntimeObjNode node, String resumePtr ) {
- //Method looks like this: void put(int allocSiteID, x
- //struct WaitingQueue * queue, //get this from hashtable
- //int effectType, //not so sure we would actually need this one.
- //void * resumePtr,
- //int traverserID); }
- int heaprootNum = connectedHRHash.get(taint).id;
- assert heaprootNum != -1;
- int allocSiteID = connectedHRHash.get(taint).getWaitingQueueBucketNum(node);
- int traverserID = doneTaints.get(taint);
-
- //NOTE if the C-side is changed, this will have to be changed accordingly
- //TODO make sure this matches c-side
- sb.append("put("+allocSiteID+", " +
- "allHashStructures["+ heaprootNum +"]->waitingQueue, " +
- resumePtr + ", " +
- traverserID+");");
- }
-
- //TODO finish waitingQueue side
- /**
- * Inserts check to see if waitingQueue is occupied.
- *
- * On C-side, =0 means empty queue, else occupied.
- */
- private void checkWaitingQueue(StringBuilder sb, Taint taint, ConcreteRuntimeObjNode node) {
- //Method looks like int check(struct WaitingQueue * queue, int allocSiteID)
- assert sb != null && taint !=null;
- int heaprootNum = connectedHRHash.get(taint).id;
- assert heaprootNum != -1;
- int allocSiteID = connectedHRHash.get(taint).getWaitingQueueBucketNum(node);
-
- sb.append(" (check(" + "allHashStructures["+ heaprootNum +"]->waitingQueue, " + allocSiteID + ") == "+ allocQueueIsNotEmpty+") ");
- }
-
private void enumerateHeaproots() {
- //reset numbers jsut in case
weaklyConnectedHRCounter = 0;
num2WeaklyConnectedHRGroup = new ArrayList<WeaklyConectedHRGroup>();
System.out.println("\t\t For Taint " + t);
EffectsGroup eg = boe.taint2EffectsGroup.get(t);
- if(eg.hasPrimativeConflicts()) {
+ if(eg.hasPrimitiveConflicts()) {
System.out.print("\t\t\tPrimitive Conflicts at alloc " + as.getUniqueAllocSiteID() +" : ");
- for(String field: eg.primativeConflictingFields) {
+ for(String field: eg.primitiveConflictingFields.keySet()) {
System.out.print(field + " ");
}
System.out.println();
}
- private class EffectsGroup
- {
+ private class EffectsGroup {
Hashtable<String, CombinedObjEffects> myEffects;
- ArrayList<String> primativeConflictingFields;
+ Hashtable<String, CombinedObjEffects> primitiveConflictingFields;
public EffectsGroup() {
myEffects = new Hashtable<String, CombinedObjEffects>();
- primativeConflictingFields = new ArrayList<String>();
+ primitiveConflictingFields = new Hashtable<String, CombinedObjEffects>();
}
- public void addPrimative(Effect e) {
- primativeConflictingFields.add(e.getField().toPrettyStringBrief());
+ public void addPrimitive(Effect e, boolean conflict) {
+ CombinedObjEffects effects;
+ if((effects = primitiveConflictingFields.get(e.getField().getSymbol())) == null) {
+ effects = new CombinedObjEffects();
+ primitiveConflictingFields.put(e.getField().getSymbol(), effects);
+ }
+ effects.add(e, conflict);
}
public void addObjEffect(Effect e, boolean conflict) {
}
public boolean isEmpty() {
- return myEffects.isEmpty() && primativeConflictingFields.isEmpty();
+ return myEffects.isEmpty() && primitiveConflictingFields.isEmpty();
}
- public boolean hasPrimativeConflicts(){
- return !primativeConflictingFields.isEmpty();
+ public boolean hasPrimitiveConflicts(){
+ return !primitiveConflictingFields.isEmpty();
}
+ public CombinedObjEffects getPrimEffect(String field) {
+ return primitiveConflictingFields.get(field);
+ }
+
public boolean hasObjectEffects() {
return !myEffects.isEmpty();
}
public boolean hasConflict() {
return hasReadConflict || hasWriteConflict || hasStrongUpdateConflict;
}
+
+ public void mergeWith(CombinedObjEffects other) {
+ for(Effect e: other.originalEffects) {
+ if(!originalEffects.contains(e)){
+ originalEffects.add(e);
+ }
+ }
+
+ hasReadEffect |= other.hasReadEffect;
+ hasWriteEffect |= other.hasWriteEffect;
+ hasStrongUpdateEffect |= other.hasStrongUpdateEffect;
+
+ hasReadConflict |= other.hasReadConflict;
+ hasWriteConflict |= other.hasWriteConflict;
+ hasStrongUpdateConflict |= other.hasStrongUpdateConflict;
+ }
}
//This will keep track of a reference
public boolean hasDirectObjConflict() {
return myEffects.hasConflict();
}
+
+ public boolean equals(Object other) {
+ if(other == null || !(other instanceof ObjRef))
+ return false;
+
+ ObjRef o = (ObjRef) other;
+
+ if(o.field == this.field && o.allocSite == this.allocSite && this.child.equals(o.child))
+ return true;
+
+ return false;
+ }
+
+ public int hashCode() {
+ return child.allocSite.hashCode() ^ field.hashCode();
+ }
+
+ public void mergeWith(ObjRef ref) {
+ myEffects.mergeWith(ref.myEffects);
+ }
}
private class ConcreteRuntimeObjNode {
- ArrayList<ObjRef> objectRefs;
- ArrayList<String> conflictingPrimitiveFields;
+ Hashtable<String, ObjRefList> objectRefs;
+ Hashtable<String, CombinedObjEffects> primitiveConflictingFields;
HashSet<ConcreteRuntimeObjNode> parentsWithReadToNode;
HashSet<ConcreteRuntimeObjNode> parentsThatWillLeadToConflicts;
//this set keeps track of references down the line that need to be enqueued if traverser is "paused"
HeapRegionNode original;
public ConcreteRuntimeObjNode(HeapRegionNode me, boolean isInVar) {
- objectRefs = new ArrayList<ObjRef>();
- conflictingPrimitiveFields = null;
+ objectRefs = new Hashtable<String, ObjRefList>(5);
+ primitiveConflictingFields = null;
parentsThatWillLeadToConflicts = new HashSet<ConcreteRuntimeObjNode>();
parentsWithReadToNode = new HashSet<ConcreteRuntimeObjNode>();
enqueueToWaitingQueueUponConflict = new HashSet<ConcreteRuntimeObjNode>();
}
@Override
- public boolean equals(Object obj) {
- return original.equals(obj);
+ public boolean equals(Object other) {
+ if(other == null || !(other instanceof ConcreteRuntimeObjNode))
+ return false;
+
+ return original.equals(((ConcreteRuntimeObjNode)other).original);
}
public int getAllocationSite() {
}
public boolean hasPrimitiveConflicts() {
- return conflictingPrimitiveFields != null;
+ return primitiveConflictingFields != null && !primitiveConflictingFields.isEmpty();
}
public boolean decendantsConflict() {
}
public void addObjChild(String field, ConcreteRuntimeObjNode child, CombinedObjEffects ce) {
+ printDebug(javaDebug,this.allocSite.getUniqueAllocSiteID() + " added child at " + child.getAllocationSite());
ObjRef ref = new ObjRef(field, child, ce);
- objectRefs.add(ref);
+
+ if(objectRefs.containsKey(field)){
+ ObjRefList array = objectRefs.get(field);
+
+ if(array.contains(ref)) {
+ ObjRef other = array.get(array.indexOf(ref));
+ other.mergeWith(ref);
+ printDebug(javaDebug," Merged with old");
+ printDebug(javaDebug," Old="+ other.child.original + "\n new="+ref.child.original);
+ }
+ else {
+ array.add(ref);
+ printDebug(javaDebug," Just added new;\n Field: " + field);
+ printDebug(javaDebug," AllocSite: " + child.getAllocationSite());
+ printDebug(javaDebug," Child: "+child.original);
+ }
+ }
+ else {
+ ObjRefList array = new ObjRefList(3);
+
+ array.add(ref);
+ objectRefs.put(field, array);
+ }
}
- public String toString()
- {
+ public boolean isArray() {
+ return original.getType().isArray();
+ }
+
+ public ArrayList<Integer> getReferencedAllocSites() {
+ ArrayList<Integer> list = new ArrayList<Integer>();
+
+ for(String key: objectRefs.keySet()) {
+ for(ObjRef r: objectRefs.get(key)) {
+ if(r.hasDirectObjConflict() || (r.child.parentsWithReadToNode.contains(this) && r.hasConflictsDownThisPath())) {
+ list.add(r.allocSite);
+ }
+ }
+ }
+
+ return list;
+ }
+
+ public String toString() {
return "AllocSite=" + getAllocationSite() + " myConflict=" + !parentsThatWillLeadToConflicts.isEmpty() +
" decCon="+decendantsObjConflict+
" NumOfConParents=" + getNumOfReachableParents() + " ObjectChildren=" + objectRefs.size();
}
}
+ //Simple extension of the ArrayList to allow it to find if any ObjRefs conflict.
+ private class ObjRefList extends ArrayList<ObjRef> {
+ private static final long serialVersionUID = 326523675530835596L;
+
+ public ObjRefList(int size) {
+ super(size);
+ }
+
+ public boolean add(ObjRef o){
+ return super.add(o);
+ }
+
+ public boolean hasConflicts() {
+ for(ObjRef r: this) {
+ if(r.hasConflictsDownThisPath() || r.child.hasPrimitiveConflicts())
+ return true;
+ }
+
+ return false;
+ }
+ }
+
private class EffectsTable {
private Hashtable<AllocSite, BucketOfEffects> table;
// rehash all effects (as a 5-tuple) by their affected allocation site
for (Taint t : effects.keySet()) {
Set<Effect> localConflicts = conflicts.get(t);
-
for (Effect e : effects.get(t)) {
BucketOfEffects bucket;
if ((bucket = table.get(e.getAffectedAllocSite())) == null) {
bucket = new BucketOfEffects();
table.put(e.getAffectedAllocSite(), bucket);
}
- printDebug(javaDebug, "Added Taint" + t + " Effect " + e + "Conflict Status = " + localConflicts.contains(e));
- bucket.add(t, e, localConflicts.contains(e));
+ printDebug(javaDebug, "Added Taint" + t + " Effect " + e + "Conflict Status = " + (localConflicts!=null?localConflicts.contains(e):false)+" localConflicts = "+localConflicts);
+ bucket.add(t, e, localConflicts!=null?localConflicts.contains(e):false);
}
}
}
public EffectsGroup getEffects(AllocSite parentKey, Taint taint) {
//This would get the proper bucket of effects and then get all the effects
//for a parent for a specific taint
- return table.get(parentKey).taint2EffectsGroup.get(taint);
+ try {
+ return table.get(parentKey).taint2EffectsGroup.get(taint);
+ }
+ catch (NullPointerException e) {
+ return null;
+ }
}
// Run Analysis will walk the data structure and figure out the weakly
// connected heap roots.
- public void runAnaylsis() {
+ public void runAnalysis() {
if(javaDebug) {
printoutTable(this);
}
- //TODO is there a higher performance way to do this?
for(AllocSite key: table.keySet()) {
BucketOfEffects effects = table.get(key);
//make sure there are actually conflicts in the bucket
public int getWaitingQueueBucketNum(ConcreteRuntimeObjNode node) {
if(allocSiteToWaitingQueueMap.containsKey(node.allocSite)) {
return allocSiteToWaitingQueueMap.get(node.allocSite);
- }
- else {
+ } else {
allocSiteToWaitingQueueMap.put(node.allocSite, waitingQueueCounter);
return waitingQueueCounter++;
}
taint2EffectsGroup.put(t, effectsForGivenTaint);
}
- if (e.getField().getType().isPrimitive()) {
+ if (isReallyAPrimitive(e.getField().getType())) {
if (conflict) {
- effectsForGivenTaint.addPrimative(e);
+ effectsForGivenTaint.addPrimitive(e, true);
}
} else {
effectsForGivenTaint.addObjEffect(e, conflict);
private class TaintAndInternalHeapStructure {
public Taint t;
- public Hashtable<AllocSite, ConcreteRuntimeObjNode> nodesInHeap;
+ public Hashtable<Integer, ConcreteRuntimeObjNode> nodesInHeap;
- public TaintAndInternalHeapStructure(Taint taint, Hashtable<AllocSite, ConcreteRuntimeObjNode> nodesInHeap) {
+ public TaintAndInternalHeapStructure(Taint taint, Hashtable<Integer, ConcreteRuntimeObjNode> nodesInHeap) {
t = taint;
this.nodesInHeap = nodesInHeap;
}