Search code examples
javabytecode

How to perform Java Bytecode liveness analysis?


I am specifically trying to determine how many initialized variables in a program are "live" at the end of it. I have multiple class files that I have disassembled into one file using

java -c file1 file2 ... >> out.txt

How would I go about this. Could I simply count the first occurrence of a variable, and then check if it is ever referred to again in the program? This has the big assumption of sequential bytecode however, which is not necessarily true.

Is liveness analysis possible for functions as well?


Solution

  • Runtime liveness analysis for variables which are actually properties guarded by get/set accessors can be translated to problem of measuring the code coverage of the set accessors.

    There are already Java tools that can measure it automatically (no inventing of some instrumentation magic suggested by @amir-afghani would be needed)

    See also: