JVM Architecture in Java – Components, Memory Areas and Working (JVM आर्किटेक्चर)
What is JVM Architecture? (JVM आर्किटेक्चर क्या है?)
The JVM (Java Virtual Machine) is an essential part of the Java platform. It provides the runtime environment required to execute Java bytecode. JVM Architecture describes the internal components and memory areas that work together to load, verify and execute Java programs.
JVM (Java Virtual Machine), Java Platform का एक महत्वपूर्ण हिस्सा है। यह Java Bytecode को execute करने के लिए आवश्यक Runtime Environment प्रदान करती है। JVM Architecture उन Internal Components और Memory Areas की संरचना को दर्शाता है, जो Java Programs को Load, Verify और Execute करने के लिए मिलकर कार्य करते हैं।
Main Components of JVM Architecture (JVM आर्किटेक्चर के मुख्य घटक)
JVM Architecture consists of the following major components:
Class Loader Subsystem
Runtime Data Areas
Execution Engine
Java Native Interface (JNI)
Native Method Libraries
JVM Architecture में मुख्य रूप से निम्नलिखित Components शामिल होते हैं:
Class Loader Subsystem
Runtime Data Areas
Execution Engine
Java Native Interface (JNI)
Native Method Libraries
1. Class Loader Subsystem (क्लास लोडर सबसिस्टम)
The Class Loader Subsystem loads Java class files into the JVM when they are required. It also performs linking and class initialization.
Class Loader Subsystem आवश्यकता पड़ने पर Java Class Files को JVM में Load करता है। यह Linking और Class Initialization का कार्य भी करता है।
The Class Loader Subsystem mainly performs three operations:
A. Loading
The loading process finds the required class file, reads its bytecode and creates the corresponding class representation inside the JVM.
Loading Process में आवश्यक Class File को खोजा जाता है, उसका Bytecode पढ़ा जाता है और JVM में उसकी Class Representation तैयार की जाती है।
B. Linking
Linking prepares the loaded class for execution. It consists of three steps:
Verification: Checks whether the bytecode is structurally valid and follows JVM rules.
Preparation: Allocates memory for static fields and assigns their default values.
Resolution: Converts symbolic references into direct references where required.
Linking, Loaded Class को Execution के लिए तैयार करता है। इसमें तीन Steps शामिल होते हैं:
Verification: यह Check करता है कि Bytecode सही Structure में है और JVM Rules का पालन करता है।
Preparation: Static Fields के लिए Memory Allocate करता है और उन्हें Default Values देता है।
Resolution: आवश्यकता के अनुसार Symbolic References को Direct References में बदलता है।
C. Initialization
During initialization, static variables are assigned their specified initial values and static initialization blocks are executed.
Initialization के दौरान Static Variables को उनकी निर्धारित Initial Values दी जाती हैं और Static Initialization Blocks Execute किए जाते हैं।
2. Runtime Data Areas (रनटाइम डेटा एरियाज)
Runtime Data Areas are the memory areas used by the JVM during program execution. Some areas are shared among threads, while others are created separately for each thread.
Runtime Data Areas वे Memory Areas हैं जिनका उपयोग JVM Program Execution के दौरान करती है। इनमें से कुछ Areas सभी Threads के बीच Shared होते हैं, जबकि कुछ प्रत्येक Thread के लिए अलग-अलग बनाए जाते हैं।
The main Runtime Data Areas are:
A. Method Area (मेथड एरिया)
The Method Area stores class-level information such as class metadata, method information, runtime constant pools and details of fields. It is shared among JVM threads.
Method Area में Class-Level Information जैसे Class Metadata, Method Information, Runtime Constant Pools और Fields की जानकारी Store होती है। यह JVM के सभी Threads के बीच Shared होता है।
Note: In the HotSpot JVM, class metadata is generally stored in Metaspace, which uses native memory.
नोट: HotSpot JVM में Class Metadata सामान्यतः Metaspace में Store होता है, जो Native Memory का उपयोग करता है।
B. Heap Area (हीप एरिया)
The Heap is the runtime memory area from which memory is allocated for objects and arrays. It is shared among all JVM threads and is managed by the Garbage Collector.
Heap वह Runtime Memory Area है जहाँ Objects और Arrays के लिए Memory Allocate की जाती है। यह सभी JVM Threads के बीच Shared होता है और Garbage Collector द्वारा Manage किया जाता है।
Example:
class Student {public static void main(String[] args) {Student s = new Student();}}
In this example, the new Student() expression creates a Student object in the Heap, while the local variable s is stored in the current method's stack frame.
इस Example में new Student() Expression Heap में Student Object बनाता है, जबकि Local Variable s वर्तमान Method के Stack Frame में Store होता है।
C. Java Stack (जावा स्टैक)
Each JVM thread has its own Java Stack. It stores method call frames, local variables, intermediate calculations and method execution information.
प्रत्येक JVM Thread का अपना Java Stack होता है। इसमें Method Call Frames, Local Variables, Intermediate Calculations और Method Execution से संबंधित Information Store होती है।
Whenever a method is called, a new frame is created on the stack. When the method completes, its frame is removed.
जब भी कोई Method Call होता है, तो Stack में एक नया Frame बनता है। Method का Execution पूरा होने पर उसका Frame Stack से Remove हो जाता है।
D. PC Register (पीसी रजिस्टर)
Each JVM thread has its own Program Counter (PC) Register. It keeps track of the address of the current JVM instruction being executed by that thread.
प्रत्येक JVM Thread का अपना Program Counter (PC) Register होता है। यह उस Thread द्वारा Execute की जा रही वर्तमान JVM Instruction के Address को Track करता है।
E. Native Method Stack (नेटिव मेथड स्टैक)
The Native Method Stack supports the execution of native methods written in languages such as C and C++. Its implementation depends on the JVM.
Native Method Stack, C और C++ जैसी Languages में लिखे गए Native Methods के Execution में सहायता करता है। इसका Implementation JVM पर निर्भर करता है।
3. Execution Engine (एक्जीक्यूशन इंजन)
The Execution Engine executes the bytecode loaded into the JVM. It uses different mechanisms, including interpretation and Just-In-Time (JIT) compilation, to execute program instructions.
Execution Engine, JVM में Load किए गए Bytecode को Execute करता है। यह Program Instructions को Execute करने के लिए Interpretation और Just-In-Time (JIT) Compilation जैसी Techniques का उपयोग करता है।
The Execution Engine mainly includes the following components:
A. Interpreter (इंटरप्रेटर)
The Interpreter executes bytecode instructions one by one. It helps the JVM start executing a program without first compiling all its code into native machine code.
Interpreter Bytecode Instructions को एक-एक करके Execute करता है। इसकी सहायता से JVM Program के सभी Code को पहले Native Machine Code में Compile किए बिना Execution शुरू कर सकती है।
B. JIT Compiler (जस्ट-इन-टाइम कंपाइलर)
The JIT Compiler identifies frequently executed code and compiles selected sections into native machine code at runtime. This helps improve application performance.
JIT Compiler बार-बार Execute होने वाले Code की पहचान करता है और चुने गए Code Sections को Runtime पर Native Machine Code में Compile करता है। इससे Application की Performance बेहतर करने में सहायता मिलती है।
C. Garbage Collector (गार्बेज कलेक्टर)
The Garbage Collector automatically reclaims Heap Memory occupied by objects that are no longer reachable by the application. This reduces the need for manual memory deallocation.
Garbage Collector उन Objects द्वारा उपयोग की गई Heap Memory को Automatically Reclaim करता है, जो Application के लिए अब Reachable नहीं हैं। इससे Manual Memory Deallocation की आवश्यकता कम हो जाती है।
4. Java Native Interface (JNI) (जावा नेटिव इंटरफेस)
The JNI (Java Native Interface) is a programming interface that allows Java code running inside the JVM to interact with native code written in languages such as C and C++.
JNI (Java Native Interface) एक Programming Interface है, जो JVM में चल रहे Java Code को C और C++ जैसी Languages में लिखे गए Native Code के साथ Interact करने की सुविधा प्रदान करता है।
For example, a Java application can use JNI to call a native library when a required operation is implemented outside Java.
उदाहरण के लिए, यदि कोई आवश्यक Operation Java के बाहर Implement किया गया है, तो Java Application JNI की सहायता से Native Library को Call कर सकता है।
5. Native Method Libraries (नेटिव मेथड लाइब्रेरीज)
Native Method Libraries are platform-specific libraries that contain native code required by native methods. These libraries work with the JVM through JNI.
Native Method Libraries, Platform-Specific Libraries होती हैं जिनमें Native Methods के लिए आवश्यक Native Code मौजूद होता है। ये Libraries JNI के माध्यम से JVM के साथ कार्य करती हैं।
JVM Architecture Diagram (JVM आर्किटेक्चर का चित्र)
The following diagram shows the major components of JVM Architecture and their relationship.
नीचे दिया गया Diagram JVM Architecture के मुख्य Components और उनके आपसी संबंध को दर्शाता है।
Java Source Code|javac Compiler|Java Bytecode(.class)|+---------------------+| JVM || || Class Loader || Subsystem || | || Runtime Data Areas || | || Execution Engine || | | || Interpreter || JIT Compiler || Garbage Collector || || JNI |+---------|-----------+|Native Method Libraries
How Does JVM Architecture Work? (JVM आर्किटेक्चर कैसे कार्य करता है?)
The JVM follows a sequence of operations to execute a Java application.
JVM एक Java Application को Execute करने के लिए निम्नलिखित प्रक्रिया का पालन करती है।
Compilation: The Java compiler converts source code into bytecode.
Class Loading: The Class Loader loads the required class files.
Verification and Linking: The JVM verifies and prepares the loaded classes.
Memory Allocation: Runtime Data Areas provide memory for program execution.
Execution: The Execution Engine executes bytecode using the interpreter and JIT compiler.
Memory Management: The Garbage Collector reclaims memory from unreachable objects.
Compilation: Java Compiler Source Code को Bytecode में बदलता है।
Class Loading: Class Loader आवश्यक Class Files को Load करता है।
Verification and Linking: JVM Loaded Classes को Verify और Prepare करती है।
Memory Allocation: Runtime Data Areas Program Execution के लिए Memory प्रदान करते हैं।
Execution: Execution Engine Interpreter और JIT Compiler की सहायता से Bytecode Execute करता है।
Memory Management: Garbage Collector Unreachable Objects की Memory Reclaim करता है।
Advantages of JVM Architecture (JVM आर्किटेक्चर के लाभ)
Platform Independence: Supports execution of Java bytecode on compatible JVM implementations.
Automatic Memory Management: Garbage Collection helps manage memory automatically.
Security: Bytecode verification and runtime security mechanisms help protect the execution environment.
Performance Optimization: JIT compilation improves the performance of frequently executed code.
Multithreading Support: Provides runtime support for multiple threads.
Native Integration: JNI allows Java applications to interact with native libraries.
Platform Independence: Compatible JVM Implementations पर Java Bytecode को Execute करने की सुविधा देता है।
Automatic Memory Management: Garbage Collection Memory को Automatically Manage करने में सहायता करता है।
Security: Bytecode Verification और Runtime Security Mechanisms Execution Environment की सुरक्षा में सहायता करते हैं।
Performance Optimization: JIT Compilation बार-बार Execute होने वाले Code की Performance बेहतर करती है।
Multithreading Support: Multiple Threads के लिए Runtime Support प्रदान करता है।
Native Integration: JNI Java Applications को Native Libraries के साथ Interact करने की सुविधा देता है।
JVM Architecture is the foundation of Java program execution. Its Class Loader, Runtime Data Areas, Execution Engine, JNI and Native Method Libraries work together to load, manage and execute Java applications. Understanding JVM Architecture helps programmers understand how Java programs run internally.
JVM Architecture, Java Program Execution का आधार है। इसके Class Loader, Runtime Data Areas, Execution Engine, JNI और Native Method Libraries मिलकर Java Applications को Load, Manage और Execute करते हैं। JVM Architecture को समझने से Programmers को यह जानने में मदद मिलती है कि Java Programs Internally कैसे कार्य करते हैं।
Comments
Post a Comment