From: yeom Date: Wed, 30 Nov 2011 00:50:58 +0000 (+0000) Subject: more changes. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4e6e3860c77a7d2a8817976d909533a74ce8d02c;p=IRC.git more changes. --- diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index c4524b92..63cbf7e3 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -58,7 +58,7 @@ public class DefinitelyWrittenCheck { private Hashtable> mapHeapPath; // maps a temp descriptor to its composite location - private Hashtable> mapDescriptorToLocationStrPath; + private Hashtable> mapDescriptorToLocationStrPath; // maps a flat method to the READ that is the set of heap path that is // expected to be written before method invocation @@ -129,7 +129,9 @@ public class DefinitelyWrittenCheck { // it is for setting clearance flag when all read set is overwritten private Hashtable mapMethodDescriptorToReadSummary; - private MultiSourceMap mapLocationPathToMayWrittenSet; + private MultiSourceMap mapLocationPathToMayWrittenSet; + + private Hashtable> mapMethodToSharedWriteMapping; private Hashtable mapFlatNodeToSharedLocMapping; @@ -160,7 +162,7 @@ public class DefinitelyWrittenCheck { this.mapFlatNodeToMustWriteSet = new Hashtable>>(); this.mapDescriptorToSetDependents = new Hashtable>(); this.mapHeapPath = new Hashtable>(); - this.mapDescriptorToLocationStrPath = new Hashtable>(); + this.mapDescriptorToLocationStrPath = new Hashtable>(); this.mapFlatMethodToReadSet = new Hashtable>>(); this.mapFlatMethodToMustWriteSet = new Hashtable>>(); this.mapFlatMethodToMayWriteSet = new Hashtable>>(); @@ -191,7 +193,9 @@ public class DefinitelyWrittenCheck { this.calleeUnionBoundDeleteSet = new HashSet>(); this.calleeIntersectBoundSharedSet = new SharedLocMappingSet(); this.mapFlatMethodToSharedLocMappingSet = new Hashtable(); - this.mapLocationPathToMayWrittenSet = new MultiSourceMap(); + this.mapLocationPathToMayWrittenSet = new MultiSourceMap(); + this.mapMethodToSharedWriteMapping = + new Hashtable>(); } public void definitelyWrittenCheck() { @@ -202,7 +206,7 @@ public class DefinitelyWrittenCheck { System.out.println("#"); System.out.println(mapLocationPathToMayWrittenSet); - // methodReadWriteSetAnalysis(); + methodReadWriteSetAnalysis(); // sharedLocAnalysis(); @@ -1114,8 +1118,6 @@ public class DefinitelyWrittenCheck { private void computeSharedCoverSet_analyzeMethod(FlatMethod fm, boolean onlyVisitSSJavaLoop) { - System.out.println("computeSharedCoverSet_analyzeMethod=" + fm); - MethodDescriptor md = fm.getMethod(); Set flatNodesToVisit = new HashSet(); @@ -1147,10 +1149,6 @@ public class DefinitelyWrittenCheck { } - System.out.println("result=" + mapLocationPathToMayWrittenSet); - System.out.println("###############"); - System.out.println(); - } private void computeSharedCoverSet_nodeActions(MethodDescriptor md, FlatNode fn) { @@ -1192,8 +1190,9 @@ public class DefinitelyWrittenCheck { && !lhs.getSymbol().startsWith("srctmp") && !lhs.getSymbol().startsWith("leftop") && !lhs.getSymbol().startsWith("rightop")) { - NTuple locStrTuple = deriveLocationTuple(md, rhs); - mapLocationPathToMayWrittenSet.put(locStrTuple, null, lhs); + NTuple locTuple = deriveLocationTuple(md, rhs); + mapLocationPathToMayWrittenSet.put(locTuple, null, lhs); + addMayWrittenSet(md, locTuple, lhs); } @@ -1201,13 +1200,9 @@ public class DefinitelyWrittenCheck { mapDescriptorToLocationStrPath.put(lhs, mapDescriptorToLocationStrPath.get(rhs)); } else { if (rhs.getType().getExtension() instanceof SSJavaType) { - NTuple locStrTuple = new NTuple(); NTuple locTuple = ((SSJavaType) rhs.getType().getExtension()).getCompLoc().getTuple(); - for (int i = 0; i < locTuple.size(); i++) { - locStrTuple.add(locTuple.get(i).getSymbol()); - } - mapDescriptorToLocationStrPath.put(lhs, locStrTuple); + mapDescriptorToLocationStrPath.put(lhs, locTuple); } } @@ -1238,12 +1233,12 @@ public class DefinitelyWrittenCheck { addSharedLocDescriptor(fieldLocation, fld); System.out.println("FIELD WRITE FN=" + fn); - NTuple locStrTuple = deriveLocationTuple(md, lhs); - locStrTuple.addAll(deriveLocationTuple(md, fld)); - System.out.println("LOC TUPLE=" + locStrTuple); - - mapLocationPathToMayWrittenSet.put(locStrTuple, null, fld); + NTuple locTuple = deriveLocationTuple(md, lhs); + locTuple.addAll(deriveLocationTuple(md, fld)); + System.out.println("LOC TUPLE=" + locTuple); + // mapLocationPathToMayWrittenSet.put(locTuple, null, fld); + addMayWrittenSet(md, locTuple, fld); } } @@ -1272,16 +1267,16 @@ public class DefinitelyWrittenCheck { break; } - NTuple locStrTuple = deriveLocationTuple(md, rhs); - locStrTuple.addAll(deriveLocationTuple(md, fld)); - mapDescriptorToLocationStrPath.put(lhs, locStrTuple); + NTuple locTuple = deriveLocationTuple(md, rhs); + locTuple.addAll(deriveLocationTuple(md, fld)); + mapDescriptorToLocationStrPath.put(lhs, locTuple); } break; case FKind.FlatCall: { - System.out.println("###FLATCALL=" + fn); + // System.out.println("###FLATCALL=" + fn); FlatCall fc = (FlatCall) fn; bindLocationPathCallerArgWithCalleeParam(md, fc); @@ -1291,15 +1286,33 @@ public class DefinitelyWrittenCheck { } } + private void addMayWrittenSet(MethodDescriptor md, NTuple locTuple, Descriptor d) { + + MultiSourceMap map = mapMethodToSharedWriteMapping.get(md); + if (map == null) { + map = new MultiSourceMap(); + mapMethodToSharedWriteMapping.put(md, map); + } + + Set writeSet = map.get(locTuple); + if (writeSet == null) { + writeSet = new HashSet(); + map.put(locTuple, writeSet); + } + writeSet.add(d); + + System.out.println("ADD WRITE DESC=" + d + " TO locTuple=" + locTuple); + } + private void bindLocationPathCallerArgWithCalleeParam(MethodDescriptor mdCaller, FlatCall fc) { if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) { // ssjava util case! // have write effects on the first argument TempDescriptor arg = fc.getArg(0); - NTuple argLocationStrPath = deriveLocationTuple(mdCaller, arg); + NTuple argLocationPath = deriveLocationTuple(mdCaller, arg); NTuple argHeapPath = computePath(arg); - mapLocationPathToMayWrittenSet.put(argLocationStrPath, null, + mapLocationPathToMayWrittenSet.put(argLocationPath, null, argHeapPath.get(argHeapPath.size() - 1)); } else { @@ -1312,19 +1325,26 @@ public class DefinitelyWrittenCheck { setPossibleCallees.addAll(callGraph.getMethods(mdCallee)); // create mapping from arg idx to its heap paths - Hashtable> mapArgIdx2CallerAgLocationStrPath = - new Hashtable>(); + Hashtable> mapArgIdx2CallerAgLocationStrPath = + new Hashtable>(); // arg idx is starting from 'this' arg if (fc.getThis() != null) { - NTuple thisLocationStrPath = deriveLocationTuple(mdCaller, fc.getThis()); - mapArgIdx2CallerAgLocationStrPath.put(Integer.valueOf(0), thisLocationStrPath); + NTuple thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis()); + mapArgIdx2CallerAgLocationStrPath.put(Integer.valueOf(0), thisLocationPath); + } + + Hashtable> mapParamIdx2WriteSet = + new Hashtable>(); + + for (int i = 0; i < fc.numArgs() + 1; i++) { + mapParamIdx2WriteSet.put(Integer.valueOf(i), new HashSet()); } for (int i = 0; i < fc.numArgs(); i++) { TempDescriptor arg = fc.getArg(i); - NTuple argLocationStrPath = deriveLocationTuple(mdCaller, arg); - mapArgIdx2CallerAgLocationStrPath.put(Integer.valueOf(i + 1), argLocationStrPath); + NTuple argLocationPath = deriveLocationTuple(mdCaller, arg); + mapArgIdx2CallerAgLocationStrPath.put(Integer.valueOf(i + 1), argLocationPath); } for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) { @@ -1348,12 +1368,19 @@ public class DefinitelyWrittenCheck { Set keySet = mapArgIdx2CallerAgLocationStrPath.keySet(); for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) { Integer idx = (Integer) iterator2.next(); - NTuple callerArgLocationStrPath = mapArgIdx2CallerAgLocationStrPath.get(idx); + NTuple callerArgLocationStrPath = mapArgIdx2CallerAgLocationStrPath.get(idx); TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx); - NTuple calleeLocationStrPath = deriveLocationTuple(mdCallee, calleeParam); + NTuple calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam); - createNewMappingOfMayWrittenSet(callerArgLocationStrPath, calleeLocationStrPath); + // System.out.println("#createNewMappingOfMayWrittenSet callee=" + + // callee + // + " callerArgLocationStrPath=" + callerArgLocationStrPath + + // "calleeLocationPath=" + // + calleeLocationPath + " idx=" + idx + " writeset=" + + // mapParamIdx2WriteSet.get(idx)); + createNewMappingOfMayWrittenSet(callee, callerArgLocationStrPath, calleeLocationPath, + mapParamIdx2WriteSet.get(idx)); } @@ -1363,8 +1390,8 @@ public class DefinitelyWrittenCheck { } - private void createNewMappingOfMayWrittenSet(NTuple callerPath, - NTuple calleeParamPath) { + private void createNewMappingOfMayWrittenSet(MethodDescriptor callee, + NTuple callerPath, NTuple calleeParamPath, Set writeSet) { // propagate may-written-set associated with the key that is started with // calleepath to the caller @@ -1373,27 +1400,36 @@ public class DefinitelyWrittenCheck { // 2) create new mapping of may-written-set of callee path to caller path // extract all may written effect accessed through callee param path - Hashtable, Set> mapping = - mapLocationPathToMayWrittenSet.getMappingByStartedWith(calleeParamPath); - System.out.println("CALLEE MAPPING=" + mapping); + MultiSourceMap mapping = mapMethodToSharedWriteMapping.get(callee); - Set> calleeKeySet = mapping.keySet(); + if (mapping == null) { + return; + } + + Hashtable, Set> paramMapping = + mapping.getMappingByStartedWith(calleeParamPath); + + Set> calleeKeySet = mapping.keySet(); for (Iterator iterator = calleeKeySet.iterator(); iterator.hasNext();) { - NTuple calleeKey = (NTuple) iterator.next(); - Set calleeMayWriteSet = mapLocationPathToMayWrittenSet.get(calleeKey); + NTuple calleeKey = (NTuple) iterator.next(); + Set calleeMayWriteSet = paramMapping.get(calleeKey); + + if (calleeMayWriteSet != null) { + writeSet.addAll(calleeMayWriteSet); + + NTuple newKey = new NTuple(); + newKey.addAll(callerPath); + // need to replace the local location with the caller's path so skip the + // local location of the parameter + for (int i = 1; i < calleeKey.size(); i++) { + newKey.add(calleeKey.get(i)); + } - NTuple newKey = new NTuple(); - newKey.addAll(callerPath); - // need to replace the local location with the caller's path so skip the - // local location of the parameter - for (int i = 1; i < calleeKey.size(); i++) { - newKey.add(calleeKey.get(i)); + System.out.println("calleeParamPath=" + calleeParamPath + " newKey=" + newKey + + " maywriteSet=" + writeSet); + mapLocationPathToMayWrittenSet.put(calleeKey, newKey, writeSet); } - System.out.println("calleeParamPath=" + calleeParamPath + " newKey=" + newKey - + " maywriteSet=" + calleeMayWriteSet); - mapLocationPathToMayWrittenSet.put(newKey, calleeKey, calleeMayWriteSet); - } } @@ -1406,24 +1442,10 @@ public class DefinitelyWrittenCheck { mapSharedLocationToCoverSet.put(sharedLoc, descSet); } - System.out.println("add " + desc + " to shared loc" + sharedLoc); descSet.add(desc); } - private void mergeReadLocationAnaylsis(ReadSummary curr, Set inSet) { - - if (inSet.size() == 0) { - return; - } - - for (Iterator inIterator = inSet.iterator(); inIterator.hasNext();) { - ReadSummary inSummary = (ReadSummary) inIterator.next(); - curr.merge(inSummary); - } - - } - private boolean hasReadingEffectOnSharedLocation(MethodDescriptor md, NTuple hp, Location loc, Descriptor d) { @@ -2848,15 +2870,15 @@ public class DefinitelyWrittenCheck { } } - private NTuple deriveThisLocationTuple(MethodDescriptor md) { + private NTuple deriveThisLocationTuple(MethodDescriptor md) { String thisLocIdentifier = ssjava.getMethodLattice(md).getThisLoc(); Location thisLoc = new Location(md, thisLocIdentifier); - NTuple locStrTuple = new NTuple(); - locStrTuple.add(thisLoc.getSymbol()); - return locStrTuple; + NTuple locTuple = new NTuple(); + locTuple.add(thisLoc); + return locTuple; } - private NTuple deriveLocationTuple(MethodDescriptor md, TempDescriptor td) { + private NTuple deriveLocationTuple(MethodDescriptor md, TempDescriptor td) { assert td.getType() != null; @@ -2868,24 +2890,20 @@ public class DefinitelyWrittenCheck { } else { NTuple locTuple = ((SSJavaType) td.getType().getExtension()).getCompLoc().getTuple(); - NTuple locStrTuple = new NTuple(); - for (int i = 0; i < locTuple.size(); i++) { - locStrTuple.add(locTuple.get(i).getSymbol()); - } - return locStrTuple; + return locTuple; } } } - private NTuple deriveLocationTuple(MethodDescriptor md, FieldDescriptor fld) { + private NTuple deriveLocationTuple(MethodDescriptor md, FieldDescriptor fld) { assert fld.getType() != null; Location fieldLoc = (Location) fld.getType().getExtension(); - NTuple locStrTuple = new NTuple(); - locStrTuple.add(fieldLoc.getSymbol()); - return locStrTuple; + NTuple locTuple = new NTuple(); + locTuple.add(fieldLoc); + return locTuple; } } \ No newline at end of file diff --git a/Robust/src/Analysis/SSJava/MultiSourceMap.java b/Robust/src/Analysis/SSJava/MultiSourceMap.java index 68135da2..1dc22ec7 100644 --- a/Robust/src/Analysis/SSJava/MultiSourceMap.java +++ b/Robust/src/Analysis/SSJava/MultiSourceMap.java @@ -13,6 +13,10 @@ public class MultiSourceMap { map = new Hashtable, Set>(); } + public void put(NTuple key, Set set) { + map.put(key, set); + } + public void put(NTuple key, NTuple setKey, Set set) { if (!map.containsKey(setKey)) { @@ -64,4 +68,8 @@ public class MultiSourceMap { return rtrMapping; } + + public Set> keySet() { + return map.keySet(); + } }