Commonly used JVM Options
Understanding memory usage has more options to diagnose out of memory errors, garbage collection pauses and JIT compilation
Java heap size
Set heap with respect to garbage collection
-XX:-OmitStackTraceInFastThrow no StackTrace for implicit exceptions thrown by JVM, e.g. NullPointerException, ArithmeticException, ArrayIndexOutOfBoundsException, ArrayStoreException or ClassCastException.
- permit (default) - generates warning only when the first illegal access was detected
- warn - emit warning after each illegal access detection
- debug - add stack trace to warning
- deny - like debug for the first detection, then killing the program.
Java 16 deprecates
--illegal-accessflag, via work done for JEP403 - may still be useful for 3rd party Java libraries.
Enable class data sharing
Handling ‘OutOfMemory’ Error
Generating a Heap Dump for out of memory (OOM) issues is recommended for production systems, to provide data for a deep analysis of the problem. Generating a heap dump does not add overhead to the running JVM.
Trace classloading and unloading
Profiling JVM processes provides a fine-grained view of application execution and resource utilization. Monitor parameters including Method Executions, Thread Executions, Garbage Collections and Object Creations.
Skip byte code verification
The byte code for each class loaded by the JVM Class Loader is verified, which is a relatively expensive task at startup. Adding classes on the boot classpath skips the cost of the verification, although also introduces a security risk so should only be used when classes have been previously verified.
- Uninitialized Variables
- Access rules for private data and methods are not violated
- Method calls match the object Reference
- There are no operand stack overflows or under-flows
- Arguments to all JVM instructions are valid types
- Final classes are not subclassed and final methods are not overridden
- field and method references have valid names, valid classes and valid type descriptor
Enable the garbage collection logging to capture detailed statistics, e.g. type of garbage collector, how often memory is restored and how much time memory was held for. Garbage collection can last several milliseconds, so logging is useful for latency-sensitive processes.
-verbose:gc- logs garbage collector runs and how long they're taking.
-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.
Consider using LMAX disruptor for a Garbage Collection free architecture for ultra latency-sensitive applications