Static analysis of Java call graph

25,558

Solution 1

You can use the java-callgraph tool suite to create accurate enough static and dynamic callgraphs for Java.

Solution 2

You can try JavaDepend , it gives many features needed for dependencies and metrics, it provides also a CQL like SQL to request your code base.

Disclosure: it's a commercial software.

Solution 3

You can use Doxygen with Graphviz. It is easy to install and use.

Solution 4

Soot should allow you to easily achieve what you are looking for: http://www.sable.mcgill.ca/soot/

It can construct precise call graphs fully automatically.

You can find all necessary documentation here: http://www.sable.mcgill.ca/soot/tutorial/index.html

Also, there's an active mailing list for Soot.

Solution 5

It sounds like you want something that provides access to the abstract syntax and a complete symbol table. Then a custom scan of the ASTs of the functions in the call graph rooted in each implementing method (as indicated by the symbol tables) of an abstract method gives you a chance to locate a new operation whose type is the specific class of interest.

The DMS Software Reengineering Toolkit is generalized compiler technology providing basic services of parsing, AST building/navigation, symbol table building/navigation, control flow, data flow and call graph construction. DMS has an optional Java Front End that provides a full Java parser, builds Java ASTs and symbol tables, and can construct a call graph. The Java Front End can also read .class files; you weren't clear as to whether you wanted to climb into class files, too, hunting for information.

The answer you want isn't off the shelf. You need to build some custom code to implement the ideas in the first paragraph, but DMS can provide most of the raw material. It doesn't provide much detail from the .class files (these are used mostly to resolve types in source code).

Share:
25,558
Josh
Author by

Josh

Software Engineer / Android @ Google

Updated on July 06, 2021

Comments

  • Josh
    Josh almost 3 years

    What I'd like to do is scan a set of Java classes, and trace all method calls from a specific method of an Abstract Class, and within that context, build a list of all code which performs some operation (in this case, instantiates an instance of a certain class). I want to know, the line number, and the arguments supplied.

    I've begun looking at BCEL, but it doesn't seem to have call graph tracing built in? I'm hesitant to write my own because getting the overloading, type signatures and polymorphic dispatch right might be be tricky.

    I half expected a tool or example code to exist, but I haven't found anything yet. It really feels like I'm about to reinvent a wheel. But if I do it will be an open source wheel and available on GitHub ;-)

    PS: You will find the existing question "How to Generator a Java Call Graph", because it sounds identical, but it's not at all what I need.

  • Kumar Roshan Mehta
    Kumar Roshan Mehta about 10 years
    I have got the jimple from apk but not able to build the call graph using command line. Help required.