Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static analysis of Java call graph

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.

like image 401
Mark Renouf Avatar asked Feb 09 '11 22:02

Mark Renouf


People also ask

What is a static call graph?

A static call graph is a call graph intended to represent every possible run of the program. The exact static call graph is an undecidable problem, so static call graph algorithms are generally overapproximations.

What is call graph in Java?

The Java Call Graph presents the chain of possible calls at runtime in Java. The nodes in the graph represent the project components, while the edges (arrows) represent relationships between the components. Both nodes and edges are color coded to show the type of component or relationship.

What does a call graph show?

A call graph provides general information about the total execution time, the node name, the time stamp for the start of execution, and the unique identifier for the business transaction instance. You can use call graphs to diagnose performance issues and optimize the flow of a complex business transaction.


1 Answers

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

like image 52
Georgios Gousios Avatar answered Sep 19 '22 06:09

Georgios Gousios