From 721409a448d35d8ef42faf7fbbe96d4e425081ae Mon Sep 17 00:00:00 2001 From: yeom Date: Mon, 5 Dec 2011 23:57:49 +0000 Subject: [PATCH] fixes on analyses to compile the eyetracking benchmark --- Robust/src/Analysis/Loops/LoopTerminate.java | 6 +- .../SSJava/DefinitelyWrittenCheck.java | 147 +++++++++++------- .../src/Analysis/SSJava/SSJavaAnalysis.java | 11 ++ 3 files changed, 105 insertions(+), 59 deletions(-) diff --git a/Robust/src/Analysis/Loops/LoopTerminate.java b/Robust/src/Analysis/Loops/LoopTerminate.java index 054ad337..2a71eed2 100644 --- a/Robust/src/Analysis/Loops/LoopTerminate.java +++ b/Robust/src/Analysis/Loops/LoopTerminate.java @@ -115,7 +115,11 @@ public class LoopTerminate { init(); detectBasicInductionVar(loopElements); detectDerivedInductionVar(loopElements); - checkConditionBranch(loopEntrance, loopElements); + + if (!ssjava.getSSJavaLoopEntrance().equals(loopEntrance)) { + checkConditionBranch(loopEntrance, loopElements); + } + } } diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index 594952b9..fd51237c 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -26,6 +26,7 @@ import IR.Flat.FlatElementNode; import IR.Flat.FlatFieldNode; import IR.Flat.FlatLiteralNode; import IR.Flat.FlatMethod; +import IR.Flat.FlatNew; import IR.Flat.FlatNode; import IR.Flat.FlatOpNode; import IR.Flat.FlatSetElementNode; @@ -123,7 +124,6 @@ public class DefinitelyWrittenCheck { private LinkedList sortedDescriptors; - private FlatNode ssjavaLoopEntrance; private LoopFinder ssjavaLoop; private Set loopIncElements; @@ -256,8 +256,8 @@ public class DefinitelyWrittenCheck { } SharedLocMap sharedLocMap = new SharedLocMap(); SharedLocMap deleteSet = new SharedLocMap(); - sharedLoc_analyzeBody(state.getMethodFlat(methodContainingSSJavaLoop), ssjavaLoopEntrance, - sharedLocMap, deleteSet, true); + sharedLoc_analyzeBody(state.getMethodFlat(methodContainingSSJavaLoop), + ssjava.getSSJavaLoopEntrance(), sharedLocMap, deleteSet, true); } @@ -408,6 +408,7 @@ public class DefinitelyWrittenCheck { // write(field) NTuple fieldLocTuple = new NTuple(); + fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs)); fieldLocTuple.add(fieldLoc); @@ -614,7 +615,7 @@ public class DefinitelyWrittenCheck { Set visited = new HashSet(); if (onlyVisitSSJavaLoop) { - flatNodesToVisit.add(ssjavaLoopEntrance); + flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance()); } else { flatNodesToVisit.add(fm); } @@ -646,6 +647,7 @@ public class DefinitelyWrittenCheck { TempDescriptor rhs; FieldDescriptor fld; + switch (fn.kind()) { case FKind.FlatLiteralNode: { @@ -680,45 +682,54 @@ public class DefinitelyWrittenCheck { rhs = fon.getLeft(); lhs = fon.getDest(); + NTuple rhsLocTuple = new NTuple(); + NTuple lhsLocTuple = new NTuple(); if (mapDescriptorToLocationPath.containsKey(rhs)) { mapDescriptorToLocationPath.put(lhs, mapDescriptorToLocationPath.get(rhs)); } else { - // lhs side - if (lhs.getType().getExtension() != null - && lhs.getType().getExtension() instanceof SSJavaType) { - NTuple lhsLocTuple = new NTuple(); - lhsLocTuple.addAll(((SSJavaType) lhs.getType().getExtension()).getCompLoc().getTuple()); - - mapDescriptorToLocationPath.put(lhs, lhsLocTuple); - } - // rhs side if (rhs.getType().getExtension() != null && rhs.getType().getExtension() instanceof SSJavaType) { if (((SSJavaType) rhs.getType().getExtension()).getCompLoc() != null) { - NTuple rhsLocTuple = new NTuple(); rhsLocTuple.addAll(((SSJavaType) rhs.getType().getExtension()).getCompLoc() .getTuple()); - mapDescriptorToLocationPath.put(rhs, rhsLocTuple); } + } else { + NTuple locTuple = deriveLocationTuple(md, rhs); + if (locTuple != null) { + rhsLocTuple.addAll(locTuple); + } + } + if (rhsLocTuple.size() > 0) { + mapDescriptorToLocationPath.put(rhs, rhsLocTuple); + } + + // lhs side + if (lhs.getType().getExtension() != null + && lhs.getType().getExtension() instanceof SSJavaType) { + lhsLocTuple.addAll(((SSJavaType) lhs.getType().getExtension()).getCompLoc().getTuple()); + mapDescriptorToLocationPath.put(lhs, lhsLocTuple); + } else if (mapDescriptorToLocationPath.get(rhs) != null) { + // propagate rhs's location to lhs + lhsLocTuple.addAll(mapDescriptorToLocationPath.get(rhs)); + mapDescriptorToLocationPath.put(lhs, lhsLocTuple); } } + if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("srctmp") && !lhs.getSymbol().startsWith("leftop") && !lhs.getSymbol().startsWith("rightop")) { - // NTuple lhsLocTuple = new NTuple(); - // System.out.println("fon=" + fn); - // System.out.println("rhs=" + rhs); - // lhsLocTuple.addAll(deriveLocationTuple(md, rhs)); NTuple lhsHeapPath = computePath(lhs); - addMayWrittenSet(md, mapDescriptorToLocationPath.get(lhs), lhsHeapPath); + if (lhsLocTuple != null) { + addMayWrittenSet(md, lhsLocTuple, lhsHeapPath); + } } @@ -749,6 +760,13 @@ public class DefinitelyWrittenCheck { fieldLocation = locTuple.get(locTuple.size() - 1); } + NTuple lTuple = deriveLocationTuple(md, lhs); + if (lTuple != null) { + NTuple lhsLocTuple = new NTuple(); + lhsLocTuple.addAll(lTuple); + mapDescriptorToLocationPath.put(lhs, lhsLocTuple); + } + if (ssjava.isSharedLocation(fieldLocation)) { addSharedLocDescriptor(fieldLocation, fld); @@ -811,6 +829,20 @@ public class DefinitelyWrittenCheck { } break; + case FKind.FlatNew: { + + FlatNew fnew = (FlatNew) fn; + TempDescriptor dst = fnew.getDst(); + NTuple locTuple = deriveLocationTuple(md, dst); + + if (locTuple != null) { + NTuple dstLocTuple = new NTuple(); + dstLocTuple.addAll(locTuple); + mapDescriptorToLocationPath.put(dst, dstLocTuple); + } + + } + break; } } @@ -976,6 +1008,11 @@ public class DefinitelyWrittenCheck { MultiSourceMap, NTuple> callerMapping = mapMethodToSharedLocCoverSet.get(caller); + if (callerMapping == null) { + callerMapping = new MultiSourceMap, NTuple>(); + mapMethodToSharedLocCoverSet.put(caller, callerMapping); + } + if (calleeMapping == null) { return; } @@ -1063,8 +1100,12 @@ public class DefinitelyWrittenCheck { if (te != null) { if (te instanceof SSJavaType) { SSJavaType ssType = (SSJavaType) te; - CompositeLocation comp = ssType.getCompLoc(); - return comp.get(comp.getSize() - 1); + if (ssType.getCompLoc() != null) { + CompositeLocation comp = ssType.getCompLoc(); + return comp.get(comp.getSize() - 1); + } else { + return null; + } } else { return (Location) te; } @@ -1080,7 +1121,7 @@ public class DefinitelyWrittenCheck { // variables are definitely written in-between the same read Set flatNodesToVisit = new HashSet(); - flatNodesToVisit.add(ssjavaLoopEntrance); + flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance()); while (!flatNodesToVisit.isEmpty()) { FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); @@ -1098,7 +1139,7 @@ public class DefinitelyWrittenCheck { } } - eventLoopAnalysis_nodeAction(fn, curr, ssjavaLoopEntrance); + eventLoopAnalysis_nodeAction(fn, curr, ssjava.getSSJavaLoopEntrance()); // if a new result, schedule forward nodes for analysis if (!curr.equals(prev)) { @@ -1161,7 +1202,6 @@ public class DefinitelyWrittenCheck { } } - // System.out.println("EVENT LOOP ENTRY=" + curr); } else { TempDescriptor lhs; @@ -1187,7 +1227,6 @@ public class DefinitelyWrittenCheck { NTuple path = new NTuple(); path.add(lhs); - // System.out.println("#VARIABLE WRITE:" + fn); Location lhsLoc = getLocation(lhs); if (ssjava.isSharedLocation(lhsLoc)) { @@ -1204,6 +1243,7 @@ public class DefinitelyWrittenCheck { } else { computeGENSetForSharedNonCoverWrite(curr, varHeapPath, readWriteGenSet); } + } else { computeKILLSetForWrite(curr, path, readWriteKillSet); @@ -1213,6 +1253,9 @@ public class DefinitelyWrittenCheck { // System.out.println("#KILLSET=" + readWriteKillSet); // System.out.println("#GENSet=" + readWriteGenSet); + Set writeAgeSet = curr.get(path); + checkWriteAgeSet(writeAgeSet, path, fn); + } } @@ -1399,6 +1442,10 @@ public class DefinitelyWrittenCheck { } private void checkWriteAgeSet(Set writeAgeSet, NTuple path, FlatNode fn) { + + // System.out.println("# CHECK WRITE AGE of " + path + " from set=" + + // writeAgeSet); + if (writeAgeSet != null) { for (Iterator iterator = writeAgeSet.iterator(); iterator.hasNext();) { WriteAge writeAge = (WriteAge) iterator.next(); @@ -1427,7 +1474,6 @@ public class DefinitelyWrittenCheck { } else { // if the current heap path is shared location - System.out.println("heapPath=" + heapPath); NTuple locTuple = getLocationTuple(heapPath, sharedLocMap); Set> sharedWriteHeapPathSet = sharedLocMap.get(locTuple); @@ -1499,8 +1545,6 @@ public class DefinitelyWrittenCheck { NTuple locTuple = new NTuple(); - System.out.println("# 0 locPath=" + mapDescriptorToLocationPath.get(heapPath.get(0))); - locTuple.addAll(mapDescriptorToLocationPath.get(heapPath.get(0))); for (int i = 1; i < heapPath.size(); i++) { locTuple.add(getLocation(heapPath.get(i))); @@ -1846,7 +1890,7 @@ public class DefinitelyWrittenCheck { if (label != null) { if (label.equals(ssjava.SSJAVA)) { - ssjavaLoopEntrance = fn; + ssjava.setSSJavaLoopEntrance(fn); break; } } @@ -1857,13 +1901,13 @@ public class DefinitelyWrittenCheck { } } - assert ssjavaLoopEntrance != null; + assert ssjava.getSSJavaLoopEntrance() != null; // assume that ssjava loop is top-level loop in method, not nested loop Set nestedLoop = loopFinder.nestedLoops(); for (Iterator loopIter = nestedLoop.iterator(); loopIter.hasNext();) { LoopFinder lf = (LoopFinder) loopIter.next(); - if (lf.loopEntrances().iterator().next().equals(ssjavaLoopEntrance)) { + if (lf.loopEntrances().iterator().next().equals(ssjava.getSSJavaLoopEntrance())) { ssjavaLoop = lf; } } @@ -1971,7 +2015,8 @@ public class DefinitelyWrittenCheck { mapFlatMethodToMustWriteSet.put(flatMethodContainingSSJavaLoop, mustWriteSet); mapFlatMethodToMayWriteSet.put(flatMethodContainingSSJavaLoop, mayWriteSet); - methodReadWriteSet_analyzeBody(ssjavaLoopEntrance, readSet, mustWriteSet, mayWriteSet, true); + methodReadWriteSet_analyzeBody(ssjava.getSSJavaLoopEntrance(), readSet, mustWriteSet, + mayWriteSet, true); } @@ -2084,25 +2129,6 @@ public class DefinitelyWrittenCheck { writeHeapPath.addAll(heapPath); writeHeapPath.add(lhs); - System.out.println("VAR WRITE:" + fn); - System.out.println("LHS TYPE EXTENSION=" + lhs.getType().getExtension()); - System.out.println("RHS TYPE EXTENSION=" + rhs.getType().getExtension() - + " HEAPPATH=" + rhsHeapPath); - - // computing gen/kill set - // computeKILLSetForWrite(currSharedLocMapping, heapPath, dstLoc, - // killSetSharedLoc); - // if (!dstLoc.equals(rhsLoc)) { - // computeGENSetForHigherWrite(currSharedLocMapping, heapPath, - // dstLoc, lhs, - // genSetSharedLoc); - // deleteSet.remove(writeHeapPath); - // } else { - // computeGENSetForSharedWrite(currSharedLocMapping, heapPath, - // dstLoc, lhs, - // genSetSharedLoc); - // deleteSet.add(writeHeapPath); - // } } } @@ -2423,14 +2449,19 @@ public class DefinitelyWrittenCheck { if (td.getSymbol().startsWith("this")) { return deriveThisLocationTuple(md); } else { - if (td.getType().getExtension() == null) { - return null; + + if (td.getType().getExtension() != null) { + SSJavaType ssJavaType = (SSJavaType) td.getType().getExtension(); + if (ssJavaType.getCompLoc() != null) { + NTuple locTuple = new NTuple(); + locTuple.addAll(ssJavaType.getCompLoc().getTuple()); + return locTuple; + } } - NTuple locTuple = - ((SSJavaType) td.getType().getExtension()).getCompLoc().getTuple(); - return locTuple; + + return null; + } } - } } \ No newline at end of file diff --git a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java index a768b7f6..58369f8f 100644 --- a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java +++ b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java @@ -28,6 +28,7 @@ import IR.SymbolTable; import IR.TypeUtil; import IR.Flat.BuildFlat; import IR.Flat.FlatMethod; +import IR.Flat.FlatNode; import Util.Pair; public class SSJavaAnalysis { @@ -81,6 +82,8 @@ public class SSJavaAnalysis { // points to method containing SSJAVA Loop private MethodDescriptor methodContainingSSJavaLoop; + private FlatNode ssjavaLoopEntrance; + // keep the field ownership from the linear type checking Hashtable> mapMethodToOwnedFieldSet; @@ -549,4 +552,12 @@ public class SSJavaAnalysis { return false; } + public FlatNode getSSJavaLoopEntrance() { + return ssjavaLoopEntrance; + } + + public void setSSJavaLoopEntrance(FlatNode ssjavaLoopEntrance) { + this.ssjavaLoopEntrance = ssjavaLoopEntrance; + } + } -- 2.34.1