Thursday, 12 November 2015

JVM Architecture

1. JVM is the heart of entire java program execution process.

2. It is responsible for taking the .class file and converting each bytecode instruction into the m/c language instruction that can be executed by the microprocessor

3. First Java compiler converts .java to .class file and this compiler outside of the JVM

4. In JVM, there is a module called class loader subsystem, which performs the following operations:

a. It loads the .class file into memory
b. Then it verifies whether all bytecode instructions are proper or not.
If it finds any instruction suspicious, the execution rejected immediately. if it finds instructions are proper, then it allocates memory to execute the program.

5. This memory is divided into 5 parts, called "Runtime data areas", which contain data and results while running the program.



Types of memory areas are allocated by JVM:

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

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

c.    Java Stacks: Method code is stored on method area. But while running a method, it needs some more memory to store the data and results. This memory is allocated on the java stacks. So java stacks are memory areas where java methods are executed. While executing methods, a separate frame will be created in the java stack, where the method is executed. JVM uses separate thread/process to execute each method.

d.   PC Registers: These are the registers (memory areas), which contain memory address of the instructions of methods. If there are 3 methods, 3 PC Registers will be used to track the instructions of the methods. It contains address of the JVM Instruction currently being executed.

e.   Native method stacks: Java methods are executed on java stacks. Similarly, native methods (for ex: c/c++ functions) are executed on native method stacks. To execute the native methods, generally native method libraries (c/c++ header files) are required. These header files are located and connected to JVM by a program, called Native method interface.



JIT Compiler:

Execution Engine: It contains interpreter and JIT (Just in Time) compiler, which are responsible for converting the byte code instructions into machine code so that the processor will execute them. Most of JVM implementations use both the interpreter and JIT compiler simultaneously to convert the byte code. This technique also called as Adaptive Optimizer

No comments:

Post a Comment