fix bug reported by Benedikt Nordhoff on mailing list: for cases where an enclosing exception handler catches all exception types, don't add an exceptional edge from a throw instruction to method exit.
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4057 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
03517ec393
commit
06b652d1fb
|
@ -0,0 +1,24 @@
|
||||||
|
package cfg;
|
||||||
|
|
||||||
|
public class MonitorTest {
|
||||||
|
void sync1() {
|
||||||
|
Object a = new Object();
|
||||||
|
synchronized (this) {
|
||||||
|
synchronized (a) {
|
||||||
|
dummy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sync2() {
|
||||||
|
Object a = new Object();
|
||||||
|
synchronized (this) {
|
||||||
|
synchronized (a) {
|
||||||
|
// Nothing here.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dummy() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,21 +10,27 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.ibm.wala.core.tests.ir;
|
package com.ibm.wala.core.tests.ir;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.ibm.wala.cfg.ControlFlowGraph;
|
import com.ibm.wala.cfg.ControlFlowGraph;
|
||||||
|
import com.ibm.wala.classLoader.ClassLoaderFactory;
|
||||||
|
import com.ibm.wala.classLoader.ClassLoaderFactoryImpl;
|
||||||
import com.ibm.wala.classLoader.IMethod;
|
import com.ibm.wala.classLoader.IMethod;
|
||||||
import com.ibm.wala.classLoader.Language;
|
import com.ibm.wala.classLoader.Language;
|
||||||
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
|
import com.ibm.wala.core.tests.util.TestConstants;
|
||||||
import com.ibm.wala.core.tests.util.WalaTestCase;
|
import com.ibm.wala.core.tests.util.WalaTestCase;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
|
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
|
||||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||||
|
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||||
import com.ibm.wala.ssa.IR;
|
import com.ibm.wala.ssa.IR;
|
||||||
import com.ibm.wala.ssa.ISSABasicBlock;
|
import com.ibm.wala.ssa.ISSABasicBlock;
|
||||||
|
import com.ibm.wala.ssa.SSACFG;
|
||||||
import com.ibm.wala.ssa.SSAInstruction;
|
import com.ibm.wala.ssa.SSAInstruction;
|
||||||
import com.ibm.wala.ssa.SSAOptions;
|
import com.ibm.wala.ssa.SSAOptions;
|
||||||
import com.ibm.wala.types.MethodReference;
|
import com.ibm.wala.types.MethodReference;
|
||||||
|
@ -34,12 +40,38 @@ import com.ibm.wala.util.graph.GraphIntegrity;
|
||||||
import com.ibm.wala.util.graph.GraphIntegrity.UnsoundGraphException;
|
import com.ibm.wala.util.graph.GraphIntegrity.UnsoundGraphException;
|
||||||
import com.ibm.wala.util.io.FileProvider;
|
import com.ibm.wala.util.io.FileProvider;
|
||||||
import com.ibm.wala.util.strings.StringStuff;
|
import com.ibm.wala.util.strings.StringStuff;
|
||||||
|
import com.ibm.wala.util.warnings.Warnings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test integrity of CFGs
|
* Test integrity of CFGs
|
||||||
*/
|
*/
|
||||||
public class CFGTest extends WalaTestCase {
|
public class CFGTest extends WalaTestCase {
|
||||||
|
|
||||||
|
private static AnalysisScope scope;
|
||||||
|
|
||||||
|
private static ClassHierarchy cha;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() throws Exception {
|
||||||
|
|
||||||
|
scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA,
|
||||||
|
FileProvider.getFile("J2SEClassHierarchyExclusions.txt"), CFGTest.class.getClassLoader());
|
||||||
|
ClassLoaderFactory factory = new ClassLoaderFactoryImpl(scope.getExclusions());
|
||||||
|
|
||||||
|
try {
|
||||||
|
cha = ClassHierarchy.make(scope, factory);
|
||||||
|
} catch (ClassHierarchyException e) {
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() throws Exception {
|
||||||
|
Warnings.clear();
|
||||||
|
scope = null;
|
||||||
|
cha = null;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
justThisTest(CFGTest.class);
|
justThisTest(CFGTest.class);
|
||||||
}
|
}
|
||||||
|
@ -49,10 +81,6 @@ public class CFGTest extends WalaTestCase {
|
||||||
*/
|
*/
|
||||||
private void doMethod(String methodSig) {
|
private void doMethod(String methodSig) {
|
||||||
try {
|
try {
|
||||||
AnalysisScope scope = AnalysisScopeReader.makePrimordialScope(FileProvider.getFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS));
|
|
||||||
|
|
||||||
ClassHierarchy cha = ClassHierarchy.make(scope);
|
|
||||||
|
|
||||||
MethodReference mr = StringStuff.makeMethodReference(Language.JAVA, methodSig);
|
MethodReference mr = StringStuff.makeMethodReference(Language.JAVA, methodSig);
|
||||||
|
|
||||||
IMethod m = cha.resolveMethod(mr);
|
IMethod m = cha.resolveMethod(mr);
|
||||||
|
@ -88,11 +116,38 @@ public class CFGTest extends WalaTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method does not exist in 1.5 libraries @Test public void testFDBigInt() {
|
* this method does not exist in 1.5 libraries @Test public void
|
||||||
* doMethod("java.lang.FDBigInt.class$(Ljava/lang/String;)Ljava/lang/Class;"); }
|
* testFDBigInt() {
|
||||||
|
* doMethod("java.lang.FDBigInt.class$(Ljava/lang/String;)Ljava/lang/Class;");
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Test public void testResolveProxyClass() {
|
@Test
|
||||||
|
public void testResolveProxyClass() {
|
||||||
doMethod("java.io.ObjectInputStream.resolveProxyClass([Ljava/lang/String;)Ljava/lang/Class;");
|
doMethod("java.io.ObjectInputStream.resolveProxyClass([Ljava/lang/String;)Ljava/lang/Class;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSync1() {
|
||||||
|
MethodReference mr = StringStuff.makeMethodReference("cfg.MonitorTest.sync1()V");
|
||||||
|
|
||||||
|
IMethod m = cha.resolveMethod(mr);
|
||||||
|
AnalysisCache cache = new AnalysisCache();
|
||||||
|
IR ir = cache.getIR(m);
|
||||||
|
SSACFG controlFlowGraph = ir.getControlFlowGraph();
|
||||||
|
// System.out.println(ir);
|
||||||
|
Assert.assertEquals(1, controlFlowGraph.getSuccNodeCount(controlFlowGraph.getBlockForInstruction(21)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@Test
|
||||||
|
public void testSync2() {
|
||||||
|
MethodReference mr = StringStuff.makeMethodReference("cfg.MonitorTest.sync2()V");
|
||||||
|
|
||||||
|
IMethod m = cha.resolveMethod(mr);
|
||||||
|
AnalysisCache cache = new AnalysisCache();
|
||||||
|
IR ir = cache.getIR(m);
|
||||||
|
System.out.println(ir);
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,6 +303,9 @@ public class ShrikeCFG extends AbstractCFG<IInstruction, ShrikeCFG.BasicBlock> {
|
||||||
exceptionTypes = HashSetFactory.make(exceptionTypes);
|
exceptionTypes = HashSetFactory.make(exceptionTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this var gets set to false if goToAllHandlers is true but some enclosing exception handler catches all
|
||||||
|
// exceptions. in such a case, we need not add an exceptional edge to the method exit
|
||||||
|
boolean needEdgeToExitForAllHandlers = true;
|
||||||
for (int j = 0; j < hs.length; j++) {
|
for (int j = 0; j < hs.length; j++) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
System.err.println(" handler " + hs[j]);
|
System.err.println(" handler " + hs[j]);
|
||||||
|
@ -317,6 +320,10 @@ public class ShrikeCFG extends AbstractCFG<IInstruction, ShrikeCFG.BasicBlock> {
|
||||||
System.err.println(" gotoAllHandlers " + b);
|
System.err.println(" gotoAllHandlers " + b);
|
||||||
}
|
}
|
||||||
addExceptionalEdgeTo(b);
|
addExceptionalEdgeTo(b);
|
||||||
|
// if the handler catches all exceptions, we don't need to add an edge to the exit
|
||||||
|
if (hs[j].getCatchClass() == null) {
|
||||||
|
needEdgeToExitForAllHandlers = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
TypeReference caughtException = null;
|
TypeReference caughtException = null;
|
||||||
if (hs[j].getCatchClass() != null) {
|
if (hs[j].getCatchClass() != null) {
|
||||||
|
@ -376,7 +383,7 @@ public class ShrikeCFG extends AbstractCFG<IInstruction, ShrikeCFG.BasicBlock> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if needed, add an edge to the exit block.
|
// if needed, add an edge to the exit block.
|
||||||
if (exceptionTypes == null || !exceptionTypes.isEmpty()) {
|
if ((exceptionTypes == null && needEdgeToExitForAllHandlers) || (exceptionTypes != null && !exceptionTypes.isEmpty())) {
|
||||||
BasicBlock exit = exit();
|
BasicBlock exit = exit();
|
||||||
addExceptionalEdgeTo(exit);
|
addExceptionalEdgeTo(exit);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue