JVM Internals & Memory

JVM Architecture

The JVM is a managed runtime: it loads bytecode through class loaders, interprets it, profiles it, JIT-compiles the hot parts to machine code, and manages memory with garbage collection — trading a warm-up phase for adaptive, profile-guided speed.
  • Pipeline: class loading → bytecode verification → interpretation → profiling → JIT compilation
  • Major subsystems: class loader, runtime data areas (heap, stacks, metaspace), execution engine (interpreter + JIT), GC
  • HotSpot optimizes the common path based on observed runtime behavior — often beating static compilation
  • Java's two value kinds: primitives and object references — no raw pointers
  • java -XX:+PrintFlagsFinal reveals the ~700 tunables; most should stay untouched

The design bet of the managed runtime (Optimizing Java ch. 2): accept an abstraction layer between code and CPU, and repay it with runtime knowledge no static compiler has — which branches are actually taken, which types actually flow, which locks are actually contended. The interpreter starts instantly; the JIT (Jit Compilation) recompiles hot methods with profile-guided aggression; GC (Gc Fundamentals) replaces manual memory management with throughput-tuned automation.

Runtime data areas
AreaHoldsPerFailure mode
Heapall objects and arraysJVMOutOfMemoryError: Java heap space
Java stacksframes: locals, operand stack, return addressesthreadStackOverflowError
Metaspaceclass metadata (native memory since Java 8)JVMOOME: Metaspace
Code cacheJIT-compiled machine codeJVMJIT stops compiling (silent slowdown)
Native/directdirect ByteBuffers, thread stacks, JNIJVM/OSRSS growth invisible to heap monitoring

A running JVM is a multithreaded native process: your application threads share the process with JIT compiler threads, GC worker threads, and service threads (signal dispatch, attach listener). "The application is idle but CPU is busy" frequently means GC or JIT activity — visible with jcmd/JFR (Profiling).

Interrogating the JVM
$ java -XX:+PrintFlagsFinal -version | grep -i maxheap   // effective flag values
$ jcmd <pid> VM.flags                                     // a live process's flags
$ jcmd <pid> VM.version
$ jcmd <pid> GC.heap_info
Sources
  • Optimizing JavaCh. 2 — Overview of the JVM
  • Optimizing Cloud Native Java (2nd ed.)Ch. 3 — Overview of the JVM
  • Java Secrets: High Performance and ScalabilityJava execution model chapters