Comprehensive Overview of JVM Garbage Collectors and Their Configurations
This article provides a detailed overview of JVM garbage collection, classifying the seven major collectors for young and old generations, explaining their algorithms, advantages, drawbacks, and common configuration flags for optimizing Java application performance.
JVM garbage collection is a core topic in Java performance tuning, and this article offers a complete classification and explanation of the seven primary collectors used for both young and old generations.
Young generation collectors include:
Serial – a single‑threaded collector using the copy algorithm; simple and efficient, default for client‑mode VMs.
ParNew – a multithreaded version of Serial, sharing the same parameters and behavior.
Parallel Scavenge – a parallel collector focused on high throughput, also based on the copy algorithm.
Old generation collectors consist of:
Serial Old – the old‑generation counterpart of Serial, using a mark‑compact algorithm.
Parallel Old – the old‑generation counterpart of Parallel Scavenge, also multithreaded.
CMS (Concurrent Mark‑Sweep) – aims for minimal pause times, employing a mark‑sweep algorithm with four phases (initial mark, concurrent mark, final mark, concurrent sweep) and offering concurrent collection but with higher CPU sensitivity and potential fragmentation.
G1 (Garbage‑First) collector (available since JDK 1.7) replaces CMS and provides a generational, region‑based approach with parallelism, concurrent phases, space compaction, and predictable pause times. Its operation includes initial marking, concurrent marking, final marking, and region‑based reclamation.
Typical JVM GC configuration flags are:
-XX:+UseSerialGC – use Serial collector for both generations -XX:+UseParNewGC – use ParNew for young generation -XX:+UseParallelGC – use Parallel Scavenge for young generation (throughput‑focused) -XX:+UseParallelOldGC – use Parallel Old for old generation -XX:ParallelGCThreads=<n> – set number of GC threads -XX:+UseConcMarkSweepGC – enable CMS for old generation -XX:ParallelCMSThreads=<n> – set CMS thread count -XX:+UseG1GC – enable G1 collector
The article also mentions that newer collectors exist and will be covered later, and includes several illustrative diagrams (images) to aid understanding.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.