This commit is contained in:
Julian Dolby 2015-08-09 13:47:01 -04:00
commit b1538aece6
8 changed files with 61 additions and 9 deletions

1
.gitignore vendored
View File

@ -26,6 +26,7 @@ com.ibm.wala.cast.js/lib/
com.ibm.wala.core.testdata/*.jar
com.ibm.wala.core.testdata/@dot/
com.ibm.wala.core.testdata/lib/
com.ibm.wala.core.testdata/ocaml/
com.ibm.wala.core.tests/dat/wala.examples.properties
com.ibm.wala.core.tests/report
com.ibm.wala.core/@dot

View File

@ -16,13 +16,14 @@
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;com.ibm.wala.cast.js.rhino.test&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento exportedEntriesOnly=&quot;false&quot; project=&quot;com.ibm.wala.cast.js.rhino.test&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/com.ibm.wala.cast.js.test.data/examples-src&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/1.7.0 25/"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.js.rhino.test"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx2048M -verbose:gc -ea"/>

View File

@ -0,0 +1,18 @@
package slice;
import java.io.IOException;
public class JustThrow {
private static int throwException() {
throw new RuntimeException();
}
public static void main(String[] argv) throws IOException{
doNothing(throwException());
}
private static void doNothing(int x) {
}
}

View File

@ -692,6 +692,28 @@ public class SlicerTest {
GraphIntegrity.check(sdg);
}
@Test
public void testJustThrow() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException, UnsoundGraphException {
AnalysisScope scope = findOrCreateAnalysisScope();
IClassHierarchy cha = findOrCreateCHA(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha,
TestConstants.SLICE_JUSTTHROW);
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
CallGraphBuilder builder = Util.makeZeroOneCFABuilder(options, new AnalysisCache(), cha, scope);
CallGraph cg = builder.makeCallGraph(options, null);
CGNode main = findMainMethod(cg);
Statement s = findCallToDoNothing(main);
System.err.println("Statement: " + s);
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, builder.getPointerAnalysis(), DataDependenceOptions.FULL,
ControlDependenceOptions.NO_EXCEPTIONAL_EDGES);
dumpSlice(slice);
}
public static int countAllocations(Collection<Statement> slice) {
int count = 0;
for (Statement s : slice) {

View File

@ -139,4 +139,6 @@ public interface TestConstants {
public final static String SLICE_TESTINETADDR = "Lslice/TestInetAddr";
public final static String SLICE_JUSTTHROW = "Lslice/JustThrow";
}

View File

@ -289,10 +289,8 @@ public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGrap
Set<T> reachable = DFS.getReachableNodes(temp, Collections.singleton(cfg.entry()));
Set<T> back = DFS.getReachableNodes(GraphInverter.invert(temp), Collections.singleton(cfg.exit()));
reachable.retainAll(back);
/** BEGIN Custom change: entry and exit in every cfg */
reachable.add(cfg.entry());
reachable.add(cfg.exit());
/** END Custom change: entry and exit in every cfg */
this.nodes = new FilteredNodes<T>(cfg, reachable);
this.edges = new FilteredCFGEdges<I, T>(cfg, nodes, filter);

View File

@ -28,6 +28,7 @@ import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.cfg.ExceptionPrunedCFG;
import com.ibm.wala.ipa.cfg.PrunedCFG;
import com.ibm.wala.ipa.modref.DelegatingExtendedHeapModel;
import com.ibm.wala.ipa.modref.ExtendedHeapModel;
import com.ibm.wala.ipa.modref.ModRef;
@ -62,6 +63,7 @@ import com.ibm.wala.util.collections.MapUtil;
import com.ibm.wala.util.config.SetOfClasses;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError;
import com.ibm.wala.util.graph.GraphUtil;
import com.ibm.wala.util.graph.NumberedGraph;
import com.ibm.wala.util.graph.dominators.Dominators;
import com.ibm.wala.util.graph.labeled.SlowSparseNumberedLabeledGraph;
@ -233,14 +235,18 @@ public class PDG implements NumberedGraph<Statement> {
}
ControlFlowGraph<SSAInstruction, ISSABasicBlock> controlFlowGraph = ir.getControlFlowGraph();
if (cOptions.equals(ControlDependenceOptions.NO_EXCEPTIONAL_EDGES)) {
controlFlowGraph = ExceptionPrunedCFG.make(controlFlowGraph);
// In case the CFG has no nodes left because the only control dependencies
// were
// exceptional, simply return because at this point there are no nodes.
PrunedCFG<SSAInstruction, ISSABasicBlock> prunedCFG = ExceptionPrunedCFG.make(controlFlowGraph);
// In case the CFG has only the entry and exit nodes left
// and no edges because the only control dependencies
// were exceptional, simply return because at this point there are no nodes.
// Otherwise, later this may raise an Exception.
if (controlFlowGraph.getNumberOfNodes() == 0) {
if (prunedCFG.getNumberOfNodes() == 2
&& prunedCFG.containsNode(controlFlowGraph.entry())
&& prunedCFG.containsNode(controlFlowGraph.exit())
&& GraphUtil.countEdges(prunedCFG) == 0) {
return;
}
controlFlowGraph = prunedCFG;
} else {
Assertions.productionAssertion(cOptions.equals(ControlDependenceOptions.FULL));
}

View File

@ -47,7 +47,11 @@ public class DominanceFrontiers<T> {
}
public Iterator<T> getDominanceFrontier(T n) {
return DF.get(n).iterator();
Set<T> frontier = DF.get(n);
if (frontier == null) {
throw new IllegalArgumentException("no dominance frontier for node " + n);
}
return frontier.iterator();
}
public boolean isDominatedBy(T node, T master) {