Java virtual machine(JVM) Architecture (JVM Main Components)

Anojaa Gnaneswaran
5 min readJan 31, 2022

--

As a Java developer, Important to understand Basic concept of Java Virtual Machine (JVM) architecture and how Java works to get the most out of it in an efficient manner. After reading this article You will get the Good idea of JVM Internal architecture.

Before we moving to JVM architecture ,we quickly look for background of Java.

Background

Java is one of the widely using high level and object oriented programming language.It was Layout by James Gosling and released by sun Micro-systems in 1995, but java currently owned by oracle.It was currently used by multiple devices some of are desktop application,web application,mobile,smart card and etc.Java is give an opportunity for students and learners to use as open source and business purpose allowed to use commercial version of software.

Java components

It is important to understand about java components.There are three main components in java.

  1. Java Development kit.(JDK)
  2. Java Runtime Environment.(JRE)
  3. Java Virtual Machine.(JVM)

Virtual Machine

First we must to know what is virtual machine,Its give a good idea to understand “what is JVM?”

I hope you all know what is a virtual ,that mean“the object should not be in real but creating simulate environment for feel real object”. Machine is “used for do our works in easy way”.

There are two types of virtual machine,Lets discuss one by one

  1. System based virtual machine(SVM) :- One or multiple hardware will be Generate multiple environment to work,most important fact is this environment are completely independent.

eg:- xen, Hypervisor

2. Application based virtual machine(AVM) :- This will only Include software application for help to create platform to run programs,doesn’t have any hardware here.Also AVM called as process based virtual machine.

eg:-JVM , CLR (Common Language Runtime:- .net), PVM(Parrot Virtual Machine :- Its create environment for dynamic virtual machine)

What is the Java virtual machine (JVM)?

JVM is a engine that provide a runtime environment for our Java programs.Its convert byte code into machine code and It is come under Application based virtual machine(AVM). JVM is completely specification. Java Virtual Environment(JRE) contain Java Virtual Machine(JVM). when we Install JRE, JVM come within JRE. It will deployed all the code which can Generate the JVM.

We Install JRE on a window platform,It will deploy code which is required to create the JVM on window platform.like the way It mac and other operating systems.when we start the Java program then JVM instance create on our computer.JVM create non-daemon thread for execution our programs.

Existence of Java Virtual Machine

  • JVM born :- when application started
  • JVM die:- when application ended
  • If you started three different programs in your computer,It create three different Environment on your computer.
JVM Required each Application

JVM will be exit in two ways

  1. If all the non-daemon Threads are exit(Distroyed),Then JVM terminate active daemon threads.
  2. If Application died by itself .

ex:- system.exit() method

Components of JVM

JVM contain three components.

  1. Class Loader:- It used for load class file
  2. Memory Area:- It used for store the class file
  3. Execution Engine:- It used for object instruction need to execute
components of JVM(https://miro.medium.com/max/1400/1*nG2zHY15dg4fQtG5DC1SOw.png)

Lets going to discuss about each of three components in deeper.

1. Class Loader

class loader It will be perform main three activities,those are

  1. Loading
  2. Linking
  3. initialization

Loading

It take class file and loading into memory area.there are three types of class loader. Bootstrap ClassLoader, Extension ClassLoader,Application ClassLoader.

we run our Java program ClasssLoder load it first ,JVM loads the class ,It store below Information in the memory area

1.Fully qualified loaded class name.

2.Read about variables, modifier information.

3.Read about Immediate parent class information(If there no parent class JVM decide loaded class as a parent class).

4.Read about whether .class file is class,Interface or Enum.

Linking

Linking perform three main activities,those are below

  1. Verification :- Byte code Verifier verify valid compiler,correct structure and this class file has correct formatting,any of this not there JVM thrown exception.
  2. Preparation :- If we use any static level variable in our class ,preparation will assign Default value .
  3. Resolution :- the symbolic memory reference take replaced with original method from memory area.

Initialization

Initialization is final step of class loader.All static variable are assigned to original value and static block execute here.

2.Memory Area

All the data will be store in this memory area(only one method area per JVM). It contain five divided types,those are method area, heap,stack,PC Registers,Native method area.

JVM memory area structure

Method area- when we load a class,all the class information should be save into method area.

Heap- when we load the class all the object and corresponding array and instance variable are store in the heap(only one heap area per JVM).

Stack- It hold method information (local variable) when ever thread exist from the method,It pop frame out.when frame method is finished ,it is destroyed.

Program counter Register- per thread as own PC register,it hole information currently execution and it hole information about next execution.

Native method stack- here store all the information about native methods,each of thread has there own native method stack.

3.Execution Engine

Execution Engine that run the byte code that has assign in memory area.java class files are executed by class engine. class engine contain three main components.

Interpreter- It read byte code after it generate into machine code and execute in sequence way.The main cons of this Interpreter was if the same method called many times , it need new interpretation in every time,so It decrease the system’s performance.

JIT compiler (Just In Time compiler)- Java Runtime Environment includes the JIT compiler,It help to compile byte code to machine code at run time .

Garbage Collector- It is the programming for free the heap memory destroyed unreachable methods.

References

  1. 2016,what is JVM[Video],https://www.youtube.com/watch?v=bUtIIWbaFKc&
  2. 2020,Execution engine,[Document],https://youtu.be/bUtIIWbaFKc

--

--

Anojaa Gnaneswaran

Faculty of IT, University of Moratuwa, Associated Software Engineer at Virtusa