Understanding JVM

JVM (Java Virtual Machine) is all about,

an abstract specification; which is a concept

a concrete implementation; which runs on many platforms (can be a combination of hardware and software)

a runtime instance; which can host a single java application (each runs on different JVM)

Every java application will be running in a separate JVM instance even if they are in the same machine. The JVM starts the execution of a Java application from an initial class’ main method. The “java” program from Sun’s JDK is an implementation of a java virtual machine.

java <initial class name> <arg1> <arg2> …. ” is the implementation dependent way in Sun’s JDK to spawn a new instance of JVM along with the specification of the application initial class and the arguments needed. The main() of the initial class is the starting point of the application’s initial thread.

  

JVM Architecture

Major subsystems

Class loader subsystem:
Responsible for loading classes and interfaces

Execution engine:
Responsible for the execution of the instructions specified in the classes

Other components
Runtime data areas
Native interface; interacts with the native libraries

JVM Architecture

More about runtime data areas
Mechanism to hold all kinds of data items such as instructions, object data, local variable data, return values & intermediate results.

Organization of runtime data areas
How runtime data are stored in the runtime data areas depends on the implementation of the JVM. Some implementation may enjoy the availability of memory and some others may not. The abstract nature of runtime data area specification allows the implementation of JVM in different machines easier.

Some runtime data areas are shared among all the threads in the application, while some others are too specific to an active thread.

Runtime data areas shared among all threads:

Method area: holds the details of each class loaded by the class loader subsystem.

Heap: holds every object being created by the threads during execution

Thread specific runtime data areas:

Program counter register:
points to the next instruction to be executed.

Java stack:
hold the state of each method (java method, not a native method) invocations for the thread such as the local variables, method arguments, return values, intermediate results. Each entry in the Java stack is called “stack frames“. Whenever a method is invoked a new stack frame is added to the stack and corresponding frame is removed when its execution is completed.

Native method stack:
holds the state of each native method call in an implementation dependent way.

Note:
In JVM there is no registers to store the intermediate values. They are stored in the java stack itself.

Advertisements