Java Reference
In-Depth Information
The throughput collector stops all application threads during both minor and full GCs, and it
fully compacts the old generation during a full GC. Since it is the default in most situations
where it would be used, it needn't be explicitly enabled. To enable it where necessary, use
the flags -XX:+UseParallelGC -XX:+UseParallelOldGC .
The CMS collector
The CMS collector is designed to eliminate the long pauses associated with the full GC
cycles of the throughput and serial collectors. CMS stops all application threads during a
minor GC, which it also performs with multiple threads. Notably, though, CMS uses a differ-
ent algorithm to collect the young generation ( -XX:+UseParNewGC ) than the throughput col-
lector uses ( -XX:+UseParallelGC ).
Instead of stopping the application threads during a full GC, CMS uses one or more back-
ground threads to periodically scan through the old generation and discard unused objects.
This makes CMS a low-pause collector: application threads are only paused during minor
collections, and for some very short periods of time at certain points as the background
threads scan the old generation. The overall amount of time that application threads are
stopped is much less than with the throughput collector.
The trade-off here comes with increased CPU usage: there must be adequate CPU available
for the background GC thread(s) to scan the heap at the same time the application threads are
running. In addition, the background threads do not perform any compaction, which means
that the heap can become fragmented. If the CMS background threads don't get enough CPU
to complete their tasks, or if the heap becomes too fragmented to allocate an object, CMS re-
verts to the behavior of the serial collector: it stops all application threads in order to clean
and compact the old generation using a single thread. Then it begins its concurrent, back-
ground processing again (until, possibly, the next time the heap becomes too fragmented).
CMS is enabled by specifying the flags -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
(both of which are false by default).
The G1 collector
The G1 (or Garbage First) collector is designed to process large heaps (greater than about 4
GB) with minimal pauses. It divides the heap into a number of regions, but it is still a genera-
tional collector. Some number of those regions comprise the young generation, and the
young generation is still collected by stopping all application threads and moving all objects
that are alive into the old generation or the survivor spaces. As in the other algorithms, this
occurs using multiple threads.
Search WWH ::

Custom Search