Open In App

How JVM Works - JVM Architecture

Last Updated : 09 Oct, 2025
Comments
Improve
Suggest changes
787 Likes
Like
Report

The Java Virtual Machine (JVM) is a core component of the Java Runtime Environment (JRE) that allows Java programs to run on any platform without modification. JVM acts as an interpreter between Java bytecode and the underlying hardware, providing Java’s famous Write Once, Run Anywhere (WORA) capability.

  • Java source (.java) -> compiled by javac -> bytecode (.class)
  • JVM loads the bytecode, verifies it, links it, and then executes it
  • Execution may involve interpreting bytecode or using Just-In-Time (JIT) compilation to convert “hot” code into native machine code for performance
  • Garbage collection runs in the background to reclaim memory from unused objects

Architecture of JVM

The image below demonstrates the architecture and key components of JVM.

Jvm

Components of JVM Architecture

Now, we are going to discuss each component of the JVM in detail.

1. Class Loader Subsystem

It is mainly responsible for three activities. 

class_loader_subsystem

1. Loading

  • Reads .class files and stores class metadata in the Method Area.
  • Creates a Class object in the heap representing the loaded class.
Java
class GFG{
    
    static{
        
        System.out.println("GFG class is loaded by the JVM!");
    }

    public void display(){
        
        System.out.println("Method of GFG class is executed.");
    }
}

public class Test{
    public static void main(String[] args) throws Exception{
        
        System.out.println("Main method started.");

        // Loading the class explicitly using Class.forName()
        Class.forName("GFG");

        System.out.println("Class loaded successfully.");

        // Creating object to execute method
        GFG obj = new GFG();
        obj.display();
    }
}

Output
Main method started.
GFG class is loaded by the JVM!
Class loaded successfully.
Method of GFG class is executed.

Note: For every loaded “.class” file, only one object of the class is created.

2. Linking: Responsible for preparing the loaded class for execution. It includes three steps:

  • Verification: Ensures the bytecode follows JVM rules and is safe to execute.
  • Preparation: Allocates memory for static variables and assigns default values.
  • Resolution: Converts symbolic references into direct references in memory.

3. Initialization

  • Assigns actual values to static variables.
  • Executes static blocks defined in the class.

Class Loader Types

  • Bootstrap Class Loader: Loads core Java classes (JAVA_HOME/lib).
  • Extension Class Loader: Loads classes from extensions directory (JAVA_HOME/jre/lib/ext).
  • System/Application Class Loader: Loads classes from the application classpath.
Java
// Java code to demonstrate Class Loader subsystem

public class Geeks 
{
    public static void main(String[] args)
    {
        // String class is loaded by bootstrap loader, and
        // bootstrap loader is not Java object, hence null
        System.out.println(String.class.getClassLoader());

        // Test class is loaded by Application loader
        System.out.println(Geeks.class.getClassLoader());
    }
}

Output
null
jdk.internal.loader.ClassLoaders$AppClassLoader@8bcc55f

2. JVM Memory Areas

  • Method Area: Stores class-level information like class name, parent class, methods, variables, and static data. Shared across the JVM.
  • Heap Area: Stores all objects. Shared across the JVM.
  • Stack Area: Each thread has its own runtime stack; stores method calls, local variables in stack frames. Destroyed when the thread ends.
  • PC Registers: Hold the address of the currently executing instruction for each thread.
  • Native Method Stacks: Each thread has a separate stack for native method execution.

3. Execution Engine 

Execution engine executes the “.class” (bytecode). It reads the byte-code line by line, uses data and information present in various memory area and executes instructions. It can be classified into three parts:

  • Interpreter: It interprets the bytecode line by line and then executes. The disadvantage here is that when one method is called multiple times, every time interpretation is required.
  • Just-In-Time Compiler(JIT): It is used to increase the efficiency of an interpreter. It compiles the entire bytecode and changes it to native code so whenever the interpreter sees repeated method calls, JIT provides direct native code for that part so re-interpretation is not required, thus efficiency is improved.
  • Garbage Collector: It destroys un-referenced objects. For more on Garbage Collector, refer Garbage Collector.

4. Java Native Interface (JNI)

It is an interface that interacts with the Native Method Libraries and provides the native libraries(C, C++) required for the execution. It enables JVM to call C/C++ libraries and to be called by C/C++ libraries which may be specific to hardware.

5. Native Method Libraries

These are collections of native libraries required for executing native methods. They include libraries written in languages like C and C++.



How JVM Works - JVM Architecture?
Article Tags :

Explore