- int index = 0;
- boolean isRblock = (fn instanceof FlatSESEEnterNode);
- if (isRblock) {
- FlatSESEEnterNode fsese = (FlatSESEEnterNode) fn;
- index = fsese.getInVarsForDynamicCoarseConflictResolution().indexOf(tmp);
- }
-
- String strrcr = isRblock ? "&record->rcrRecords[" + index + "], " : "NULL, ";
- String tasksrc =isRblock ? "(SESEcommon *) record, ":"(SESEcommon *)(((INTPTR)record)|1LL), ";
-
- // Do call if we need it.
- if (curr.primConfWrite || curr.objConfWrite) {
- assert heaprootNum != -1;
- cFile.append(" int tmpkey" + depth + "=rcr_generateKey(" + prefix + ");\n");
- if (curr.descendantsConflict())
- cFile.append(" int tmpvar" + depth + "=rcr_WTWRITEBINCASE(allHashStructures[" + heaprootNum + "], tmpkey" + depth + ", " + tasksrc + strrcr + index + ");\n");
- else
- cFile.append(" int tmpvar" + depth + "=rcr_WRITEBINCASE(allHashStructures["+ heaprootNum + "], tmpkey" + depth + ", " + tasksrc + strrcr + index + ");\n");
- } else if (curr.primConfRead || curr.objConfRead) {
- assert heaprootNum != -1;
- cFile.append(" int tmpkey" + depth + "=rcr_generateKey(" + prefix + ");\n");
- if (curr.descendantsConflict())
- cFile.append(" int tmpvar" + depth + "=rcr_WTREADBINCASE(allHashStructures[" + heaprootNum + "], tmpkey" + depth + ", " + tasksrc + strrcr + index + ");\n");
- else
- cFile.append(" int tmpvar" + depth + "=rcr_READBINCASE(allHashStructures["+ heaprootNum + "], tmpkey" + depth + ", " + tasksrc + strrcr + index + ");\n");
- }
-
- if (curr.primConfWrite || curr.objConfWrite || curr.primConfRead || curr.objConfRead) {
- cFile.append("if (!(tmpvar" + depth + "&READYMASK)) totalcount--;\n");
- }
- }
-
- private void printObjRefSwitchStatement(FlatNode fn,
- EffectsTable et,
- int pDepth,
- ArrayList<ObjRef> refsAtParticularField,
- String childPtr,
- String currPtr,
- int heaprootNum,
- int stateID,
- Set<SMFEState> toVisit) {
-
- cFile.println(" "+currPtr+"= (struct ___Object___ * ) " + childPtr + ";");
- cFile.println(" if (" + currPtr + " != NULL) { ");
- cFile.println(" switch(" + currPtr + getAllocSiteInC + ") {");
-
- for(ObjRef ref: refsAtParticularField) {
- cFile.println(" case "+ref.allocID+":\n {");
- //The hash insert is here because we don't want to enqueue things unless we know it conflicts.
- cFile.println(" if (" + queryAndAddToVistedHashtable +"("+ currPtr + ", "+stateID+")) {");
-
- if(ref.child.isTransition()) {
- for(SMFEState s: ref.child.transitions) {
- cFile.println(" " + addToQueueInC + childPtr + ", "+s.getID()+");");
- }
- } else if(qualifiesForCaseStatement(ref.child)){
- cFile.println(" " + addToQueueInC + childPtr + ", "+stateID+");");
- } else {
-// public void addChecker(AllocNode a, FlatNode fn, EffectsTable et, String prefix, int depth)
- addCheker(..);
- }
-
- cFile.println(" }"); //close for queryVistedHashtable
-
- cFile.println("}"); //close for internal case statement
- }
-
- cFile.append(" default:\n" +
- " break;\n"+
- " }}\n"); //internal switch.
- }
-
- //Walks the connected heaproot groups, coalesces them, and numbers them
- //Special Note: Lookup Table must already be created
- private void enumerateHeaproots() {
- weaklyConnectedHRCounter = 0;
- num2WeaklyConnectedHRGroup = new ArrayList<WeaklyConectedHRGroup>();
-
- for(Taint t: connectedHRHash.keySet()) {
- if(connectedHRHash.get(t).id == -1) {
- WeaklyConectedHRGroup hg = connectedHRHash.get(t);
- hg.id = weaklyConnectedHRCounter;
- num2WeaklyConnectedHRGroup.add(weaklyConnectedHRCounter, hg);
- weaklyConnectedHRCounter++;
- }
-
- if(t.isRBlockTaint()) {
- int id=connectedHRHash.get(t).id;
- Pair tup=new Pair(t.getVar(),t.getSESE());
- if (weakMap.containsKey(tup)) {
- if (weakMap.get(tup).intValue()!=id)
- throw new Error("Var/SESE not unique for weak component.");
- } else
- weakMap.put(tup, new Integer(id));
- }
- }
-
- //output weakly connected groups for verification
- if(generalDebug) {
- System.out.println("==============Weakly Connected HeapRoots==============");
-
- for(int i=0; i < num2WeaklyConnectedHRGroup.size(); i++){
- System.out.println("Heap Group #" + i);
- WeaklyConectedHRGroup hg = num2WeaklyConnectedHRGroup.get(i);
- for(Taint t: hg.connectedHRs) {
- System.out.println("\t" + t);
- }
- }
-
- System.out.println("=======================END LIST=======================");
- }
- }
- */
-
-
- /*
- private class EffectsGroup {
- Hashtable<String, CombinedEffects> myObjEffects;
- //In the end, we don't really care what the primitive fields are.
- Hashtable<String, CombinedEffects> primitiveConflictingFields;
- private boolean primConfRead;
- private boolean primConfWrite;
-
- public EffectsGroup() {
- myObjEffects = new Hashtable<String, CombinedEffects>();
- primitiveConflictingFields = new Hashtable<String, CombinedEffects>();
-
- primConfRead = false;
- primConfWrite = false;
- }
-
- public void add(Effect e, boolean conflict, boolean leadsToTransistion) {
- CombinedEffects effects;
- if ((effects = myObjEffects.get(e.getField().getSymbol())) == null) {
- effects = new CombinedEffects();
- myObjEffects.put(e.getField().getSymbol(), effects);
- }
-
- effects.add(e, conflict, leadsToTransistion);
-
- if (isReallyAPrimitive(e.getField().getType())) {
- effects.add(e, conflict, false);
-
- primConfRead |= effects.hasReadConflict;
- primConfWrite |= effects.hasWriteConflict;
- }
- }
-
-
- public boolean isEmpty() {
- return myObjEffects.isEmpty() && primitiveConflictingFields.isEmpty();
- }
-
- public boolean hasPrimitiveConflicts(){
- return !primitiveConflictingFields.isEmpty();
- }
-
- public CombinedEffects getPrimEffect(String field) {
- return primitiveConflictingFields.get(field);
- }
-
- public boolean hasObjectEffects() {
- return !myObjEffects.isEmpty();
- }
-
- public CombinedEffects getObjEffect(String field) {
- return myObjEffects.get(field);
- }
- }
- */
-
-
-
-
-
- /*
- //Performs a reverse traversal from the conflict nodes up to the
- //inset variables and sets conflict flags on inner nodes.
- private void propagateConflicts(Hashtable<Alloc, ConcreteRuntimeObjNode> created) {
- for(ConcreteRuntimeObjNode node: created.values()) {
- if(node.hasConflict()) {
- markReferencers(node, node.objConfRead || node.objConfWrite, node.primConfRead || node.primConfWrite);
- }
- }
- }
-
- private void markReferencers(ConcreteRuntimeObjNode node, boolean ObjConf, boolean PrimConf) {
- for(ObjRef ref: node.referencers) {
- //if not already marked or data does not match
- if(!ref.reachesConflict ||
- (ObjConf && !ref.parent.descendantsObjConflict) ||
- (PrimConf && !ref.parent.descendantsPrimConflict)) {
-
- ref.parent.descendantsObjConflict |= ObjConf;
- ref.parent.descendantsPrimConflict |= PrimConf;
- ref.reachesConflict = true;
- markReferencers(ref.parent, ObjConf, PrimConf);
- }
- }
- }
- */
-
-
- /*
- private class WeaklyConectedHRGroup {
- HashSet<Taint> connectedHRs;
- int id;
-
- public WeaklyConectedHRGroup() {
- connectedHRs = new HashSet<Taint>();
- id = -1;
- }
-
- public void add(ArrayList<Taint> list) {
- for(Taint t: list) {
- this.add(t);
- }
- }
-
- public void add(Taint t) {
- connectedHRs.add(t);
- WeaklyConectedHRGroup oldGroup = connectedHRHash.get(t);
- connectedHRHash.put(t, this); //put new group into hash
- //If the taint was already in another group, move all its buddies over.
- if(oldGroup != this && oldGroup != null) {
- Iterator<Taint> it = oldGroup.connectedHRs.iterator();
- Taint relatedTaint;
-
- while(it.hasNext() && (relatedTaint = it.next()) != null) {
- if(!connectedHRs.contains(relatedTaint)){
- this.add(relatedTaint);
- }
- }
- }
- }
- }
-
-
- //This is a class that stores all the effects for an affected allocation site
- //across ALL taints. The structure is a hashtable of EffectGroups (see above) hashed
- //by a Taint. This way, I can keep EffectsGroups so I can reuse most to all of my old code
- //and allows for easier tracking of effects. In addition, a hashtable (keyed by the string
- //of the field access) keeps track of an ArrayList of taints of SESEblocks that conflict on that
- //field.
- private class BucketOfEffects {
- // This table is used for lookup while creating the traversal.
- Hashtable<Taint, EffectsGroup> taint2EffectsGroup;
-
- //This table is used to help identify weakly connected groups: Contains ONLY
- //conflicting effects AND is only initialized when needed
- //String stores the field
- Hashtable<String, ArrayList<Taint>> potentiallyConflictingRoots;
-
- public BucketOfEffects() {
- taint2EffectsGroup = new Hashtable<Taint, EffectsGroup>();
- }
-
- public void add(Taint t, Effect e, boolean conflict, boolean leadsToTransition) {
- EffectsGroup effectsForGivenTaint;
-
- if ((effectsForGivenTaint = taint2EffectsGroup.get(t)) == null) {
- effectsForGivenTaint = new EffectsGroup();
- taint2EffectsGroup.put(t, effectsForGivenTaint);
- }
-
- if (isReallyAPrimitive(e.getField().getType())) {
- if (conflict) {
- effectsForGivenTaint.addPrimitive(e, true);
- }
- } else {
- effectsForGivenTaint.addObjEffect(e, conflict,leadsToTransition);
- }
-
- if(conflict) {
- if(potentiallyConflictingRoots == null) {
- potentiallyConflictingRoots = new Hashtable<String, ArrayList<Taint>>();
- }
-
- ArrayList<Taint> taintsForField = potentiallyConflictingRoots.get(e.getField().getSafeSymbol());
- if(taintsForField == null) {
- taintsForField = new ArrayList<Taint>();
- potentiallyConflictingRoots.put(e.getField().getSafeSymbol(), taintsForField);
- }
-
- if(!taintsForField.contains(t)) {
- taintsForField.add(t);
- }