Lably
Skip to content

Java virtual machine

Virtual machine that runs Java programs

  • 15 min read
  • 3 chapters
Java Virtual Machine Java 7 Specification base
Michelle Ridomi · CC BY-SA 4.0

Learn it on Lably

The JVM reference implementation is developed by the OpenJDK project as open source code and includes a JIT compiler called HotSpot. The commercially supported Java releases available from Oracle are based on the OpenJDK runtime. Eclipse OpenJ9 is another open source JVM for OpenJDK.

JVM specification

The Java virtual machine is an abstract (virtual) computer defined by a specification. It is a part of the Java Runtime Environment. The garbage collection algorithm used and any internal optimization of the Java virtual machine instructions (their translation into machine code) are not specified. The main reason for this omission is to not unnecessarily constrain implementers. Any Java application can be run only inside some concrete implementation of the abstract specification of the Java virtual machine.

Starting with Java Platform, Standard Edition (J2SE) 5.0, changes to the JVM specification have been developed under the Java Community Process as JSR 924. As of 2006, changes to the specification to support changes proposed to the class file format (JSR 202) are being done as a maintenance release of JSR 924. The specification for the JVM was published as the blue book, whose preface states:

We intend that this specification should sufficiently document the Java Virtual Machine to make possible compatible clean-room implementations. Oracle provides tests that verify the proper operation of implementations of the Java Virtual Machine.

The most commonly used Java virtual machine is Oracle's HotSpot.

Oracle owns the Java trademark and may allow its use to certify implementation suites as fully compatible with Oracle's specification.

Garbage collectors

Garbage collectors available in Java OpenJDKs virtual machine (JVM) include:

  • Serial
  • Parallel
  • CMS (Concurrent Mark Sweep)
  • G1 (Garbage-First)
  • ZGC (Z Garbage Collector)
  • Epsilon
  • Shenandoah
  • GenZGC (Generational ZGC)
  • GenShen (Generational Shenandoah)
  • IBM Metronome (only in IBM OpenJDK)
  • SAP (only in SAP OpenJDK)
  • Azul C4 (Continuously Concurrent Compacting Collector) (only in Azul Systems OpenJDK)

Java's design philosophy revolves around the assumption of a garbage collector. Unlike languages such as C++ and Rust, deterministic memory management through a delete keyword (as in C++) is not possible. Even introducing such a feature is not possible, due to a lack of ownership, aside from using sun.misc.Unsafe or through java.lang.foreign to allocate/deallocate memory outside the Java heap. Due to Java primarily using heap-based allocation, objects are stored as references, and deletion would result in dangling pointers.

<span id="mwwg"></span><span class="n" id="mwww">Foo</span><span class="w" id="mwxA"> </span><span class="n" id="mwxQ">a</span><span class="w" id="mwxg"> </span><span class="o" id="mwxw">=</span><span class="w" id="mwyA"> </span><span class="k" id="mwyQ">new</span><span class="w" id="mwyg"> </span><span class="n" id="mwyw">Foo</span><span class="p" id="mwzA">();</span> <span class="n" id="mwzQ">Foo</span><span class="w" id="mwzg"> </span><span class="n" id="mwzw">b</span><span class="w" id="mw0A"> </span><span class="o" id="mw0Q">=</span><span class="w" id="mw0g"> </span><span class="n" id="mw0w">a</span><span class="p" id="mw1A">;</span> <span class="k" id="mw1Q">delete</span><span class="w" id="mw1g"> </span><span class="n" id="mw1w">a</span><span class="p" id="mw2A">;</span> <span class="n" id="mw2Q">System</span><span class="p" id="mw2g">.</span><span class="n" id="mw2w">out</span><span class="p" id="mw3A">.</span><span class="n" id="mw3Q">println</span><span class="p" id="mw3g">(</span><span class="n" id="mw3w">b</span><span class="p" id="mw4A">);</span>

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication