What is a JIT compiler?

By | September 25, 2021

A JIT compiler translates a program or program parts at startup or during runtime as required. The program is compiled just-is-time in machine language. The program itself is in a language other than the machine language.

According to PHOTIONARY, the abbreviation JIT stands for “Just in Time”. It is about the translation of a program into the required machine language as required. The decisive factor is the fact that the program to be translated is in a foreign language that does not correspond to that of the executing system. Therefore there is a need for translation or compilation of the program.

The program is usually in a higher programming language , for example Java , C / C ++ or HTML. It can also happen that a program in an intermediate language (IL) has to be translated. It is the job of the JIT compiler to carry out this translation. The compiler can either compile the complete program at the start or program parts at runtime as required.

JIT Compilation for Executing Programs: Use and Process

JIT compilation is a technique that is used by various runtime environments and interpreters. It is used to execute programs that are not written in machine language. An example of such runtime environments is the Java Virtual Machine (JVM).

JIT compilers differ from those compilers that convert the full source code into executable programs in just one pass. The JIT compiler does not work in one go, but according to its name just in time, i.e. as required. In practice, it is only active in the process of program execution.

JIT as a combination of two approaches to machine code translation

The JIT compilation can be understood as a combination of two older, traditional approaches to code translation. These are the

  • AOT (Ahead of time Compilation) and the
  • interpretation

The JIT compiler thus also combines the respective advantages and weaknesses of these approaches. The JIT compilation combines the pace of the compiled code with the greater flexibility of interpretation. This is connected with an additional compilation effort. JIT compilation can be understood as a variant of dynamic compilation. The approach enables various adaptive optimizations. This includes dynamic recompilation.

How JIT compilation works

The JIT compiler translates the existing code into what is known as native machine code. This is code that the processor used can process immediately. The specialty of the JIT compilation is that the compiler only becomes active during runtime . So the compilation does not take place in advance.

After compilation, the machine code is executed, which can now be processed by the processor. This approach has performance advantages over conventional compilation. Whole whole blocks of code are processed during compilation. This also represents a speed advantage compared to the otherwise usual line-by-line processing.

Particularly highly developed JIT compilers are able to generate code more quickly, especially for dynamic languages. The JIT compilation also has the advantage that only a small part is compiled at all before the program starts. This reduces the problem of delays in starting the program.

Furthermore, there is an advantage in the conservation of system resources. Certain parts of the program that are not run anyway are not compiled either. With JIT compilation, once fully compiled program parts are still held in a software cache. This has the advantage that the program parts do not have to be recompiled for each additional run.

Areas of application of the JIT compiler

JIT compilers can be used with a variety of programs, but especially for dynamic capacities. This includes regular expressions. For example, a text editor can compile regular expressions that are available for the machine code during runtime. In this way a faster comparison is possible. It is not possible for this to happen in advance, because the sample must be provided at runtime.

Many modern runtimes use JIT compilation as a basis when it comes to running their code at high speed. This includes most of the Java implementations, along with Microsoft’s NET framework .

Further examples of current JIT compilers can be found in many web browsers for desktop operating systems. A JIT compiler is used here to speed up JavaScript execution. As part of the virtual machine, the JIT compiler supplements the interpreter (such as the Java Virtual Machine (JVM) for Java or CLR for .NET).

Similarly, many libraries that work with regular expressions offer JIT compilation. In these cases, the compilation takes place either in bytecode or in machine code. JIT compilation is also used in various emulators, for example to transfer or translate the machine code of one CPU architecture into another.

JIT compilers are also used after an AOT compilation in bytecode (the code of the VM or virtual machine) has already taken place. The bytecode compilation is then followed by a subsequent JIT compilation in machine code. This dynamic compilation prevents the bytecode from having to be laboriously interpreted first. The runtime performance improves in direct comparison to the regular interpretation.

What is a JIT compiler