Thursday 28 May 2015

JVM Instrumentation Tools

In this blog, I shall talk about a few popular testing/debugging tools from java application instrumentation perspective running on Java Virtual Machines (JVM). The blog implicitly refers to Oracle's Hotspot JVM wherever applicable. Hence, tools specific to Oracle's JDK shall be discussed here.

General

jps - JVM Process Status tool
Use this command to figure out the running instrumented JVM instances running on your local/remote server. Refer here for more details.

jstat - Java Virtual Machine statistics monitoring tool
Displays performance statistics of an instrumented JVM reported above. Refer here for more details.

Statistics about classloader, compiler, garbage collector etc., can be viewed through this command

jstack - Thread dump of the JVM
Use this tool to get the thread dump with stack trace of the JVM at any given moment. Refer here for more details.

jinfo - Configuration Info
The Java specific configuration information about the JVM is displayed through this command. Refer here for more details.

Memory

jmap - JVM heap dump tool
Use this tool to collect the heap dump of the JVM. Details about the shared object mapping, object size and instances can be obtained through this tool. As of Java 8, this is an experimental and unsupported tool. Refer here for more details.

jhat - Java Heap Analysis Tool
The dump generated using the above (jmap) tool can be analyzed by this tool. Refer here for more details. It analyses the dump and provides a web service (by default runs on 7000) for users to explore the dump through their favorite web browser.

CPU

TODO

Custom

Thread Count Summary
Using a combination of the above tools, I have written a simple shell script to determine the summary of the non-daemon thread count during the execution of JVM. The script can be accessed from my gist page .

Usage:
    sh thread_cnt_summary.sh <vmid> [interval] [count]
        vmid - Virtual Machine Identifier, string that indicates the target JVM
        interval - Sampling interval in seconds
        count - Number of samples to display

Heap Usage Summary

There are various tools like jConsole, jVisualVM etc., that provides details about the heap memory usage. Tools like jmap, jstat etc., provide point in time analysis of java heap memory. I could not find a suitable CLI based tool that helps to monitor the live heap memory usage of the JVM during the execution. Hence, created a wrapper around jmap to monitor java heap memory usage. This includes Eden, Survivor 1 & 2 and the tenured generation spaces.
The tool can be located at my gist page.