22 Jun Java Virtual Machine (JVM)
A Java Virtual Machine (JVM) is a platform-independent abstract computing machine. It is a virtual machine that converts Java bytecode into machine language. JRE is the implementation of the Java Virtual Machine (JVM).
After execution, this specification executes it.
- Java bytecode is the machine language for the Java Virtual Machine (JVM).
- JVM also shields users from malicious programs.
- The Java Runtime Environment (JRE) includes a Java Virtual Machine implementation and a Java Class Library implementation.
The following are the three notions of the Java Virtual Machine (JVM):
- JVM Specification:
As the name suggests, a specification is a document describing what is needed of a JVM implementation. It specifies the functioning of the JVM. - JVM Implementation:
It is a computer program that meets the requirements of the document describing the function of JVM, i.e., the Specification. - JVM Instance:
It is an implementation running in a process that executes a computer program. This program is compiled into Java bytecode. Running a Java Class, creates an instance of the JVM.
JVM Architecture
Let’s see the components of JVM Architecture:

Class Loader
Class Loader does the work of loading, linking, and initialization. It is a subsystem of JVM, which first loads the .class file. After loading, the linking is done. Linking includes verification of the .class file. At last, the initialization stage comes.
JVM Memory
It includes the memory areas allocated.
- Method Area: Here, all the class-level information is placed. It stores the class name, immediate parent class name, methods, and variable information, etc. The storage also includes the static variables.
- Heap: The Heap area is a shared resource, which stores the Information of all the objects. There is only one Heap area per JVM.
- JVM Language Stacks: JVM creates one run-time stack for every thread. The stack has blocks, which are called a stack frame, to store method calls. The local variables of these methods get into their individual related frames.
- On thread termination, the run-time stack also gets destroyed.
- PC Registers: The store address of the JVM instruction currently being executed. Remember, each thread has separate registers.
- Native Method Stacks: A native stack gets created for every thread. The stack also contains the native methods.
Execution Engine
It executes the .class file and has the following parts:
- Interpreter: As the name suggests, the Interpreter takes a single instruction as input, i.e., interprets bytecode line by line before execution.
- Compiler: In JAVA, Just-In-Time (JIT) comes enabled by default and leads to faster execution of code. It helps in solving the issues of using an interpreter. An interpreter needs to be executed again and again on method calling, whereas JIT compiles the entire bytecode once and improves the efficiency. When a method gets compiled, the JVM calls the compiled code of that particular method directly.
Java Native Interface (JNI)
It interacts with the Native Method Libraries and enables the JVM to call libraries. It also provides the native libraries required for execution.
Native Method Libraries
The Native Method Libraries are a collection of the Native Libraries(C, C++), which are required by the Execution Engine.
No Comments