2006-11-22 17:45:24 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 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 com.ibm.wala.core.tests.callGraph;
|
|
|
|
|
2008-01-02 22:27:45 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2007-07-20 15:19:57 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
2006-11-22 17:45:24 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
|
2007-05-15 17:44:54 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
2006-11-22 17:45:24 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.impl.Util;
|
2009-07-28 02:26:03 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2009-06-22 15:06:12 +00:00
|
|
|
import com.ibm.wala.util.CancelException;
|
2007-12-13 00:40:14 +00:00
|
|
|
import com.ibm.wala.util.config.AnalysisScopeReader;
|
2008-01-24 22:54:05 +00:00
|
|
|
import com.ibm.wala.util.io.FileProvider;
|
2008-01-07 17:18:23 +00:00
|
|
|
import com.ibm.wala.util.perf.StopwatchGC;
|
2006-11-22 17:45:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Utilities for call graph tests
|
|
|
|
*/
|
|
|
|
public class CallGraphTestUtil {
|
|
|
|
|
|
|
|
private static final ClassLoader MY_CLASSLOADER = CallGraphTestUtil.class.getClassLoader();
|
|
|
|
|
2007-05-15 17:44:54 +00:00
|
|
|
public static AnalysisOptions makeAnalysisOptions(AnalysisScope scope, Iterable<Entrypoint> entrypoints) {
|
2006-11-22 17:45:24 +00:00
|
|
|
AnalysisOptions options = new AnalysisOptions(scope, entrypoints);
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2007-12-12 20:47:35 +00:00
|
|
|
public static String REGRESSION_EXCLUSIONS = "Java60RegressionExclusions.txt";
|
2007-12-13 00:43:03 +00:00
|
|
|
|
2009-07-27 22:43:06 +00:00
|
|
|
/**
|
|
|
|
* should we check the heap footprint before and after CG construction?
|
|
|
|
*/
|
|
|
|
private static final boolean CHECK_FOOTPRINT = false;
|
|
|
|
|
2008-01-02 22:27:45 +00:00
|
|
|
public static AnalysisScope makeJ2SEAnalysisScope(String scopeFile, String exclusionsFile) throws IOException {
|
2012-04-16 18:57:14 +00:00
|
|
|
AnalysisScope scope = AnalysisScopeReader.readJavaScope(scopeFile, (new FileProvider()).getFile(exclusionsFile), MY_CLASSLOADER);
|
2007-12-12 20:47:35 +00:00
|
|
|
return scope;
|
2006-11-22 17:45:24 +00:00
|
|
|
}
|
|
|
|
|
2009-07-28 02:26:03 +00:00
|
|
|
public static CallGraph buildRTA(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope)
|
2007-12-13 00:43:03 +00:00
|
|
|
throws IllegalArgumentException, CancelException {
|
2009-07-27 22:43:06 +00:00
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2007-07-20 15:19:57 +00:00
|
|
|
CallGraphBuilder builder = Util.makeRTABuilder(options, cache, cha, scope);
|
2008-02-13 22:34:50 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2009-07-27 22:43:06 +00:00
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2009-07-28 02:26:03 +00:00
|
|
|
public static CallGraph buildZeroCFA(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope,
|
2007-12-13 00:43:03 +00:00
|
|
|
boolean testPAtoString) throws IllegalArgumentException, CancelException {
|
2009-07-27 22:43:06 +00:00
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2007-07-20 15:19:57 +00:00
|
|
|
CallGraphBuilder builder = Util.makeZeroCFABuilder(options, cache, cha, scope);
|
2008-02-13 22:34:50 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
2007-08-20 21:34:16 +00:00
|
|
|
if (testPAtoString) {
|
|
|
|
builder.getPointerAnalysis().toString();
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2009-07-27 22:43:06 +00:00
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
return cg;
|
|
|
|
}
|
2007-07-20 15:19:57 +00:00
|
|
|
|
2011-03-21 16:04:45 +00:00
|
|
|
public static CallGraph buildVanillaZeroOneCFA(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha,
|
2007-11-13 16:19:01 +00:00
|
|
|
AnalysisScope scope) throws IllegalArgumentException, CancelException {
|
2009-07-27 22:43:06 +00:00
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2007-07-20 15:19:57 +00:00
|
|
|
CallGraphBuilder builder = Util.makeVanillaZeroOneCFABuilder(options, cache, cha, scope);
|
2008-02-13 22:34:50 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2009-07-27 22:43:06 +00:00
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2009-07-28 02:26:03 +00:00
|
|
|
public static CallGraph buildZeroOneCFA(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope,
|
2007-12-13 00:43:03 +00:00
|
|
|
boolean testPAtoString) throws IllegalArgumentException, CancelException {
|
2009-07-27 22:43:06 +00:00
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2007-07-20 15:19:57 +00:00
|
|
|
CallGraphBuilder builder = Util.makeZeroOneCFABuilder(options, cache, cha, scope);
|
2008-02-13 22:34:50 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
2007-08-20 21:34:16 +00:00
|
|
|
if (testPAtoString) {
|
|
|
|
builder.getPointerAnalysis().toString();
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2009-07-27 22:43:06 +00:00
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2009-07-28 02:26:03 +00:00
|
|
|
public static CallGraph buildZeroContainerCFA(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha,
|
2007-11-13 16:19:01 +00:00
|
|
|
AnalysisScope scope) throws IllegalArgumentException, CancelException {
|
2009-07-27 22:43:06 +00:00
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2007-07-20 15:19:57 +00:00
|
|
|
CallGraphBuilder builder = Util.makeZeroContainerCFABuilder(options, cache, cha, scope);
|
2008-02-13 22:34:50 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2009-07-27 22:43:06 +00:00
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2009-07-28 02:26:03 +00:00
|
|
|
public static CallGraph buildZeroOneContainerCFA(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha,
|
2007-11-13 16:19:01 +00:00
|
|
|
AnalysisScope scope) throws IllegalArgumentException, CancelException {
|
2009-07-27 22:43:06 +00:00
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2007-07-20 15:19:57 +00:00
|
|
|
CallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
|
2008-02-13 22:34:50 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
2006-11-22 17:45:24 +00:00
|
|
|
|
2009-07-27 22:43:06 +00:00
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
2006-11-22 17:45:24 +00:00
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|