Computer science
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.
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.
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.
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.
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.
Help improve the encyclopedia. Reports go straight to the site manager.