From fe371c596d92481a3acb00894fbf92a8a2738daf Mon Sep 17 00:00:00 2001 From: yeom Date: Sat, 10 Dec 2011 00:17:50 +0000 Subject: [PATCH] changes. --- .../SSJava/DefinitelyWrittenCheck.java | 244 +++++++++++------- 1 file changed, 144 insertions(+), 100 deletions(-) diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index 9f27398a..35aef24d 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -398,6 +398,7 @@ public class DefinitelyWrittenCheck { NTuple locTuple = deriveLocationTuple(md, lhs); fieldLoc = locTuple.get(locTuple.size() - 1); + break; } if (!isEventLoopBody && fieldLoc.getDescriptor().equals(md)) { @@ -438,7 +439,9 @@ public class DefinitelyWrittenCheck { NTuple fldHeapPath = new NTuple(); fldHeapPath.addAll(computePath(lhs)); - fldHeapPath.add(fld); + if (fn.kind() == FKind.FlatSetFieldNode) { + fldHeapPath.add(fld); + } // computing gen/kill set computeKILLSetForWrite(curr, killSet, fieldLocTuple, fldHeapPath); @@ -466,19 +469,20 @@ public class DefinitelyWrittenCheck { case FKind.FlatCall: { FlatCall fc = (FlatCall) fn; - if (ssjava.needTobeAnnotated(fc.getMethod())) { + // if (ssjava.needTobeAnnotated(fc.getMethod())) { + // System.out.println("#FLATCALL=" + fc); - bindHeapPathCallerArgWithCaleeParamForSharedLoc(fm.getMethod(), fc); + bindHeapPathCallerArgWithCaleeParamForSharedLoc(fm.getMethod(), fc); - // computing gen/kill set - generateKILLSetForFlatCall(curr, killSet); - generateGENSetForFlatCall(curr, genSet); + // 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); -// System.out.println("bound DELETE Set=" + calleeUnionBoundDeleteSet); + // } + // System.out.println("#FLATCALL=" + fc); + // System.out.println("KILLSET=" + killSet); + // System.out.println("GENSet=" + genSet); + // System.out.println("bound DELETE Set=" + calleeUnionBoundDeleteSet); } break; @@ -496,7 +500,7 @@ public class DefinitelyWrittenCheck { computeNewMapping(curr, killSet, genSet); if (!curr.map.isEmpty()) { -// System.out.println(fn + "#######" + curr); + // System.out.println(fn + "#######" + curr); } } @@ -639,6 +643,7 @@ public class DefinitelyWrittenCheck { System.out.println("computeSharedCoverSet_analyzeMethod=" + fm); MethodDescriptor md = fm.getMethod(); + Set flatNodesToVisit = new HashSet(); Set visited = new HashSet(); @@ -717,7 +722,7 @@ public class DefinitelyWrittenCheck { NTuple rhsLocTuple = new NTuple(); NTuple lhsLocTuple = new NTuple(); if (mapDescriptorToLocationPath.containsKey(rhs)) { - mapDescriptorToLocationPath.put(lhs, mapDescriptorToLocationPath.get(rhs)); + mapDescriptorToLocationPath.put(lhs, deriveLocationTuple(md, rhs)); } else { // rhs side if (rhs.getType().getExtension() != null @@ -831,7 +836,9 @@ public class DefinitelyWrittenCheck { NTuple fieldHeapPath = new NTuple(); fieldHeapPath.addAll(computePath(lhs)); - fieldHeapPath.add(fld); + if (fn.kind() == FKind.FlatSetFieldNode) { + fieldHeapPath.add(fld); + } // mapLocationPathToMayWrittenSet.put(locTuple, null, fld); addMayWrittenSet(md, fieldLocTuple, fieldHeapPath); @@ -890,9 +897,9 @@ public class DefinitelyWrittenCheck { FlatCall fc = (FlatCall) fn; - if (ssjava.needTobeAnnotated(fc.getMethod())) { - bindLocationPathCallerArgWithCalleeParam(md, fc); - } + // if (ssjava.needTobeAnnotated(fc.getMethod())) { + bindLocationPathCallerArgWithCalleeParam(md, fc); + // } } break; @@ -966,11 +973,12 @@ public class DefinitelyWrittenCheck { mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(0), thisLocationPath); // heap path for 'this' - NTuple thisHeapPath = mapHeapPath.get(fc.getThis()); - if (thisHeapPath == null) { + NTuple thisHeapPath = new NTuple(); + if (mapHeapPath.containsKey(fc.getThis())) { + thisHeapPath.addAll(mapHeapPath.get(fc.getThis())); + } else { // method is called without creating new flat node representing // 'this' - thisHeapPath = new NTuple(); thisHeapPath.add(fc.getThis()); } mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath); @@ -1404,7 +1412,9 @@ public class DefinitelyWrittenCheck { // write(field) NTuple lhsHeapPath = computePath(lhs); NTuple fldHeapPath = new NTuple(lhsHeapPath.getList()); - fldHeapPath.add(fld); + if (fn.kind() == FKind.FlatSetFieldNode) { + fldHeapPath.add(fld); + } // shared loc extension Location fieldLoc = (Location) fld.getType().getExtension(); @@ -1412,7 +1422,9 @@ public class DefinitelyWrittenCheck { NTuple fieldLocTuple = new NTuple(); fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs)); - fieldLocTuple.add(fieldLoc); + if (fn.kind() == FKind.FlatSetFieldNode) { + fieldLocTuple.add(fieldLoc); + } Set> writtenSet = mapFlatNodeToSharedLocMapping.get(fn).get(fieldLocTuple); @@ -1443,8 +1455,8 @@ public class DefinitelyWrittenCheck { generateKILLSetForFlatCall(fc, curr, sharedLocMap, readWriteKillSet); generateGENSetForFlatCall(fc, sharedLocMap, readWriteGenSet); -// System.out.println("KILLSET=" + readWriteKillSet); -// System.out.println("GENSet=" + readWriteGenSet); + // System.out.println("KILLSET=" + readWriteKillSet); + // System.out.println("GENSet=" + readWriteGenSet); checkManyRead(fc, curr); } @@ -1453,7 +1465,7 @@ public class DefinitelyWrittenCheck { } computeNewMapping(curr, readWriteKillSet, readWriteGenSet); -// System.out.println("#######" + curr); + // System.out.println("#######" + curr); } @@ -1542,7 +1554,7 @@ public class DefinitelyWrittenCheck { private void generateErrorMessage(NTuple path, FlatNode fn) { - Descriptor lastDesc = path.get(path.size() - 1); + Descriptor lastDesc = path.get(getArrayBaseDescriptorIdx(path)); if (ssjava.isSharedLocation(getLocation(lastDesc))) { NTuple locPathTuple = getLocationTuple(path); @@ -1568,7 +1580,7 @@ public class DefinitelyWrittenCheck { Hashtable, Set> GENSet) { Set> boundMayWriteSet = mapFlatNodeToBoundMayWriteSet.get(fc); -// System.out.println("boundMayWriteSet=" + boundMayWriteSet); + // System.out.println("boundMayWriteSet=" + boundMayWriteSet); for (Iterator iterator = boundMayWriteSet.iterator(); iterator.hasNext();) { NTuple heapPath = (NTuple) iterator.next(); @@ -1620,7 +1632,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(); @@ -1633,9 +1645,14 @@ public class DefinitelyWrittenCheck { KILLSet.put(heapPath, curr.get(heapPath)); } } else { - if (curr.get(heapPath) != null) { - KILLSet.put(heapPath, curr.get(heapPath)); + + for (Enumeration> e = curr.keys(); e.hasMoreElements();) { + NTuple key = e.nextElement(); + if (key.startsWith(heapPath)) { + KILLSet.put(key, curr.get(key)); + } } + } } @@ -1846,94 +1863,114 @@ public class DefinitelyWrittenCheck { calleeIntersectBoundSharedSet.clear(); calleeUnionBoundDeleteSet.clear(); - // if arg is not primitive type, we need to propagate maywritten set to - // the caller's location path + if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) { + // ssjava util case! + // have write effects on the first argument + TempDescriptor arg = fc.getArg(0); + NTuple argHeapPath = computePath(arg); - MethodDescriptor mdCallee = fc.getMethod(); - Set setPossibleCallees = new HashSet(); - setPossibleCallees.addAll(callGraph.getMethods(mdCallee)); + // convert heap path to location path + NTuple argLocTuple = new NTuple(); + argLocTuple.addAll(deriveLocationTuple(mdCaller, (TempDescriptor) argHeapPath.get(0))); + for (int i = 1; i < argHeapPath.size(); i++) { + argLocTuple.add(getLocation(argHeapPath.get(i))); + } - // create mapping from arg idx to its heap paths - Hashtable> mapArgIdx2CallerArgHeapPath = - new Hashtable>(); + calleeIntersectBoundSharedSet.addWrite(argLocTuple, argHeapPath); - // arg idx is starting from 'this' arg - if (fc.getThis() != null) { - NTuple thisHeapPath = mapHeapPath.get(fc.getThis()); - if (thisHeapPath == null) { - // method is called without creating new flat node representing 'this' - thisHeapPath = new NTuple(); - thisHeapPath.add(fc.getThis()); - } + } else { - mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath); - } + // if arg is not primitive type, we need to propagate maywritten set to + // the caller's location path - for (int i = 0; i < fc.numArgs(); i++) { - TempDescriptor arg = fc.getArg(i); - NTuple argHeapPath = computePath(arg); - mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath); - } + MethodDescriptor mdCallee = fc.getMethod(); + Set setPossibleCallees = new HashSet(); + setPossibleCallees.addAll(callGraph.getMethods(mdCallee)); - // create mapping from arg idx to its location paths - Hashtable> mapArgIdx2CallerAgLocationPath = - new Hashtable>(); + // create mapping from arg idx to its heap paths + Hashtable> mapArgIdx2CallerArgHeapPath = + new Hashtable>(); - // arg idx is starting from 'this' arg - if (fc.getThis() != null) { - NTuple thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis()); - mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath); - } + // arg idx is starting from 'this' arg + if (fc.getThis() != null) { + NTuple thisHeapPath = mapHeapPath.get(fc.getThis()); + if (thisHeapPath == null) { + // method is called without creating new flat node representing 'this' + thisHeapPath = new NTuple(); + thisHeapPath.add(fc.getThis()); + } - for (int i = 0; i < fc.numArgs(); i++) { - TempDescriptor arg = fc.getArg(i); - NTuple argLocationPath = deriveLocationTuple(mdCaller, arg); - if (argLocationPath != null) { - mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(i + 1), argLocationPath); + mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath); } - } - for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) { - MethodDescriptor callee = (MethodDescriptor) iterator.next(); - FlatMethod calleeFlatMethod = state.getMethodFlat(callee); + for (int i = 0; i < fc.numArgs(); i++) { + TempDescriptor arg = fc.getArg(i); + NTuple argHeapPath = computePath(arg); + mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath); + } - // binding caller's args and callee's params + // create mapping from arg idx to its location paths + Hashtable> mapArgIdx2CallerAgLocationPath = + new Hashtable>(); - Hashtable mapParamIdx2ParamTempDesc = - new Hashtable(); - int offset = 0; - if (calleeFlatMethod.getMethod().isStatic()) { - // static method does not have implicit 'this' arg - offset = 1; + // arg idx is starting from 'this' arg + if (fc.getThis() != null) { + NTuple thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis()); + if (thisLocationPath != null) { + mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath); + } } - for (int i = 0; i < calleeFlatMethod.numParameters(); i++) { - TempDescriptor param = calleeFlatMethod.getParameter(i); - mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param); + + for (int i = 0; i < fc.numArgs(); i++) { + TempDescriptor arg = fc.getArg(i); + NTuple argLocationPath = deriveLocationTuple(mdCaller, arg); + if (argLocationPath != null) { + mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(i + 1), argLocationPath); + } } - Set keySet = mapArgIdx2CallerAgLocationPath.keySet(); - for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) { - Integer idx = (Integer) iterator2.next(); - NTuple callerArgLocationPath = mapArgIdx2CallerAgLocationPath.get(idx); - NTuple callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx); + for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) { + MethodDescriptor callee = (MethodDescriptor) iterator.next(); + FlatMethod calleeFlatMethod = state.getMethodFlat(callee); - TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx); - NTuple calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam); - SharedLocMap calleeDeleteSet = mapFlatMethodToDeleteSet.get(calleeFlatMethod); - SharedLocMap calleeSharedLocMap = mapFlatMethodToSharedLocMap.get(calleeFlatMethod); + // binding caller's args and callee's params - if (calleeDeleteSet != null) { - createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath, calleeLocationPath, - calleeDeleteSet); + Hashtable mapParamIdx2ParamTempDesc = + new Hashtable(); + int offset = 0; + if (calleeFlatMethod.getMethod().isStatic()) { + // 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); } - if (calleeSharedLocMap != null) { - createNewMappingOfSharedSet(callerArgLocationPath, callerArgHeapPath, calleeLocationPath, - calleeSharedLocMap); + Set keySet = mapArgIdx2CallerAgLocationPath.keySet(); + for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) { + Integer idx = (Integer) iterator2.next(); + NTuple callerArgLocationPath = mapArgIdx2CallerAgLocationPath.get(idx); + NTuple callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx); + + TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx); + NTuple calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam); + SharedLocMap calleeDeleteSet = mapFlatMethodToDeleteSet.get(calleeFlatMethod); + SharedLocMap calleeSharedLocMap = mapFlatMethodToSharedLocMap.get(calleeFlatMethod); + + if (calleeDeleteSet != null) { + createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath, + calleeLocationPath, calleeDeleteSet); + } + + if (calleeSharedLocMap != null) { + createNewMappingOfSharedSet(callerArgLocationPath, callerArgHeapPath, + calleeLocationPath, calleeSharedLocMap); + } + } } - } } @@ -2295,7 +2332,10 @@ public class DefinitelyWrittenCheck { // callee's parameters. so just ignore it NTuple readingHeapPath = new NTuple(srcHeapPath.getList()); - readingHeapPath.add(fld); + if (fn.kind() == FKind.FlatFieldNode) { + readingHeapPath.add(fld); + } + mapHeapPath.put(lhs, readingHeapPath); // read (x.f) @@ -2337,12 +2377,16 @@ public class DefinitelyWrittenCheck { // if lhs heap path is null, it means that it is not reachable from // callee's parameters. so just ignore it NTuple fldHeapPath = new NTuple(lhsHeapPath.getList()); - fldHeapPath.add(fld); - mapHeapPath.put(fld, fldHeapPath); + if (fn.kind() != FKind.FlatSetElementNode) { + fldHeapPath.add(fld); + } + // mapHeapPath.put(fld, fldHeapPath); // write(x.f) // need to add hp(y) to WT - currMustWriteSet.add(fldHeapPath); + if (fn.kind() != FKind.FlatSetElementNode) { + currMustWriteSet.add(fldHeapPath); + } mayWriteSet.add(fldHeapPath); } -- 2.34.1