← New search

Computer science

Java Virtual Machine

The Java Virtual Machine (JVM) is an abstract computing machine that enables a computer to run Java programs as well as programs written in other languages that compile to Java bytecode. It is a core component of the Java Platform, Standard Edition, providing platform independence through the write once, run anywhere principle.1 The JVM executes bytecode, manages memory with garbage collection, and includes a Just-in-time compiler for performance.

1.0
First public release
1996
17 (LTS)
Latest stable version
2021
~70
Number of JVM implementations
estimated
100+
Languages targeting JVM
including Kotlin, Scala, Groovy, Clojure
1

Design and architecture

The JVM's architecture is defined by the Java Virtual Machine Specification.2 It consists of a class loader subsystem that loads, links, and initializes class files; runtime data areas including the heap, stack, method area, and program counter registers; and an execution engine that interprets or compiles bytecode. The heap is shared among all threads and stores objects and arrays, while each thread has its own stack holding frames for method calls. The method area stores class metadata, constants, and static variables. The native method stack supports the Java Native Interface (JNI) for calling native code.

2

Execution model

Bytecode is initially interpreted by the JVM. Frequently executed methods are identified as hot spots and compiled to native machine code by the JIT compiler, improving performance.3 The JVM also performs bytecode verification to ensure type safety and prevent malicious code. Garbage collection (GC) automatically reclaims memory from unreachable objects. Modern JVMs, such as HotSpot and OpenJ9, implement generational GC, dividing the heap into young and old generations to optimize collection cycles. The JVM's threading model maps Java threads to operating system threads, supporting multithreading and synchronization via monitors.

3

Memory management

Memory management is a critical JVM function. The heap is divided into the Eden space, survivor spaces (young generation), and the tenured generation (old generation).4 Minor garbage collections are frequent in the young generation, promoting surviving objects to the old generation. Full GCs collect the entire heap, including the method area (metaspace in Java 8+). Tuning JVM parameters such as heap size, garbage collector selection (e.g., G1, ZGC, Shenandoah) and GC threads can significantly affect application performance. The JVM also provides monitoring tools like jstat and jvisualvm to inspect memory usage.

4

Lesser-known aspects

Beyond Java, the JVM serves as a runtime for many languages: Kotlin, Scala, Groovy, Clojure, and even Jython (Python).5 The GraalVM project extends the JVM to support polyglot programming, ahead-of-time compilation, and native images. The JVM specification defines a strict class file format, including the constant pool, which stores symbolic references. The Dalvik virtual machine used in early Android was not JVM-compliant, but Android Runtime (ART) now executes DEX bytecode. A niche fact: the JVM includes a verifier that checks bytecode for type safety even before execution, a feature that has been exploited in research on proof-carrying code.

Glossary

bytecode
Intermediate representation of Java source code, executed by the JVM.
class loader
Subsystem that loads, links, and initializes Java class files into the JVM.
garbage collection
Automatic memory management that reclaims memory occupied by unreachable objects.
JIT compilation
Just-in-time compilation of bytecode to native machine code at runtime.
heap
Runtime data area where all objects and arrays are allocated.
stack
Per-thread memory area storing method frames and local variables.
HotSpot
The primary reference implementation of the JVM, developed by Oracle.
OpenJ9
An open-source JVM contributed by IBM, now part of the Eclipse Foundation.