sources JIT Source
IT compilers alter the role of the VM a little by directly compiling Java bytecode into native platform code, thereby relieving the VM of its need to manually call underlying native system services. The purpose of JIT compilers, however, isn't to allow the VM to relax. By compiling bytecodes into native code, execution speed can be greatly improved because the native code can be executed directly on the underlying platform.
When JIT compiler is installed, instead of the VM calling the underlying native operating system, it calls the JIT compiler. The JIT compiler in turn generates native code that can be passed on to the native operating system for execution. The primary benefit of this arrangement is that the JIT compiler is completely transparent to everything except the VM.
Stage 1:
JIT compiler maintains a internal table called as V-Table (Virtual Table) that has pointer to the methods in a Class. In case of derived classes only the Derived method are taken into consideration. When a JIT compiler is first loaded, the VM pulls a little trick with the V-table to make sure that methods are compiled into native code rather than executed. What happens is that each bytecode address in the V-table is replaced with the address of the JIT compiler itself.
Stage 2:
When the VM calls a method through the address in the V-table, the JIT compiler is executed instead. The JIT compiler steps in and compiles the Java bytecode into native code and then patches the native code address back to the V-table. From now on, each call to the method results in a call to the native version. Methods are compiled only when they are called. The first time a method is called, it is compiled; subsequent calls result in the native code being executed.
Stage 3:
For Backward compatilibily purposes, VM actually maintains two V-Tables. One for Native Code and the other for original Bytecode, so that when methods needs to be executed with JIT compiler off, then they are executed from V-table having Methods in Bytecode
Improvement in Performance:
Because the AWT is already written in native code, programs that rely heavily on the AWT don't reap the same performance gains as programs that depend on pure Java bytecode. A heavily graphical program that makes great use of the AWT may see performance gains by an order of only two or three.
On the other hand, a heavily processing-intensive Java program that uses lots of floating-point math may see performance gains closer to an order of fifteen. This happens because native Pentium code on a Windows machine is very efficient with floating-point math. Of course, other platforms may differ in this regard.
When to enable JIT compiler
if 80% of the execution time is dependent on 20% of the code,this is very good scenario to use JIT. Its going to reduce the execution time by 30%
No comments:
Post a Comment