Runtime code generation in JVM and CLR

The Java Virtual Machine (JVM) and the Common Language Runtime (CLR) are bytecode-based abstract stack machines. Since modern implementations include highly optimizing just-in-time (JIT) compilers, these machines are excellent targets for runtime code generation: the generation of new program code just prior to its execution.

Here we present several complete examples of runtime code generation on these platforms. The purpose of this work is to investigate the suitability of these technologies that have recently entered the mainstream, and that can be expected to be widely available in the near future.

Further information about the examples, and results from experiments made with them, can be found here:

Useful resources

Overview of example programs

What is generatedC# versionJava version
A very simple methodRTCG1.cs 
A method with integer argument and resultRTCG2.csRTCG2.java, RTCG2B.java
Methods that contain loops, for timingRTCG3.csRTCG3.java
Specialized versions of the power functionRTCG4.csRTCG4.java, RTCG4B.java
Specialized evaluator for polynomialsRTCG5.cs 
Specialized evaluator for arithmetic expressionsRTCG6.cs 
Large methods, for timing of code generationRTCG7.csRTCG7.java, RTCG7B.java
Specialized sparse matrix multiplicationRTCG8.csRTCG8.java
Specialized AES encryption/decryption routinesAesFast.cs, AesGen.cs 
Efficient delegate objects in Java  Delegate.java, TryDelegate3.java, TryDelegate4.java


Peter Sestoft (sestoft@itu.dk) 2002-09-23, 2006-02-24