diff --git a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationSolver.java b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationSolver.java index bded7eca3..b6b33fc61 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationSolver.java +++ b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationSolver.java @@ -192,6 +192,13 @@ public class TabulationSolver { } } + /** + * Restart tabulation from a particular path edge. Use with care. + */ + public void propagate(PathEdge seed) { + propagate(seed.entry, seed.d1, seed.target, seed.d2); + } + /** * See POPL 95 paper for this algorithm, Figure 3 * @@ -700,7 +707,7 @@ public class TabulationSolver { } protected PathEdge popFromWorkList() { - return worklist.take() ; + return worklist.take(); } private PathEdge peekFromWorkList() { diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/Slicer.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/Slicer.java index 4389ad17a..b1ee13320 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/Slicer.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/Slicer.java @@ -168,8 +168,7 @@ public class Slicer { * * @throws CancelException */ - public static Collection computeBackwardSlice(SDG sdg, Statement s) - throws IllegalArgumentException, CancelException { + public static Collection computeBackwardSlice(SDG sdg, Statement s) throws IllegalArgumentException, CancelException { return computeSlice(sdg, Collections.singleton(s), true); } @@ -178,8 +177,7 @@ public class Slicer { * * @throws CancelException */ - public static Collection computeForwardSlice(SDG sdg, Statement s) - throws IllegalArgumentException, CancelException { + public static Collection computeForwardSlice(SDG sdg, Statement s) throws IllegalArgumentException, CancelException { return computeSlice(sdg, Collections.singleton(s), false); } @@ -188,8 +186,8 @@ public class Slicer { * * @throws CancelException */ - public static Collection computeBackwardSlice(SDG sdg, Collection ss) - throws IllegalArgumentException, CancelException { + public static Collection computeBackwardSlice(SDG sdg, Collection ss) throws IllegalArgumentException, + CancelException { return computeSlice(sdg, ss, true); } @@ -206,8 +204,14 @@ public class Slicer { /** * Main driver logic. + * + * @param sdg governing system dependence graph + * @param roots set of roots to slice from + * @param backward do a backwards slice? + * @return the {@link Statement}s found by the slicer + * @throws CancelException */ - public Collection slice(SDG sdg, Collection ss, boolean backward) throws CancelException { + public Collection slice(SDG sdg, Collection roots, boolean backward) throws CancelException { if (sdg == null) { throw new IllegalArgumentException("sdg cannot be null"); @@ -216,13 +220,14 @@ public class Slicer { Collection rootsConsidered = HashSetFactory.make(); Stack workList = new Stack(); Collection result = HashSetFactory.make(); - for (Statement s : ss) { + for (Statement s : roots) { workList.push(s); } + SliceProblem p = makeSliceProblem(roots, sdg, backward); + while (!workList.isEmpty()) { Statement root = workList.pop(); rootsConsidered.add(root); - SliceProblem p = makeSliceProblem(root, sdg, backward); if (VERBOSE) { System.err.println("worklist now: " + workList.size()); @@ -231,6 +236,9 @@ public class Slicer { } TabulationSolver solver = TabulationSolver.make(p); + if (!roots.contains(root)) { + solver.propagate(PathEdge.createPathEdge(new MethodEntryStatement(root.getNode()), 0, root, 0)); + } TabulationResult tr = solver.solve(); if (DEBUG) { @@ -269,8 +277,8 @@ public class Slicer { * Return an object which encapsulates the tabulation logic for the slice problem. Subclasses can override this method * to implement special semantics. */ - protected SliceProblem makeSliceProblem(Statement root, ISDG sdgView, boolean backward) { - return new SliceProblem(root, sdgView, backward); + protected SliceProblem makeSliceProblem(Collection roots, ISDG sdgView, boolean backward) { + return new SliceProblem(roots, sdgView, backward); } public static Collection computeNewRoots(Collection slice, Statement root, @@ -376,14 +384,14 @@ public class Slicer { */ public static class SliceProblem implements TabulationProblem { - private final Statement src; + private final Collection roots; private final ISupergraph supergraph; private final IFlowFunctionMap f; - public SliceProblem(Statement s, ISDG sdg, boolean backward) { - this.src = s; + public SliceProblem(Collection roots, ISDG sdg, boolean backward) { + this.roots = roots; SDGSupergraph forwards = new SDGSupergraph(sdg, backward); this.supergraph = backward ? BackwardsSupergraph.make(forwards) : forwards; f = new SliceFunctions(); @@ -411,7 +419,6 @@ public class Slicer { return null; } - /* * @see com.ibm.wala.dataflow.IFDS.TabulationProblem#getSupergraph() */ @@ -420,8 +427,12 @@ public class Slicer { } public Collection> initialSeeds() { - PathEdge seed = PathEdge.createPathEdge(new MethodEntryStatement(src.getNode()), 0, src, 0); - return Collections.singleton(seed); + Collection> result = HashSetFactory.make(); + for (Statement st : roots) { + PathEdge seed = PathEdge.createPathEdge(new MethodEntryStatement(st.getNode()), 0, st, 0); + return Collections.singleton(seed); + } + return result; } }