Sunday, 28 May 2017

Introduction To JVM

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, *.java files are first compiled into .class files containing bytecode. This bytecode is platform-independent and can be executed by the JVM.

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 LoaderThe Class Loader is responsible for loading classes into memory for execution.
There are three main types of class loaders:
  1. Boot Strap ClassLoader → Loads core Java classes from the rt.jar file (located in JRE/lib). It has the highest priority.
  2. Extension ClassLoader – → Loads classes from the ext directory (jre/lib/ext).
  3. 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 :
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.

8.Native Method Interface : Acts as a bridge between Java code and native applications/libraries (C, C++, etc.). Allows Java to call platform-specific native methods when needed.

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

Java Development Kit (JDK) and Java Runtime Environment (JRE)

                  Java Development Kit (JDK) and Java Runtime Environment (JRE)  To download and install the Java Development Kit (  JDK ) ...