Return back to the blog

Java Bytecode manipulation : Tools of the trade

Posted by Prashant Deva on November 11, 2011

Since the Chronon recorder uses bytecode instrumentation to record your java applications, I thought I would list some of the tools we use to help us with it:

ASM framework

The de-facto Java framework for bytecode manipulation. The ASM framework is the fastest, most flexible and well known framework around for doing bytecode manipulation.  At the time of writing its the only framework that supports the Java 7 class file format. If you are trying to choose a framwork for bytecode manipulation, stop, just learn and use ASM.

Bytecode Outline plugin

This eclipse plugin can automatically show you the bytecode for java file open in your editor. It can also show the corresponding ASM code that would be needed to generate the said bytecode. It will help you understand both bytecodes and the ASM framework better.

jClassLib Bytecode Viewer

This free tool, made by the same guys who make JProfiler, is the most comprehensive way to view your generated .class files. It can show you the bytecodes individually for a method along with things like the local variable table, exceptions table, constant pool, etc.  Its a must have, in my opinion, if you are fiddling around with Java byetcodes in any way.

Chronon Time Travelling Debugger

This may sound like self promotion, but I remember the time before Chronon was born and each time we would run into issues with the generated bytecode, (which btw you will at some point too, no matter how hard you try not to), it would take hours trying to use the standard debugger or littering our code with println() statements everywhere before we found the root cause. Now if we find any error in the generated bytecode, we just look at the Chronon recording of the executed code in the Time Travelling Debugger and can find root cause in minutes.

 

 

Tagged 5 Comments |

5 thoughts on “Java Bytecode manipulation : Tools of the trade

  1. Interesting, but how do you relate whatever you see in the Chronon recording to what was dynamically generated (i.e. no source code)?Also, I’ve found javassist to be an easier way through the looking glass and into wonderland ;)

  2. Well, you look at the generated code using jClasslib Bytecode Viewer.Then you use Chronon to look at *your* code which *generated* the (faulty) bytecode.

  3. Ah, I misread.. I thought you meant using Chronon to debug the *generated* code itself, not the code that does the generating.

Comments are closed.