Anda di halaman 1dari 10

JDK(Java Development

Kit)
JDK contains two parts

First part contains Javac , jar, Debugging


tools, javap etc.
Second Part is JRE(Java Runtime Env):
Which conatains Java, javaw, rt.jar , libraries
and
JVM etc..

JRE(Java Runtime Environment)


JAVA API Which contains all packages/
classes and runtime libraries etc.

JVM- Java Virtual


Machine

JVM
Class Loader Sub System

Garbage Collector
Verifier

Byte Code

Execution Engine
etc

Execution Engine
Interpreter : Which reads instruction by

instruction and converts from byte code to


machine code.

JIT(Just in Time) Compiler : This compiler is


invoked by JVM whenever there are repeated
statements to convert from byte code to
machine code.

A nano second is .0000000001 a second. so its 1,000,000,000


nano's are one second.
OR
A nanosecond (ns) is one billionth of a second (109 or
1

/1,000,000,000 s).

public class Sample {


public static void main(String args[]){
int a=10;//line no 1
int b=20; // line no 2
System.out.println(Value of a :+ a);//line no 3
System.out.println(Value of b:+ b);// line no 4
for(int i=1;i<=10;i++){
System.out.println(Value of b:+ b);
}
}
}

When , the interpreter starts execution from 3rd


instruction , it converts System.out.println("value of
a:"+a); into machine code and gives it to the
microprocessor. For this, say the interpreter has taken 2
nanoseconds time. The processor takes it , executes it ,
and the value of a is displayed.
Now, the interpreter comes to the 4th instruction and
reads the System.out.println(Value of b :+b); converts
into machine code, it takes another 2 nanoseconds .
Then the instruction is given to the processor, it executes
and displays the b value.

times and this is known to the interpreter. Hence , the first


time it converts System.out.println(Value of b :+b); int
machine code . It takes 2 nanoseconds for this. After giving
this instruction to the processor , it comes back and reads the
System.out.println(Value of b:+b); instruction 2nd time and
converts it to machine code. This will take another 2
nanoseconds . This will be given to the processor and the
interpreter comes back and reads the
System.out.println(Value of b:+b); again and converts it 3rd
time taking another 2 nanoseconds .Like this , the interpreter
will convert the System.out.println(Value of b :+b); for 10
times , consuming a total of 10*2=20 nanoseconds . This
procedure is not efficient in terms of time. That is the reason
why JVM does not allocate this code to the interpreter. It allots
this code to the JIT compiler.

Let us see how the JIT compiler wll execute the looping
instruction . First of all , the JIT compiler reads the
System.out.println(value of b :+b); instruction and converts
that into machine code. For this , say, it is taking 2
nanoseconds . Then the JIT compiler allots a block of memory
and pushes this machine code instruction into memory. For
this, say , it is taking another 2 nanoseconds . This means JIT
compiler has taken 4 nanoseconds . Now , the processor will
fetch this instruction from memory and executes it 10 times .
Just observe that the JIT compiler has taken 4 nanoseconds for
execution , whereas to execute the same loop the interpreter
needs 20 nanoseconds . Thus , JIT compiler increases the speed
of execution. Recognize that the 3rd and 4th instructions will
not be allotted to JIT compiler by the JVM. The reason is clear.
Here it takes 4 nanoseconds to convert each instruction ,
whereas the interpreter actually took only 2 nanoseconds .

After loading the .class code into the memory, JVM first
of all identifies which code is to be left to interpreter and
which one to JIT compiler so that the performance is
better. The block of code allocated to JIT compiler are
also called hotspots. Thus, both the interpreter and JIT
compiler will work simultaneously to translate the byte
code into machine code.

Anda mungkin juga menyukai