Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Java / Inside the JVM

    Quick Reference

    Glossary and cheat sheet for Inside the JVM — the page to reread before an interview.

    Extra: Reference7 min read

    Glossary#

    TermPlain meaningChapter
    HotSpotthe standard JVM implementation1
    class loader / parent delegationloads classes / ask the parent first2
    loading / linking (verify, prepare, resolve) / initialisationclass loading phases2
    ClassNotFoundException / NoClassDefFoundErrorrequested-by-name class missing / compiled-against class missing at run time2
    heap / metaspace / PermGenobjects / class metadata (native) / the pre-Java-8 area3
    JVM stack / frame / PC registerper-thread call stack / one call / current instruction3
    code cachestores JIT-compiled machine code3
    object header / mark word / compressed oopsper-object overhead / hash, lock, age bits / 32-bit references3
    humongous objecta G1 object ≥ half a region3, 8
    bytecode / operand stack / javapJVM instructions / their working stack / the disassembler4
    interpreter / JIT / C1 / C2 / tiered compilationexecution modes and compilers4
    inlining / deoptimisation / escape analysis / scalar replacementJIT optimisations4
    warm-up / CDS / GraalVM Native Imageslow start / faster start-up data / ahead-of-time compilation4
    GC root / reachable / live / garbagestarting points / found by tracing / kept / freed5
    reference countingcounting references per object; can't free cycles5
    generational hypothesismost objects die young6
    Eden / survivor (S0, S1) / old generationnew objects / young survivors / long-lived6
    minor / major / full GCyoung / old / everything6
    tenuring threshold / promotion / premature promotionsurvivals before moving to old / the move / moving too early6
    TLABper-thread allocation chunk in Eden6
    mark–sweep / mark–compact / copyingGC algorithms7
    stop-the-world / concurrent collection / barrierpause everything / GC alongside the app / tracking code7
    throughput / latencytime not spent in GC / pause length7
    Serial / Parallel / G1 / ZGC / Shenandoah / Epsilonthe collectors8
    region / mixed GC / pause targetG1's heap unit / young + chosen old regions / MaxGCPauseMillis8
    allocation stallallocating faster than concurrent GC frees8
    strong / soft / weak / phantom referencereference strengths9
    Cleaner / finalizemodern clean-up hook / deprecated old one9
    -Xms / -Xmx / -Xss / MaxRAMPercentageinitial heap / max heap / stack size / heap as % of RAM10
    heap dump / thread dump / JFR / MATobject snapshot / thread stacks / flight recorder / dump analyser10
    dominator tree / path to GC rootswhat retains the most / why it's alive10

    Cheat Sheet#

    Memory map

    Output
      shared:     HEAP [ young: Eden | S0 | S1 ][ old ]      METASPACE (native)      CODE CACHE
      per thread: STACK (frames: locals, operand stack)      PC register      native stack
      errors:     heap space OOM · Metaspace OOM · StackOverflowError · (container) OOMKilled 137

    GC in one breath

    Output
      mark from roots → young GC copies survivors (cheap: cost ∝ live) → promote after N survivals → old gen collected rarely
      G1 default (regions, garbage-first, ~200 ms target) · ZGC sub-ms (needs headroom) · Parallel for throughput

    Flags

    Output
      -Xms2g -Xmx2g · -XX:MaxRAMPercentage=75 (containers) · -Xss1m · -XX:+UseZGC · -XX:MaxGCPauseMillis=100
      -Xlog:gc*:file=gc.log · -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps · -XX:+PrintCommandLineFlags

    Tools

    Output
      jcmd <pid> GC.heap_info | GC.heap_dump f.hprof | Thread.print | JFR.start duration=60s filename=r.jfr
      jstat -gc <pid> 1000 · jstack <pid> · javap -c -p Foo.class · Eclipse MAT · JDK Mission Control · VisualVM

    Read a GC log line

    Output
      GC(2) Pause Young (Normal) (G1 Evacuation Pause) 153M->1M(256M) 0.977ms
            kind of pause         cause                before->after(heap size) pause length

    Try This Yourself#

    1. Read your own bytecode. Compile any method from Java Basics, run javap -c -p, and annotate each instruction like Ch 4. Find where a for loop jumps backwards.

    2. Watch generations. Run the 3-million-notes program with -Xmx256m -Xlog:gc, then change it to keep 1 in 10 notes instead of 1 in 1,000. How do the "after" sizes and pause times change? Do you see Pause Young (Mixed) or a full GC?

    3. Make and find a leak. Write a service loop that stores every "request" in a static List and never removes them. Run with -Xmx128m -XX:+HeapDumpOnOutOfMemoryError, open the dump in Eclipse MAT (free), and find the static list in the dominator tree and its path to GC roots.

    4. Compare collectors. Run the same allocation-heavy program with -XX:+UseSerialGC, -XX:+UseParallelGC, -XX:+UseG1GC and -XX:+UseZGC (with a generous heap, e.g. -Xmx1g), and compare total time and the longest pause in each log.