OpenJDK 9: Life Without HPROF and jhat
OpenJDK is decommissioning the HPROF agent and removing the 'jhat' tool from the JDK. This is a result of the modularization coming to OpenJDK 9’s Java SE Platform in the form of Project Jigsaw; in order to prepare for modularization, multiple proposals (JEPs) were drafted and many have already reached completion.
Let’s take a closer look at two JEPs that relate to the modular JDK, aimed at removal of the HPROF agent and the ‘jhat’ tool:
HPROF is a profiler agent that uses the JVM Tool Interface (JVMTI) to demonstrate the tool interface and usage of Bytecode Instrumentation. The HPROF agent can write profiling information to a file, such as heap usage based on allocation sites, heap dumps, CPU usage, monitor contention, etc. or send it over a socket. HPROF was not intended to be a production tool; it has been superseded by various other alternatives as documented below:
HPROF would be able to obtain heap allocation profiles and CPU usage sampling and times profiles by the following commands in their simplest forms (respectively):
java -agentlib:hprof=heap=sites <classname> java -agentlib:hprof=cpu=samples <classname> java -agentlib:hprof=cpu=times <classname>
The corresponding functionality can also be provided by Java performance monitoring tool VisualVM, a visual tool that integrates several command line JDK tools and lightweight profiling capabilities. Unlike HPROF, VisualVM is intended for use in production as well as development, and provides additional features such as generation of thread (and heap) dumps, browsing heap dumps, local and remote Java application monitoring, offline performance analysis, etc.
The HPROF tool also generates heap dumps by the following command:
java -agentlib:hprof=heap=dump <classname>
According to JEP 240, this functionality is superseded by the same functionality in the JVM by using the command line utilities such as ‘jcmd’ and ‘jmap’ as shown below:
jcmd GC.heap_dump filename=<filename>
jmap [option] <pid> where <option>: -dump:<dump-options> to dump java heap in hprof binary format dump-options: live dump only live objects; if not specified, all objects in the heap are dumped. format=b binary format file=<file> dump heap to <file> Example: jmap -dump:live,format=b,file=heap.bin <pid>
According to the ‘jcmd’ utility document, ‘jcmd’ is the recommended tool to use in order to create a heap (hprof) dump.
‘jhat’ is a heap analysis tool that parses a Java heap dump and enables web-browsing a parsed heap dump. With ‘jhat’, the user can choose to execute a few standard queries or write their own using the OQL interface.
According to JEP 241, jhat is an experimental, unsupported, and out-of-date tool. Although the JEP doesn’t specify any particular replacement tool, InfoQ would once again point users to Java VisualVM for heap dump creation, visualization and analysis. VisualVM also allows users to execute their own queries or use the standard ones.
We will be providing additional coverage of the above mentioned use-cases in upcoming items.
For heap dump analysis Eclipse MAT is a great jhat alternative