JVM | Java Virtual Machine | JVM Architecture

 JVM Architecture

JVM is the part of JRE and it is responsible to load and run Java class files.
 

Basic Architecture diagram of JVM

JVM class loader

Class loader sub system:

It is responsible for the following three activities
  1. Loading
  2. Linking
  3. Initialization

1. Loading

Loading means reading class files and store corresponding binary data in method area. For each class file JVM will Store corresponding information in the method area
  • Fully qualified name of class 
  • Fully qualified name of immediate parent class
  • Method information
  • Variable information
  • Constructor information
  • Modifier information
  • Constant pool information
 
 
 
 

after loading dot class file immediately JVM create an object for the loaded class on the heap memory of type java.lang.Class
 


Class file storage in java

The Class class object can be used by programmer to get class level information like method, variable and constructor information etc.
 
Ex: 
JVM first program of Class class

Note:

For every loaded type only one class object will be created even though we are using class multiple times in our program
 
JVM class loading program 2


 

2. Linking

  Linking perform 3 activities

  1. Verify
  2. Prepare/ Preparation
  3. Resolve/ resolution

 

Verify

  • It is the process of insuring that binary representation of a class is structurally correct or not. i.e.  JVM will check whether the dot class file generated by valid compiler or not and properly formatted or not with the help of bytecode verifier.  
  • bytecode verifier is a part of the class loader subsystem.
  • If verification fails then we will get Runtime exception saying: java.lang.VerifyError. 

Preparation

  •  In this phase JVM will allocate memory for class level static variables and assign default values

Note: In initialization phase original values will be assigned to the static variable and here only default value will be assigned.

Resolve/ Resolution

It is the process of re-planning symbolic names in our program with original memory reference from method area.

 Ex: 

class Test
{
public static void main(String[] agrs)
{
String s1= new String("Raka"); 
Student s2 = new Student(); 
 
 
 For  the Test program .class loader loads
  • Test.class
  • String.class
  • Student.class
  • Object.class 
the name of the three classes are constant pool of test class. In resolution phase these names are replace with original memory level references from method area. 
 

3. Initialization

In this all static variables are assigned with original value and static blocks will be executed from parent to child and from top to bottom.
Initialization process in JVM

 Note: while loading, linking and initialization if any error occurs then we will get Runtime exception saying java.lang.LinkageError.

VerifyError is child class of LinkageError 
 

Related Post

JVM Architecture : Virtual Machine in Java

JVM Architecture : Java Virtual Machine

Class Loader in Java 

JVM memory type | Memory types in Java 


RAKESH RAKA

I am Rakesh Raka, senior software engineer (JAVA) in Sopra Steria.

1 Comments

  1. Casino Site - Lucky Club
    All you have to do is register and get your welcome bonus. To claim this bonus, simply click on luckyclub.live 'Join Now' and start gambling online. It will appear

    ReplyDelete
Post a Comment
Previous Post Next Post