From: yeom Date: Mon, 12 Dec 2011 01:18:55 +0000 (+0000) Subject: more changes, but still broken with mp3decoder X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=dd95464156548b1573a14a2f39d8deed7ed4d840;p=IRC.git more changes, but still broken with mp3decoder --- diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index 35aef24d..1e31d7d6 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -116,8 +116,6 @@ public class DefinitelyWrittenCheck { private Hashtable mapFlatNodeToSharedLocMapping; private Hashtable mapFlatNodeToDeleteSet; - private Hashtable> mapSharedLocationToCoverSet; - private LinkedList sortedDescriptors; private LoopFinder ssjavaLoop; @@ -162,7 +160,6 @@ public class DefinitelyWrittenCheck { this.mapFlatNodeToBoundReadSet = new Hashtable>>(); this.mapFlatNodeToBoundMustWriteSet = new Hashtable>>(); this.mapFlatNodeToBoundMayWriteSet = new Hashtable>>(); - this.mapSharedLocationToCoverSet = new Hashtable>(); this.mapFlatNodeToSharedLocMapping = new Hashtable(); this.mapFlatMethodToDeleteSet = new Hashtable(); this.calleeUnionBoundDeleteSet = new SharedLocMap(); @@ -180,6 +177,10 @@ public class DefinitelyWrittenCheck { methodReadWriteSetAnalysis(); computeSharedCoverSet(); + // System.out.println("$$$=" + + // mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop)); + // System.exit(0); + sharedLocAnalysis(); eventLoopAnalysis(); @@ -390,14 +391,6 @@ public class DefinitelyWrittenCheck { rhs = fsfn.getSrc(); fieldLoc = (Location) fld.getType().getExtension(); } else { - FlatSetElementNode fsen = (FlatSetElementNode) fn; - lhs = fsen.getDst(); - rhs = fsen.getSrc(); - TypeDescriptor td = lhs.getType().dereference(); - fld = getArrayField(td); - - NTuple locTuple = deriveLocationTuple(md, lhs); - fieldLoc = locTuple.get(locTuple.size() - 1); break; } @@ -469,16 +462,12 @@ public class DefinitelyWrittenCheck { case FKind.FlatCall: { FlatCall fc = (FlatCall) fn; - // if (ssjava.needTobeAnnotated(fc.getMethod())) { - // System.out.println("#FLATCALL=" + fc); - bindHeapPathCallerArgWithCaleeParamForSharedLoc(fm.getMethod(), fc); // computing gen/kill set generateKILLSetForFlatCall(curr, killSet); generateGENSetForFlatCall(curr, genSet); - // } // System.out.println("#FLATCALL=" + fc); // System.out.println("KILLSET=" + killSet); // System.out.println("GENSet=" + genSet); @@ -641,6 +630,7 @@ public class DefinitelyWrittenCheck { private void computeSharedCoverSet_analyzeMethod(FlatMethod fm, boolean onlyVisitSSJavaLoop) { + System.out.println("\n###"); System.out.println("computeSharedCoverSet_analyzeMethod=" + fm); MethodDescriptor md = fm.getMethod(); @@ -698,10 +688,6 @@ public class DefinitelyWrittenCheck { if (lhs.getType().getExtension() instanceof SSJavaType) { CompositeLocation compLoc = ((SSJavaType) lhs.getType().getExtension()).getCompLoc(); Location lastLocElement = compLoc.get(compLoc.getSize() - 1); - // check if the last one is shared loc - if (ssjava.isSharedLocation(lastLocElement)) { - addSharedLocDescriptor(lastLocElement, lhs); - } } } @@ -723,6 +709,7 @@ public class DefinitelyWrittenCheck { NTuple lhsLocTuple = new NTuple(); if (mapDescriptorToLocationPath.containsKey(rhs)) { mapDescriptorToLocationPath.put(lhs, deriveLocationTuple(md, rhs)); + lhsLocTuple = mapDescriptorToLocationPath.get(lhs); } else { // rhs side if (rhs.getType().getExtension() != null @@ -754,10 +741,10 @@ public class DefinitelyWrittenCheck { lhsLocTuple.addAll(mapDescriptorToLocationPath.get(rhs)); mapDescriptorToLocationPath.put(lhs, lhsLocTuple); } - } - if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("srctmp")) { + if (isEventLoopBody && lhs.getType().isPrimitive() + && !lhs.getSymbol().startsWith("srctmp")) { NTuple lhsHeapPath = computePath(lhs); @@ -790,59 +777,42 @@ public class DefinitelyWrittenCheck { fld = getArrayField(td); } - Location fieldLocation; + NTuple fieldLocTuple = new NTuple(); + fieldLocTuple.addAll(deriveLocationTuple(md, lhs)); if (fn.kind() == FKind.FlatSetFieldNode) { - fieldLocation = (Location) fld.getType().getExtension(); - } else { - NTuple locTuple = mapDescriptorToLocationPath.get(lhs); - fieldLocation = locTuple.get(locTuple.size() - 1); + fieldLocTuple.add((Location) fld.getType().getExtension()); } - if (!isEventLoopBody && fieldLocation.getDescriptor().equals(md)) { - // if the field belongs to the local lattice, no reason to calculate - // shared location - break; - } + if (mapHeapPath.containsKey(lhs)) { + // fields reachable from the param can have heap path entry. + NTuple lhsHeapPath = new NTuple(); + lhsHeapPath.addAll(mapHeapPath.get(lhs)); - NTuple fieldLocTuple = new NTuple(); - if (fld.isStatic()) { - if (fld.isFinal()) { - // in this case, fld has TOP location - Location topLocation = Location.createTopLocation(md); - fieldLocTuple.add(topLocation); + Location fieldLocation; + if (fn.kind() == FKind.FlatSetFieldNode) { + fieldLocation = getLocation(fld); } else { - fieldLocTuple.addAll(deriveGlobalLocationTuple(md)); - if (fn.kind() == FKind.FlatSetFieldNode) { - fieldLocTuple.add((Location) fld.getType().getExtension()); - } + fieldLocation = getLocation(lhsHeapPath.get(getArrayBaseDescriptorIdx(lhsHeapPath))); } - } else { - fieldLocTuple.addAll(deriveLocationTuple(md, lhs)); - if (fn.kind() == FKind.FlatSetFieldNode) { - fieldLocTuple.add((Location) fld.getType().getExtension()); + // Location fieldLocation = getLocation(lhs); + if (!isEventLoopBody && fieldLocation.getDescriptor().equals(md)) { + // if the field belongs to the local lattice, no reason to calculate + // shared location + break; } - } - - 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); + if (ssjava.isSharedLocation(fieldLocation)) { - NTuple fieldHeapPath = new NTuple(); - fieldHeapPath.addAll(computePath(lhs)); - if (fn.kind() == FKind.FlatSetFieldNode) { - fieldHeapPath.add(fld); - } + NTuple fieldHeapPath = new NTuple(); + fieldHeapPath.addAll(computePath(lhs)); + if (fn.kind() == FKind.FlatSetFieldNode) { + fieldHeapPath.add(fld); + } - // mapLocationPathToMayWrittenSet.put(locTuple, null, fld); - addMayWrittenSet(md, fieldLocTuple, fieldHeapPath); + addMayWrittenSet(md, fieldLocTuple, fieldHeapPath); + } } } @@ -897,9 +867,7 @@ public class DefinitelyWrittenCheck { FlatCall fc = (FlatCall) fn; - // if (ssjava.needTobeAnnotated(fc.getMethod())) { bindLocationPathCallerArgWithCalleeParam(md, fc); - // } } break; @@ -948,7 +916,7 @@ public class DefinitelyWrittenCheck { NTuple argLocationPath = deriveLocationTuple(mdCaller, arg); NTuple argHeapPath = computePath(arg); addMayWrittenSet(mdCaller, argLocationPath, argHeapPath); - } else { + } else if (ssjava.needTobeAnnotated(fc.getMethod())) { // if arg is not primitive type, we need to propagate maywritten set to // the caller's location path @@ -983,7 +951,6 @@ public class DefinitelyWrittenCheck { } mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath); } - } for (int i = 0; i < fc.numArgs(); i++) { @@ -999,19 +966,15 @@ public class DefinitelyWrittenCheck { } - Hashtable>> mapParamIdx2WriteSet = - new Hashtable>>(); - - for (int i = 0; i < fc.numArgs() + 1; i++) { - mapParamIdx2WriteSet.put(Integer.valueOf(i), new HashSet>()); - } - for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) { MethodDescriptor callee = (MethodDescriptor) iterator.next(); FlatMethod calleeFlatMethod = state.getMethodFlat(callee); // binding caller's args and callee's params + Hashtable, NTuple> mapParamHeapPathToCallerArgHeapPath = + new Hashtable, NTuple>(); + Hashtable mapParamIdx2ParamTempDesc = new Hashtable(); int offset = 0; @@ -1019,26 +982,40 @@ public class DefinitelyWrittenCheck { // static method does not have implicit 'this' arg offset = 1; } + for (int i = 0; i < calleeFlatMethod.numParameters(); i++) { TempDescriptor param = calleeFlatMethod.getParameter(i); mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param); + + NTuple calleeHeapPath = computePath(param); + + NTuple argHeapPath = + mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i + offset)); + + if (argHeapPath != null) { + mapParamHeapPathToCallerArgHeapPath.put(calleeHeapPath, argHeapPath); + + } + } Set keySet = mapArgIdx2CallerArgLocationPath.keySet(); for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) { Integer idx = (Integer) iterator2.next(); + NTuple callerArgLocationPath = mapArgIdx2CallerArgLocationPath.get(idx); TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx); + NTuple calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam); NTuple callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx); - NTuple calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam); NTuple calleeHeapPath = computePath(calleeParam); - createNewMappingOfMayWrittenSet(mdCaller, callee, callerArgHeapPath, - callerArgLocationPath, calleeHeapPath, calleeLocationPath, - mapParamIdx2WriteSet.get(idx)); - + if (!calleeParam.getType().isPrimitive()) { + createNewMappingOfMayWrittenSet(mdCaller, callee, callerArgHeapPath, + callerArgLocationPath, calleeHeapPath, calleeLocationPath, + mapParamHeapPathToCallerArgHeapPath); + } } } @@ -1069,7 +1046,7 @@ public class DefinitelyWrittenCheck { private void createNewMappingOfMayWrittenSet(MethodDescriptor caller, MethodDescriptor callee, NTuple callerArgHeapPath, NTuple callerArgLocPath, NTuple calleeParamHeapPath, NTuple calleeParamLocPath, - Set> writeSet) { + Hashtable, NTuple> mapParamHeapPathToCallerArgHeapPath) { // propagate may-written-set associated with the key that is started with // calleepath to the caller @@ -1081,6 +1058,10 @@ public class DefinitelyWrittenCheck { MultiSourceMap, NTuple> calleeMapping = mapMethodToSharedLocCoverSet.get(callee); + if (calleeMapping == null) { + return; + } + MultiSourceMap, NTuple> callerMapping = mapMethodToSharedLocCoverSet.get(caller); @@ -1089,24 +1070,25 @@ public class DefinitelyWrittenCheck { mapMethodToSharedLocCoverSet.put(caller, callerMapping); } - if (calleeMapping == null) { - return; - } - Hashtable, Set>> paramMapping = getMappingByStartedWith(calleeMapping, calleeParamLocPath); - Set> calleeKeySet = calleeMapping.keySet(); + Set> calleeKeySet = paramMapping.keySet(); + for (Iterator iterator = calleeKeySet.iterator(); iterator.hasNext();) { NTuple calleeKey = (NTuple) iterator.next(); + Set> calleeMayWriteSet = paramMapping.get(calleeKey); if (calleeMayWriteSet != null) { - Set> boundWriteSet = - convertCallerMayWriteSet(callerArgHeapPath, calleeParamHeapPath, calleeMayWriteSet); + Set> boundMayWriteSet = new HashSet>(); - writeSet.addAll(boundWriteSet); + Set> boundSet = + convertToCallerMayWriteSet(calleeParamHeapPath, calleeMayWriteSet, callerMapping, + mapParamHeapPathToCallerArgHeapPath); + + boundMayWriteSet.addAll(boundSet); NTuple newKey = new NTuple(); newKey.addAll(callerArgLocPath); @@ -1116,16 +1098,17 @@ public class DefinitelyWrittenCheck { newKey.add(calleeKey.get(i)); } - callerMapping.union(newKey, writeSet); - // mapLocationPathToMayWrittenSet.put(calleeKey, newKey, writeSet); + callerMapping.union(newKey, boundMayWriteSet); } } } - private Set> convertCallerMayWriteSet(NTuple callerArgHeapPath, - NTuple calleeParamHeapPath, Set> calleeMayWriteSet) { + private Set> convertToCallerMayWriteSet( + NTuple calleeParamHeapPath, Set> calleeMayWriteSet, + MultiSourceMap, NTuple> callerMapping, + Hashtable, NTuple> mapParamHeapPathToCallerArgHeapPath) { Set> boundSet = new HashSet>(); @@ -1133,12 +1116,15 @@ public class DefinitelyWrittenCheck { for (Iterator iterator = calleeMayWriteSet.iterator(); iterator.hasNext();) { NTuple calleeWriteHeapPath = (NTuple) iterator.next(); + NTuple writeHeapPathParamHeapPath = calleeWriteHeapPath.subList(0, 1); + + NTuple callerArgHeapPath = + mapParamHeapPathToCallerArgHeapPath.get(writeHeapPathParamHeapPath); + NTuple boundHeapPath = new NTuple(); boundHeapPath.addAll(callerArgHeapPath); - int startIdx = calleeParamHeapPath.size(); - - for (int i = startIdx; i < calleeWriteHeapPath.size(); i++) { + for (int i = 1; i < calleeWriteHeapPath.size(); i++) { boundHeapPath.add(calleeWriteHeapPath.get(i)); } @@ -1149,18 +1135,6 @@ public class DefinitelyWrittenCheck { return boundSet; } - private void addSharedLocDescriptor(Location sharedLoc, Descriptor desc) { - - Set descSet = mapSharedLocationToCoverSet.get(sharedLoc); - if (descSet == null) { - descSet = new HashSet(); - mapSharedLocationToCoverSet.put(sharedLoc, descSet); - } - - descSet.add(desc); - - } - private Location getLocation(Descriptor d) { if (d instanceof FieldDescriptor) { @@ -1297,7 +1271,6 @@ public class DefinitelyWrittenCheck { && !lhs.getSymbol().startsWith("rightop")) { boolean hasWriteEffect = false; - NTuple rhsHeapPath = computePath(rhs); if (rhs.getType().getExtension() instanceof SSJavaType && lhs.getType().getExtension() instanceof SSJavaType) { @@ -1319,8 +1292,10 @@ public class DefinitelyWrittenCheck { if (hasWriteEffect) { // write(lhs) - NTuple lhsPath = new NTuple(); - lhsPath.add(lhs); + NTuple rhsHeapPath = computePath(rhs); + NTuple lhsHeapPath = new NTuple(); + lhsHeapPath.addAll(rhsHeapPath); + Location lhsLoc = getLocation(lhs); if (ssjava.isSharedLocation(lhsLoc)) { @@ -1339,15 +1314,16 @@ public class DefinitelyWrittenCheck { } else { - computeKILLSetForWrite(curr, lhsPath, readWriteKillSet); - computeGENSetForWrite(lhsPath, readWriteGenSet); + computeKILLSetForWrite(curr, lhsHeapPath, readWriteKillSet); + computeGENSetForWrite(lhsHeapPath, readWriteGenSet); } + // System.out.println("write effect on =" + lhsHeapPath); // System.out.println("#KILLSET=" + readWriteKillSet); // System.out.println("#GENSet=" + readWriteGenSet + "\n"); - Set writeAgeSet = curr.get(lhsPath); - checkWriteAgeSet(writeAgeSet, lhsPath, fn); + Set writeAgeSet = curr.get(lhsHeapPath); + checkWriteAgeSet(writeAgeSet, lhsHeapPath, fn); } } @@ -1407,8 +1383,6 @@ public class DefinitelyWrittenCheck { fld = getArrayField(td); } - // System.out.println("FIELD WRITE:" + fn); - // write(field) NTuple lhsHeapPath = computePath(lhs); NTuple fldHeapPath = new NTuple(lhsHeapPath.getList()); @@ -1417,7 +1391,14 @@ public class DefinitelyWrittenCheck { } // shared loc extension - Location fieldLoc = (Location) fld.getType().getExtension(); + Location fieldLoc; + if (fn.kind() == FKind.FlatSetFieldNode) { + fieldLoc = (Location) fld.getType().getExtension(); + } else { + NTuple locTuple = mapDescriptorToLocationPath.get(lhs); + fieldLoc = locTuple.get(locTuple.size() - 1); + } + if (ssjava.isSharedLocation(fieldLoc)) { NTuple fieldLocTuple = new NTuple(); @@ -1632,7 +1613,7 @@ public class DefinitelyWrittenCheck { Hashtable, Set> KILLSet) { Set> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc); - // System.out.println("boundMustWriteSet=" + boundMustWriteSet); + System.out.println("boundMustWriteSet=" + boundMustWriteSet); for (Iterator iterator = boundMustWriteSet.iterator(); iterator.hasNext();) { NTuple heapPath = (NTuple) iterator.next(); @@ -1661,7 +1642,7 @@ public class DefinitelyWrittenCheck { private int getArrayBaseDescriptorIdx(NTuple heapPath) { - for (int i = heapPath.size() - 1; i > 1; i--) { + for (int i = heapPath.size() - 1; i >= 0; i--) { if (!heapPath.get(i).getSymbol().equals(arrayElementFieldName)) { return i; } @@ -1673,16 +1654,10 @@ public class DefinitelyWrittenCheck { private boolean isSharedLocation(NTuple heapPath) { - Descriptor d = heapPath.get(heapPath.size() - 1); - - if (d instanceof FieldDescriptor) { + Descriptor d = heapPath.get(getArrayBaseDescriptorIdx(heapPath)); - return ssjava - .isSharedLocation(getLocation(heapPath.get(getArrayBaseDescriptorIdx(heapPath)))); + return ssjava.isSharedLocation(getLocation(heapPath.get(getArrayBaseDescriptorIdx(heapPath)))); - } else { - return ssjava.isSharedLocation(getLocation(heapPath.get(heapPath.size() - 1))); - } } private NTuple getLocationTuple(NTuple heapPath) { @@ -1878,7 +1853,7 @@ public class DefinitelyWrittenCheck { calleeIntersectBoundSharedSet.addWrite(argLocTuple, argHeapPath); - } else { + } else if (ssjava.needTobeAnnotated(fc.getMethod())) { // if arg is not primitive type, we need to propagate maywritten set to // the caller's location path @@ -2261,16 +2236,22 @@ public class DefinitelyWrittenCheck { NTuple rhsHeapPath = mapHeapPath.get(rhs); - if (lhs.getType().isPrimitive()) { - NTuple lhsHeapPath = new NTuple(); - lhsHeapPath.add(lhs); - mapHeapPath.put(lhs, lhsHeapPath); - } else if (rhsHeapPath != null) { + // if (lhs.getType().isPrimitive()) { + // NTuple lhsHeapPath = new NTuple(); + // lhsHeapPath.add(lhs); + // mapHeapPath.put(lhs, lhsHeapPath); + // } else + + if (rhsHeapPath != null) { mapHeapPath.put(lhs, mapHeapPath.get(rhs)); } else { - NTuple heapPath = new NTuple(); - heapPath.add(rhs); - mapHeapPath.put(lhs, heapPath); + if (isEventLoopBody) { + NTuple heapPath = new NTuple(); + heapPath.add(rhs); + mapHeapPath.put(lhs, heapPath); + } else { + break; + } } // shared loc extension @@ -2632,10 +2613,8 @@ public class DefinitelyWrittenCheck { } else { if (td.getSymbol().startsWith("this")) { NTuple thisPath = deriveThisLocationTuple(md); - NTuple rtrPath = new NTuple(); rtrPath.addAll(thisPath); - return rtrPath; } else {