X

Sundararajan's Weblog

  • Java
    February 17, 2006

Yes, there is also fifth way :-)

Guest Author

In my previous post on heap histograms, I missed another way to view histogram. Thanks to Alan Bateman for pointing out the same in his comment! Here it is:

The fifth way!
Use the heapViewer demo JVM TI agent shipped with JDK.


On Windows:
java -agentpath:%JAVA_HOME%\\demo\\jvmti\\heapViewer\\lib\\heapViewer.dll MainClass
On Unix:
java -agentpath:$JAVA_HOME/demo/jvmti/heapViewer/lib/libheapViewer.so MainClass

where JAVA_HOME is the directory where your JDK is installed. This heapViewer agent prints histogram whenever SIGQUIT signal is sent to the Java process or when the Java process exits (normal exit or Ctrl-C). Sample output of the heapViewer agent is in this blog entry by Alan.

You can look at the source code of this heapViewer agent under $JAVA_HOME/demo/jvmti/heapViewer/src directory. If you want to learn about JVM TI agents, you may want to read Kelly's blog on agents.

Join the discussion

Comments ( 2 )
  • Alan Friday, February 17, 2006
    How about the debugger APIs? In Mustang the Java Debug Interface (JDI) was updated to allow for some limited heap profiling capabilities in the debugger. A histogram should be relatively easy as the instance counts are readily available with code like this:

    List<ReferenceType> allClasses = vm.allClasses();
    long[] counts = vm.instanceCounts(allClasses);

    If you sort the classes and counts by descending count then you end up with a class-wise histogram. Does this qualify as a 6th way :-)

  • A. Sundararajan Saturday, February 18, 2006
    Alan: we can't get sizeof individual objects using JDI (can we? do I miss any API?). Hence, sum of instance sizes (by which histograms are normally sorted) can't be computed :-) But, I agree that it is good to highlight debugger APIs for heap walking. Thanks for highlighting the same!
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.