Common JVM Arguments

Let’s discuss some of the important JVM arguments.

Heap Size

Please visit Heap for better understanding of the below arguments.

Xms
This species the initial size of heap.
For Example, -Xms2048m means an initial heap size of JVM is 2GB.
-Xmx
This option is to specify the maximum heap size of JVM, e.g., -Xmx2048m means a maximum heap size of JVM will be 2GB.
-XX:NewRatio
sets the ratio of old/new generation sizes. The default value is 2.
-XX:SurvivorRatio
sets the ratio of eden/survivor space size. The default value is 8.
Screen Shot 2020-02-07 at 9.36.39 PM
Non Heap Size – Method Area

Please visit the Method Area for better understanding of the below arguments.

-XX:PermSize
This option is to specify the initial size of PermGen space.
Please note that PermGen space is replaced by Metaspace in Java 8 and this option is not relevant if you are using Java 8.
-XX:MaxPermSize
This option is to specify the maximum size of PermGen space.
Please note that PermGen space is replaced by Metaspace in Java 8 and this option is not relevant if you are using Java 8.
Please visit Metaspace for better understanding of the below arguments.
-XX:MetaspaceSize
sets the initial (and minimum size) of the Metaspace. It is introduced in Java 8.
-XX:MaxMetaspaceSize
sets the maximum size of the Metaspace.It is introduced in Java 8.
Print GC Activities

-verbose:gc

This JVM option is used to enable Garbage collection logging in your Java application

-XX:-PrintGC

It will simply print a message out every time a garbage collection event is performed.

-XX:+PrintGCDetails

includes the data from -verbose:gc but also adds information about the size of the new generation and more accurate timings.

-XX:-PrintGCTimeStamps

Print timestamps at garbage collection.

Specify Garbage Collector (GC) Type

JVM provide following type of Gargabe collector

  • Serial Garbage Collector (-XX:+UseSerialGC)
  • Parallel Garbage Collector (-XX:+UseParallelGC)
  • CMS Garbage Collector (XX:+USeParNewGC)
  • G1 Garbage Collector (XX:+USeG1GC)
Handling Out of Memory

-XX:+HeapDumpOnOutOfMemoryError

This JVM option creates a heap dump when your JVM dies with OutOfMemory Error. This flag is a must for production systems as it is often the only way to further analyze the problem. It instructs the JVM to dump heap into physical file in case of OutOfMemoryError

-XX:HeapDumpPath

The heap dump will be generated in the current directory of the JVM by default.

If you want to create heap dumps on specific directory then use -XX:HeapDumpPath=[path-to-heap-dump-directory]

e.g. -XX:HeapDumpPath=/dsk/heap/dumps.

-XX:OnOutOfMemoryError

This is used to issue emergency commands to be executed in case of out of memory error; proper command should be used in the space of cmd args.

-XX:+UseGCOverheadLimit

This is a policy that limits the proportion of the VM’s time that is spent in GC before an OutOfMemory error is thrown

Trace classloading and unloading

-XX:+TraceClassLoading and -XX:+TraceClassUnloading are two JVM options that we use to print logging information whenever classes loads into JVM or unload from JVM. 

Misc

-XX:+UseStringCache

Enables caching of commonly allocated strings. This option was removed from JDK 8   with no replacement.

-XX:+PrintCompilation

This prints out the name of each Java method Hotspot decides to JIT compile.

Leave a Reply

Your email address will not be published. Required fields are marked *