Architecture Overview
HotSpot is structured around several key subsystems that work together to execute Java bytecode efficiently:Runtime Components
The runtime system manages the fundamental execution environment:- Thread Management
- Class Loading
- Interpreter
The thread hierarchy in HotSpot (defined in All Thread subclasses must be either JavaThread or NonJavaThread. The execution sequence includes:
src/hotspot/share/runtime/thread.hpp:71-87):thread_native_entry- per-OS native entry point- Stack initialization
- OS-level initialization (signal masks, etc.)
- Handshake with creating thread
this->call_run()- common shared entry pointthis->pre_run()- virtual per-thread-type initializationthis->run()- virtual per-thread-type main logic
Memory Management
The Universe class (src/hotspot/share/memory/universe.hpp:48) is a namespace holding known system classes and objects in the VM:
Array of klasses for primitive array types (boolean[], byte[], int[], etc.)
Klass for object arrays
Reference to the main thread group object
Reference to the system thread group object
Preallocated error objects (no backtrace) for OOM situations
Garbage Collection
HotSpot provides multiple garbage collector implementations insrc/hotspot/share/gc/:
Available GC Implementations
- Serial GC
- Parallel GC
- G1 GC
- Z GC
- Shenandoah
- Epsilon
Single-threaded stop-the-world collector suitable for small applications.
- Young generation: Copy collector
- Old generation: Mark-sweep-compact
- Best for: Single-processor machines or small heaps
JIT Compilation
HotSpot uses adaptive compilation with multiple tiers:Compilation Tiers
Initial execution mode, collects profiling data
Client compiler with minimal optimizations
C1 with limited profiling overhead
C1 with full profiling for C2
Server compiler with aggressive optimizations
Compiler Architecture
Fromsrc/hotspot/share/compiler/compileBroker.hpp:94-100:
- Queues compilation tasks based on method hotness
- Manages compiler threads (C1 and C2)
- Handles compilation lifecycle and inlining decisions
VM Globals and Configuration
VM behavior is controlled through flags defined insrc/hotspot/share/runtime/globals.hpp:37-99:
Flag Categories
Always settable and visible in production builds
Settable only during development, constant in PRODUCT builds
For VM quality assurance or field diagnosis. Requires
-XX:+UnlockDiagnosticVMOptionsFor experimental features. Requires
-XX:+UnlockExperimentalVMOptionsDynamically writeable through JMX (HotSpotDiagnosticMXBean API)
Object Representation
Klass Kinds
Fromsrc/hotspot/share/oops/klass.hpp:68-77:
- InstanceKlassKind: Regular Java class instances
- InstanceRefKlassKind: Reference objects (WeakReference, etc.)
- InstanceMirrorKlassKind: java.lang.Class instances
- TypeArrayKlassKind: Primitive arrays
- ObjArrayKlassKind: Object arrays
Layout Helper
The layout helper is a combined descriptor of object layout:- For instances: positive number representing instance size
- For arrays: negative number with encoded metadata (tag, header size, element type, log2 of element size)
JVM Interface Functions
Core JVM functions fromsrc/hotspot/share/include/jvm.h:66-150:
Object Operations
System Operations
Memory Management
These JVM_ functions complement the standard JNI support and are used by native libraries in the standard Java API. For example, java.lang.Object uses VM-level functions for monitor wait and notify operations.
Thread-Local Allocation Buffers (TLABs)
HotSpot uses TLABs for fast, thread-local allocation:- Each thread has a private allocation buffer in Eden
- Most allocations are satisfied with a simple pointer bump
- Reduces allocation contention between threads
- Falls back to slow-path allocation when TLAB is full
Safepoints
Safepoints are synchronization points where all Java threads are stopped:- Required for operations like GC, deoptimization, biased locking revocation
- Thread-local polling mechanism for safepoint checks
- Managed by SafepointMechanism and SafepointSynchronize
- Threads must reach a safepoint to ensure a consistent heap state