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;
+ }
}
//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.");
// 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++) {
}
if (state.RCR) {
- outputStructs.println("struct rcrRecord rcrRecords["+incount+"]");
+ outputStructs.println("struct rcrRecord rcrRecords["+inset.size()+"];");
}
if( fsen.getFirstDepRecField() != null ) {
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) ) {
output.println(" atomic_inc(&(runningSESE->numRunningChildren));");
}
-
// allocate the space for this record
output.println( "#ifndef OOO_DISABLE_TASKMEMPOOL" );
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]);");
}
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
output.println(" }");
}
- if (state.RCR) {
-
-
- }
-
- if(state.RCR) {
- //TODO BCD
- //clear out the parameter records
-
- }
if( state.COREPROF ) {
////////////////
// 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()) {
+ "],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);");
}
}
}
+ 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,
protected Set<FlatSESEEnterNode> children;
- protected Vector<TempDescriptor> inVars;
+ protected Set<TempDescriptor> inVars;
protected Set<TempDescriptor> outVars;
protected Set<SESEandAgePair> needStaticNameInCode;
// 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;
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>();
dynamicInVars = new HashSet<TempDescriptor>();
dynamicVars = new HashSet<TempDescriptor>();
- inVarsForDynamicCoarseConflictResolution = new HashSet<TempDescriptor>();
+ inVarsForDynamicCoarseConflictResolution = new Vector<TempDescriptor>();
staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
}
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;
}
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 ) {
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.
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"));
}
}
- private void traverseSESEBlock(FlatSESEEnterNode rblock,
- ReachGraph rg) {
+ private void traverseSESEBlock(FlatSESEEnterNode rblock, ReachGraph rg) {
Collection<TempDescriptor> inVars = rblock.getInVarSet();
if (inVars.size() == 0)
//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));
}
}
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) {");
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) {