All Topics  
Just-in-time compilation

 

   Email Print
   Bookmark   Link






 

Just-in-time compilation



 
 
In computing
Computing

Computing is usually defined as the activity of using and developing computer technology, computer hardware and computer software. It is the computer-specific part of information technology....
, just-in-time compilation (JIT), also known as dynamic translation, is a technique for improving the runtime performance of a computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
. JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation
Dynamic compilation

Dynamic compilation is a process used by some computer programming programming language implementations to gain performance during program execution....
. It converts code at runtime prior to executing it natively, for example bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
 into native machine code. The performance improvement over interpreters originates from caching the results of translating blocks of code, and not simply reevaluating each line or operand each time it is met (see Interpreted language
Interpreted language

In computer programming an interpreted language is a programming language whose implementation often takes the form of an interpreter . Theoretically, any language may be compiler or interpreted, so this designation is applied purely because of common implementation practice and not some underlying property of a language....
).






Discussion
Ask a question about 'Just-in-time compilation'
Start a new discussion about 'Just-in-time compilation'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computing
Computing

Computing is usually defined as the activity of using and developing computer technology, computer hardware and computer software. It is the computer-specific part of information technology....
, just-in-time compilation (JIT), also known as dynamic translation, is a technique for improving the runtime performance of a computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
. JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation
Dynamic compilation

Dynamic compilation is a process used by some computer programming programming language implementations to gain performance during program execution....
. It converts code at runtime prior to executing it natively, for example bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
 into native machine code. The performance improvement over interpreters originates from caching the results of translating blocks of code, and not simply reevaluating each line or operand each time it is met (see Interpreted language
Interpreted language

In computer programming an interpreted language is a programming language whose implementation often takes the form of an interpreter . Theoretically, any language may be compiler or interpreted, so this designation is applied purely because of common implementation practice and not some underlying property of a language....
). It also has advantages over statically compiling the code at development time, as it can recompile the code if this is found to be advantageous, and may be able to enforce security guarantees. Thus JIT can combine some of the advantages of interpretation and static (ahead-of-time
AOT compiler

An Ahead-of-Time compiler is a compiler that implements Ahead of Time Compilation. This refers to the act of compiling an intermediate language, such as Java bytecode, .NET Common Intermediate Language , or IBM System/38 or IBM System i "Technology Independent Machine Interface" code, into a system-dependent binary....
) compilation.

Several modern runtime environments, such as Microsoft
Microsoft

Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices....
's .NET Framework
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
 and most implementations of Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, rely on JIT compilation for high-speed code execution.

Overview

In a bytecode-compiled system, source code
Source code

In computer science, source code is any collection of statements or declarations written in some human-readable computer programming language....
 is translated to an intermediate representation known as bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
. Bytecode is not the machine code for any particular computer, and may be portable among computer architectures. The bytecode may then be interpreted by, or run on, a virtual machine
Virtual machine

In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions...
. A just-in-time compiler can be used as a way to speed up execution of bytecode. At the time the bytecode is run, the just-in-time compiler will compile some or all of it to native machine code for better performance. This can be done per-file, per-function or even on any arbitrary code fragment; the code can be compiled when it is about to be executed (hence the name "just-in-time").

In contrast, a traditional interpreted virtual machine will simply interpret the bytecode, generally with much lower performance. Some interpreters even interpret source code, without the step of first compiling to bytecode, with even worse performance. Statically compiled code or native code is compiled prior to deployment. A dynamic compilation environment is one in which the compiler can be used during execution. For instance, most Common Lisp
Common Lisp

Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in American National Standards Institute standard document Information Technology - Programming Language - Common Lisp, formerly X3.226-1994 ....
 systems have a compile function which can compile new functions created during the run. This provides many of the advantages of JIT, but the programmer, rather than the runtime, is in control of what parts of the code are compiled. This can also compile dynamically generated code, which can, in many scenarios, provide substantial performance advantages over statically compiled code, as well as over most JIT systems.

