Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 858
JPC Avatar asked Jun 03 '26 11:06

JPC


1 Answers

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

like image 199
Quantico Avatar answered Jun 05 '26 01:06

Quantico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!