Cojen's primary goal is making raw Java classfile generation easy, without hiding any of the advanced features. Basic knowledge of how Java classfiles are structured is still required, however. The Virtual Machine Specification is an excellent reference.

Method bytecode is constructed via a builder, in which virtual machine opcodes are represented as slightly higher level instructions. It takes care of selecting optimal opcodes, managing branch labels, computing operand stack depth, choosing local variable registers, and reducing register usage by liveness analysis. In addition, it supports long branches, pushing large string constants onto the stack, boxing and unboxing conversions, and inlining of Java code.

The builder is represented by an interface, which can be used as a visitor into a code disassembler. This feature can be used for just-in-time method mutation, and to aid in understanding how to use the code building facilities.

A simple "Hello World" example is provided which demonstrates the major class generation and loading features. Disassembly tools which can be run from the command line show how any class can be used as an example for class generation.

URL: http://cojen.sourceforge.net/
Licence: Apache License