2012-09-04 22:56:05 +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;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2018-02-05 23:18:37 +00:00
|
|
|
import com.ibm.wala.classLoader.Language;
|
2012-09-04 22:56:05 +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;
|
|
|
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
2017-03-16 02:06:19 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
2012-09-04 22:56:05 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.impl.Util;
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
2015-08-12 19:20:21 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
|
2012-09-04 22:56:05 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
|
|
|
import com.ibm.wala.util.CancelException;
|
|
|
|
import com.ibm.wala.util.config.AnalysisScopeReader;
|
|
|
|
import com.ibm.wala.util.io.FileProvider;
|
|
|
|
import com.ibm.wala.util.perf.StopwatchGC;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utilities for call graph tests
|
|
|
|
*/
|
|
|
|
public class CallGraphTestUtil {
|
|
|
|
|
|
|
|
private static final ClassLoader MY_CLASSLOADER = CallGraphTestUtil.class.getClassLoader();
|
|
|
|
|
|
|
|
public static AnalysisOptions makeAnalysisOptions(AnalysisScope scope, Iterable<Entrypoint> entrypoints) {
|
|
|
|
AnalysisOptions options = new AnalysisOptions(scope, entrypoints);
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String REGRESSION_EXCLUSIONS = "Java60RegressionExclusions.txt";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* should we check the heap footprint before and after CG construction?
|
|
|
|
*/
|
|
|
|
private static final boolean CHECK_FOOTPRINT = false;
|
|
|
|
|
2013-05-02 17:55:45 +00:00
|
|
|
public static AnalysisScope makeJ2SEAnalysisScope(String scopeFile, String exclusionsFile) throws IOException {
|
2017-03-11 18:22:45 +00:00
|
|
|
return makeJ2SEAnalysisScope(scopeFile, exclusionsFile, MY_CLASSLOADER);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AnalysisScope makeJ2SEAnalysisScope(String scopeFile, String exclusionsFile, ClassLoader myClassLoader) throws IOException {
|
|
|
|
AnalysisScope scope = AnalysisScopeReader.readJavaScope(scopeFile, (new FileProvider()).getFile(exclusionsFile), myClassLoader);
|
2012-09-04 22:56:05 +00:00
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:06:19 +00:00
|
|
|
public static CallGraph buildRTA(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, AnalysisScope scope)
|
2012-09-04 22:56:05 +00:00
|
|
|
throws IllegalArgumentException, CancelException {
|
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
CallGraphBuilder<InstanceKey> builder = Util.makeRTABuilder(options, cache, cha, scope);
|
2012-09-04 22:56:05 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
|
|
|
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:06:19 +00:00
|
|
|
public static CallGraph buildZeroCFA(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, AnalysisScope scope,
|
2012-09-04 22:56:05 +00:00
|
|
|
boolean testPAtoString) throws IllegalArgumentException, CancelException {
|
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
|
|
|
|
2018-02-05 23:18:37 +00:00
|
|
|
SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope);
|
2012-09-04 22:56:05 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
|
|
|
if (testPAtoString) {
|
|
|
|
builder.getPointerAnalysis().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:06:19 +00:00
|
|
|
public static CallGraph buildVanillaZeroOneCFA(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha,
|
2012-09-04 22:56:05 +00:00
|
|
|
AnalysisScope scope) throws IllegalArgumentException, CancelException {
|
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
|
|
|
|
2018-02-05 23:18:37 +00:00
|
|
|
CallGraphBuilder<InstanceKey> builder = Util.makeVanillaZeroOneCFABuilder(Language.JAVA, options, cache, cha, scope);
|
2012-09-04 22:56:05 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
|
|
|
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:06:19 +00:00
|
|
|
public static CallGraph buildZeroOneCFA(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, AnalysisScope scope,
|
2012-09-04 22:56:05 +00:00
|
|
|
boolean testPAtoString) throws IllegalArgumentException, CancelException {
|
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
|
|
|
|
2018-02-05 23:18:37 +00:00
|
|
|
CallGraphBuilder<InstanceKey> builder = Util.makeZeroOneCFABuilder(Language.JAVA, options, cache, cha, scope);
|
2012-09-04 22:56:05 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
|
|
|
if (testPAtoString) {
|
|
|
|
builder.getPointerAnalysis().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:06:19 +00:00
|
|
|
public static CallGraph buildZeroContainerCFA(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha,
|
2012-09-04 22:56:05 +00:00
|
|
|
AnalysisScope scope) throws IllegalArgumentException, CancelException {
|
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
CallGraphBuilder<InstanceKey> builder = Util.makeZeroContainerCFABuilder(options, cache, cha, scope);
|
2012-09-04 22:56:05 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
|
|
|
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:06:19 +00:00
|
|
|
public static CallGraph buildZeroOneContainerCFA(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha,
|
2012-09-04 22:56:05 +00:00
|
|
|
AnalysisScope scope) throws IllegalArgumentException, CancelException {
|
|
|
|
StopwatchGC S = null;
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S = new StopwatchGC("build RTA graph");
|
|
|
|
S.start();
|
|
|
|
}
|
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
CallGraphBuilder<InstanceKey> builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
|
2012-09-04 22:56:05 +00:00
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
|
|
|
|
|
|
|
if (CHECK_FOOTPRINT) {
|
|
|
|
S.stop();
|
|
|
|
System.err.println(S.report());
|
|
|
|
}
|
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|