Sign up ×

I'm confused with JIT compiler,

  1. What is JIT compiler?
  2. JIT compiler compiles byte codes before each execution or each time JVM loads?
share|improve this question

4 Answers 4

up vote 4 down vote accepted

JIT stands for "Just In Time". It's a compiler that translates Java bytecode to native machine code as your program runs.

Sun's JIT does not compile all your bytecode up front each time you run a Java program; it contains some very sophisticated logic to decide when to compile parts of the bytecode, one of the criteria it uses is how often the code is executed.

See Just-in-time compilation and HotSpot (Wikipedia) for more details.

share|improve this answer

The JIT compiler is a specialized compiler that will watch Java bye code run and compile it into native instructions if necessary.

If the JIT determines that a part of your code is running very frequently, or that compiling it to native code will significantly increase performance, it will do so.

JIT compilation is completely optional, and the standard implementation of Java allows you to turn it off. However, there is really no reason to turn it off.

share|improve this answer
Does it mean that the JIT compilation is an optional? –  Tony Jun 23 '10 at 17:09
Yes, it is optional in the sense that you can turn it off; however, it is turned on by default (and that's a good thing). –  Edwin Buck Jun 23 '10 at 17:12
On Sun's implementation of Java you can turn JIT compilation off by using the command line option -Xint but normally you would not do that. –  Jesper Jun 23 '10 at 17:14


JIT compilers are supplied as standalone platform-dependent native libraries. If the JIT Compiler library exists, the Java VM initializes Java Native Interface (JNI) native code hooks to call JIT functions available in that library instead of the equivalent function in the interpreter.The java.lang.Compiler class is used to load the native library and start the initialization inside the JIT compiler.The JIT compiler uses its own invoker. Sun production releases check the method access bit for value ACC_MACHINE_COMPILED to notify the interpreter that the code for this method has already been compiled and stored in the loaded class.When a method is called the first time(depends on JVM vendor) the JIT compiler compiles the method block into native code for this method and stored that in the code block for that method.


The first thing to remember is that the JIT compiler achieves most of its speed improvements the second time(depends on JVM vendor) it calls a method. The JIT compiler does compile the whole method instead of interpreting it line by line which can also be a performance gain for when running an application with the JIT enabled. This means that if code is only called once you will not see a significant performance gain. The JIT compiler also ignores class constructors so if possible keep constructor code to a minimum.

The JIT compiler also achieves a minor performance gain by not pre-checking certain Java boundary conditions such as Null pointer or array out of bounds exceptions. The only way the JIT compiler knows it has a null pointer exception is by a signal raised by the operating system. Because the signal comes from the operating system and not the Java VM, your program takes a performance hit. To ensure the best performance when running an application with the JIT, make sure your code is very clean with no errors like Null pointer or array out of bounds exceptions.

Reference :

share|improve this answer

The JIT compiler was an external just-in-time compiler that shipped with Java 1.1. The term is now obsolete. Java ships with a 'HotSpot' JVM that has compilation built in to it.

share|improve this answer

Your Answer


