Static analysis of Java call graph

Mark Renouf picture Mark Renouf · Feb 9, 2011 · Viewed 23k times · Source

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.

Answer

Georgios Gousios picture Georgios Gousios · May 18, 2012

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