Let’s discuss some of the important JVM arguments.
Heap Size
Please visit Heap for better understanding of the below arguments.
Non Heap Size – Method Area
Please visit the Method Area for better understanding of the below arguments.
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.