A common goal of using JIT techniques is to reach or surpass the performance of static compilation, while maintaining the advantages of bytecode interpretation: Much of the "heavy lifting" of parsing the original source code and performing basic optimization is often handled at compile time, prior to deployment: compilation from bytecode to machine code is much faster than compiling from source. The deployed bytecode is portable, unlike native code. Since the runtime has control over the compilation, like interpreted bytecode, it can run in a secure sandbox. Compilers from bytecode to machine code are easier to write, because the portable bytecode compiler has already done much of the work.

JIT code generally offers far better performance than interpreters. In addition, it can in some or many cases offer better performance than static compilation, as many optimizations are only feasible at run-time:

  1. The compilation can be optimized to the targeted CPU and the operating system model where the application runs. For example JIT can choose SSE2
    SSE2

    SSE2, Streaming SIMD Extensions 2, is one of the IA-32 SIMD instruction sets. SSE2 was first introduced by Intel with the initial version of the Pentium 4 in 2001....
     CPU instructions when it detects that the CPU supports them. With a static compiler one must write two versions of the code, possibly using inline assembly.
  2. 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. However, some static compilers can also take profile information as input.
  3. The system can do global code optimizations (e.g. inlining of library functions) without losing the advantages of dynamic linking and without the overheads inherent to static compilers and linkers. Specifically, when doing global inline substitutions, a static compiler must insert run-time checks and ensure that a virtual call would occur if the actual class of the object overrides the inlined method.
  4. Although this is possible with statically compiled garbage collected languages, a bytecode system can more easily rearrange memory for better cache utilization.


However, JIT typically causes 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, users will experience a longer delay. A JIT compiler therefore has to make a trade-off between the compilation time and the quality of the code it hopes to generate.

One possible optimization, used by Sun's HotSpot
Hotspot

A hot spot is a region of high or special activity within a larger area of low or normal activity. It may refer to:...
 Java Virtual Machine, is to combine interpretation and JIT compilation. The application code is initially interpreted, but the JVM monitors which sequences of bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
 are frequently executed and translates them to machine code for direct execution on the hardware. For bytecode which is executed only a few times, this saves the compilation time and reduces the initial latency; for frequently executed bytecode, JIT compilation is used to run at high speed, after an initial phase of slow interpretation. Additionally, since a program spends most time executing a minority of its code, the saved compilation time is big. Finally, during the initial code interpretation, execution statistics can be collected before compilation, which helps to perform better optimization.

Also, Sun's Java Virtual Machine has two major modes -- client and server. In client mode, minimal compilation and optimization is performed, to reduce startup time. In server mode, extensive compilation and optimization is performed, to maximize performance once the application is running by sacrificing startup time.

"" (Ngen.exe) by Microsoft
Microsoft

Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices....
 is another approach at reducing the initial delay. Ngen pre-compiles (or pre-jits) bytecode in a Common Intermediate Language
Common Intermediate Language

Common Intermediate Language is the lowest-level human-readable programming language in the Common Language Infrastructure and in the .NET Framework....
 image into machine native code. As a result, no runtime compilation is needed. .NET framework
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software 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 of the same reasons why statically compiled code cannot be as good as JIT compiled code in the extreme case.

There also exist Java implementations that combine an AOT (ahead-of-time) compiler
AOT compiler

An Ahead-of-Time compiler is a compiler that implements Ahead of Time Compilation. This refers to the act of compiling an intermediate language, such as Java bytecode, .NET Common Intermediate Language , or IBM System/38 or IBM System i "Technology Independent Machine Interface" code, into a system-dependent binary....
 with either a JIT compiler (Excelsior JET
Excelsior JET

Excelsior JET is a commercial Java Platform, Standard Edition technology implementation built around an AOT compiler Java to native code compiler....
) or interpreter (GNU Compiler for Java
GNU Compiler for Java

The GNU Compiler for Java , a free software compiler for the Java , forms part of the GNU Compiler Collection.GCJ can compile Java source code to either Java Virtual Machine bytecode, or directly to machine code for any of a number of CPU architectures....
.)

