Internal working of JVM

JVM is an abstract computing machine or Virtual machine which is a platform independent environment and converts the bytecodes into machine language and help to execute the program.We will study about its internal working.The explanation is divided in 4 parts as given below.

  1. Compiler usage
  2. Class loader Subsystem
  3. Memory Areas
  4. Execution Engine

1. Compiler Usage: We write java program in simple files with .java extension. Compiler’s job is to convert the .java file into .class files which is nothing but the bytecodes(as shown below). The input from this part goes to class loader subsystem.



2. Class loader Subsystem: The class loader subsystem is divided into 3 main parts as follows.

  • Class loader
  • Linking
  • Initialization

Class Loader: Class loader performs the loading of .class files. There are 3 types of class loaders

  1. Bootstrap Class loader
  2. Extension class loader
  3. Application class loader

The priority is given to the Bootstrap class loader to load the class. If it is unable to find the class files, then job is transferred to ‘Extension Class loader’ and if the same is not done by ‘Extension class loader’, Application class loader takes the charge.

Linking: Verification of bytecodes, default values assignments to static variables etc. This section also contains 3 subareas as given below

  1. Verify: It is responsible to verify the bytecodes that it is coming from a valid source or there is no error etc. It helps to make the process more secured.
  2. Prepare: It allocates the default values to static variables.
  3. Resolve: All symbolic reference are resolved with original reference coming from method area.

Initialization: Original values to static variables are assigned and static blocks are executed.

Class loader Subsystem

Class loader Subsystem

3. Memory Areas: There are various memory areas as defined below.

  1. Method Area
  2. Heap Area
  3. Stack Area
  4. PC Register Area
  5. Native method Area

Method Area:  All class data and static variables are stored here.
Heap Area: All the object data,instance variable, arrays etc. are stored here.
Stack Area: It contains threads. A thread provides an independent path for execution of the program. Many threads can run parallel within a program. For every thread, one run time stack is present. All local variables and method calls are stored here per thread.
PC Register: For every thread, there is one PC registration created to hold the address of next executing instruction.
Native method Area: This will stored native method information.

Note: Stack area is thread safe but method area and heap area are not thread safe. Let’s understand with an example. Suppose there are 4 thread running like T1,T2,T3 and T4. For all these threads separate stack area will be created. That means, thread each thread will run in its own stack, and will not be able to access another stack. But method and heap area are shared one, and in multithreading all threads will be able to access these 2 areas. That’s why method area and heap area are not thread safe.

Memory Area

4. Execution Engine: It is simply responsible to execute the programs i.e .class file. It contains the following components mentioned below.

  1. Interpreter
  2. JIT (Just In Time) compiler
  3. Profiler
  4. Garbage collector

Interpreter: It read, interpret and execute the program line by line.Every java program should be interpreted at least once. I

JIT(Just In Time) Compiler: It is responsible to convert the bytecodes into machine language which is understood by any platform. It is mainly used for the methods which are repetitive in nature.JIT compiler runs the program much faster.

Profile: Its job is to inform JIT about the repetitive methods.

Garbage Collector: It is used to release the memory which is occupied by unused objects.



Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...