JVM Architecture
JVM Architecture
JVM Architecture
_______________________________________________________________________________
Q. What is JVM?
JVM stands for Java Virtual Machine it is application which is used for load the class file generated by
compiler and perform different operation on it like as allocate memory for object, verify byte code or
perform garbage collection on objects etc
Now we want to discuss about JVM Architecture
Class Loader: class loader is subsystem of JVM and it is mainly responsible for following activities
1. Loading
2. Linking
3. Initialization
Loading: the class loader reads the .class file by compiler, generate the corresponding binary data or
machine code and save it in method area.
JVM store the following information in method area
1. The fully qualified name of the loaded classes and its immediate parent may be interface class or
enum
2. Store information about modifier, variables and method information etc.
after loading .class file create object of type of Class in heap memory.
Verification: it ensures that correctness of .class i.e cross verify .class generated by valid compiler means
check its version and everything is there if .class file not generate property we get run time error.
.class file verification done by component name as ByteCodeVerifier. Once this activity is completed
then the class file is ready for loading.
Preparation: Preparation means JVM allocate memory for static variables and initialize the default
values.
Initialization: in this phase, all static variables are assigned with their default values define in the code
and static block if any and this executed from top to bottom
Extension class loader: it is child of bootstrap class loader it is used for load class present in
JAVA/jre/ext package
System/Application class loader: it is responsible for load classes from application path means used
project.
JVM memory
_______________________________________________________
Method Area: In the method area all class level information like class name, immediate parent name ,
method name variable name , access modifier details including static method etc
Native method stacks: native stack means every thread has special stack called as native method stack
and thread can store information it
Execution engine: this is used for execute the .class file means read byte code line by line and uses data
and information present in different memory area and execute the code.
There is some stages perform in execution engine.
1. Interpreter: interpreter interprets bye code line by line and then executes. the disadvantages is that
when one method is called multiple times every time interpretation is required.
2. Just in time: it is used for increase the efficiently of an interpreter it compile the entire byte code and
changes it to native code so whenever the interpreter see repetated method call JIT provide direct
native code for that part
3. Garbage Collector: it is used for destroy un-referenced objects or release the objects from memory
those never use in future
Native method interface: it is an interface that interacts with native method libraries and provides the
native libraries (C,C++) required for the execution. It enable JVM to call C/C++ libraries and within may
be specified hardware
Native Method library: It is a collection of the native libraries (C,C++) which are required by the
execution engine.