JVM Tutorials - Herong's Tutorial Examples - Version 4.23, by Dr. Herong Yang
Serial, Parallel, Concurrent, and Regionalized Collectors
This section describes different types garbage collectors supported in HotSpot JVM: Serial Collector, Parallel Collector, Parallel Compacting Collector, Concurrent Mark-Sweep Collector, and Garbage First Collector.
HotSpot JVM also offers variations of the Serial Collector, which could be more efficient based the type of your Java application and the computer system you are using:
1. Serial Collector (invoked by "-XX:+UseSerialGC" option) - GC operation is performed serially using 1 CPU only in a stop-the-world fashion for Minor GC and Full GC. Minor GC uses the 3-area (Eden, Survivor Space "From" and Survivor Space "To") algorithm. Full GC uses the 3-step (Mark, Sweep and Compact) algorithm.
2. Parallel Collector (also called Throughput Collector, invoked by "-XX:+UseParallelGC" option) - Minor GC uses multiple CPUs and Full GC uses 1 CPU. Both Minor GC and Full GC are done in a stop-the-world fashion and same algorithms as the Serial Collector.
3. Parallel Compacting Collector (invoked by "-XX:+UseParallelOldGC" option) - Minor GC is done in the same way as the Parallel Collector. Full GC is done in a stop-the-world fashion but using multiple CPUs most of the time.
4. Concurrent Mark-Sweep (CMS) Collector (also called Low-Latency Collector, invoked by "-XX:+UseConcMarkSweepGC" option) - Minor GC is done in the same way as the Parallel Collector. Full GC is done concurrently with the execution of the Java application nost of the time.
5. Garbage First (G1) Collector (invoked by "-XX:+UseG1GC" option) - The Garbage First (G1) Collector is a regionalized and generational garbage collector. The Heap area is first divided into a number of equally sized regions. Then sets of regions are picked up to form the Eden, Survivor Space "From", Survivor Space "To" and Tenured Generation spaces. This region concept allows Garbage First Collector to measure how much garbage each region has, and to collect garbage in regions mostly filled with garbage first. This is why it is called "Garbage First". When performing garbage collection in a region, The Garbage First Collector follows an algorithm similar to the Concurrent Mark-Sweep Collector.
The table below summarizes all 4 garbage collectors supported in HotSpot:
GC Variations Minor GC Full GC CPU ------------- -------- ------- --- Serial Collector Serial Serial 1 -XX:+UseSerialGC Stop-the-world Stop-the-world Parallel Collector Mostly Parallel Serial Multi Throughput Collector Stop-the-world Stop-the-world -XX:+UseParallelGC Parallel Compacting Mostly Parallel Mostly Parallel Multi -XX:+UseParallelOldGC Stop-the-world Stop-the-world Concurrent Mark-Sweep Mostly Parallel Mostly Parallel Multi CMS Collector Stop-the-world Mostly concurrent Low-Latency Collector -XX:+UseConcMarkSweepGC Garbage First (G1) Mostly Parallel Mostly Parallel Multi -XX:+UseG1GC Stop-the-world Mostly concurrent
Today most computers have multiple CPUs. So the best option for majority of Java application is to use the Parallel Compacting Collector, which gives the most throughput in terms of application execution time over GC time.
If your application requires fast response time, then you should use the G1 Collector, which gives the least and predictable GC pauses.
The picture below shows how the Heap area is divided into regions and how regions are assigned to
Eden, Survivor Spaces ("From" and "To"), and Tenured (Old) Generation:
Last update: 2014.
Table of Contents