From: yeom Date: Tue, 7 Aug 2012 16:25:40 +0000 (+0000) Subject: changes. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=commitdiff_plain;h=91395d24f0facd4c9d37aa9818212c259b60e4c8 changes. --- diff --git a/Robust/src/Analysis/SSJava/Location.java b/Robust/src/Analysis/SSJava/Location.java index 7fe9331a..1c90d577 100644 --- a/Robust/src/Analysis/SSJava/Location.java +++ b/Robust/src/Analysis/SSJava/Location.java @@ -30,6 +30,10 @@ public class Location implements TypeExtension { } } + public void setLocIdentifier(String s) { + loc = s; + } + public void setLocDescriptor(Descriptor d) { locDesc = d; } diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 64aa39ad..ed8bb86d 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -46,6 +46,7 @@ import IR.Tree.SubBlockNode; import IR.Tree.SwitchStatementNode; import IR.Tree.TertiaryNode; import IR.Tree.TreeNode; +import Util.Pair; public class LocationInference { @@ -88,6 +89,8 @@ public class LocationInference { public static final Descriptor TOPDESC = new NameDescriptor(TOPLOC); + LocationInfo curMethodInfo; + boolean debug = true; public LocationInference(SSJavaAnalysis ssjava, State state) { @@ -290,6 +293,7 @@ public class LocationInference { new SSJavaLattice(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM); MethodLocationInfo methodInfo = new MethodLocationInfo(md); + curMethodInfo = methodInfo; System.out.println(); System.out.println("SSJAVA: Inferencing the lattice from " + md); @@ -731,6 +735,7 @@ public class LocationInference { private void addRelation(SSJavaLattice methodLattice, MethodLocationInfo methodInfo, CompositeLocation srcInferLoc, CompositeLocation dstInferLoc) throws CyclicFlowException { + System.out.println("--- srcInferLoc=" + srcInferLoc + " dstInferLoc=" + dstInferLoc); String srcLocalLocSymbol = srcInferLoc.get(0).getLocIdentifier(); String dstLocalLocSymbol = dstInferLoc.get(0).getLocIdentifier(); @@ -752,9 +757,11 @@ public class LocationInference { } } + System.out.println(); + } - private LocationInfo getLocationInfo(Descriptor d) { + public LocationInfo getLocationInfo(Descriptor d) { if (d instanceof MethodDescriptor) { return getMethodLocationInfo((MethodDescriptor) d); } else { @@ -1000,6 +1007,7 @@ public class LocationInference { inferLocation.addLocation(fieldLoc); methodInfo.mapDescriptorToLocation(localVarDesc, inferLocation); + addMapLocSymbolToInferredLocation(methodInfo.md, localVarDesc, inferLocation); methodInfo.removeMaplocalVarToLocSet(localVarDesc); String newMethodLocationSymbol = curPrefix.get(0).getLocIdentifier(); @@ -1039,6 +1047,7 @@ public class LocationInference { if (isCompositeLocation(inNodeInferLoc)) { // need to make sure that newLocSymbol is lower than the infernode // location in the field lattice + System.out.println("--- srcNode=" + localNode + " dstNode=" + flowNode); addRelation(methodLattice, methodInfo, inNodeInferLoc, inferLocation); } @@ -1071,6 +1080,7 @@ public class LocationInference { if (isCompositeLocation(outNodeInferLoc)) { // need to make sure that newLocSymbol is higher than the infernode // location + System.out.println("--- srcNode=" + flowNode + " dstNode=" + localOutNode); addRelation(methodLattice, methodInfo, inferLocation, outNodeInferLoc); @@ -1086,6 +1096,15 @@ public class LocationInference { } + private void addMapLocSymbolToInferredLocation(MethodDescriptor md, Descriptor localVar, + CompositeLocation inferLoc) { + + Location locElement = inferLoc.get((inferLoc.getSize() - 1)); + Descriptor enclosingDesc = locElement.getDescriptor(); + LocationInfo locInfo = getLocationInfo(enclosingDesc); + locInfo.addMapLocSymbolToRelatedInferLoc(locElement.getLocIdentifier(), md, localVar); + } + private boolean isCompositeLocation(CompositeLocation cl) { return cl.getSize() > 1; } @@ -1138,13 +1157,35 @@ public class LocationInference { } if (cycleElementSet.size() > 0) { + String newSharedLoc = "SharedLoc" + (SSJavaLattice.seed++); lattice.mergeIntoSharedLocation(cycleElementSet, newSharedLoc); for (Iterator iterator = cycleElementSet.iterator(); iterator.hasNext();) { String oldLocSymbol = (String) iterator.next(); - locInfo.mergeMapping(oldLocSymbol, newSharedLoc); + + Set> inferLocSet = locInfo.getRelatedInferLocSet(oldLocSymbol); + for (Iterator iterator2 = inferLocSet.iterator(); iterator2.hasNext();) { + Pair pair = (Pair) iterator2.next(); + Descriptor enclosingDesc = pair.getFirst(); + Descriptor desc = pair.getSecond(); + + CompositeLocation inferLoc; + if (curMethodInfo.md.equals(enclosingDesc)) { + inferLoc = curMethodInfo.getInferLocation(desc); + } else { + inferLoc = getLocationInfo(enclosingDesc).getInferLocation(desc); + } + + Location locElement = inferLoc.get(inferLoc.getSize() - 1); + + locElement.setLocIdentifier(newSharedLoc); + locInfo.addMapLocSymbolToRelatedInferLoc(newSharedLoc, enclosingDesc, desc); + + } + locInfo.removeRelatedInferLocSet(oldLocSymbol, newSharedLoc); + } lattice.addSharedLoc(newSharedLoc); diff --git a/Robust/src/Analysis/SSJava/LocationInfo.java b/Robust/src/Analysis/SSJava/LocationInfo.java index bfe82249..048f5cf1 100644 --- a/Robust/src/Analysis/SSJava/LocationInfo.java +++ b/Robust/src/Analysis/SSJava/LocationInfo.java @@ -9,12 +9,12 @@ import java.util.Set; import IR.ClassDescriptor; import IR.Descriptor; import IR.MethodDescriptor; +import Util.Pair; public class LocationInfo { - // Map mapDescToLocSymbol; Map> mapLocSymbolToDescSet; - + Map>> mapLocSymbolToRelatedInferLocSet; Map mapDescToInferCompositeLocation; MethodDescriptor md; ClassDescriptor cd; @@ -22,6 +22,7 @@ public class LocationInfo { public LocationInfo() { mapDescToInferCompositeLocation = new HashMap(); mapLocSymbolToDescSet = new HashMap>(); + mapLocSymbolToRelatedInferLocSet = new HashMap>>(); } public LocationInfo(ClassDescriptor cd) { @@ -37,27 +38,40 @@ public class LocationInfo { return mapDescToInferCompositeLocation; } + public void addMapLocSymbolToRelatedInferLoc(String locSymbol, Descriptor enclosingDesc, + Descriptor desc) { + if (!mapLocSymbolToRelatedInferLocSet.containsKey(locSymbol)) { + mapLocSymbolToRelatedInferLocSet.put(locSymbol, new HashSet>()); + } + mapLocSymbolToRelatedInferLocSet.get(locSymbol).add( + new Pair(enclosingDesc, desc)); + } + + public Set> getRelatedInferLocSet(String locSymbol) { + return mapLocSymbolToRelatedInferLocSet.get(locSymbol); + } + public void mapDescriptorToLocation(Descriptor desc, CompositeLocation inferLoc) { mapDescToInferCompositeLocation.put(desc, inferLoc); } - // public void mapDescSymbolToLocName(String descSymbol, String locName) { - // mapDescSymbolToLocName.put(descSymbol, locName); - // } - public CompositeLocation getInferLocation(Descriptor desc) { if (!mapDescToInferCompositeLocation.containsKey(desc)) { CompositeLocation newInferLoc = new CompositeLocation(); Location loc; + Descriptor enclosingDesc; if (md != null) { // method lattice - loc = new Location(md, desc.getSymbol()); + enclosingDesc = md; } else { - loc = new Location(cd, desc.getSymbol()); + enclosingDesc = cd; } + loc = new Location(enclosingDesc, desc.getSymbol()); + newInferLoc.addLocation(loc); mapDescToInferCompositeLocation.put(desc, newInferLoc); addMapLocSymbolToDescSet(desc.getSymbol(), desc); + addMapLocSymbolToRelatedInferLoc(desc.getSymbol(), enclosingDesc, desc); } return mapDescToInferCompositeLocation.get(desc); } @@ -80,49 +94,11 @@ public class LocationInfo { return mapLocSymbolToDescSet.get(locSymbol); } - public void mergeMapping(String oldLocSymbol, String newSharedLoc) { + public void removeRelatedInferLocSet(String oldLocSymbol, String newSharedLoc) { Set descSet = getDescSet(oldLocSymbol); getDescSet(newSharedLoc).addAll(descSet); mapLocSymbolToDescSet.remove(oldLocSymbol); - - Set keySet = mapDescToInferCompositeLocation.keySet(); - for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { - Descriptor key = (Descriptor) iterator.next(); - CompositeLocation inferLoc = getInferLocation(key); - - CompositeLocation newInferLoc = new CompositeLocation(); - if (inferLoc.getSize() > 1) { - // local variable has a composite location [refLoc.inferedLoc] - - Location oldLoc = inferLoc.get(inferLoc.getSize() - 1); - // oldLoc corresponds to infered loc. - - if (oldLoc.getLocIdentifier().equals(oldLocSymbol)) { - for (int i = 0; i < inferLoc.getSize() - 1; i++) { - Location loc = inferLoc.get(i); - newInferLoc.addLocation(loc); - } - Location newLoc = new Location(oldLoc.getDescriptor(), newSharedLoc); - newInferLoc.addLocation(newLoc); - mapDescriptorToLocation(key, newInferLoc); - } - // else { - // return; - // } - } else { - // local var has a local location - Location oldLoc = inferLoc.get(0); - if (oldLoc.getLocIdentifier().equals(oldLocSymbol)) { - Location newLoc = new Location(oldLoc.getDescriptor(), newSharedLoc); - newInferLoc.addLocation(newLoc); - mapDescriptorToLocation(key, newInferLoc); - } - // else { - // return; - // } - } - - } + mapLocSymbolToRelatedInferLocSet.remove(oldLocSymbol); } }