JUST-IN-TIME COMPILATION


In computing, 'just-in-time compilation' ('JIT'), also known as 'dynamic translation', is a technique for improving the runtime performance of a computer program. It converts, at runtime, code from one format into another, for example bytecode into native machine code. The performance improvement originates from caching the results of translating blocks of code, and not simply evaluating each line or operand separately (see Interpreted language), or compiling the code at development time. JIT builds upon two earlier ideas in run-time environments: ''bytecode compilation'' and ''dynamic compilation''. Several modern runtime environments, such as Microsoft's .NET Framework and most implementations of Java, rely on JIT compilation for high-speed code execution.

Contents
Overview
History
See also
Notes
References
External links

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 code is executed, the runtime environment's compiler translates it into native machine code. This can be done per-file, per-function or even on any arbitrary code fragment; code can be compiled when it is 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 generally offers far better performance than interpreters as the compiled code is stored in memory cache at runtime, such that subsequent recompilation or reinterpretation of compiled code can be skipped, while also giving flexibility to automatically recompile and optimise code that is found at runtime to be frequently executed.
However, JIT may have a drawback by causing a slight delay in initial execution of an application, due to the time taken to compile the bytecode. Sometimes this delay is called "startup time delay". In general, the more optimization JIT performs, the better code it will generate. However, the longer delay users will experience. Therefore a well written JIT has to make the trade-offs between the compilation time and the quality of the code it hopes to generate.
Other advantages of a JIT runtime include:
#The compilation can be optimized to the targeted CPU and the operating system model where the application runs. For example JIT can choose SSE2 CPU instructions when it detects that the CPU supports them.
#The system is able to collect statistics about how the program is actually running in the environment it is in, and it can rearrange and recompile for optimum performance. This data is normally difficult or even impossible to obtain for conventional compilers.
JIT compilation is considered advantageous in many scenarios because of its portability, flexibility and performance. The only major drawback is the startup time delay. Various technologies exist for reducing this delay. "Native Image Generator" (Ngen.exe) by Microsoft is one of the examples. Ngen pre-compiles (or ''pre-jits'') bytecode in a Common Intermediate Language image into machine native code. As a result, no runtime compilation is needed. .NET framework 2.0 shipped with Visual Studio 2005 runs Ngen.exe on all of the Microsoft library DLLs right after the installation. Pre-jitting provides a way to improve the startup time. However, the quality of code it generates might not be as good as the one that is jitted, for many reasons. For example, the pre-jitter is only allowed to choose the common subset of the CPU instructions from the CPU architectures it plans to support.

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, as HotSpot builds on, and extensively uses, this research base.

See also



Code generation (compiler)

Binary translation

HotSpot

Java performance

Common Language Runtime

Crusoe, a microprocessor that essentially performs just-in-time compilation from x86 code to microcode within the microprocessor

★ Works records system, online interactive spreadsheet utilizing JIT compilation in 1974

Notes


1. Ars Techica on HP's Dynamo

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

External links



GNU ''lightning'' — A library that generates assembly language code at run-time

This article provided by Wikipedia. To edit the contents of this article, click here for original source.

psst.. try this: add to faves