Bytecode Manipulation Techniques for Dynamic Applications for the JVM

This JavaOne 2007 technical session seemed like a panel discussion between Eugene Kuleshov and Tim Eck of Terracotta, Tom Ware of Oracle/TopLink, and Charles Nutter of Sun/JRuby. The session started off by describing the Java Virtual Machine, the Java bytecode, and the ASM framework. The Java Virtual Machine (JVM) is a proven and reliable platform aimed at high-performing applications. The JVM is designed for statically-typed languages but provides class loading and a reflection API for dynamic languages. The discussion also delved into the class file format. The class file format simply consists of field and method names, string literals and constants, and debug information.

The ASM bytecode framework is a simple, small, and fast library for adding dynamism to your Java application. The ASM framework is useful for Java code generation and modification. Terracotta, TopLink, and JRuby use ASM to dynamically inject code into an existing class.

Charles Nutter described how the JRuby team is using the ASM framework to support Ruby’s dynamic and open class nature. Speaking of JRuby’s move to ASM Charles said, “To be slower than one of the slowest dynamic languages was embarrassing.” Using ASM, recent version of JRuby are performing better than the C implementation of Ruby in some cases.

As a word of warning, you should always document use of code generation because it is hard to debug and maintain if you don’t know what is going on.

Technorati Tags: , , , , , ,

Leave a Reply