Monday, April 23, 2007

Using JHAT tool to analyze process running on JDK5.

JHAT is available only with JDK6. However it is possible to use this tool for analysis of a process running on JDK6.

Steps to use HAT tool on JDK5 in association with jHAT on JDK6.
**********************************************************

1. setup environment variables
------------------------------
$ export SA=/net/${JDK5_HOST}/tools/bin/sa15
$ export SA_HOME=/net/${JDK5_HOST}/tools/bin/sa15
$ export SA_JAVA=/net/${JDK6_HOST}/usr/jdk/entsys-j2se/bin/java

2. verify variables are set correctly
-------------------------------------
$ echo $SA ; echo $SA_HOME ; echo $SA_JAVA
/net/${JDK5_HOST}/tools/bin/sa15
/net/${JDK5_HOST}/tools/bin/sa15
/net/${JDK6_HOST}/usr/jdk/entsys-j2se/bin/java

3. generate preload_mappings thru dbx
-------------------------------------
$ /net/${JDK5_HOST}/${DBX_HOST}/bin/dbx -xexec32 -s dbxrc
(dbx) source /net/${JDK5_HOST}/tools/bin/dbxscripts/gen_pm.txt
(dbx) gen_pm
preload_mappings have been generated.
(dbx) quit

4. Generate core file using gcore to a running pid for processes that have not dumped core.

5. Use heapdumpproc.sh to generate heap.bin
--------------------------------------------
$ /net/${JDK5_HOST}/tools/bin/sa15/heapdumpproc.sh executable corefile

6. Start the http server
------------------------
/net/${JDK6_HOST}/${JAVA_HOME}/bin/jhat heap.bin

7. Review the heap dump at http://localhost:7000 - This is the default port.

Note:
------
* Results reported by this approach on JDK5 JVM may not be 100% accurate.
* The results are more accurate if the core is generated by a process crash instead of using gcore on a running pid.

No comments: