Friday, 21 November 2014

Java Virtual machine - JVM

Java Virtual machine

JVM is the main part of entire java program execution process.

It is taking the .class file and converting each byte code instruction into machine language instruction 
that can be executed by the microprocessor.



.java program is converted into a .class file consisting of byte code instructions by the java compiler.
Remember, this java compiler is outside the JVM. Now this .class file is given to the JVM. In JVM, there is a module (or program) called class loader sub system, which perform the following functions:

First of all, it loads the .class file in memory
Then it verifies whether all byte code instructions are proper or not. If it is not proper, the execution is rejected immediately.

If byte instructions are proper, then it allocates necessary memory to execute the program.

This memory is divided into 5 parts, called runtime data areas, which contains the data and result
while running the program.

1) Method area: It is the memory block, which stores the class code, code of the variable, and the code
of the methods in the java program.

2) Heap: This is the area where objects are created. Whenever JVM loads a class, method and heap area
 are immediately created in it.

3) Java stack: Method code is stored in method, but while running a method, it needs some more
 memory to store the data and result. So, java stack are memory area where java methods are
 executed. JVM uses separate thread (or process) to execute each method.

4) PC (program counter) registers: these are the registers (memory area) which contain memory address
 of the instructions of the methods. If there are 3 methods, 3 PC register will be used to track the
 instructions of the methods.

5) 
Native method stack: Native methods are executed on native method stacks. To execute the native methods, native libraries are required and these libraries are located and connected to JVM by a program called native method interface.



Execution engine contains interpreter and JIT (Just in time) compiler, which are responsible for
converting the byte code instructions into machine code. So that processor will execute them. Most of the JVM implementations use both the interpreter and JIT compiler simultaneously to converting
the byte code. This technique is called adaptive optimizer.

 

No comments:

Post a Comment