0% found this document useful (0 votes)
63 views

Java 7 - GC Cheatsheet

This document provides a summary of Java Virtual Machine (JVM) options for configuring garbage collection and memory usage. It lists the available garbage collection algorithms and combinations in HotSpot JVM. It also describes JVM memory areas and various JVM flags for configuring garbage collection logging, memory sizing, and garbage collection tuning.

Uploaded by

cososchi.stefan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Java 7 - GC Cheatsheet

This document provides a summary of Java Virtual Machine (JVM) options for configuring garbage collection and memory usage. It lists the available garbage collection algorithms and combinations in HotSpot JVM. It also describes JVM memory areas and various JVM flags for configuring garbage collection logging, memory sizing, and garbage collection tuning.

Uploaded by

cososchi.stefan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

HotSpot JVM options 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

GC log detail options GC Log rotation Memory sizing options


-verbose:gc or -XX:+PrintGC Print basic GC info -Xloggc:<file> Redirects GC output to a file instead of console -Xms256m or -XX:InitialHeapSize=256m
Initial size of JVM heap (young + old)
-XX:+PrintGCDetails Print more details GC info -XX:+UseGCLogFileRotation Enable GC log rotation
-Xmx2g or -XX:MaxHeapSize=2g
-XX:+PrintGCTimeStamps Print timestamps for each GC -XX:GCLogFileSize=512m Size threshold for GC log file Max size of JVM heap (young + old)
event (seconds count from start of JVM)
-XX:NumberOfGCLogFiles=5 Number GC log files -XX:NewSize=64m Absolute (initial and max) size of
-XX:+PrintGCDateStamps Print date stamps at garbage More logging options -XX:MaxNewSize=64m young space (Eden + 2 Survivours)
collection events: 2011-09-08T14:20:29.557+0400: [GC...
-XX:+PrintTenuringDistribution Print detailed -XX:NewRatio=3 Alternative way to specify size
-XX:+PrintReferenceGC Print times for special demography of young space after each collection of young space. Sets ratio of young vs old space
(weak, JNI, etc) reference processing during STW pause (e.g. -XX:NewRatio=2 means that young space will be 2 time
-XX:+PrintTLAB Print TLAB allocation statistics smaller than old space, i.e. 1/3 of heap size).
-XX:+PrintJNIGCStalls Reports if GC is waiting for -XX:+PrintPLAB Print survivor PLAB details -XX:SurvivorRatio=15 Sets size of single survivor space
native code to unpin object in memory
relative to Eden space size
-XX:+PrintOldPLAB Print old space PLAB details (e.g. -XX:NewSize=64m -XX:SurvivorRatio=6 means that each
-XX:+PrintGCCause Add cause of GC in log Survivor space will be 8m and Eden will be 48m).
-XX:+PrintGCTaskTimeStamps Print timestamps for
-XX:+PrintAdaptiveSizePolicy -XX:PermSize=512m Initial and max size of
individual GC worker thread tasks (very verbose)
Print young space sizing decisions -XX:MaxPermSize=1g JVM’s permanent generation
-XX:+PrintHeapAtGC Print heap details on GC
-XX:+PrintPromotionFailure -Xss256k (size in bytes) or Thread stack size
Print additional information for promotion failure -XX:+PrintHeapAtSIGBREAK Print heap details on signal -XX:ThreadStackSize=256 (size in Kbytes)
-XX:+PrintGCApplicationStoppedTime -XX:+PrintClassHistogramAfterFullGC -XX:InitialCodeCacheSize=256m Initial size and max
Print summary after each JVM safepoint (including non-GC) Prints class histogram after full GC -XX:ReservedCodeCacheSize=512m size of code cache area

-XX:+PrintGCApplicationConcurrentTime -XX:+PrintClassHistogramBeforeFullGC -XX:MaxDirectMemorySize=2g Maximum amount


Print time for each concurrent phase of GC Prints class histogram before full GC of memory available for NIO off-heap byte buffers

- Highly recommended option - Highly recommended option

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

You might also like