Just-in-time compilation
|
- See also Just in time for the business technique
In computing, just-in-time compilation (JIT), also known as dynamic translation, is a technique for improving the performance of bytecode-compiled programming systems, by translating bytecode into native machine code at runtime. JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation.
In a bytecode-compiled system such as Perl, GNU CLISP, or early versions of Java, source code is translated to an intermediate representation known as bytecode. Bytecode is not the machine code for any particular computer, and may be portable among computer architectures. The bytecode is then interpreted, or run on a virtual machine.
A dynamic compilation environment is one in which the compiler can be used during execution. For instance, most Common Lisp systems have a compile function which can compile new functions created during the run. While advantageous in interactive debugging, dynamic compilation is less useful in a hands-off deployed system.
In a JIT environment, bytecode compilation is the first step, reducing source code to a portable and optimizable intermediate representation. The bytecode is deployed onto the target system. When the code is executed, the runtime environment's compiler translates it into native machine code. This can be done on a per-file or per-function basis: functions can be compiled only when they are about to be executed (hence the name "just-in-time").
The goal is to combine many of the advantages of native and bytecode compilation: Much of the "heavy lifting" of parsing the original source code and performing basic optimization is handled at compile time, well prior to deployment -- compilation from bytecode to machine code is much faster than from source. The deployed bytecode is portable, unlike machine code for any given architecture. Compilers from bytecode to machine code are easier to write, because the portable bytecode compiler has already done much of the work.
History
Dynamic translation was pioneered by the commercial Smalltalk implementation currently known as VisualWorks, in the early 1980s. Currently it is also used by most implementations of the Java virtual machine.
Sun's HotSpot (Java) Java virtual machine contains an example of a successful JIT implementation. In fact, it uses two: a "client" compiler which emphasizes fast compilation speed for applications that will be short-lived, and a "server" compiler which emphasizes highly optimized code for applications that will be long-lived. Users can choose which dynamic compiler is used depending upon the characteristics of their application.
Microsoft selected a JIT-based system for their .NET environment, and the Crusoe processor uses similar techniques in hardware. Parrot virtual machine also uses JIT. Psyco is a JIT compiler for Python.
Related topics
References
- L. Peter Deutsch and Allan M. Schiffman, "Efficient Implementation of the Smalltalk-80 System" (http://webpages.charter.net/allanms/popl84.pdf), 11th Annual Symposium on Principles of Programming Languages, Jan 1984, pp. 297-302
- Free Online Dictionary of Computing (http://www.foldoc.org)de:JIT-Compiler