add option to (unsoundly) ignore possible static initializer calls when building call graph

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3187 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
msridhar1 2009-01-21 18:18:26 +00:00
parent d642197db0
commit 91c850058b
4 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2008 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package staticInit;
/**
* @author manu
*
*/
public class TestStaticInit {
private static class A {
static {
doNothing();
}
private static void doNothing() {
}
}
public static void main(String[] args) {
new A();
}
}

View File

@ -23,6 +23,7 @@ import com.ibm.wala.eclipse.util.CancelException;
import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.CallGraphStats;
import com.ibm.wala.ipa.callgraph.Entrypoint;
@ -117,6 +118,28 @@ public class CallGraphTest extends WalaTestCase {
doCallGraphs(options, new AnalysisCache(), cha, scope);
}
public void testStaticInit() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA,
CallGraphTestUtil.REGRESSION_EXCLUSIONS);
ClassHierarchy cha = ClassHierarchy.make(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha,
"LstaticInit/TestStaticInit");
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
CallGraph cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCache(), cha, scope, false);
boolean foundDoNothing = false;
for (CGNode n : cg) {
if (n.toString().contains("doNothing")) {
foundDoNothing = true;
break;
}
}
assertTrue(foundDoNothing);
options.setHandleStaticInit(false);
cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCache(), cha, scope, false);
for (CGNode n : cg) {
assertTrue(!n.toString().contains("doNothing"));
}
}
public void testRecursion() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA,
@ -208,6 +231,7 @@ public class CallGraphTest extends WalaTestCase {
/**
* TODO: refactor this to avoid excessive code bloat.
*
* @throws CancelException
* @throws IllegalArgumentException
*/

View File

@ -77,6 +77,10 @@ public class AnalysisOptions {
*/
private boolean handleReflection = true;
/**
* Should call graph construction handle possible invocations of static initializer methods?
*/
private boolean handleStaticInit = true;
/**
* Should we use the pretransitive solver for pointer analysis? Not yet ready for prime-time.
*/
@ -336,4 +340,12 @@ public class AnalysisOptions {
public void setHandleReflection(boolean handleReflection) {
this.handleReflection = handleReflection;
}
public boolean getHandleStaticInit() {
return handleStaticInit;
}
public void setHandleStaticInit(boolean handleStaticInit) {
this.handleStaticInit = handleStaticInit;
}
}

View File

@ -1382,6 +1382,10 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
Assertions._assert(klass != null);
}
if (!getBuilder().getOptions().getHandleStaticInit()) {
return;
}
if (getBuilder().clinitVisited.contains(klass)) {
return;
}