100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Java JVM Internals Cheat Sheet

Java JVM Internals Cheat Sheet

Explains JVM memory regions, class loading, garbage collectors, GC tuning flags, and diagnostic tools for troubleshooting Java applications.

3 PagesAdvancedApr 12, 2026

JVM Runtime Memory Areas

The regions the JVM divides memory into at runtime.

  • Heap- Stores all objects and arrays; shared across threads; divided into Young (Eden, S0, S1) and Old generations.
  • Metaspace- Stores class metadata; replaced PermGen in Java 8+; grows into native memory, not the heap.
  • Stack- Per-thread; stores stack frames with local variables, operand stack, and return addresses.
  • PC Register- Per-thread; holds the address of the current executing JVM instruction.
  • Native Method Stack- Per-thread; used for native (JNI) method calls.
  • Runtime Constant Pool- Per-class pool (part of Metaspace) holding literals and symbolic references resolved at runtime.

Class Loading & Class Loaders

Delegation model used to load classes.

java
// Class loader hierarchy (parent-first delegation)// Bootstrap ClassLoader   -> loads java.lang.*, core JDK classes (native code)// Platform ClassLoader    -> loads JDK extension modules (was Ext ClassLoader pre-9)// Application ClassLoader -> loads classes on the classpath// Inspect a class's loaderSystem.out.println(String.class.getClassLoader());   // null (bootstrap)System.out.println(MyApp.class.getClassLoader());     // AppClassLoader// Class loading phases: Loading -> Linking (Verify, Prepare, Resolve) -> Initialization

Common GC & Memory Flags

JVM flags for tuning heap size and garbage collector.

bash
java -Xms512m -Xmx2g -jar app.jar             # Initial / max heap sizejava -XX:+UseG1GC -jar app.jar                # Use G1 collector (default since JDK 9)java -XX:+UseZGC -jar app.jar                 # Use low-latency ZGC (JDK 15+)java -XX:MaxMetaspaceSize=256m -jar app.jar   # Cap Metaspace sizejava -Xss512k -jar app.jar                    # Thread stack sizejava -XX:+HeapDumpOnOutOfMemoryError -jar app.jar  # Dump heap on OOMjava -Xlog:gc* -jar app.jar                   # Unified GC logging (JDK 9+)

Garbage Collectors

Built-in collectors and where they fit.

  • Serial GC- Single-threaded, stop-the-world; best for small heaps and single-CPU environments (-XX:+UseSerialGC).
  • Parallel GC- Multi-threaded throughput collector; stop-the-world for both minor and major GC (-XX:+UseParallelGC).
  • G1 (Garbage First)- Region-based, default collector since JDK 9; balances throughput and pause time (-XX:+UseG1GC).
  • ZGC- Low-latency, concurrent collector scalable to huge heaps with sub-millisecond pauses (JDK 15+ production).
  • Shenandoah- Concurrent, low-pause collector with goals similar to ZGC, developed by Red Hat.

Diagnostic Tools

Command-line tools shipped with the JDK for inspecting a running JVM.

bash
jps                     # List running JVM processesjstat -gc <pid> 1000    # GC stats every secondjmap -heap <pid>        # Heap summaryjmap -dump:file=heap.hprof,live <pid>  # Heap dumpjstack <pid>            # Thread dumpjcmd <pid> VM.flags     # Show active JVM flagsjconsole                # GUI monitoring console
Pro Tip

Stop-the-world pauses come from GC roots being scanned while all app threads are frozen - favor G1 or ZGC over Parallel GC for latency-sensitive services, but benchmark; Parallel GC often has better raw throughput for batch jobs.

Was this cheat sheet helpful?

Explore Topics

#JavaJVMInternals#JavaJVMInternalsCheatSheet#Programming#Advanced#JVM#Runtime#Memory#Areas#OOP#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet