Yes, there is also fifth way :-)

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.

Comments:

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 :-)

Posted by Alan on February 17, 2006 at 01:46 PM IST #

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!

Posted by A. Sundararajan on February 18, 2006 at 01:19 PM IST #

Post a Comment:
Comments are closed for this entry.
About

sundararajan

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks
Links

No bookmarks in folder

Blogroll

No bookmarks in folder

News

No bookmarks in folder