From 8c2890bf00bb5ab0be44c3900d7e38e15ae2343a Mon Sep 17 00:00:00 2001 From: yeom Date: Thu, 1 Dec 2011 20:38:19 +0000 Subject: [PATCH] fix problems of shared loc extension --- .../SSJava/DefinitelyWrittenCheck.java | 470 ++++++++++-------- Robust/src/Analysis/SSJava/SharedLocMap.java | 69 ++- 2 files changed, 312 insertions(+), 227 deletions(-) diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index 237cacd4..d14c5e2c 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -57,7 +57,7 @@ public class DefinitelyWrittenCheck { private Hashtable> mapHeapPath; // maps a temp descriptor to its composite location - private Hashtable> mapDescriptorToLocationPath; + private Hashtable> mapDescriptorToLocationPath; // maps a flat method to the READ that is the set of heap path that is // expected to be written before method invocation @@ -146,8 +146,8 @@ public class DefinitelyWrittenCheck { private Set> calleeUnionBoundReadSet; private Set> calleeIntersectBoundMustWriteSet; private Set> calleeUnionBoundMayWriteSet; - private Set> calleeUnionBoundDeleteSet; - private Hashtable, Set> calleeIntersectBoundSharedSet; + private SharedLocMap calleeUnionBoundDeleteSet; + private SharedLocMap calleeIntersectBoundSharedSet; private Hashtable mapDescToLocation; @@ -162,7 +162,7 @@ public class DefinitelyWrittenCheck { this.mapFlatNodeToMustWriteSet = new Hashtable>>(); this.mapDescriptorToSetDependents = new Hashtable>(); this.mapHeapPath = new Hashtable>(); - this.mapDescriptorToLocationPath = new Hashtable>(); + this.mapDescriptorToLocationPath = new Hashtable>(); this.mapFlatMethodToReadSet = new Hashtable>>(); this.mapFlatMethodToMustWriteSet = new Hashtable>>(); this.mapFlatMethodToMayWriteSet = new Hashtable>>(); @@ -190,8 +190,8 @@ public class DefinitelyWrittenCheck { this.mapSharedLocationToCoverSet = new Hashtable>(); this.mapFlatNodeToSharedLocMapping = new Hashtable(); this.mapFlatMethodToDeleteSet = new Hashtable(); - this.calleeUnionBoundDeleteSet = new HashSet>(); - this.calleeIntersectBoundSharedSet = new Hashtable, Set>(); + this.calleeUnionBoundDeleteSet = new SharedLocMap(); + this.calleeIntersectBoundSharedSet = new SharedLocMap(); this.mapFlatMethodToSharedLocMap = new Hashtable(); this.mapLocationPathToMayWrittenSet = new MultiSourceMap(); this.mapMethodToSharedWriteMapping = @@ -204,21 +204,14 @@ public class DefinitelyWrittenCheck { initialize(); computeSharedCoverSet(); - System.out.println("#"); - System.out.println(mapLocationPathToMayWrittenSet); + // System.out.println("#"); + // System.out.println(mapLocationPathToMayWrittenSet); methodReadWriteSetAnalysis(); sharedLocAnalysis(); - // eventLoopAnalysis(); + eventLoopAnalysis(); - // XXXXXXX - // methodReadWriteSetAnalysis(); - // methodReadWriteSetAnalysisToEventLoopBody(); - // eventLoopAnalysis(); - // XXXXXXX - // sharedLocationAnalysis(); - // checkSharedLocationResult(); } } @@ -376,33 +369,32 @@ public class DefinitelyWrittenCheck { Location dstLoc = getLocation(lhs); if (dstLoc != null && ssjava.isSharedLocation(dstLoc)) { - System.out.println("FlatOpNode=" + fon); - } + NTuple lhsHeapPath = computePath(lhs); + NTuple lhsLocTuple = mapDescriptorToLocationPath.get(lhs); - NTuple lhsHeapPath = computePath(lhs); - NTuple lhsLocTuple = mapDescriptorToLocationPath.get(lhs); + Location srcLoc = getLocation(lhs); - Location srcLoc = getLocation(lhs); + // computing gen/kill set + computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath); + if (!dstLoc.equals(srcLoc)) { + computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath); + updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath); + } else { + computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath); + updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath); + } - System.out.println("VAR WRITE:" + fn); - System.out.println("lhsLocTuple=" + lhsLocTuple + " lhsHeapPath=" + lhsHeapPath); - System.out.println("dstLoc=" + dstLoc + " srcLoc=" + srcLoc); + // System.out.println("VAR WRITE:" + fn); + // System.out.println("lhsLocTuple=" + lhsLocTuple + + // " lhsHeapPath=" + // + lhsHeapPath); + // System.out.println("dstLoc=" + dstLoc + " srcLoc=" + srcLoc); + // System.out.println("KILLSET=" + killSet); + // System.out.println("GENSet=" + genSet); + // System.out.println("DELETESET=" + currDeleteSet); - // computing gen/kill set - computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath); - if (!dstLoc.equals(srcLoc)) { - System.out.println("LOC IS DIFFERENT"); - computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath); - updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath); - } else { - computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath); - updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath); } - System.out.println("KILLSET=" + killSet); - System.out.println("GENSet=" + genSet); - System.out.println("DELETESET=" + currDeleteSet); - } } @@ -434,27 +426,30 @@ public class DefinitelyWrittenCheck { // only care the case that loc(f) is shared location // write(field) - NTuple fieldLocTuple = mapDescriptorToLocationPath.get(fld); + NTuple fieldLocTuple = new NTuple(); + fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs)); + fieldLocTuple.add(fieldLoc); + NTuple fldHeapPath = computePath(fld); // computing gen/kill set computeKILLSetForWrite(curr, killSet, fieldLocTuple, fldHeapPath); if (!fieldLoc.equals(srcLoc)) { - System.out.println("LOC IS DIFFERENT"); - computeGENSetForHigherWrite(curr, killSet, fieldLocTuple, fldHeapPath); + computeGENSetForHigherWrite(curr, genSet, fieldLocTuple, fldHeapPath); updateDeleteSetForHigherWrite(currDeleteSet, fieldLocTuple, fldHeapPath); } else { - computeGENSetForSameHeightWrite(curr, killSet, fieldLocTuple, fldHeapPath); + computeGENSetForSameHeightWrite(curr, genSet, fieldLocTuple, fldHeapPath); updateDeleteSetForSameHeightWrite(currDeleteSet, fieldLocTuple, fldHeapPath); } - System.out.println("################"); - System.out.println("FIELD WRITE:" + fn); - System.out.println("FldHeapPath=" + fldHeapPath); - System.out.println("fieldLocTuple=" + fieldLocTuple + " srcLoc=" + srcLoc); - System.out.println("KILLSET=" + killSet); - System.out.println("GENSet=" + genSet); - System.out.println("DELETESET=" + currDeleteSet); + // System.out.println("################"); + // System.out.println("FIELD WRITE:" + fn); + // System.out.println("FldHeapPath=" + fldHeapPath); + // System.out.println("fieldLocTuple=" + fieldLocTuple + " srcLoc=" + + // srcLoc); + // System.out.println("KILLSET=" + killSet); + // System.out.println("GENSet=" + genSet); + // System.out.println("DELETESET=" + currDeleteSet); } } @@ -463,34 +458,17 @@ public class DefinitelyWrittenCheck { case FKind.FlatCall: { FlatCall fc = (FlatCall) fn; - bindHeapPathCallerArgWithCaleeParamForSharedLoc(fc); - - // generateKILLSetForFlatCall(fc, curr, readWriteKillSet); - // generateGENSetForFlatCall(fc, readWriteGenSet); - - // System.out.println - // // only care the case that loc(f) is shared location - // // write(field) - // NTuple lhsHeapPath = computePath(lhs); - // NTuple fldHeapPath = new - // NTuple(lhsHeapPath.getList()); - // fldHeapPath.add(fld); - // - // // computing gen/kill set - // computeKILLSetForWrite(curr, lhsHeapPath, fieldLoc, killSet); - // if (!fieldLoc.equals(srcLoc)) { - // System.out.println("LOC IS DIFFERENT"); - // computeGENSetForHigherWrite(curr, lhsHeapPath, fieldLoc, fld, genSet); - // deleteSet.remove(fldHeapPath); - // } else { - // computeGENSetForSharedWrite(curr, lhsHeapPath, fieldLoc, fld, genSet); - // deleteSet.add(fldHeapPath); - // } - // ("FLATCALL:" + fn); + 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); // System.out.println("bound DELETE Set=" + calleeUnionBoundDeleteSet); - // // System.out.println("KILLSET=" + KILLSet); - // // System.out.println("GENSet=" + GENSet); - // + } break; @@ -499,12 +477,37 @@ public class DefinitelyWrittenCheck { mergeSharedLocMap(sharedLocMap, curr); mergeDeleteSet(deleteSet, currDeleteSet); + // System.out.println("#FLATEXIT sharedLocMap=" + sharedLocMap); } + break; } computeNewMapping(curr, killSet, genSet); - System.out.println("#######" + curr); + // System.out.println("#######" + curr); + + } + + private void generateGENSetForFlatCall(SharedLocMap curr, SharedLocMap genSet) { + + Set> locTupleSet = calleeIntersectBoundSharedSet.keySet(); + for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) { + NTuple locTupleKey = (NTuple) iterator.next(); + genSet.addWrite(locTupleKey, curr.get(locTupleKey)); + genSet.addWrite(locTupleKey, calleeIntersectBoundSharedSet.get(locTupleKey)); + + genSet.removeWriteAll(locTupleKey, calleeUnionBoundDeleteSet.get(locTupleKey)); + } + + } + + private void generateKILLSetForFlatCall(SharedLocMap curr, SharedLocMap killSet) { + + Set> locTupleSet = calleeIntersectBoundSharedSet.keySet(); + for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) { + NTuple locTupleKey = (NTuple) iterator.next(); + killSet.addWrite(locTupleKey, curr.get(locTupleKey)); + } } @@ -1242,9 +1245,11 @@ public class DefinitelyWrittenCheck { && !lhs.getSymbol().startsWith("srctmp") && !lhs.getSymbol().startsWith("leftop") && !lhs.getSymbol().startsWith("rightop")) { - NTuple locTuple = deriveLocationTuple(md, rhs); - mapLocationPathToMayWrittenSet.put(locTuple, null, lhs); - addMayWrittenSet(md, locTuple, lhs); + NTuple lhsLocTuple = new NTuple(); + lhsLocTuple.addAll(deriveLocationTuple(md, rhs)); + + mapLocationPathToMayWrittenSet.put(lhsLocTuple, null, lhs); + addMayWrittenSet(md, lhsLocTuple, lhs); } @@ -1252,9 +1257,15 @@ public class DefinitelyWrittenCheck { mapDescriptorToLocationPath.put(lhs, mapDescriptorToLocationPath.get(rhs)); } else { if (rhs.getType().getExtension() instanceof SSJavaType) { - NTuple locTuple = + NTuple rhsLocTuple = ((SSJavaType) rhs.getType().getExtension()).getCompLoc().getTuple(); - mapDescriptorToLocationPath.put(lhs, locTuple); + + NTuple lhsLocTuple = new NTuple(); + lhsLocTuple.addAll(rhsLocTuple); + + mapDescriptorToLocationPath.put(rhs, rhsLocTuple); + mapDescriptorToLocationPath.put(lhs, lhsLocTuple); + } } @@ -1284,15 +1295,13 @@ public class DefinitelyWrittenCheck { if (ssjava.isSharedLocation(fieldLocation)) { addSharedLocDescriptor(fieldLocation, fld); - // System.out.println("FIELD WRITE FN=" + fn); - NTuple locTuple = deriveLocationTuple(md, lhs); - locTuple.addAll(deriveLocationTuple(md, fld)); - // System.out.println("LOC TUPLE=" + locTuple); + NTuple locTuple = new NTuple(); + locTuple.addAll(deriveLocationTuple(md, lhs)); + locTuple.add(fieldLocation); // mapLocationPathToMayWrittenSet.put(locTuple, null, fld); addMayWrittenSet(md, locTuple, fld); - mapDescriptorToLocationPath.put(fld, locTuple); } } @@ -1321,8 +1330,10 @@ public class DefinitelyWrittenCheck { break; } - NTuple locTuple = deriveLocationTuple(md, rhs); - locTuple.addAll(deriveLocationTuple(md, fld)); + NTuple locTuple = new NTuple(); + locTuple.addAll(deriveLocationTuple(md, rhs)); + locTuple.add((Location) fld.getType().getExtension()); + mapDescriptorToLocationPath.put(lhs, locTuple); } @@ -1330,7 +1341,6 @@ public class DefinitelyWrittenCheck { case FKind.FlatCall: { - // System.out.println("###FLATCALL=" + fn); FlatCall fc = (FlatCall) fn; bindLocationPathCallerArgWithCalleeParam(md, fc); @@ -1479,8 +1489,6 @@ public class DefinitelyWrittenCheck { newKey.add(calleeKey.get(i)); } - System.out.println("calleeParamPath=" + calleeParamPath + " newKey=" + newKey - + " maywriteSet=" + writeSet); mapLocationPathToMayWrittenSet.put(calleeKey, newKey, writeSet); } @@ -1520,8 +1528,6 @@ public class DefinitelyWrittenCheck { private Location getLocation(Descriptor d) { - System.out.println("GETLOCATION d=" + d + " d=" + d.getClass()); - if (d instanceof FieldDescriptor) { TypeExtension te = ((FieldDescriptor) d).getType().getExtension(); if (te != null) { @@ -2049,107 +2055,160 @@ public class DefinitelyWrittenCheck { } - private void bindHeapPathCallerArgWithCaleeParamForSharedLoc(FlatCall fc) { - // // compute all possible callee set - // // transform all DELETE set from the any possible - // // callees to the caller - // calleeUnionBoundDeleteSet.clear(); - // calleeIntersectBoundSharedSet.clear(); - // - // MethodDescriptor mdCallee = fc.getMethod(); - // Set setPossibleCallees = new - // HashSet(); - // setPossibleCallees.addAll(callGraph.getMethods(mdCallee)); - // - // // 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 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()); - // } - // - // mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath); - // } - // - // for (int i = 0; i < fc.numArgs(); i++) { - // TempDescriptor arg = fc.getArg(i); - // NTuple argHeapPath = computePath(arg); - // mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath); - // } - // - // 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 - // - // Set> calleeReadSet = - // mapFlatMethodToDeleteSet.get(calleeFlatMethod); - // if (calleeReadSet == null) { - // calleeReadSet = new HashSet>(); - // mapFlatMethodToDeleteSet.put(calleeFlatMethod, calleeReadSet); - // } - // - // 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); - // } - // - // Set> calleeBoundDeleteSet = - // bindSet(calleeReadSet, mapParamIdx2ParamTempDesc, - // mapArgIdx2CallerArgHeapPath); - // // union of the current read set and the current callee's - // // read set - // calleeUnionBoundDeleteSet.addAll(calleeBoundDeleteSet); - // - // SharedLocMappingSet calleeSharedLocMap = - // mapFlatMethodToSharedLocMappingSet.get(calleeFlatMethod); - // - // Set> calleeHeapPathKeySet = - // calleeSharedLocMap.getHeapPathKeySet(); - // - // for (Iterator iterator2 = calleeHeapPathKeySet.iterator(); - // iterator2.hasNext();) { - // NTuple calleeHeapPathKey = (NTuple) - // iterator2.next(); - // - // NTuple calleeBoundHeapPathKey = - // bind(calleeHeapPathKey, mapParamIdx2ParamTempDesc, - // mapArgIdx2CallerArgHeapPath); - // - // Set calleeLocSet = - // calleeSharedLocMap.getLocationKeySet(calleeHeapPathKey); - // - // for (Iterator iterator3 = calleeLocSet.iterator(); iterator3.hasNext();) - // { - // Location calleeLocKey = (Location) iterator3.next(); - // Set calleeWriteSet = - // calleeSharedLocMap.getWriteSet(calleeHeapPathKey, calleeLocKey); - // - // calleeIntersectBoundSharedSet.intersectWriteSet(calleeBoundHeapPathKey, - // calleeLocKey, - // calleeWriteSet); - // - // } - // - // } - // - // } - // + private void bindHeapPathCallerArgWithCaleeParamForSharedLoc(MethodDescriptor mdCaller, + FlatCall fc) { + + calleeIntersectBoundSharedSet.clear(); + calleeUnionBoundDeleteSet.clear(); + + // if arg is not primitive type, we need to propagate maywritten set to + // the caller's location path + + MethodDescriptor mdCallee = fc.getMethod(); + Set setPossibleCallees = new HashSet(); + setPossibleCallees.addAll(callGraph.getMethods(mdCallee)); + + // 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 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()); + } + + mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath); + } + + for (int i = 0; i < fc.numArgs(); i++) { + TempDescriptor arg = fc.getArg(i); + NTuple argHeapPath = computePath(arg); + mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath); + } + + // create mapping from arg idx to its location paths + Hashtable> mapArgIdx2CallerAgLocationPath = + 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); + } + + for (int i = 0; i < fc.numArgs(); i++) { + TempDescriptor arg = fc.getArg(i); + NTuple argLocationPath = deriveLocationTuple(mdCaller, arg); + mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(i + 1), argLocationPath); + } + + 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 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); + } + + 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); + } + + } + + } + + } + + private void createNewMappingOfDeleteSet(NTuple callerArgLocationPath, + NTuple callerArgHeapPath, NTuple calleeLocationPath, + SharedLocMap calleeDeleteSet) { + + SharedLocMap calleeParamDeleteSet = calleeDeleteSet.getHeapPathStartedWith(calleeLocationPath); + + Set> keySet = calleeParamDeleteSet.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + NTuple calleeLocTupleKey = (NTuple) iterator.next(); + Set> heapPathSet = calleeParamDeleteSet.get(calleeLocTupleKey); + for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) { + NTuple calleeHeapPath = (NTuple) iterator2.next(); + calleeUnionBoundDeleteSet.addWrite( + bindLocationPath(callerArgLocationPath, calleeLocTupleKey), + bindHeapPath(callerArgHeapPath, calleeHeapPath)); + } + } + + } + + private void createNewMappingOfSharedSet(NTuple callerArgLocationPath, + NTuple callerArgHeapPath, NTuple calleeLocationPath, + SharedLocMap calleeSharedLocMap) { + + SharedLocMap calleeParamSharedSet = + calleeSharedLocMap.getHeapPathStartedWith(calleeLocationPath); + + Set> keySet = calleeParamSharedSet.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + NTuple calleeLocTupleKey = (NTuple) iterator.next(); + Set> heapPathSet = calleeParamSharedSet.get(calleeLocTupleKey); + Set> boundHeapPathSet = new HashSet>(); + for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) { + NTuple calleeHeapPath = (NTuple) iterator2.next(); + boundHeapPathSet.add(bindHeapPath(callerArgHeapPath, calleeHeapPath)); + } + calleeIntersectBoundSharedSet.intersect( + bindLocationPath(callerArgLocationPath, calleeLocTupleKey), boundHeapPathSet); + } + + } + + private NTuple bindLocationPath(NTuple start, NTuple end) { + NTuple locPath = new NTuple(); + locPath.addAll(start); + for (int i = 1; i < end.size(); i++) { + locPath.add(end.get(i)); + } + return locPath; + } + + private NTuple bindHeapPath(NTuple start, NTuple end) { + NTuple heapPath = new NTuple(); + heapPath.addAll(start); + for (int i = 1; i < end.size(); i++) { + heapPath.add(end.get(i)); + } + return heapPath; } private NTuple bind(NTuple calleeHeapPathKey, @@ -2612,19 +2671,6 @@ public class DefinitelyWrittenCheck { return in.subList(in.size() - 1, in.size()); } - private Set computeRemoveSet(NTuple hpKey, Location locKey) { - Set removeSet = new HashSet(); - - for (Iterator iterator = calleeUnionBoundDeleteSet.iterator(); iterator.hasNext();) { - NTuple removeHeapPath = (NTuple) iterator.next(); - if (getPrefix(removeHeapPath).equals(hpKey)) { - removeSet.add(getSuffix(removeHeapPath).get(0)); - } - } - - return removeSet; - } - static public FieldDescriptor getArrayField(TypeDescriptor td) { FieldDescriptor fd = mapTypeToArrayField.get(td); if (fd == null) { @@ -2869,14 +2915,4 @@ public class DefinitelyWrittenCheck { } - private NTuple deriveLocationTuple(MethodDescriptor md, FieldDescriptor fld) { - - assert fld.getType() != null; - - Location fieldLoc = (Location) fld.getType().getExtension(); - NTuple locTuple = new NTuple(); - locTuple.add(fieldLoc); - return locTuple; - } - } \ No newline at end of file diff --git a/Robust/src/Analysis/SSJava/SharedLocMap.java b/Robust/src/Analysis/SSJava/SharedLocMap.java index 822c3e2b..863ea95b 100644 --- a/Robust/src/Analysis/SSJava/SharedLocMap.java +++ b/Robust/src/Analysis/SSJava/SharedLocMap.java @@ -39,22 +39,41 @@ public class SharedLocMap { public void addWrite(NTuple locTuple, Set> hpSet) { - Set> writeSet = map.get(locTuple); - if (writeSet == null) { - writeSet = new HashSet>(); - map.put(locTuple, writeSet); + if (hpSet != null) { + Set> writeSet = map.get(locTuple); + if (writeSet == null) { + writeSet = new HashSet>(); + map.put(locTuple, writeSet); + } + writeSet.addAll(hpSet); } - writeSet.addAll(hpSet); + } public void addWrite(NTuple locTuple, NTuple hp) { - Set> writeSet = map.get(locTuple); - if (writeSet == null) { - writeSet = new HashSet>(); - map.put(locTuple, writeSet); + if (hp != null) { + Set> writeSet = map.get(locTuple); + if (writeSet == null) { + writeSet = new HashSet>(); + map.put(locTuple, writeSet); + } + writeSet.add(hp); } - writeSet.add(hp); + + } + + public void intersect(NTuple locTuple, Set> hpSet) { + + Set> set = map.get(locTuple); + if (set == null) { + set = new HashSet>(); + map.put(locTuple, set); + set.addAll(hpSet); + } + + set.addAll(hpSet); + } public void removeWrite(NTuple locTuple, NTuple hp) { @@ -64,6 +83,17 @@ public class SharedLocMap { } } + public void removeWriteAll(NTuple locTuple, Set> hpSet) { + + if(hpSet!=null){ + Set> writeSet = map.get(locTuple); + if (writeSet != null) { + writeSet.removeAll(hpSet); + } + } + + } + public String toString() { return map.toString(); } @@ -88,4 +118,23 @@ public class SharedLocMap { } } + public void clear() { + map.clear(); + } + + public SharedLocMap getHeapPathStartedWith(NTuple locTuple) { + + SharedLocMap rtrSet = new SharedLocMap(); + + Set> keySet = map.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + NTuple key = (NTuple) iterator.next(); + if (key.startsWith(locTuple)) { + rtrSet.addWrite(key, map.get(key)); + } + } + return rtrSet; + + } + } -- 2.34.1