? in-Depth Guide to JVM Architecture ?
? in-Depth Guide to JVM Architecture ?
JVM (Java Virtual Machine) is a software that interprets and executes Java code.
------------------Hierarchy ---------------
o Class Loader
▪ Loading
• Bootstrap class loader
o Load – core java libraries
o From – jre/lib/rt.jar
• Extension Class Loader
o Load – java extended libraries(3rd Parties)
o From – jre/lib/ext and java.ext.dir
• Application or System Class loader
o Load – application classes
o From – ClassPath specifies by User / CodeBase
▪ Linking
• Verify- byte code verifier
• Prepare – allocate memory for static member and load default values.
• Resolve – resolve the symbols in the byteCodes
▪ Initialization- executing the static members and assign the original value.
o Runtime Memory Area
▪ Method area- class level data – method, field, staticvars.
▪ Heap area – Objects and corresponding instances ,Arrays, variables
▪ Stack area – per Thread – local vars, Object refs, Method calls
▪ Pc registers – store current thread execution operation data
▪ Native stack – per Thread – native method info
o Execution Engine
▪ Interpreter – interpret the bytecode (having slow execution)
▪ JIT compiler – for repeated call it will once convert to native it reuse(faster execution)
-------oooooooooo----------
▪ The class loader is responsible for loading classes into the JVM. When you run a Java program,
the class loader searches for the necessary classes and loads them into the runtime data area.
▪ The runtime data area is where the JVM stores data during program execution. It consists of
several different areas, including the method area (where class and method information is
stored), the heap (where objects are stored), and the stack (where method calls and local
▪ The execution engine is responsible for executing the bytecode (compiled Java code) that is
loaded into the JVM. The execution engine reads the bytecode and performs the necessary
▪ The JVM also includes a garbage collector, which automatically frees up memory that is no
class loader,
ClassLoader in Java is a class that is used to load class files in Java. Java code is
compiled into a class file by javac compiler and JVM executes the Java program,
by executing byte codes written in the class file. ClassLoader is responsible for
loading class files from file systems, networks, or any other source.
Java class loaders are used to load classes at runtime.
There is three default class loader used in Java,
▪ Bootstrap class loader.
▪ Extension class loader.
▪ System or Application class loader.
▪ The bootstrap class loader is responsible for loading standard JDK class files
from rt.jar and it is the parent of all class loaders in Java.
▪ Bootstrap ClassLoader - JRE/lib/rt.jar
Extension class loader.
The Extension Class Loader is responsible for loading classes from the extensions directory, which
contains JAR files with third-party extensions to the Java platform. The extensions directory is
specified by the java.ext.dirs system property, and the Extension Class Loader loads the classes from
JAR files located in this directory. For example, if you use a third-party library that extends the
functionality of the Java platform, the Extension Class Loader will load the classes from the JAR file
containing that library.
▪ Extension ClassLoader - JRE/lib/ext or any directory denoted by java.ext.dirs
When this program is executed, the JVM will allocate memory in the runtime data area to store the
• Method area: The method area is where the JVM stores class and method information. In
our example program, the method area would store information about
the ExampleProgram class and its main method.
• Heap: The heap is where objects are stored. In our example program, the String object
• Stack: The stack is where method calls and local variables are stored. In our example
program, the main method would be added to the stack when it is called.
The int variable a would also be allocated on the stack, along with a reference to
area:
Method area:
- ExampleProgram class
- main method
Heap:
- String object ("Hello, world!")
Stack:
- main method
- int variable a (value = 10)
- String reference variable message (points to the String object on the heap)
Java Dynamic Class loading functionality is handled by class loader subsystem. “Load -> Link -> Initialize
1. Bootstrap Class Loader — loads class from bootstrap class path (rt.jar -high priority)
1. Verify : Bytecode verifier will verify whether the generated bytecode is proper or not , else we will
loaded.
3. Resolve(Optional): Symbolic References of class will replaced with original References from
method area.
1.3 Initialization : Final phase of class loader , here all static variables will be assigned original values
1. Method Area : this will store all the class level data (fields, method,static variable). Only one method
2. Heap Area : all the objects & corresponding instance , variable , array will be stored. One Heap per
JVM’=
o where Heap & Method Area are not thread safe it shared resource for JVM
3. Stack Area : For every thread new stack at runtime will be created. for every method call , one entry
4. PC Registers: Each Thread will have register which stores the current executing operation.(once
5. Native Method Stack: Holds native method information for every thread
#3. Execution Engine : Byte code which is assigned in Runtime data area will be executed.
1. Interpreter: Interprets the bytecode faster but execution slowly.(one method is called
It will compile the bytecode into native code (Native code will used directly for Repeated
method calls).