This article aims to systematize knowledge about all modern garbage collectors used in HotSpot, JRockit and J9 JVMs. The article contains a brief overview of all garbage collection modes with the analogies made between all the JVMs considered here. The article will be interesting to anyone who is interested in the issue of GC, and will also be useful to those who are considering or planning to port JAVA applications to alternative JVMs.
It is assumed that the reader is already familiar with the basic concepts of garbage collection, such as the Copying collector, the Mark-Sweep-Compact algorithm, and the Generational collection.
Also, it should immediately be said that the article does not pretend to the completeness of the garbage collection algorithms, there are fairly well illustrated materials on any of the algorithms in the network. Implementations of similar algorithms may differ from one JVM to another - if the single-threaded Mark-Sweep-Compact is implemented about the same everywhere, then the competing Mark-Sweep-Compact already has various variations that are not affected here either.
Oracle HostSpot JVM (versions 6 and 7)
Virtually all garbage collection modes in HotSpot use assembly by generation. The whole Heap is divided into 3 generations depending on the age of the objects - respectively Young for young, Tenured for “mature” and Perm for classes and constant pools. In turn, the younger generation is divided into 3 more areas - Eden and 2 Surviver areas. First, objects are created in Eden, then they fall into the Surviver area (one or more times), and then only into Tenured. For G1, the split by generations also exists, but has a different character (described below).
')
Copy (-XX: + UseSerialGC)Single-flow (
serial ) copying collector for the young generation.
ParNew (-XX: + UseParNewGC)Multi-stream (
parallel ) copying collector for the young generation.
MarkSweepCompact (-XX: + UseSerialGC)Single flow collector for Tenured generation using Mark-Sweep-Compact algorithm.
ConcurrentMarkSweep (-XX: + UseConcMarkSweepGC)A competitive Mark-Sweep (
concurrent ) collector for the Tenured generation, most of the time working simultaneously with application flows. With strong fragmentation, one-threaded
MarkSweepCompact calls for help. Additional parameters are possible:
- -XX: ± CMSIncrementalMode - uses or disables an incremental concurrent GC algorithm
- -XX: ± CMSConcurrentMTEnabled - concurrent GC algorithm
- -XX: ± UseCMSCompactAtFullCollection - use or disables a compaction when a full GC occurs
PS Scavenge + PS MarkSweep (-XX: + UseParallelGC -XX: + UseParallelOldGC)For the young generation, the
PS Scavenge multi-stream copy collector is used to
match the similar
ParNew . For the Tenured generation,
PS MarkSweep is used - a multi-threaded version of the Mark-Sweep-Compact algorithm. This pair of collectors supports the so-called. Adaptive Size Policy (or GC ergonomics) - the ability of the JVM to automatically optimize the size of Young and Tenured generations to achieve specified pauses. Additional parameters are possible:
- -XX: ± UseAdaptiveSizePolicy - uses or disables Adaptive Size Policy
- -XX: MaxGCPauseMillis = nnn - sets desirable max GC pause time
- -XX: GCTimeRatio = nnn - sets desirable relation between application and GC work times
G1 Young Generation + G1 Mixed Generation (-XX: + UseG1GC)New mode using the "regional" assembly. Heap is divided into many regions of equal size (0.5-2 mb). A competitive tracing and labeling process assesses the size of living objects in regions, this happens in parallel without stopping application flows. In the next cycle, GC processes all Young regions (special regions in which new objects are created), as well as several of those in which the smallest size of living objects. So collector minimizes the number of copies between regions. Here you can also set the desired pause time:
- -XX: MaxGCPauseMillis = nnn - sets desirable max GC pause time
IBM J9 JVM
Unlike HotSpot, in J9 only one mode uses the assembly by generations. However, in this case, the Young generation is divided not into 3, but into 2 areas - Eden and Surviver. So the object from Surviver will immediately fall into Tenured. And if Eden <Surviver, then some objects immediately have a chance to get from Eden to Tenured.
-Xgcpolicy: optthruputA multi-threaded Mark-Sweep-Compact collector that processes the entire Heap.
-Xgcpolicy: optavgpauseCompetitive Mark-Sweep-Compact collector for the entire Heap, most of the time working simultaneously with the application. It is designed to smooth pauses caused by GC.
-Xgcpolicy: genconCollector on generations. For the young generation, a multi-stream copy collector is used, but instead of the 3 areas, only 2 are used - Eden and Surviver. Objects trapped in Surviver during the next GC cycle will fall into the Tenured generation. For the Tenured generation, the above described competitive Mark-Sweep-Compact collector is used.
-Xgcpolicy: balancedThe new collector uses the division of Heap into many regions. Similar to the G1 concept in Oracle HotSpot.
Oracle JRockit JVM
In JRockit 2 assembly modes by generations, however, the Young generation is even simpler - it does not break at all, and at the first collector cycle, objects from Eden immediately fall into Tenured.
JRockit allows you to choose between dynamic and static modes. Dynamic modes - throughput, pausetime, deterministic - define the target, and can dynamically change the parameters as well as the assembly algorithm itself depending on the situation. There are also static modes that more accurately determine the way garbage collection takes place, and we’ll stop on them:
-Xgc: singleparA multi-threaded Mark-Sweep-Compact collector that processes the entire Heap.
-Xgc: genparCollector on generations. For the young generation, a multi-stream copy collector is used. For the Tenured generation, the multi-threaded Mark-Sweep-Compact is used.
-Xgc: singleconCompetitive Mark-Sweep-Compact collector for the entire Heap, most of the time working simultaneously with the application.
-Xgc: genconCollector on generations. For the Young generation, a single-flow copy collector is used. For the Tenured generation, a competitive Mark-Sweep-Compact manifold similar to
singlecon is used .
Correspondence table for different garbage collection modes
In HotSpot JVM there is a possibility to set a separate collector type for each generation. However, not every Young-generation collector can work with any of the Tenured-generation collectors. There are only 6 possible combinations. All of them are listed in the table below with the corresponding (if any) analogies in JRockit and J9.
Oracle HotSpot | Ibm j9 | Oracle JRockit |
---|
-XX: + UseSerialGC
Copy + MarkSweepCompact
| | |
-XX: + UseG1GC
G1 Young + G1 Mixed
| -Xgcpolicy: balanced
| |
-XX: + UseParallelGC -XX: + UseParallelOldGC
PS Scavenge + PS MarkSweep
| -Xgcpolicy: optthruput *
| -Xgc: genpar -Xgc: singlepar *
|
-XX: + UseParNewGC
ParNew + MarkSweepCompact
|
| |
-XX: + UseConcMarkSweepGC -XX: + UseParNewGC
ParNew + ConcurrentMarkSweep
| -Xgcpolicy: optavgpause *
| -Xgc: singlecon *
|
-XX: + UseConcMarkSweepGC -XX: -UseParNewGC
Copy + ConcurrentMarkSweep
| -Xgcpolicy: gencon -Xgcpolicy: optavgpause *
| -Xgc: gencon -Xgc: singlecon *
|
* - similarity only in the method of cleaning the tenured generation.
Sources
http://www.fasterj.com/articles/oraclecollectors1.shtmlhttp://www.ibm.com/developerworks/websphere/techjournal/1106_bailey/1106_bailey.htmlhttp://www.ibm.com/developerworks/websphere/techjournal/1108_sciampacone/1108_sciampacone.htmlhttp://www.techpaste.com/2012/02/java-garbage-collectors-gc/http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/memman.html#wp1087125http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionX.html#wp1017849