If you have to choose only one tool to troubleshoot Java memory related issues, you must choose the ‘verbose gc logs’. Verbose GC log has so much information that you can diagnose almost all types of memory issues just by carefully reviewing the data in this file. It is such a valuable tool.
What’s more? The load exerted on the JVM due to verbose GC logging is virtually nothing. So, don’t skimp on enabling verbose gc logs when you need to.
What exactly do the verbose GC logs reveal?
In addition to numerous other metrics, verbose GC logs reveal the following important metrics:
1. GC frequency (how often GC kicks in, both minor and major collections)
2. GC duration (how long each GC cycle takes to finish)
3. Before and After memory utilization of various generations following every GC cycle
Just with the above three metrics, you can pretty much tell what’s going on with the memory
How to enable verbose GC logs ?
Just add the following java command line option
-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
Two important notes:
1. –verbose:gc works for all implementations of JVM (HP, IBM etc). However the other two options are not guaranteed to work for non-Oracle JVMs
2. As usual, Oracle states that the output produced by the above options is subject to change in future releases.
You must restart your application to have the change take effect.
Where does the verbose gc logs go ?
By default, verbose gc collection logs go to the standard out (in case of IBM JVM, native_stderr.log).
However, you can override this by specifying a specific log file using the following options
Next let us look at the step by step instructions to troubleshoot memory issues by analyzing verbose gc logs
Previous: Troubleshooting GC: Native Memory issues