Java Reference
In-Depth Information
CMS threads have to do. (The chance that CMS experiences a concurrent mode failure also
depends on the amount of allocation that the application does.)
G1, on the other hand, segments the old generation into regions, so it is easier for multiple
background threads to divide the necessary work of scanning the old generation. G1 can still
experience concurrent mode failures if the background threads can't keep up, but the G1 al-
gorithm makes that less likely to occur.
CMS can also revert to a full GC because of heap fragmentation, since CMS does not com-
pact the heap (except during the lengthy full GCs). G1 compacts the heap as it goes. G1 can
still experience heap fragmentation, but its design again reduces the chance of that compared
to CMS.
There are ways to tune both CMS and G1 to attempt to avoid these failures, but for some ap-
plications, that will not always work. As heaps grow larger (and the penalty for a full GC
grows larger), it is easier to use G1 to avoid these issues. (On the other hand, for some ap-
plications it is impossible to tune either collector to avoid concurrent mode failures. Hence,
even if the performance goals for an application seem to be in line with the goals of a con-
current collector, the throughput collector may still be the better choice.)
Finally, there are some slightly intangible factors to consider among all three collectors. The
throughput collector is the oldest of the three, which means the JVM engineers have had
more opportunity to ensure it is written to perform well in the first place. G1, as a relatively
new algorithm, is more likely to encounter corner cases that its design didn't anticipate. G1
has fewer tuning knobs to affect its performance, which may be good or bad depending on
your perspective. G1 was considered experimental until Java 7u4, and some of its tuning fea-
tures aren't available until Java 7u10. G1 has significant performance benefits in Java 8 com-
pared to earlier Java 7 releases, and future work on G1 can also be expected to improve its
performance on smaller heaps relative to CMS.
1. CMS is the better of the concurrent collectors when the heap is small.
2. G1 is designed to process the heap in regions, so it will scale better than CMS on
large heaps.
Search WWH ::

Custom Search