JPC
JPC

Reputation: 1919

WALA Call Graph

I'm very new to WALA and trying to work through some simple examples to get a feel for it. I'm trying to build a call graph for the very simple class below

public class Example {
    public static void main(String[] args) {
        int x = 1;
        int y = 1;
        int z = x + y;
        Math.pow(x, y); // issue here
    }
}

My WALA code (simplified somewhat) is:

import com.ibm.wala.ipa.callgraph.*;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.util.WalaException;
import com.ibm.wala.util.config.AnalysisScopeReader;
...

AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(jar, null);
ClassHierarchy cha = ClassHierarchy.make(scope);
Iterable<Entrypoint> entryPoints = Util.makeMainEntrypoints(scope, cha);
AnalysisOptions opts = new AnalysisOptions(scope, entryPoints);
AnalysisCache cache = new AnalysisCache();
CallGraphBuilder cgBuilder = Util.makeZeroCFABuilder(opts, cache, cha, scope);
CallGraph cg = cgBuilder.makeCallGraph(opts, null);

It works fine when the example doesn't have any calls to other methods inside main, but just hangs otherwise (stuck cgBuilder.makeCallGraph).

Any advice is much appreciated.

Upvotes: 3

Views: 1777

Answers (1)

Quantico
Quantico

Reputation: 2446

Here are some options that might help making your run a bit faster

1) consider removing the reflectionOptions from your analysis options. This will not be great for more complex code, but for the basic example it might help you can do so by

options.setReflectionOptions(ReflectionOptions.NONE);

2) try using a different builder for example

ZeroXCFABuilder.make(cha, options, cache, null, null,
                ZeroXInstanceKeys.ALLOCATIONS | ZeroXInstanceKeys.CONSTANT_SPECIFIC); 

There are more options, so check ZeroXInstanceKeysto see which options you might be willing to use.

3) finally, and this is probably going to give you a good run time, add exclusions

  String exclusionFile = p.getProperty("exclusions");
  AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(appJar, exclusionFile != null ? new File(exclusionFile)

please note the following regex structure of an exclusion file

java\/awt\/.*
javax\/swing\/.*
sun\/awt\/.*
sun\/swing\/.*
com\/sun\/.*
sun\/.*

No spaces, single entry per line, etc. this should help

Upvotes: 4

Related Questions