Hi,
Many times we want to Generate the Heap Dump to see what all objects are created inside the JVMs Heap space. The Heap Dump tells us that what all objects are created inside the JVM and what is the size of those Objects. Based on this analysis we can findout that what all objects (Application Objects/Platform Objects) are consuming more memory inside the heap.
Here is a Basic Step to enable the Jhat tool to generate the Heap Dump of our WebLogic Server and a brief intro of using this Great and wonderful tool.
Jhat tool comes free and available inside the “<JAVA_HOME>bin” directory (from JDK1.6 onwards only). If you are using Jdk 1.5 or Lower version then u need to separately download the Jhat tool.from “https://hat.dev.java.net/“
.
.
Step1). Open the “startWebLogic.sh”(Unix Based OS) or “startWebLogic.cmd”(Windows OS) and then add the JAVA_OPTIONS inside it as following:
@REM **********WINDOWS Operating Systems<(startWebLogic.cmd)******************
@REM @REM Call setDomainEnv here. set DOMAIN_HOME=C:bea103user_projectsdomainsWS_Security_Domain for %%i in ("%DOMAIN_HOME%") do set DOMAIN_HOME=%%~fsi call "%DOMAIN_HOME%binsetDomainEnv.cmd" %* set SAVE_JAVA_OPTIONS=%JAVA_OPTIONS% -Xrunhprof:format=b,file=MyHeapDump.hprof set SAVE_CLASSPATH=%CLASSPATH%
#************Unix Based Operating Systems<(startWebLogic.sh)***********
# # Call setDomainEnv here. DOMAIN_HOME="C:/bea103/user_projects/domains/WLST_Domain" . ${DOMAIN_HOME}/bin/setDomainEnv.sh $* SAVE_JAVA_OPTIONS="${JAVA_OPTIONS}" -Xrunhprof:format=b,file=MyHeapDump.hprof SAVE_CLASSPATH="${CLASSPATH}"
Step2). Now restart Your Server. As soon as you will start your Server you will find that “MyHeapDump.hprof” file is created inside your <DOMAIN_HOME> root directory:
Step3). Open the HeapDump using the Jhat tool like following:
C:bea103jdk160_05bin>jhat -J-mx1024m C:bea103user_projectsdomainsWS_Security_DomainMyHeapDump.hprof
OR place the file in some other location before opening it…
C:bea103jdk160_05bin>jhat -J-mx1024m C:myHeapDumpsMyHeapDump.hprof
.
Step4). As soon as u run the Obove command jhat tool starts a Http Server on default port 7000…Please open a browser with the following URL:
http://localhost:7000
.
.
***** **** *** **____Advanced Jhat Analysis____ ***** **** *** **
.
Step5). Object Query Language (OQL)
OQL is SQL-like query language to query Java heap. OQL allows to filter/select information wanted from Java heap. While pre-defined queries such as “show all instances of class X” are already supported by HAT, OQL adds more flexibility. OQL is based on JavaScript expression language.
OQL query is of the form
select <JavaScript expression to select>
[ from [instanceof] <class name> <identifier>
[ where <JavaScript boolean expression to filter> ] ]
==================================================
========================================================
Issues U May Face While Using Jhat for Analysis:
Issue-1). While reading Heap Dump using Jhat u may find following error:
.
Reading from C:bea103user_projectsdomainsTest_DomainMyHeapDump.hprof…
Dump file created Sun Jul 11 20:22:53 IST 2010
java.io.IOException: Unrecognized heap dump sub-record type: 0at com.sun.tools.hat.internal.parser.HprofReader.readHeapDump(HprofReader.java:489)at com.sun.tools.hat.internal.parser.HprofReader.read(HprofReader.java:226)at com.sun.tools.hat.internal.parser.Reader.readFile(Reader.java:79)at com.sun.tools.hat.Main.main(Main.java:143)
Solution: Most of the time this means that the VM did not write the heap dump properly. At some point in the file, everything is zeroed out, hence the unknown sub-record type 0. There is not much you can do but get another heap dump. Or try to download “Eclipse Memory Analyzer(http://www.eclipse.org/proposals/memory-analyzer/) and just say file—>open—>MyHeapDump.hprof “
.
Issue-2). While Killing your Server Profiler will try to generate the HeapDump (around 30 MB minimum size with WLS Server) you may get the following error in the WLS Server stdout:
.
HPROF ERROR: Missing jclass when fields needed [hprof_class.c:647]HPROF ERROR: Trouble with unprepared classes [hprof_reference.c:384]HPROF ERROR: Missing jclass when fields needed [hprof_class.c:647]HPROF ERROR: Trouble with unprepared classes [hprof_reference.c:384]allocation sites … done.<Jul 11, 2010 8:11:06 PM IST> <Error> <> <BEA-000000> <THREAD DUMP from JVM taken at ‘Sun Jul 11 20:07:47 2010’>
Solution: Please collect another Heap Dump or use “Eclipse Memory Analyzer”
—————————-
WORKAROUND
——————————————————-
Use the “Jmap” utility (Which comes with JDK1.6 default or download it separately) to generate the Binary Heap Dump File and then read it using Jhat tool…. http://middlewaremagic.com/weblogic/?p=2241
.
Why “Jmap”?
Jmap is much better than Jhat utility because to start with Jmap utility u need not to apply any JAVA_OPTION on the WebLogic Server … you can directly start with any WebLogic Server which is Running on Sun JDK …. All u need to do is …Just find the Process ID of that WLS Server…thats all.
.
.
Step1). Find the process ID of your Server.
Step2). Run the following command: (Suppose 5552 is the Process ID of your Server Process)
C:bea103jdk160_05bin>jmap -dump:format=b,file=heapJMap.bin 5552
Dumping heap to C:bea103jdk160_05binheapJMap.bin …
Heap dump file created
Step3). Make sure that while reading the Binary Heap Dump using JHat …u set the Heap Size to 1024 or according to the Heap dump size….
C:bea103jdk160_05bin>jhat -J-Xmx1024m heapJMap.bin
Reading from heapJMap.bin…
Dump file created Mon Jul 12 10:05:58 IST 2010
Snapshot read, resolving…Chasing references, expect 239 dots………….
…………………………………………
Eliminating duplicate references…………….
…………………………………………
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
=================================================
.
.
Thanks
Jay SenSharma
January 4th, 2011 on 9:56 pm
hi ,
can we use virtualgc also for heap dump?
January 4th, 2011 on 11:21 pm
Hi Abhishek,
VisualGC is another best tool which can be used for the analysis of a Running JVMs memory utilization. But it cannot be used to Analyze the HeapDump. HeapDump is a binary file which contains the snapshot of the JVM Memory and the object placed inside it.
To know more about you can refer to : http://java.sun.com/performance/jvmstat/visualgc.html
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
February 24th, 2011 on 9:21 pm
Hi Jay
I have a question here. How much resource a JHat or VisualGC process eat.
Thanks
February 24th, 2011 on 11:18 pm
Hi Pintuusa,
JHat is a Heap Dump analysis tool and it’s a postmortem analysis tool. It’s best only when you have the Heap Dump already. It is not recommended to use in production. Similarly visualGC is again a profiling tool.
Any profiling tool is not recommended to be used in production environments. I don’t have exact Data how much performance impact these tools will cause. Guessing will not be useful , So the exact data can be collected only after a performance testing with & without these profilers.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 23rd, 2012 on 7:52 pm
hi jay,
please guide me basics on how to analyze as there is tons of data AFTER RUNNING JHAT.
March 12th, 2013 on 11:27 am
I ran JHAT command after creating the HeapDump using JMAP.
below is what I ran it gives me below error.Can you suggest on this soon..
#/data/oracle/jdk1.6.0_24/bin/jhat -J-Xmx1024m /data/oracle/user_projects/domains/domainName/bin/heapJmap.bin
Reading from /data/oracle/user_projects/domains/domainName/bin/heapJmap.bin…
Dump file created Tue Mar 12 01:44:12 EDT 2013
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.sun.tools.hat.internal.parser.HprofReader.readInstance(HprofReader.java:726)
at com.sun.tools.hat.internal.parser.HprofReader.readHeapDump(HprofReader.java:474)
at com.sun.tools.hat.internal.parser.HprofReader.read(HprofReader.java:226)
at com.sun.tools.hat.internal.parser.Reader.readFile(Reader.java:79)
at com.sun.tools.hat.Main.main(Main.java:143)
I also tried using the Options as :
#/data/oracle/jdk1.6.0_24/bin/jhat -J-Xmx2048m /data/oracle/user_projects/domains/domainName/bin/heapJmap.bin
it gives a Continues warning as below.My .bin file is of 417 MB.what is wrong with it???
WARNING: Failed to resolve object id 0x7e9cb2c28 for field localPart (signature L)
WARNING: Failed to resolve object id 0x7e8db8b90 for field namespaceURI (signature L)
WARNING: Failed to resolve object id 0x7e8110d38 for field name (signature L)
WARNING: Failed to resolve object id 0x7e8442110 for field name (signature L)
Thanks.
Kamlesh.
March 12th, 2013 on 11:45 am
I also tried using the Options as :
#/data/oracle/jdk1.6.0_24/bin/jhat -J-Xmx2048m /data/oracle/user_projects/domains/domainName/bin/heapJmap.bin
it gives a Continues warning as below.My .bin file is of 417 MB.what is wrong with it???
WARNING: Failed to resolve object id 0x7e9cb2c28 for field localPart (signature L)
WARNING: Failed to resolve object id 0x7e8db8b90 for field namespaceURI (signature L)
WARNING: Failed to resolve object id 0x7e8110d38 for field name (signature L)
WARNING: Failed to resolve object id 0x7e8442110 for field name (signature L)
October 4th, 2013 on 2:58 am
Hello Jay,
This is the best blog ever.
I was reading about the taking and analyzing the thread dumps on middleware magic. It is very very helpfull.
Through your discussion you mentioned we dont use Jhat or Jmap in production to take the heap dumps. What are the best tool available and used to take the thread dump and can you also tell us how to find out a rootcaue and resolve the issue after analyzing the thread dumps.
April 22nd, 2014 on 1:28 pm
Hi Jay,
Can you tell how to find the list of class loaders using OQL.I refer this page http://blog.bosch-si.com/debugging-dynamic-classloaders-in-heap-dumps/.It is not working.
Thanks,
Krish