Thursday, April 14, 2011

What is JIT

The Just-In-Time (JIT) compiler is a part of JVM to improve application performance.

As we all know the class files generated with javac contain platform-independent bytecodes to be interpreted by a JVM on specific OS/machine.  Due to this interpretation performance will be slow than that of a native application.  The JIT compiler compiles bytecodes into native machine code at run time and helps in improving the performance.  Below are some points to be noted:
  • It is enabled by default, and is activated when a Java method is called.
  • It compiles the bytecodes of that method into native machine code, compiling it "just in time" to run.
  • After a method is compiled, JVM calls the compiled code directly instead of interpreting it.
  • Methods are not compiled the first time they are called.  For each method, JVM maintains a call counter.  JVM interprets a method until its call count exceeds a JIT compilation threshold.
  • After a method is compiled, its call count is reset to zero and subsequent calls to the method will continue to increment its count.  When the call count of a method reaches the JIT recompilation threshold, the JIT compiler compiles it a second time, applying further optimizations than on the previous compilation.  This process is repeated until the maximum optimization level is reached.
  • The JIT compiler can be disabled (-Xint interpret-only mode), in which case the entire Java program will be interpreted.


No comments:

Post a Comment