Just-in-time compilation
From Wikipedia, the free encyclopedia
- For other uses, see Just In Time.
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. The performance improvement originates from pre-translating the entire file, and not each line separately (see Interpreted Language). JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation.
Contents |
[edit] Overview
In a bytecode-compiled system, 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, 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.
This also offers a better performance as the compiled code is stored in memory cache at runtime, such that subsequent recompilation of compiled code is skipped. However, JIT may have a minor drawback by causing a slight delay in initial execution of an application, because certain optimization processes, such as optimizations for target CPU and operating system model are first performed before pre-compilation into bytecode. Neverthless, JIT compilation is still considered advantageous in many scenarios because of its portability.
[edit] History
Dynamic translation was pioneered by the commercial Smalltalk implementation currently known as VisualWorks, in the early 1980s; various Lisp implementations like Emacs picked the technique up quickly.
Sun's Self language used these techniques extensively and was at one point the fastest Smalltalk system in the world; achieving approximately half the speed of optimised C but with a fully object-oriented language.
The HP project Dynamo was an experimental JIT compiler where the bytecode format and the machine code format were of the same type; the system turned HPA-8000 machine code into HPA-8000 machine code. Counterintuitively, this resulted in speed ups, in some cases of 30% since doing this permitted optimisations at the machine code level. For example inlining code for better cache usage and optimisations of calls to dynamic libraries and many other run-time optimisations which conventional compilers are not able to attempt.[1]
Self was abandoned by Sun but the research went into the Java language, and currently it is used by most implementations of the Java virtual machine, HotSpot builds on, and extensively uses this research base.
The Microsoft .NET Framework also precompiles code into a portable executable (PE) and then JIT compiles it to machine code at runtime. This is achieved by the installation and/or existence of the .NET Framework (currently, version 3.0) on the target machine, which compiles a .NET application (in MSIL (Microsoft Intermediate Language) form) into machine code.
[edit] See also
[edit] References
- L. Peter Deutsch and Allan M. Schiffman, "Efficient Implementation of the Smalltalk-80 System", 11th Annual Symposium on Principles of Programming Languages, Jan 1984, pp. 297-302
- Free Online Dictionary of Computing entry
[edit] External links
- GNU lightning — A library that generates assembly language code at run-time