🔙

jvm flags

Recently, I needed to decrease the time of stop the world stage during GC work. During work on the problem, I found out many interesting jvm flags. In order to save the information in one place, I created a table with them.

type category name description
memory common -Xms<size>[k|m|G] the initial heap size
-Xmx<size>[k|m|G] maximum heap size
-Xss<size>[k|m|G] execution stack size
-XX:NewRatio=<N> the ratio between old generation (tenured) and new generation
-XX:MinHeapFreeRatio=<N> minimum ratio between free space to decrease size of generation
-XX:MaxHeapFreeRatio=<N> minimum ratio between free space to increase size of generation
new generation -Xmn<size>[k|m|G] size of new generation memory
-XX:NewSize=<size>[k|m|G] minimum size of young generation memory
-XX:MaxNewSize=<size>[k|m|G] maximum size of young generation memory
-XX:SurvivorRatio=<N> $$ ratio = \frac{\text{eden}}{\text{survivor} * 2} $$
-XX:YoungGenerationSizeIncrement=<N> percent of increasing young generation
old generation -XX:TenuredGenerationSizeIncrement=<N> percent of increasing old generation
metaspace -XX:MaxMetaspaceSize=<size>[k|m|G] size of metaspace
-XX:+CMSClassUnloadingEnabled unload unused classes from the memory
garbage collection common -XX:+ScavengeBeforeFullGC perform GC for young generation area before Full GC
-XX:+CMSScavengeBeforeRemark perform GC for young generation area before remark> stage
-XX:-DisableExplicitGC disable System.gc()
-XX:CMSInitiatingOccupancyFraction=<N> load factor of Tenured> area to run GC
-XX:InitiatingHeapOccupancyPercent=<N> load factor of heap area to run mark stage
-XX:GCHeapFreeLimit=<N> free memory limit after full GC. In case if size of free memory is less, OutOfMemoryError occurs
-XX:-UseGCOverheadFreeLimit activity limit of GC. In case if GC takes more time, OutOfMemoryError occurs
-XX:GCTimeLimit=<N> time limit for GC. If GC time exceeds this limit, OutOfMemoryError occurs. This ratio is between summary time of execution app and GC time
Serial GC -XX:+UseSerialGC enable Serial GC
Parallel GC -XX:+UseParallelGC enable Parallel GC
-XX:MaxGCPauseMillis=<N> maximum time interval between GC
-XX:GCTimeRatio=<N> the ratio between GC time and time of execution application. $$ \text{GC} = \frac{1}{1+\text{N}} $$
Concurrent Mark and Swap -XX:+UseConcMarkSweepGC enable Concurrent Mark and Swap GC
-XX:+UseParNewGC use parallelism during GC on new generation area
-XX:ParallelGCThreads=<N> count of threads for parallel GC execution
-XX:ConcGCThreads=<N> total count of threads for GC
-XX:+CMSScavengeBeforeRemark run remark stage after GC execution on new generation area
-XX:CMSWaitDuration run GC on tenured are after GC execution on new generation
Garbage First -XX:+UseG1GC enable G1
-XX:MaxGCPauseMillis=<N> Maximum interval between GC pauses
-XX:GCPauseIntervalMillis=<N> Maximum interval between G1 executions
-XX:G1HeapRegionSize=<size>[k|m|G] heap memory size
-XX:ParallelGCThreads=<N> count of threads for parallel GC execution
-XX:ConcGCThreads=<N> total count of threads for GC
GC logging -verbose:gc enable printing GC information
-Xloggc:<filename> save logs into a file
-XX:+UseGCLogFileRotation> enable log rotation
-XX:+HeapDumpBeforeFullGC create memory before full GC stage
-XX:NumberOfGCLogFiles=<N> count of log files
-XX:+PrintGCDetails print more details about GC
-XX:+PrintGCDateStamps add time to logs
-XX:+PrintGCApplicationConcurrentTime time that taken by GC in case when all treads of application were working
-XX:+PrintGCApplicationStoppedTime stop the world time
other -XX:+PrintFlagsFinal print passed jvm flags
-XX:+HeapDumpOnOutOfMemoryError make dump before unexpected termination due to OutOfMemoryError
-XX:HeapDumpPath=dump.hprof make dump before unexpected termination due to OutOfMemoryError
-XX:+CompileThreshold=<N> count of executions that have been done until JIT optimizations are applied
-XX:+UseCompressedOops compact references in order to decrease memory usage
-XX:+OptimizeStringConcat use StringBuilder instead of + operator
-XX:+PrintCompilation show optimization levels of JIT
-XX:+AggressiveOpts aggressive optimization level
-XX:+UseStringCache cache strings
jmap tool run jmap <pid> get information about memory usage
flags -heap information about a whole heap
-histo information about memory usage in terms of each classes
-histo:live information about live objects
-dump:live,format=b,file=heap.hprof save dump into a file

\(\text{heap} = \text{young generation} + \text{old generation}\)
\(\text{young generation} = \text{eden} + \text{survivor} * 2\)
\(\text{survivor ratio} = \frac{ \text{eden}}{\text{survivor} * 2}\)