JFR, jcmd, VisualVM: which tool for Java memory problems
In this series, we have already used about six tools: GC logs, jstat, several jcmd commands, Eclipse MAT. Each one answers a clear question, and each one has a cost. This post puts them in order. Then it shows JFR, the most complete tool of the JDK, on an example: find the method that creates millions of objects. Which tool for which question Question Tool Command Cost Does the GC make long pauses? Does the heap after GC go up? GC logs -Xlog:gc*:file=gc.log keep it on in production Which area fills up, live? jstat jstat -gcutil <pid> 1s not given; its doc says “experimental and unsupported” How much heap is used? jcmd jcmd <pid> GC.heap_info medium Which class grows? jcmd jcmd <pid> GC.class_histogram high: runs a full GC What keeps the objects alive? heap dump + Eclipse MAT jcmd <pid> GC.heap_dump high: a big file Does the Metaspace grow? jcmd jcmd <pid> VM.metaspace medium What does native memory do? jcmd + NMT -XX:NativeMemoryTracking=summary, then jcmd <pid> VM.native_memory medium What do the threads do? jcmd jcmd <pid> Thread.print medium Which method allocates, where are the pauses, over time? JFR -XX:StartFlightRecording, then jfr view low with the default configuration The “medium” or “high” cost of the jcmd commands is the one given in their documentation. Each of these tools was already used in a post: GC logs, OutOfMemoryError, memory leaks and the heap dump with Eclipse MAT. ...