jvm - gc
CMS GC, the full collection is serial and STW,
CMS GC、Parallel Old GC、G1
Young generation collectors
Copy (enabled with -XX:+UseSerialGC)
the serial copy collector, uses one thread to copy surviving objects from Eden to Survivor spaces and between Survivor spaces until it decides they've been there long enough, at which point it copies them into the old generation.
PS Scavenge (enabled with -XX:+UseParallelGC)
the parallel scavenge collector, like the Copy collector, but uses multiple threads in parallel and has some knowledge of how the old generation is collected (essentially written to work with the serial and PS old gen collectors).
ParNew (enabled with -XX:+UseParNewGC)
the parallel copy collector, like the Copy collector, but uses multiple threads in parallel and has an internal 'callback' that allows an old generation collector to operate on the objects it collects (really written to work with the concurrent collector).
G1 Young Generation (enabled with -XX:+UseG1GC)
the garbage first collector, uses the 'Garbage First' algorithm which splits up the heap into lots of smaller spaces, but these are still separated into Eden and Survivor spaces in the young generation for G1.
Old generation collectors
MarkSweepCompact (enabled with -XX:+UseSerialGC)
the serial mark-sweep collector, the daddy of them all, uses a serial (one thread) full mark-sweep garbage collection algorithm, with optional compaction.
PS MarkSweep (enabled with -XX:+UseParallelOldGC)
the parallel scavenge mark-sweep collector, parallelised version (i.e. uses multiple threads) of the MarkSweepCompact.
ConcurrentMarkSweep (enabled with -XX:+UseConcMarkSweepGC)
the concurrent collector, a garbage collection algorithm that attempts to do most of the garbage collection work in the background without stopping application threads while it works (there are still phases where it has to stop application threads, but these phases are attempted to be kept to a minimum). Note if the concurrent collector fails to keep up with the garbage, it fails over to the serial MarkSweepCompact collector for (just) the next GC.
G1 Mixed Generation (enabled with -XX:+UseG1GC)
the garbage first collector, uses the 'Garbage First' algorithm which splits up the heap into lots of smaller spaces.
I drew this diagram on a white board for some customers recently. They seemed to
like it (or were just being very polite) so I thought I redraw it for your
amusement.
Each blue box represents a collector that is used to collect a generation. The
young generation is collected by the blue boxes in the yellow region and
the tenured generation is collected by the blue boxes in the gray region.
- force GC jcmd GC.run
- "Serial" is a stop-the-world, copying collector which uses a single GC thread.
- "ParNew" is a stop-the-world, copying collector which uses multiple GC threads. It differs from "Parallel Scavenge" in that it has enhancements that make it usable with CMS. For example, "ParNew" does the synchronization needed so that it can run during the concurrent phases of CMS.
- "Parallel Scavenge" is a stop-the-world, copying collector which uses multiple GC threads.
- "Serial Old" is a stop-the-world, mark-sweep-compact collector that uses a single GC thread.
- "CMS" is a mostly concurrent, low-pause collector.
- "Parallel Old" is a compacting collector that uses multiple GC threads.
- UseSerialGC is "Serial" + "Serial Old"
- UseParNewGC is "ParNew" + "Serial Old"
- UseConcMarkSweepGC is "ParNew" + "CMS" + "Serial Old". "CMS" is used most of the time to collect the tenured generation. "Serial Old" is used when a concurrent mode failure occurs.
- More predictable GC pauses
- Better GC ergonomics
- Low pauses without fragmentation
- Parallelism and concurrency in collections
- Better heap utilization
- force GC jcmd