Thursday, October 30, 2008

JVM's Execution Engine - Interpreter + JIT Compiler

//code
int a=1,b=2;


here by using interpreter
let us assume that , it will take 2 sec for doing execution of one statement.(line by line)
so .... it will take 2+2 = 4 sec for the beloved 2 statements.

//code
print a;
print b;
`````````````````````````````````````````````````````````````````
but... in loop or repeated statements execution... like ...

//code
loop 10 times
print a;

here by using interpreter ,
it will take 2 sec for each Iteration.
therefore , 2*10=20 sec

here we come across JIT compiler .
it will compile whole loop statements and store into memory.for this it will take 2 sec.
and for executing loop ,it takes 2 sec.
totally 4 sec . where as by using interpreter we do same ,in 20 sec

--------------------------------------------------------------------------------------------------------

in c,c++ like compiling languages ..
we convert them to intermediate form ... and immediate for execution.
here compiled file is not similar to text file.and it may contain pointer references.
there is a scope for virus attack.

- here ,Java.
we have bytecode as intermediate form ...which is input to JVM's execution engine - Interpreter,here we come across above discussed concepts in,Interpreter + JIT Compiler.

No comments: