JustKernel

Ray Of Hope

JIT+JVM internals

Like most virtual machines, the java virtual machine has a stack- based on architecture akin to microcontroller or microprocessor.

The jvm which is the instance of jre, comes into action when java program is executed. When execution is complete, this instance is garbage collected. JIT is a part of JVM that is used to speed up the execution time. JIT compiles parts of the byte code that have similar functionality at same time and hence reduces the amount of time needed for compilation.

The jvm is distributed along with a set of standard class libraries which implement the java API. The virtual macine and API have to be consistent with each other and are therefore bundled together as java runtime environment.

In computing , just-in-time compilation (JIT) also known as dynamic translation is a techinque for improving the runtime performance of the computer program. JIT  bilds upon two earlier ideas in run-time environmens: bytecode compilation and dynamic compilation. It converts code at runtime , prior to executing it natively, for eg. bytecode into native machine code. The performance improvement over interpreters originates from caching the results of translating blocks of ocde, and not simply revaluating each line or operand each time it is met. It also has the advantages over statically computing the code at development time, as it can recompile the code if this is found to be advantageous and may be able to inforce security gurantees. The JIT can combine some of the advantages of interpretation and static (ahead-of-time) computation.

Bytecode is not the machien code for any perticular computer, and may be portable among computer architectures. The bytecode can then be interpreted or run on virtual machine. A just – in -time compiler can be used as a way to speed up the execution of the bytecode. At the time bytecode is run, the just-in-time will compile some or all of it to native machine code for better performance. This can be done per file, per function or even on any arbitrary code fragment, , the code can be compiled when it is about to be executed (hence the name – just-in-time)

In contrast, a traditional interpreted virtual machine will simply interpret the bytecode.

Advantages of JIT  :

1) The compilation can be optimised to the targeted CPU and the OS model where applicaiton runs. for eg JIT can chose SSE2 CPU instructions when it detects that the CPU supports them.

2) Although this is possible with statically compiled garbage collected languages, a bytecode system can more easity rearrang ememory for better cache utilization.

How JIT causes a slight delay in inital execution of an application  ? Its due to time taken to compile the byte code. Sometim ethis delay is called “startup time delay” . Sun’s hotspot JVM combines interpretation and JIT compilaiton. The application code is initiall interpreted , but the JVM monitors which sequence ob bytecode are frequently executed and translates then to machine code for direct execution on the hardware. For bytecode which is executed only a few times, this reduces the computation time and reduces the initial latency; for frequently executed bytecode, JIT compilation is used to run at high speed, after virtual phase of slow interpretation.

Originally Posted On: 2010-04-08 01:31:47

Anshul Makkar, anshul_makkar@justkernel.com

Tags:


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.