JVM [Java Virtual Machine] - Architecture

Java Virtual Machine (JVM) is a designation that provides a runtime environment in which java bytecode can be executed. As the denomination implicatively insinuates, the JVM acts as a “virtual” machine or processor. Java's platform independence consists mostly of its Java Virtual Machine (JVM).

JVM is a component of the Java Run Environment (JRE). In other programming languages, the compiler engenders machine code for a particular system. However, the Java compiler engenders code for a Virtual Machine known as Java Virtual Machine.

  The JVM performs the following operation:
  • Loads code
  • Verifies code
  • Executes code 

Here is how JVM works

First, Java code is compiled into bytecode. This bytecode gets interpreted on different machines. Between host system and Java source, Bytecode is an intermediary language.JVM in Java is responsible for allocating memory space.

JVM Architecture

JVM architecture in Java contains classloader, memory area, execution engine, etc.

1) Class Loader:

The Java ClassLoader is a component of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. 

2) Method Area:

JVM has a method area prevalent across all the threads. It contains per-class elements like constant pool, fields, method local data, method code, constructor codes, etc. which are utilized in class and initialization of objects/interfaces. This method area gets engendered during JVM start-up.

3) Heap:

The Java heap is the area of recollection used to store objects instantiated by applications running on the JVM. Objects in the heap can be shared between threads. Many users restrict the Java heap size to 1-8 GB in order to minimize garbage accumulation pauses.

4) Stack:

A JVM stack, withal called thread stack, is a data area in the JVM memory engendered for a single execution thread. The JVM stack of a thread is utilized by the thread to store local variables, partial results, and data for method invocations and returns.

5) PC Registers:

Program Counter or PC register holds the address of JVM instruction currently being executed for any particular thread.

6) Native Method Stack:

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

7) Execution Engine:

It contains:
  • A virtual processor
  • Interpreter: Read bytecode stream then execute the instructions.
  • Just-In-Time(JIT) compiler: It is utilized to amend the performance. 

8) Native Method Interface:

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

9) Native Method Libraries:

Native Libraries is an accumulation of the Native Libraries(C, C++) that are needed by the Execution Engine.