Just-In-Time Compilation and the Microsoft VM for Java Previous
Previous
Virtual Machine
Virtual Machine
Next
Next

Background

The standard model of a virtual machine (VM) for Java is continually interpreting a sequence of bytecodes that describe the intent of a Java applet or application. Each time the VM encounters a bytecode, whether it has interpreted it many times before or not, there is a (relatively) lengthy translation process. Even though various approaches exist for speeding up this approach somewhat, this interpretation process accounts for significantly slower performance of execution compared to equivalent compiled native code.

To improve this performance, JIT compilers interact with the VM and compile appropriate bytecode sequences into an equivalent piece of native machine code. This process occurs at run time (i.e. as the particular piece of code is going to be executed) rather than at compile time as is traditionally the case with compiled languages such as C and C++. Rather than interpret the same bytecodes over and over again, the native code can be executed ("interpreted") by the hardware (the CPU). This can allow quite dramatic performance gains in the speed of execution. There is, however, a tradeoff.

The time taken for the JIT to compile the bytecodes is added to the overall execution time. For example, when a method executes only once and doesn't contain any loops, the overall performance might be reduced when JIT compilation occurs.

Note that JIT compilation has potential advantages over traditional code compilation techniques in some aspects: for example, it can target the specific machine upon which the program is actually running (for example, 486 vs. Pentium), rather than for a general CPU (or "the most likely" one) as is the best that can be achieved with traditional approaches (for example, targeting a generic x86 platform).

© 1996 Microsoft Corporation. All rights reserved.