Java Virtual Machine (JVM) Architecture

In this tutorial you will learn about Java Virtual Machine (JVM) architecture.

What is JVM?

Java Virtual Machine (JVM) is software or a virtual machine that takes .class file as an input and runs java bytecode. Java is machine independent but JVM is machine dependent.

 

What is Bytecode?

When java program is compiled using javac compiler, it is converted into intermediate code known as bytecode. The byte code is stored in .class file. Bytecode contains special instructions that are understandable by JVM. We can run this .class file on any platform, all we need is the JVM for that platform. This feature makes Java machine independent language.

 

Java Virtual Machine (JVM) Architecture

Phases of JVM

It has following four different phases.

  • Load code
  • Verify code
  • Execute code
  • Provide runtime environment

 

Internal Architecture of JVM

Java Virtual Machine (JVM) Architecture

Class Loader

It takes .class file as input to load java byte code. Before loading it varies the code. If code is valid then memory for code will be allocated in different memory areas.

 

Method Area

It is used to store class code, method code and static variables.

 

Heap

Heap is responsible for storing objects. It is also called as runtime data area.

 

Stack

Stack area is a combination of stack frames. Each stack frame stores the information related to a method. Like local variables, value returned by method, etc. When a method is invoked, a new frame is created. The frame is deleted when method execution completes.

 

PC Register

It contains the address of next instruction to be executed.

 

Native Method Stack

It stores native methods used in the application. The non-java code is known as native code.

 

Execution Engine

It consists of interpreter and just in time (JIT) compiler. The java code is executed by both of them simultaneously. It decreases execution time and hence increases the overall performance.

 

Comment below if you found any information incorrect or missing.

Leave a Reply

Your email address will not be published. Required fields are marked *