Yes, there is also fifth way :-)
By sundararajan on Feb 17, 2006
The fifth way! Use the heapViewer demo JVM TI agent shipped with JDK.
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.
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
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.