Basic Explanation For JVM (Java Virtual Machine) Architecture With Diagram

Java Virtual Machine (JVM) is responsible for executing the java program line by line hence it is also known as interpreter. The JVM is responsible for interpreting Java bytecode (.class file) and translating this into actions (into machine readable form) or operating system calls.

JVM architecture with diagram, How JVM works in java, Class loader, Run time data area, Execution engine

Every Java developer knows that bytecode will be executed by JRE, (to know more on JRE) but fact is that JRE is the implementation of JVM which analyzes the bytecode, interprets the code and executes it.

JVM Architecture, Class loader, Runtime data Area, Gargebe collector, JIT Compiler, JVM interview questions

As shown in the above architecture diagram JVM is divided into three main subsystems.

Class loader subsystem

  • Loading
  • Linking
  • Initialization

Runtime Data Area

  • Method Area
  • Heap Area
  • Stack Area
  • PC Registers
  • Native Method stacks

Execution Engine

  • Interpreter
  • JIT Compiler
  • Garbage Collector

Class Loader

In JVM there is a module called Class loader which perform following activities,

  • Loads .class file into memory.
  • Checks all byte code instructions are proper or not. If it finds issue, execution will be rejected.
  • Initialization of static variables.

Loading

Classes will be loaded by following components,
BootStrap, Extension and Application/System ClassLoader

  • BootStrap ClassLoader:  Responsible for loading classes from the bootstrap classpath, nothing but rt.jar. Highest priority will be given to this loader. This file always resides inside lib directory of JRE in Windows and Linux.
  • Extension ClassLoader:  Responsible for loading classes which are inside ext folder (jre\lib)
  • Application/system ClassLoader: Responsible for loading Application Level Classpath, path mentioned Environment Variable etc.

Linking

  • Verify:  Byte code verifier will verify whether the generated byte code is proper or not if verification fails we will get verification error.
  • Prepare:  For all static variables memory will be allocated and assigned with default values.
  • Resolve: All symbolic memory references are replaced with the original references from Method Area.

Initialization

All static variables will be assigned with the original values and static block will be executed

Runtime Data Area

If the byte instructions are proper, it allocates necessary memory for execution. These memories are divided into 5 major parts are called run time data areas.

  • Method Area: This area is used to store all the Class level data will be stored here including static variables.
  • Heap Area: In this area where objects are created. Java Heap space is used by java runtime to allocate memory to Objects and JRE classes. All the Objects and its corresponding instance variables and arrays will be stored here. 
  • Stack Area: All local variables will be created in the stack memory. Java stacks are area where java methods are executed.
  • PC (Program counter) registers: This area contains the memory address of the instruction of the methods. It used to hold address of current executing instruction once the instruction is executed the PC register will be updated with the next instruction.
  • Native Method stacks: Native methods are executed on native method stacks. To execute native method, native methods libraries are required. These header files are located and connected to JVM by native method interface.

Execution Engine

Execution engine contains interpreter and JIT (Just in Time) compiler, which are responsible to converts byte code instruction into machine code so the process will execute them.

  • Interpreter:  Reads the bytecode, interprets it and executes it one by one. The interpreter interprets the bytecode faster but executes slowly.
  • JIT Compiler: I enhance the speed of the execution.
  • Garbage Collector: Garbage collector is automatically invoked when the program is being run. It can also be called by calling gc() method of Runtime class or system class in java.

Java Native Interface

It will be connect with the Native Method Libraries and provides the Native Libraries needs for the Execution Engine.

Native Method Libraries

It is the collection of Native Libraries required for Execution Engine.

Top 5 interview questions:

  1. Explain briefly on JVM architecture.
  2. What is the role of Class loader in JVM?
  3. How memories are allocated during program execution?
  4. How we can call Garbage Collector explicitly?
  5. What is the use of JIT compiler in java?

Hey guys, Now it is your time! Drop a comment if more details needed or if any update requires. Your comments are more valuable to improve our site to help others.

11 thoughts on “Basic Explanation For JVM (Java Virtual Machine) Architecture With Diagram”

  1. Wonderful post however , I was wondering if you could write a litte more on this topic? I’d be very thankful if you could elaborate a little bit more. Thanks!

  2. Thanks , I have recently been searching for information approximately
    this topic for a while and yours is the best I’ve discovered till now.

    But, what in regards to the bottom line? Are you positive about the supply?

  3. Pingback: Google

  4. Wonderful blog! Do you have any helpful hints for
    aspiring writers? I’m hoping to start my own blog soon but I’m a little lost
    on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are
    so many choices out there that I’m completely overwhelmed
    .. Any ideas? Cheers!

  5. Pingback: Google

Leave a Comment

Your email address will not be published.