Static analysis of Java call graph

China☆狼群 提交于 2019-11-26 13:07:05

问题


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.


回答1:


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




回答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.




回答3:


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.




回答4:


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




回答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).



来源:https://stackoverflow.com/questions/4951517/static-analysis-of-java-call-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!