History

Dynamic translation was pioneered by the commercial Smalltalk implementation currently known as VisualWorks
VisualWorks

VisualWorks is one of the leading commercial implementations of the Smalltalk programming language and environment.The lineage of VisualWorks goes back to the first Smalltalk-80 implementation by Xerox PARC....
, in the early 1980s.

Sun's Self language improved these techniques extensively and was at one point the fastest Smalltalk system in the world; achieving up to half the speed of optimized C but with a fully object-oriented language.

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
Java Virtual Machine

A Java Virtual Machine is a set of computer software programs and data structures which use a virtual machine model for the execution of other computer programs and Scripting language....
, as HotSpot
Hotspot

A hot spot is a region of high or special activity within a larger area of low or normal activity. It may refer to:...
 builds on, and extensively uses, this research base.

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 optimizations of calls to dynamic libraries and many other run-time optimizations which conventional compilers are not able to attempt.

See also


  • AOT compiler
    AOT compiler

    An Ahead-of-Time compiler is a compiler that implements Ahead of Time Compilation. This refers to the act of compiling an intermediate language, such as Java bytecode, .NET Common Intermediate Language , or IBM System/38 or IBM System i "Technology Independent Machine Interface" code, into a system-dependent binary....
  • Code generation (compiler)
  • Binary translation
    Binary translation

    In computing, binary translation is the emulation of one instruction set by another through translation of Machine language. Sequences of instruction s are translated from the source to the target instruction set....
  • HotSpot
    Hotspot

    A hot spot is a region of high or special activity within a larger area of low or normal activity. It may refer to:...
  • Java performance
    Java performance

    Programs written in Java have had a reputation for being slower and requiring more memory than those written in compiled languages such as C or C++ ....
  • Common Language Runtime
    Common Language Runtime

    The Common Language Runtime is a core component of Microsoft .NET Framework initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code....
  • Crusoe, a microprocessor that essentially performs just-in-time compilation from x86 code to microcode within the microprocessor
  • rewriting
    Rewriting

    In mathematics, computer science and logic, rewriting covers a wide range of potentially Deterministic computation methods of replacing subterms of a formula with other terms....
  • GNU lightning
    GNU lightning

    GNU lightning is an open source library that generates assembly language code at run-time. It is extremely fast and is usable in complex code generation tasks, making it ideal for Just-In-Time compiler applications....
  • Open CIL JIT
    Open CIL JIT (compiler)

    OCJ is a Just-in-time compilation compiler that is written using a Common Intermediate Language compliant language . It targets Common Intermediate Language....
  • Works records system, online interactive spreadsheet
    Spreadsheet

    A spreadsheet is a computer application that simulates a paper worksheet. It displays multiple cells that together make up a grid consisting of rows and columns, each cell containing either alphanumeric text or numeric values....
     utilizing JIT compilation in 1974


External links

  • — A library that generates assembly language code at run-time
  • — A library by Rhys Weatherley that generates assembly language code at run-time
  • [https://gna.org/projects/softwire/ SoftWire] — A library by Nicolas Capens that generates assembly language code at run-time
  • — Complete x86/x64 jit assembler library for C++ language by Petr Kobalícek
  • An earlier implementation of JIT in 1974 at ICI
    ICI

    ICI or Ici may mean:* ICI programming language, a computer programming language developed in 1992* Ici , an alternative weekly newspaper in Montreal, Canada...
     for spreadsheet
    Spreadsheet

    A spreadsheet is a computer application that simulates a paper worksheet. It displays multiple cells that together make up a grid consisting of rows and columns, each cell containing either alphanumeric text or numeric values....
    s