Java Virtual Machine

Introduction

JVM

Image copied from tkhts.

The Java Virtual Machine is a type of machine that provides the environment for the execution of the bytecode in Java. The bytecode is generated from the source code by the compiler in Java.

Java Virtual Machine

The Java Virtual Machine is platform independent. It is meant for various hardware and software platforms. The Java Virtual Machine has four main activities. These are as follows.

  • Loading of the code
     
  • Verification of the code
     
  • Execution of the code
     
  • Providing runtime environment

JVM's Internal Architecture

JVM architecture

Image copied from careerbless

The internal architecture of the JVM is comprised of many parts, like the class loader, execution engine and so on.

  • Class Loader

    In the Java Virtual Machine, the class loader loads the class files. It also allocates memory for the program.

    Bootstrap class loader: It is used to load the Java API and object classes.

    Extension class loader:
    It is used to load the extension classes and various security extension properties.

    System class loader:
    It is used to load the application classes.

    User-defined class loader:
    This type of loader is directly created on the code.
     
  • Method Area

    The Method area is the area where the byte code is located. In the method area, the program counter points to a byte. All the threads of a process shares the method area. The Method area maintains information about the instruction that is executing currently.
     
  • Heap

    Objects are created on the heap in Java. When we create a new object using the new keyword in Java then the heap provides the memory to it.
     
  • Java Stacks

    In the Java Virtual Machine, frames are stored in Java Stacks. Java Stacks store local variables. When a method is invoked in Java then a frame is also created and when a method is invoked completely the created frame is destroyed. In Java each and every thread has its own Java Stack that is created when the thread is created.
     
  • PC Registers

    In the Java Virtual Machine, a program counter register stores the address of the instructions. These are the currently executing instructions.
     
  • Native Method Stack

    Native code is a code that is written in a language other than Java. The Native method stack has all these native methods.
     
  • Execution Engine

    The execution engine executes the bytecode. It reads the bytecode in the unit of instruction. The execution engine converts the bytecode to the machine language in the Java Virtual Machine. The execution engine consists of the following.

    Interpreter: In the execution engine the interpreter reads, interprets and then executes the bytecode. The bytecode instructions are interpreted and executed one by one.

    Just-In-Time (JIT) Compiler: The JIT compiler compiles the bytecode and then converts it into the native code. This makes the complete process of execution faster than before.

    JIT compiler

    Image copied from cubid.

    Summary

    This article explains the Java Virtual Machine and its architecture.

    Up Next
      Ebook Download
      View all
      Learn
      View all