From 7becd1f25e9936c0aabe197eadff78ebb73ba3e9 Mon Sep 17 00:00:00 2001 From: yeom Date: Thu, 7 Feb 2013 01:50:54 +0000 Subject: [PATCH] changes for the naive approach --- Robust/src/Analysis/SSJava/BuildLattice.java | 5 +- .../Analysis/SSJava/LocationInference.java | 52 ++++++++++++++----- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/Robust/src/Analysis/SSJava/BuildLattice.java b/Robust/src/Analysis/SSJava/BuildLattice.java index 3bd84fef..f8b5e14a 100644 --- a/Robust/src/Analysis/SSJava/BuildLattice.java +++ b/Robust/src/Analysis/SSJava/BuildLattice.java @@ -62,6 +62,7 @@ public class BuildLattice { } + // ///////////////////////////////////////////////////////////////////////////////////// // lattice generation for the native approach BasisSet naiveBasisSet = naiveGraph.computeBasisSet(nodeSetWithCompositeLocation); // debug_print(inputGraph); @@ -73,6 +74,8 @@ public class BuildLattice { SSJavaLattice naive_lattice = buildLattice(desc, naiveBasisSet, naiveGraph, null, naive_mapImSucc); LocationInference.numLocationsNaive += naive_lattice.getKeySet().size(); + infer.addNaiveLattice(desc, naive_lattice); + // ///////////////////////////////////////////////////////////////////////////////////// // lattice generation for the proposed approach BasisSet basisSet = inputGraph.computeBasisSet(nodeSetWithCompositeLocation); @@ -265,7 +268,7 @@ public class BuildLattice { // System.out.println("***nodeSet=" + nodeSet); for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { HNode node = (HNode) iterator.next(); - // System.out.println("node=" + node); + System.out.println("node=" + node); if (node.isSkeleton() && (!visited.contains(node))) { visited.add(node); diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 63514e30..61c61b1a 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -77,6 +77,9 @@ public class LocationInference { // keep current descriptors to visit in fixed-point interprocedural analysis, private Stack methodDescriptorsToVisitStack; + // map a descriptor to a naive lattice + private Map> desc2naiveLattice; + // map a class descriptor to a field lattice private Map> cd2lattice; @@ -194,6 +197,8 @@ public class LocationInference { this.mapMethodDescriptorToFlowGraph = new HashMap(); this.cd2lattice = new HashMap>(); this.md2lattice = new HashMap>(); + this.desc2naiveLattice = new HashMap>(); + this.methodDescriptorsToVisitStack = new Stack(); this.mapMethodDescriptorToMethodInvokeNodeSet = new HashMap>(); @@ -2565,19 +2570,35 @@ public class LocationInference { for (Iterator iterator = cdKeySet.iterator(); iterator.hasNext();) { ClassDescriptor cd = (ClassDescriptor) iterator.next(); // System.out.println("########cd=" + cd); - writeInferredLatticeDotFile((ClassDescriptor) cd, getSkeletonCombinationHierarchyGraph(cd), - cd2lattice.get(cd), ""); + writeInferredLatticeDotFile((ClassDescriptor) cd, cd2lattice.get(cd), ""); COUNT += cd2lattice.get(cd).getKeySet().size(); } Set mdKeySet = md2lattice.keySet(); for (Iterator iterator = mdKeySet.iterator(); iterator.hasNext();) { MethodDescriptor md = (MethodDescriptor) iterator.next(); - writeInferredLatticeDotFile(md.getClassDesc(), md, getSkeletonCombinationHierarchyGraph(md), - md2lattice.get(md), ""); + writeInferredLatticeDotFile(md.getClassDesc(), md, md2lattice.get(md), ""); COUNT += md2lattice.get(md).getKeySet().size(); } System.out.println("###COUNT=" + COUNT); + + Set descKeySet = desc2naiveLattice.keySet(); + for (Iterator iterator = descKeySet.iterator(); iterator.hasNext();) { + Descriptor desc = (Descriptor) iterator.next(); + // System.out.println("########cd=" + cd); + + ClassDescriptor cd_naive; + MethodDescriptor md_naive; + if (desc instanceof ClassDescriptor) { + cd_naive = (ClassDescriptor) desc; + md_naive = null; + } else { + md_naive = (MethodDescriptor) desc; + cd_naive = md_naive.getClassDesc(); + } + + writeInferredLatticeDotFile(cd_naive, md_naive, desc2naiveLattice.get(desc), "_naive"); + } } private void buildLattice(Descriptor desc) { @@ -2593,6 +2614,8 @@ public class LocationInference { buildLattice.insertIntermediateNodesToStraightLine(desc, simpleLattice); lattice.removeRedundantEdges(); + LocationInference.numLocationsSInfer += lattice.getKeySet().size(); + if (desc instanceof ClassDescriptor) { // field lattice cd2lattice.put((ClassDescriptor) desc, lattice); @@ -2607,6 +2630,7 @@ public class LocationInference { } + // deprecated: it builds method/class lattices without considering class inheritance private void buildLattice() { Set keySet = mapDescriptorToCombineSkeletonHierarchyGraph.keySet(); @@ -6568,15 +6592,15 @@ public class LocationInference { } - public void writeInferredLatticeDotFile(ClassDescriptor cd, HierarchyGraph simpleHierarchyGraph, - SSJavaLattice locOrder, String nameSuffix) { + public void writeInferredLatticeDotFile(ClassDescriptor cd, SSJavaLattice locOrder, + String nameSuffix) { // System.out.println("@cd=" + cd); // System.out.println("@sharedLoc=" + locOrder.getSharedLocSet()); - writeInferredLatticeDotFile(cd, null, simpleHierarchyGraph, locOrder, nameSuffix); + writeInferredLatticeDotFile(cd, null, locOrder, nameSuffix); } public void writeInferredLatticeDotFile(ClassDescriptor cd, MethodDescriptor md, - HierarchyGraph simpleHierarchyGraph, SSJavaLattice locOrder, String nameSuffix) { + SSJavaLattice locOrder, String nameSuffix) { String fileName = "lattice_"; if (md != null) { @@ -6608,12 +6632,12 @@ public class LocationInference { String lowLocId = pair.getSecond(); if (!addedLocSet.contains(highLocId)) { addedLocSet.add(highLocId); - drawNode(bw, locOrder, simpleHierarchyGraph, highLocId); + drawNode(bw, locOrder, highLocId); } if (!addedLocSet.contains(lowLocId)) { addedLocSet.add(lowLocId); - drawNode(bw, locOrder, simpleHierarchyGraph, lowLocId); + drawNode(bw, locOrder, lowLocId); } bw.write(highLocId + " -> " + lowLocId + ";\n"); @@ -6642,8 +6666,12 @@ public class LocationInference { return str; } - private void drawNode(BufferedWriter bw, SSJavaLattice lattice, HierarchyGraph graph, - String locName) throws IOException { + public void addNaiveLattice(Descriptor desc, SSJavaLattice lattice) { + desc2naiveLattice.put(desc, lattice); + } + + private void drawNode(BufferedWriter bw, SSJavaLattice lattice, String locName) + throws IOException { String prettyStr; if (lattice.isSharedLoc(locName)) { -- 2.34.1