Understand How JVM Treat A Class File JVM Architecture
Posted By : Rahul Sharma | 28-Sep-2017
Hi Guys,
If you know about a java or you are a Java developer then you know about the JVM In this blog we focus on basic internal working about JVM. How JVM treat a class file how a load a class file how memory mapped to different objects, variable and How it executes the class file.
Let's start with JVM Architecture.
This is the simple diagram of JVM Architecture.
First, we write a java code in a simple text file and save with.Java extension it's called a source code and it is an input file for java compiler. When a source code file compiled by java compiler after successful completion it convert the source code into bytecode called .class file the .class file work as an input file for JVM.
when we execute a bytecode by java command what will happen inside let's have a look.
The JVM Architecture contains three module
1.ClassLoader Subsystem
2. Run Time Data Aera(Memory Areas)
3.Execution Engine
1. ClassLoader Subsystem
When a class execute by the java command first module is active to take class file and perform class level action.Every class file in java is loaded by ClassLoader SubSystem.Class Loader Subsystem have three part.
1.1 Loading - Loading part is the first action when a class file execute it also has three child features of loading these are followed extension deligation Algorithm
1.1.1 Bootstrap ClassLoader - it is responsible to loads core java libraries from lib of jre. Bootstrap Class Loader is written in native code.
1.1.2 Extension ClassLoader - it is responsible to loads code in extension directory from JRE/lib/ext
1.1.3 Application/System ClassLoader - it is responsible to loads code found on java classpath(java.class.path) Enviornment Variable.
1.2 Linking - After completion of loading Immediately Linking is start it performs three actions.
1.2.1 - Verify - it verifies the bytecode it is also called bytecode verifier.it verifies that the generated bytecode is proper or not and also verify that is there any virus or any trouble in file or not.if verification fails then we got verify error. so java code always secure.
1.2.2 - Prepare - In this, the static variables are created and assigned with the default value.
1.2.3 - Resolve - transforming symbolic references from the type into direct references
After completion of Linking Final Action is Initialization is Perform by Class Loader Subsystem
3. Initialization - Static blocks are executed and all static variables are initialized with original values.
Here the work of ClassLoader Subsystem is complete and For loading class file some memory is required so here is the memory area come to the picture.
2. Run Time Data Aera(Memory Areas)
The JVM memory areas divided into various part following are the description.
2.1 Method Aera - All class level data like static variables are created in this area.
2.2 Heap Aera - All type of objects in Java are created in this area.
2.3 Stack Aera - For each thread, a separate stack is created and each entry in a stack is called stack frame. A stack frame contains three part
- FrameData
- operand stack and
- local variable Array. All Local variable is created in this aera.
2.5 PC Register - For each thread separate pc register is generated to store the next instruction.
2.6 Native Method Stack - For each thread separate native stack is created.
After class loading and memory assignment JVM starts the execution by Execution Engine.
3. Execution Engine(core part of JVM)
Our java program is executed by execution engine and it can communicate with memory aera. it contains various part first part is
Interpreter - to read, interpret and execute byte code line by line.
Jit Compiler - During runtime, it gathers statistics, finds the "hot" code compiles it from JVM interpreted bytecode (that is stored in .class files) to a native code that is executed directly by Operating System and heavily optimizes it. Contain various components:
1. Intermediate code generator
2. code Optimizer
3. targert Code generator - to generate Mission Code or native code and it also contains special component Profiler to identify which code is repeatedly or applicable for JIt
Java Native Interface (JNI)- It is responsible to provide Native Method Library.
I hope it will help you to understand Basic Architecture of JVM.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Rahul Sharma
Rahul is a bright Web App lead Developer, and has good knowledge of Core Java, Advance Java, Angularjs,javascript. His hobbies are swimming and watching movie.