Introduction to Java Virtual Machine (JVM) and its Architecture

Submitted by MoumitaMalik on Tue, 05/08/2018 - 08:49

What is Java Virtual Machine (JVM)?

The Java compiler produces an intermedia code known as bytecode for a machine that does not exist. This machine is called the Java Virtual Machine and it exists only inside the computer memory. It's a simulated computer within the computer & does all the major functions of a real computer. The process of compiling a Java program into bytecode is depicted as below -

Process of compilation

 

Basically, JVM is a engine that provides runtime environment to drive the Java Code or applications. It converts Java bytecode into machines language. JVM is responsible for allocating memory space.


Th vertual machine code is not machine code. The machine specific code is generated by the Java Interpreter by acting as an intermediatery between the vertual machine and the real machine as we can check from blow mentioned figure -

 

bytecode to machine code

 

The Java object framework acts as the intermediary between the user programs & the virtual machine which in turn acts as the intermediary between the Operating System & the Java object framework. How Java works on a typical computer is illustrated in below figure -

 

Interactions for Java program

 

JVM Architecture

Let's understand the Architecture of JVM. It contains class loader, memory area, execution engine etc.

 

JVM Architecture

 

Class Loader :

The class loader is a subsystem used for loading class files. It performs three major functions viz. Loading, Linking, and Initialization.

Method Area :

JVM Method Area stores class structures like metadata, the constant run time pool, and the code for methods.

Heap :

All the Objects, their related instance variables, and arrays are stored in the heap. This memory is common and shared across multiple threads.

JVM language Stacks :

Java language Stacks store local variables, and it’s partial results. Each thread has its own JVM stack, created simultaneously as the thread is created. A new frame is created whenever a method is invoked, and it is deleted when method invocation process is complete.

PC Registers :

PC register store the address of the Java virtual machine instruction which is currently executing. In Java, each thread has its separate PC register.

Native Method Stacks :

Native method stacks hold the instruction of native code depends on the native library. It is written in another language instead of Java.

Execution Engine :

It is a type of software used to test hardware, software, or complete systems. The test execution engine never carries any information about the tested product.

Native Method interface : 

The Native Method Interface is a programming framework. It allows Java code which is running in a JVM to call by libraries and native applications.

Native Method Libraries :

Native Libraries is a collection of the Native Libraries(C, C++) which are needed by the Execution Engine.


 

Software Code Compilation & Execution process :

In order to write and execute a software program, you need the following

1) Editor – To type your program into, a notepad could be used for this

2) Compiler – To convert your high language program into native machine code

3) Linker – To combine different program files reference in your main program together.

4) Loader – To load the files from your secondary storage device like Hard Disk, Flash Drive, CD into RAM for execution. The loading is automatically done when you execute your code.

5) Execution – Actual execution of the code which is handled by your OS & processor.

With this background, refer the following video & learn the working and architecture of the Java Virtual Machine.

 

Why is Java slow?

The two main reasons behind the slowness of Java are

  1. Dynamic Linking: Unlike C, linking is done at run-time, every time the program is run in Java.
  2. Run-time Interpreter: The conversion of byte code into native machine code is done at run-time in Java which furthers slows down the speed

However, the latest version of Java has addressed the performance bottlenecks to a great extent.

 

Comments

Related Items

Fundamentals of Object Oriented Programming

Object Oriented Programming (OOP) is an approach to program organization and development, which attempts to eliminate some of the pitfalls of conventional programming methods by incorporating...

Implementing a Java Program

We can create a program using any test editor. In this example, we will use Notepad. it is a simple editor included with the Windows Operating System. You can use a different text...

Introduction to Java Environment

Java Environment includes a large number of development tools and hundreds of classes and methods. The development tools are part of the system know as Java Development Kit (JDK) ...

How to Download and Install Java

In this tutorial, we will learn "How to Download & Install Java in Windows". This Java Development Kit (JDK) allows you to code and run Java programs. It's possible that you install multiple JDK ...

JAVA Tutorials

This Java tutorial series will help you get started learning Java programming from the basics. It covers most of the aspects of Java programming language used by a neophyte programmer.