JIT Compiler- Just in Time Compiler

JIT Compiler is part of JVM Execution engine which helps in improving the performance of java programs.It compiles the bytecode into native machine code at run time.

JIT Compiler- Just in Time Compiler

In java programs, thousands of methods are called. Compiling all of these methods can significantly affect the performance of the java programs.

For the above reason, methods are not compiled the first time they are invoked. For each method, the JVM maintains a call count, which is incremented every time the method is called. The JVM interprets a method until its call count exceeds a JIT compilation threshold. Therefore, often-used methods are compiled soon after the JVM has started, and less-used methods are compiled much later, or not at all.

After a method is compiled, its call count is reset to zero and subsequent calls to the method continue to increment its count. When the call count of a method reaches a JIT recompilation threshold, the JIT compiler compiles it a second time, applying a larger selection of optimizations than on the previous compilation. This process is repeated until the maximum optimization level is reached. The busiest methods of a Java program are always optimized most aggressively, maximizing the performance benefits of using the JIT compiler. The JIT compiler can also measure operational data at run time, and use that data to improve the quality of further recompilations.

According to most researches, 80% of execution time is spent in executing 20% of code. That would be great if there was a way to determine those 20% of code and to optimize them. That’s exactly what JIT does – during runtime it gathers statistics, finds the “hot” code compiles the bytecode (that is stored in .class files) to a native code that is executed directly by Operating System and heavily optimizes it.

The JIT compiler is enabled by default, and is activated when a Java method is called.The JIT compiler can be disabled, in which case the entire Java program will be interpreted. Disabling the JIT compiler is not recommended except to diagnose or work around JIT compilation problems.

You can disable the JIT compiler by adding -Djava.compiler=NONE in VM arguments.

Related Topics

Java Virtual Machine(JVM)

JVM Interview Questions

Method Area(Non-Heap Area)

Heap Area in JVM

Leave a Reply

Your email address will not be published. Required fields are marked *