Java 7 - GC Cheatsheet
Java 7 - GC Cheatsheet
All concrete numbers in JVM options in this card are for illustrational purposes only!
Java 7 Alexey Ragozin – http://blog.ragozin.info
Available combinations of garbage collection algorithms in HotSpot JVM Java Process Memory
Young collector Old collectior JVM Flags
JVM Memory
Non-JVM Memory
(native libraries)
Serial (DefNew) Serial Mark Sweep Compact -XX:+UseSerialGC
Parallel scavenge (PSYoungGen) Serial Mark Sweep Compact (PSOldGen) -XX:+UseParallelGC Java Heap Non-Heap
Parallel scavenge (PSYoungGen) Parallel Mark Sweep Compact (ParOldGen) -XX:+UseParallelOldGC Young Gen
Old Gen
Perm Gen
Thread Stacks
Code Cache
NIO Direct Buffers
Other JVM Memmory
Parallel (ParNew) Serial Mark Sweep Compact -XX:+UseParNewGC
Survivor 0
Survivor 1
Eden
Serial (DefNew) Concurrent Mark Sweep -XX:-UseParNewGC1 -XX:+UseConcMarkSweepGC
Parallel (ParNew) Concurrent Mark Sweep -XX:+UseParNewGC -XX:+UseConcMarkSweepGC
Garbage First (G1) -XX:+UseG1GC
1 - Notice minus before UseParNewGC, which is explicitly disables parallel mode -Xms/-Xmx
Young space tenuring Concurrent Mark Sweep (CMS) Garbage First (G1)
-XX:InitialTenuringThreshold=8 CMS initiating options
Initial value for tenuring threshold (number of collections
before object will be promoted to old space) -XX:+UseCMSInitiatingOccupancyOnly -XX:G1HeapRegionSize=32m Size of heap region
Only use predefined occupancy as only criterion for starting -XX:G1ReservePercent=10 Percentage of heap to keep free.
-XX:MaxTenuringThreshold=15 a CMS collection (disable adaptive behaviour) Reserved memory is used as last resort to avoid promotion failure.
Max value for tenuring threshold -XX:CMSInitiatingOccupancyFraction=70
Percentage CMS generation occupancy to start a CMS cycle. -XX:InitiatingHeapOccupancyPercent=45
-XX:PretenureSizeThreshold=2m Max object size Percentage of (entire) heap occupancy to trigger concurrent GC
allowed to be allocated in young space (large objects will be A negative value means that CMSTriggerRatio is used.
allocated directly in old space). Thread local allocation -XX:CMSBootstrapOccupancy=50 -XX:G1MixedGCCountTarget=8 Target number of mixed
bypasses this check, so if TLAB is large enough object Percentage CMS generation occupancy at which to initiate collections after a marking cycle
exciding size threshold still may be allocated in young space. CMS collection for bootstrapping collection stats.
-XX:G1HeapWastePercent=10 If garbage level is below
-XX:+AlwaysTenure Promote all objects surviving -XX:CMSTriggerRatio=70
Percentage of MinHeapFreeRatio in CMS generation that is threshold, G1 will not attempt to reclaim memory further
young collection immediately to tenured space
(equivalent of -XX:MaxTenuringThreshold=0) allocated before a CMS collection cycle commences. -XX:G1ConfidencePercent=50 Confidence level
-XX:CMSInitiatingPermOccupancyFraction=80 for MMU/pause prediction
-XX:+NeverTenure Objects from young space -XX:CMSTriggerPermRatio=90
will never get promoted to tenured space unless survivor CMS triggers base on perm space occupancy -XX:MaxGCPauseMillis=500 Target GC pause duration.
space is not enough to keep them G1 is not deterministic, so no guaranties for GC pause to satisfy this limit.
CMS Stop-the-World pauses tuning
Thread local allocation CMS Diagnostic options
-XX:CMSWaitDuration=30000
-XX:+UseTLAB Use thread local allocation blocks in eden Once CMS collection is triggered, it will wait for next young -XX:PrintCMSStatistics=1
-XX:+ResizeTLAB Let JVM resize TLABs per thread collection to perform initial mark right after. This parameter Print additional CMS statistics. Very verbose if n=2.
-XX:TLABSize=1m
specifies how long CMS can wait for young collection -XX:+PrintCMSInitiationStatistics
Initial size of thread’s TLAB
-XX:+CMSScavengeBeforeRemark Print CMS initiation details
-XX:MinTLABSize=64k Min size of TLAB Force young collection before remark phase -XX:+CMSDumpAtPromotionFailure
Parallel processing -XX:+CMSScheduleRemarkEdenSizeThreshold Dump useful information about the state of the CMS old
-XX:ConcGCThreads=2 If Eden used is below this value, don't try to schedule remark generation upon a promotion failure
Number of parallel threads used for concurrent phase. -XX:+CMSPrintChunksInDump (with optin above)
-XX:CMSScheduleRemarkEdenPenetration=20
-XX:ParallelGCThreads=16 Eden occupancy % at which to try and schedule remark pause Add more detailed information about the free chunks
Number of parallel threads used for stop-the-world phases. -XX:+CMSPrintObjectsInDump (with optin above)
-XX:CMSScheduleRemarkSamplingRatio=4
-XX:+ParallelRefProcEnabled Enable parallel Add more detailed information about the allocated objects
Start sampling Eden top at least before young generation occupancy
processing of references during GC pause reaches 1/ of the size at which we plan to schedule remark Misc CMS options
-XX:+DisableExplicitGC CMS Concurrency options -XX:+CMSClassUnloadingEnabled
JVM will ignore application calls to System.gc() -XX:+CMSParallelInitialMarkEnabled If not enabled, CMS will not clean permanent space. You
-XX:+ExplicitGCInvokesConcurrent Whether parallel initial mark is enabled (disabled by default) may need to enable it for containers such as JEE or OSGi.
Let System.gc() trigger concurrent collection instead of full GC
-XX:+CMSParallelRemarkEnabled -XX:+CMSIncrementalMode
-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses Enable incremental CMS mode. Incremental mode was meant for
Same as above but also triggers permanent space collection. Whether parallel remark is enabled (enabled by default)
severs with small number of CPU, but may be used on multicore
-XX:SoftRefLRUPolicyMSPerMB=1000 Factor -XX:+CMSParallelSurvivorRemarkEnabled servers to benefit from more conservative initiation strategy.
for calculating soft reference TTL based on free heap size Whether parallel remark of survivor space enabled, -XX:+CMSOldPLABMin=16 -XX:+CMSOldPLABMax=1024
Command to be executed
effective only with option above (enabled by default) Min and max size of CMS gen PLAB caches per worker per block size
-XX:OnOutOfMemoryError=…
in case of out of memory. -XX:+CMSConcurrentMTEnabled
E.g. “kill -9 %p” on Unix or “taskkill /F /PID %p” on Windows. Use multiple threads for concurrent phases. - Options for “deterministic” CMS, they disable some heuristics and
require careful validation