Skip to content

Path 2 of 4

Garbage Collection and Diagnostics

G1 and ZGC, reading pauses and allocation pressure from GC logs, finding leaks in heap dumps, and the three tools you reach for first: JFR, GC logs and async-profiler.

0 / 4 lessons completed · about 122 min in total

After this path you can

Outcomes

  • Choose between G1 and ZGC from a latency goal
  • Read a GC log and name the cause of a long pause
  • Find a leak from two histograms and a heap dump
  • Record and read a JFR file during an incident

Lessons

  1. 1Garbage collection: G1 and ZGCHow G1 and ZGC reclaim memory in JDK 21, what each one pauses for, what each one costs, and how to choose between them from a latency goal and a heap size.Intermediate30 min
  2. 2GC tuning and pause analysisRead a GC log line by line, name the cause of a long pause or a stall, and tune in the order that works: heap size, live set, allocation rate, then the pause target.Advanced32 min
  3. 3Memory leaks and heap dumpsWhat a leak is on a garbage-collected heap, the code that causes one, what each OutOfMemoryError message points at, and how to find the leak from two histograms and a heap dump.Intermediate30 min
  4. 4JFR, GC logs and async-profilerThree tools and the question each one answers: Java Flight Recorder for what the JVM and its threads were doing, GC logs for pauses, async-profiler for where CPU, allocation and waiting time go.Intermediate30 min

Simulations and labs for this path

A simulation in the browser, then the same failure on a real JVM.

  1. Simulation 4GC pressure: when the live set fills the heap
  2. Simulation 5Heap leak: the cache that never hits
  3. Simulation 6Lock contention: eight threads, the throughput of one