Skip to main content

Understanding the JVM

What is the Java Virtual Machine?

Simply, the Java Virtual Machine (JVM) is a virtual machine that loads, verifies and executes Java byte-code. A base JVM needs only to be able to read class files, and perform the operations specified therein. This means that features such as the garbage collection algorithm and internal optimisations are up to the designer.

This has allowed Java's rapid expansion, due to its ability to run on so many platforms.

The JVM also manages the resource usage of a running application, and provides a security model to protect the host.

JVM Stacks

Each JVM thread has its own private stack frame, created at the same time as the thread. The stack stores frames uses as part of the execution of a method. The size of the stack can be either dynamic or fixed, based upon the specific JVM implementation.

The following exceptional conditions are associated with JVM stacks:

  • If the computation in a thread requires a larger JVM stack than permitted, a StackOverflowError exception is thrown
  • If the JVM stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available, an OutOfMemoryError is thrown


Method Area

Stack Frames

A stack frame is used to store the local variables and operand stack required for a methods' execution. Additionally, it is also responsible for returning the result of the method to the caller, and exception handling.

Local Variable Array

The local variable array is used for both the storage of function parameters, and variables created as part of the execution of a function.