Skip to content

Commit

Permalink
Update to WALA 1.5.8 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar authored Jun 30, 2022
1 parent 0932fef commit 9611596
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 47 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

dependencies {
def walaVersion = '1.5.7'
def walaVersion = '1.5.8'

implementation "com.ibm.wala:com.ibm.wala.shrike:${walaVersion}"
implementation "com.ibm.wala:com.ibm.wala.util:${walaVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.util.Properties;

import com.ibm.wala.core.util.config.AnalysisScopeReader;
import com.ibm.wala.core.util.warnings.Warnings;
import com.ibm.wala.dataflow.IFDS.ISupergraph;
import com.ibm.wala.dataflow.IFDS.TabulationResult;
import com.ibm.wala.examples.analysis.dataflow.ContextSensitiveReachingDefs;
Expand All @@ -25,9 +27,7 @@
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.analysis.IExplodedBasicBlock;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.config.AnalysisScopeReader;
import com.ibm.wala.util.io.CommandLine;
import com.ibm.wala.util.warnings.Warnings;


/**
Expand Down Expand Up @@ -57,20 +57,20 @@ public static void main(String[] args) throws IOException, ClassHierarchyExcepti
if (mainClass == null) {
throw new IllegalArgumentException("must specify main class");
}
AnalysisScope scope = AnalysisScopeReader.readJavaScope(scopeFile, null, CSReachingDefsDriver.class.getClassLoader());
AnalysisScope scope = AnalysisScopeReader.instance.readJavaScope(scopeFile, null, CSReachingDefsDriver.class.getClassLoader());
ExampleUtil.addDefaultExclusions(scope);
IClassHierarchy cha = ClassHierarchyFactory.make(scope);
System.out.println(cha.getNumberOfClasses() + " classes");
System.out.println(Warnings.asString());
Warnings.clear();
AnalysisOptions options = new AnalysisOptions();
Iterable<Entrypoint> entrypoints = Util.makeMainEntrypoints(scope, cha, mainClass);
Iterable<Entrypoint> entrypoints = Util.makeMainEntrypoints(cha, mainClass);
options.setEntrypoints(entrypoints);
// you can dial down reflection handling if you like
options.setReflectionOptions(ReflectionOptions.NONE);
AnalysisCache cache = new AnalysisCacheImpl();
// other builders can be constructed with different Util methods
CallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
CallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha);
// CallGraphBuilder builder = Util.makeNCFABuilder(2, options, cache, cha, scope);
// CallGraphBuilder builder = Util.makeVanillaNCFABuilder(2, options, cache, cha, scope);
System.out.println("building call graph...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.core.util.config.AnalysisScopeReader;
import com.ibm.wala.core.util.ref.ReferenceCleanser;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
Expand All @@ -22,9 +24,7 @@
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.util.config.AnalysisScopeReader;
import com.ibm.wala.util.perf.Stopwatch;
import com.ibm.wala.util.ref.ReferenceCleanser;

/**
* An analysis skeleton that simply constructs IRs for all methods in a class hierarchy. Illustrates the use of
Expand Down Expand Up @@ -59,7 +59,7 @@ public static void main(String[] args) throws IOException, ClassHierarchyExcepti
// measure running time
Stopwatch s = new Stopwatch();
s.start();
AnalysisScope scope = AnalysisScopeReader.readJavaScope(scopeFile, null, ConstructAllIRs.class.getClassLoader());
AnalysisScope scope = AnalysisScopeReader.instance.readJavaScope(scopeFile, null, ConstructAllIRs.class.getClassLoader());

// build a type hierarchy
System.out.print("building class hierarchy...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.Language;
import com.ibm.wala.core.util.config.AnalysisScopeReader;
import com.ibm.wala.demandpa.alg.DemandRefinementPointsTo;
import com.ibm.wala.demandpa.alg.refinepolicy.NeverRefineCGPolicy;
import com.ibm.wala.demandpa.alg.refinepolicy.NeverRefineFieldsPolicy;
Expand Down Expand Up @@ -30,7 +31,6 @@
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.config.AnalysisScopeReader;

import java.io.IOException;
import java.util.Collection;
Expand All @@ -49,17 +49,17 @@ public static void main(String[] args)
throws IOException, ClassHierarchyException, CancelException {
// Construct the AnalysisScope from the class path.
String classpath = args[0];
AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(classpath, null);
AnalysisScope scope = AnalysisScopeReader.instance.makeJavaBinaryAnalysisScope(classpath, null);
// We need a baseline call graph. Here we use a CHACallGraph based on a ClassHierarchy.
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
CHACallGraph chaCG = new CHACallGraph(cha);
chaCG.init(Util.makeMainEntrypoints(scope, cha));
chaCG.init(Util.makeMainEntrypoints(cha));
AnalysisOptions options = new AnalysisOptions();
IAnalysisCacheView cache = new AnalysisCacheImpl();
// We also need a heap model to create InstanceKeys for allocation sites, etc.
// Here we use a 0-1 CFA builder, which will give a heap abstraction similar to
// context-insensitive Andersen's analysis
HeapModel heapModel = Util.makeZeroOneCFABuilder(Language.JAVA, options, cache, cha, scope);
HeapModel heapModel = Util.makeZeroOneCFABuilder(Language.JAVA, options, cache, cha);
// The MemoryAccessMap helps the demand analysis find matching field reads and writes
MemoryAccessMap mam = new SimpleMemoryAccessMap(chaCG, heapModel, false);
// The StateMachineFactory helps in tracking additional states like calling contexts.
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/com/ibm/wala/examples/drivers/PDFTypeHierarchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.function.Predicate;

import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.core.util.config.AnalysisScopeReader;
import com.ibm.wala.core.viz.PDFViewUtil;
import com.ibm.wala.examples.util.ExampleUtil;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.cha.ClassHierarchy;
Expand All @@ -24,12 +26,10 @@
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.util.WalaException;
import com.ibm.wala.util.collections.CollectionFilter;
import com.ibm.wala.util.config.AnalysisScopeReader;
import com.ibm.wala.util.graph.Graph;
import com.ibm.wala.util.graph.GraphSlicer;
import com.ibm.wala.util.graph.impl.SlowSparseNumberedGraph;
import com.ibm.wala.viz.DotUtil;
import com.ibm.wala.viz.PDFViewUtil;
import com.ibm.wala.util.viz.DotUtil;

/**
*
Expand All @@ -42,9 +42,6 @@ public class PDFTypeHierarchy {
// This example takes one command-line argument, so args[1] should be the "-classpath" parameter
final static int CLASSPATH_INDEX = 1;

public final static String DOT_FILE = "temp.dt";

private final static String PDF_FILE = "th.pdf";

public static void main(String[] args) throws IOException {
run(args);
Expand All @@ -54,7 +51,7 @@ public static Process run(String[] args) throws IOException {
try {
validateCommandLine(args);
String classpath = args[CLASSPATH_INDEX];
AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(classpath, null);
AnalysisScope scope = AnalysisScopeReader.instance.makeJavaBinaryAnalysisScope(classpath, null);
ExampleUtil.addDefaultExclusions(scope);

// invoke WALA to build a class hierarchy
Expand All @@ -63,7 +60,6 @@ public static Process run(String[] args) throws IOException {
Graph<IClass> g = typeHierarchy2Graph(cha);

g = pruneForAppLoader(g);
//String dotFile = "/tmp" + File.separatorChar + DOT_FILE;
String dotFile = File.createTempFile("out", ".dt").getAbsolutePath();
String pdfFile = File.createTempFile("out", ".pdf").getAbsolutePath();
String dotExe = "dot";
Expand All @@ -78,7 +74,7 @@ public static Process run(String[] args) throws IOException {
}
}

public static <T> Graph<T> pruneGraph(Graph<T> g, Predicate<T> f) throws WalaException {
public static <T> Graph<T> pruneGraph(Graph<T> g, Predicate<T> f) {
Collection<T> slice = GraphSlicer.slice(g, f);
return GraphSlicer.prune(g, new CollectionFilter<>(slice));
}
Expand All @@ -87,11 +83,7 @@ public static <T> Graph<T> pruneGraph(Graph<T> g, Predicate<T> f) throws WalaExc
* Restrict g to nodes from the Application loader
*/
public static Graph<IClass> pruneForAppLoader(Graph<IClass> g) throws WalaException {
Predicate<IClass> f = new Predicate<IClass>() {
@Override public boolean test(IClass c) {
return (c.getClassLoader().getReference().equals(ClassLoaderReference.Application));
}
};
Predicate<IClass> f = c -> (c.getClassLoader().getReference().equals(ClassLoaderReference.Application));
return pruneGraph(g, f);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
*******************************************************************************/
package com.ibm.wala.examples.drivers;

import com.ibm.wala.core.util.config.AnalysisScopeReader;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.util.config.AnalysisScopeReader;

import java.io.IOException;

Expand All @@ -25,7 +25,7 @@ public class PrintTypeHierarchy {

public static void main(String[] args) throws IOException, ClassHierarchyException {
String classpath = args[0];
AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(classpath, null);
AnalysisScope scope = AnalysisScopeReader.instance.makeJavaBinaryAnalysisScope(classpath, null);
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
System.out.println(cha);
}
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/com/ibm/wala/examples/drivers/ScopeFileCallGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
*******************************************************************************/
package com.ibm.wala.examples.drivers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;

import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.core.util.config.AnalysisScopeReader;
import com.ibm.wala.core.util.strings.StringStuff;
import com.ibm.wala.core.util.warnings.Warnings;
import com.ibm.wala.examples.util.ExampleUtil;
import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
Expand All @@ -29,15 +27,18 @@
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.DefaultEntrypoint;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.config.AnalysisScopeReader;
import com.ibm.wala.util.io.CommandLine;
import com.ibm.wala.util.strings.StringStuff;
import com.ibm.wala.util.warnings.Warnings;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;

/**
* Driver that constructs a call graph for an application specified via a scope file.
Expand Down Expand Up @@ -67,21 +68,21 @@ public static void main(String[] args) throws IOException, ClassHierarchyExcepti
if (mainClass != null && entryClass != null) {
throw new IllegalArgumentException("only specify one of mainClass or entryClass");
}
AnalysisScope scope = AnalysisScopeReader.readJavaScope(scopeFile, null, ScopeFileCallGraph.class.getClassLoader());
AnalysisScope scope = AnalysisScopeReader.instance.readJavaScope(scopeFile, null, ScopeFileCallGraph.class.getClassLoader());
// set exclusions. we use these exclusions as standard for handling JDK 8
ExampleUtil.addDefaultExclusions(scope);
IClassHierarchy cha = ClassHierarchyFactory.make(scope);
System.out.println(cha.getNumberOfClasses() + " classes");
System.out.println(Warnings.asString());
Warnings.clear();
AnalysisOptions options = new AnalysisOptions();
Iterable<Entrypoint> entrypoints = entryClass != null ? makePublicEntrypoints(scope, cha, entryClass) : Util.makeMainEntrypoints(scope, cha, mainClass);
Iterable<Entrypoint> entrypoints = entryClass != null ? makePublicEntrypoints(cha, entryClass) : Util.makeMainEntrypoints(cha, mainClass);
options.setEntrypoints(entrypoints);
// you can dial down reflection handling if you like
// options.setReflectionOptions(ReflectionOptions.NONE);
AnalysisCache cache = new AnalysisCacheImpl();
// other builders can be constructed with different Util methods
CallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
CallGraphBuilder<InstanceKey> builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha);
// CallGraphBuilder builder = Util.makeNCFABuilder(2, options, cache, cha, scope);
// CallGraphBuilder builder = Util.makeVanillaNCFABuilder(2, options, cache, cha, scope);
System.out.println("building call graph...");
Expand All @@ -92,8 +93,8 @@ public static void main(String[] args) throws IOException, ClassHierarchyExcepti
System.out.println(CallGraphStats.getStats(cg));
}

private static Iterable<Entrypoint> makePublicEntrypoints(AnalysisScope scope, IClassHierarchy cha, String entryClass) {
Collection<Entrypoint> result = new ArrayList<Entrypoint>();
private static Iterable<Entrypoint> makePublicEntrypoints(IClassHierarchy cha, String entryClass) {
Collection<Entrypoint> result = new ArrayList<>();
IClass klass = cha.lookupClass(TypeReference.findOrCreate(ClassLoaderReference.Application,
StringStuff.deployment2CanonicalTypeString(entryClass)));
for (IMethod m : klass.getDeclaredMethods()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.ibm.wala.classLoader.ClassLoaderFactory;
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.core.util.warnings.Warnings;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisOptions.ReflectionOptions;
Expand All @@ -25,7 +26,6 @@
import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.util.io.CommandLine;
import com.ibm.wala.util.warnings.Warnings;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -110,7 +110,7 @@ public void doit(String[] args, Processor processor)
// CallGraphBuilder builder = new ZeroCFABuilderFactory().make(options, cache,
// cha, scope,
// false);
CallGraphBuilder<?> builder = new ZeroOneContainerCFABuilderFactory().make(options, cache, cha, scope);
CallGraphBuilder<?> builder = new ZeroOneContainerCFABuilderFactory().make(options, cache, cha);
System.out.println("building call graph...");
CallGraph cg = builder.makeCallGraph(options, null);
long end = System.currentTimeMillis();
Expand All @@ -119,8 +119,6 @@ public void doit(String[] args, Processor processor)
}

protected Iterable<Entrypoint> getEntrypoints(String mainClass, IClassHierarchy cha) {
Iterable<Entrypoint> entrypoints =
Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE, cha, new String[] {mainClass});
return entrypoints;
return Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE, cha, new String[] {mainClass});
}
}

0 comments on commit 9611596

Please sign in to comment.