Architecture of Java Virtual Machine (JVM)

Java programmers may want to learn the full details of how Java Virtual Machine (JVM) really functions. In this topic, I am going to explain the JVM architecture. JVM has various sub components internally. These components are shown in the diagram below.

Figure 1: JVM Architecture


The different components of JVM are described below.

1. Class loader sub system: This class loader sub system of JVM performs three tasks —

a) It loads the .class  file into memory.
b) It verifies the byte code instructions.
c) It allots memory required for the program.


2. Run time data area: This is the memory resource used by JVM and it is divided into five parts —

a) Method area: Method area stores class code and method code.
b) Heap: The objects are created on heap.
c) Java stacks: Here the Java methods are executed. A Java stack contains frames. On each frame, a separate method is executed.
d) Program counter registers: The program counter registers store memory address of the instruction to be executed by the microprocessor.
e) Native method stacks: Here native methods (e.g. C/C++ programs) are executed. Native method is a function, which is written in other languages.


3. Native method interface: Native method interface is a program that connects native methods libraries (C/C++ header files) with JVM for executing native methods.


4. Native method library: It holds the native libraries information.


5. Execution engine: Execution engine contains interpreter and Just-in-time (JIT) compiler, which covert byte code into machine code. JVM uses optimization technique to decide which part of the code to be interpreted and which part of the code to be used with JIT compiler. The HotSpot represents the block of code to be executed by the JIT compiler.