Samir Hasan
Samir Hasan

Reputation: 13

How can I get the bytecodes that are executed at runtime for a Java program?

The compiled .class file contains bytecodes corresponding to whole java class. However, during execution, some bytecodes are exectued multiple times while some are probably not executed at all, depending on the logic and the input. Is there a way that I could get a trace of only those bytecodes that are executed during the lifetime of the java program?

Edit: Use case

I think a use-case may help. After a sample run of the program, I would like to count the frequency of the bytecode instructions that were executed (e.g. areturn has been carried out 10 times). Is there a profiler or any other tool that I can use for this purpose?

Upvotes: 0

Views: 390

Answers (1)

Leo
Leo

Reputation: 6570

this obscure paper talks about such a tool

http://ccsl.icmc.usp.br/files/vincenzi-et-al-2003.pdf

it's quite old (2003)

it states

This paper describes a coverage testing tool for Java programs and Java-based components, named JaBUTi (Java Bytecode Understanding and Testing). Differently from other testing tools that require the Java source code to carry out the program analysis, instrumentation and coverage assessment, our tool requires only the Java bytecode. Bytecode can be viewed as an assembly-like language that retains high-level information about a program [Lindholm and Yellin, 1999 ]. Therefore, JaBUTi enables the user to test Java programs and Java-based components even when no source code is available. There are others testing tools that work at the bytecode level. The frame work JUnit [Beck and Gamma, 2002 ], for instance, can be used to test Java bytecode, but it only enables performing black-box testing; it does not report any coverage information. JTest [Corporation, 2002] and GlassJAR [Edge, 2002 ] provide coverage information with respect to control-flow testing criteria at the bytecode level, but none of them supports dataflow coverage testing criteria. By working at the bytecode level we want to provide a tool that can be used for testing not only Java applications that have the corresponding source code available, but also, the ones that have only the bytecode, like software components

Upvotes: 1

Related Questions