Introduction To JVM
What is JVM ?
The Java Virtual Machine (JVM) is a virtual machine that provides the runtime environment to execute Java bytecode.
The Since the JVM does not understand Java source code directly, * files are first compiled into .java files containing bytecode. This bytecode is platform-independent and can be executed by the JVM..class
The JVM is responsible for controlling the execution of every Java program. It also enables important features such as:
- Automatic exception handling
- Garbage collection for memory management
- Platform independence (via bytecode execution)
JVM Architecture :
The JVM architecture consists of several key components that work together to execute Java programs:
1.Class Loader : The Class Loader is responsible for loading classes into memory for execution.
- Boot Strap ClassLoader → Loads core Java classes from the
rt.jarfile (located in JRE/lib). It has the highest priority. - Extension ClassLoader – → Loads classes from the
extdirectory (jre/lib/ext). - Application (System) ClassLoader → Loads classes from the application’s classpath (environment variables, project paths, etc.).
2.Method area : All the class-level data will be stored here, such as class structures, metadata, method code, and static variables. There is only one Method Area per JVM instance.
3.Heap :
All the Objects and their corresponding instance variables and arrays will be stored here. There is also one Heap Area per JVM. Since the Method and Heap areas share memory for multiple threads, the data stored is not thread safe.
4.Stack :
4.Stack :
Each thread has its own JVM stack, created when the thread starts. It stores:
- Local variables
- Partial results
- Method call frames (each frame holds data, local variables, and references to objects in the heap
5.Program Register : Each thread has its own PC register.It holds the address of the JVM instruction currently being executed.
6.Native method stack : Contains instructions for native methods (non-Java code, usually written in C/C++).Supports interaction between Java applications and native libraries.
7.Executive Engine :The Execution Engine is responsible for executing bytecode. It works in three parts:
- Interpreter → Reads and executes bytecode line by line (slower execution).
- JIT (Just-In-Time) Compiler → Improves performance by compiling frequently used bytecode into native machine code.
- Garbage Collector (GC) → Automatically manages memory by removing unused objects from the heap.
9.Native Method Libraries : A collection of native libraries required by the Execution Engine. These libraries are loaded and linked using the Native Method Interface (JNI).
Key Features of JVM
- Provides platform independence by executing bytecode on any system.
- Ensures memory management with garbage collection.
- Handles runtime exceptions automatically.
- Supports integration with native libraries through JNI.
No comments:
Post a Comment