Hi,
Note: Jmap will not work for Any kind of Windows Service so please refer to the following article to know how to generate HeapDump in case of Windows Services : How to Generate HeapDump in case of Windows Service ?
Here is a Simple Demonstration of using JMap to Generate the Binary heap Dump…Which we will analyze later using Jhat tool. These tools are very common and freely available for Download porpose. But from Sun JDK 1.6 Onwards it is by default available inside “<JAVA_HOME>bin” directory.
What is Jmap And Why Not Jhat?
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.
Jmap generates the Heap Dump Much faster than Jhat.
Jhat HeapDumps sometimes are seen as currupted file…But jmap is more reliable and generates the correct Heap Dump file. (correct heap dump generation percentage wise it is better than Jhat)
Step1). Start a Weblogic Server instance normally on your Local Machine and then find the Process ID (PID).
Step2). If you are using Unix Based Operating System then u can find out the Process ID (PID) by running the following Command:
ps -ef | grep java
If you are using Windows then follow the below Steps to find out the Process ID (PID):
a) Press “Ctrl+Alt+Del” 2 buttons together.
b) Press the “Task Manager” Button
c) Click on “Processes” Tab.
d) Now Select the Menu Item “View” — > “Select Columns”
e) Check the “PID (Process Identifier)” Check box as well…
f) Now u can see the Process Id of “java.exe” in the “Processes” Tab.
Step3). Start the “JMap” tool from “<JAVA_HOME>bin” directory as following:
C:bea103jdk160_05bin>jmap -dump:format=b,file=heapJMap.bin 7540
Note: use -J-d64 jvm option if your JVM is 64 Bit Jvm “jmap -J-d64 -heap pid”
Step4). To Read the Binary Heap Dump File … Jhat is one of the Best Tool… Please run the following command to inoke the “jhat” tool Http Server by passing the Heap Dump File name…
C:bea103jdk160_05bin>jhat -J-mx1024m heapJMap.bin
Step5). Now open a Web Browser with the following URL: “http://localhost:7000”
and refer to Post: heap-dump-using-jhat-for-weblogic-server-heap-analysis/
Step6). U can use different options available as part of “jmap” to analyze the Binary heap Dump like
To See the Heap Histogram u can do the following:
You can use some other “Jmap” options as well:
- -finalizerinfo
- Prints information on objects awaiting finalization.
- -heap
- Prints a heap summary. GC algorithm used, heap configuration and generation wise heap usage are printed.
- -permstat
- Prints class loader wise statistics of permanent generation of Java heap. For each class loader, its name, liveness, address, parent class loader, and the number and size of classes it has loaded are printed. In addition, the number and size of interned Strings are printed.
.
.
Thanks
Jay SenSharma
July 23rd, 2010 on 11:07 pm
hi jay,
i try to take heapdump throug jmap on unix box , iam getting the following error , my weblogic is on unixbox
jmap -dump:format=b,file=dump1.bin 6816
Dumping heap to /opt/weblogic/dump1.bin …
Exception in thread “main” java.io.IOException: Premature EOF
at sun.tools.attach.HotSpotVirtualMachine.readInt(HotSpotVirtualMachine.java:226)
at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:175)
at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:195)
at sun.tools.attach.HotSpotVirtualMachine.dumpHeap(HotSpotVirtualMachine.java:162)
at sun.tools.jmap.JMap.dump(JMap.java:224)
at sun.tools.jmap.JMap.main(JMap.java:122)
July 23rd, 2010 on 11:25 pm
Hi Rocky,
This happens some times…we get “java.io.IOException: Premature EOF”… (Which is very common issue) when due to some reasons Jmap or Jhat tools are not able to get the correct Heap Dump. There are many reasons behind this. It is mentioned in the Sun’s JMap that if u see this kind of issue …better try to get another heap dump.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 23rd, 2010 on 11:29 pm
Hi Rocky,
If you are continuously getting the same error then Please try to use a different Jmap tool (Means the Jmap utility available with a different version of JDK or download the Jmap separately) sometimes i have seen this issue with JDK1.6 on unix boxes.
This happens some times…we get “java.io.IOException: Premature EOF”… (Which is very common issue) when due to some reasons Jmap or Jhat tools are not able to get the correct Heap Dump. There are many reasons behind this. It is mentioned in the Sun’s JMap that if u see this kind of issue …better try to get another heap dump.
.
.
Keep Posting :
Thanks
Jay SenSharma
July 24th, 2010 on 12:59 am
Thanks!
July 24th, 2010 on 7:13 pm
Hi Jay. i am using AIX boxes and my JVM is IBM JVM.
Is jmap and jhat utilities running under ibm jvm?
July 24th, 2010 on 8:18 pm
Hi Yusuf,
Jmap and jhat are Sun’s utilities for taking and analyzing Sun Jdk Dumps. IBM jdk has their own utility to analyze the heap dump ..it’s name is “HeapAnalyzer”..U can find it’s screen shot http://www.alphaworks.ibm.com/screenshots/0IN/heapanalyzer01.html?opendocument&techid=0IN
And the details of HeapAnalyzer: http://www.alphaworks.ibm.com/tech/heapanalyzer
I have never tried to use Jmap to collect the heapDump for IBM Jdk using Jmap so i cannot exactly say whether it will work or not. But i will try to find the answer or related information on this … and will let u know.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 24th, 2010 on 8:22 pm
Hi Yusuf,
The following Video presentation says that IBM JVM doesnot generate the Heap Dump using Jmap/Jhat tools. But it Clearly demonstrates how we can take heap dump using IBM JDK…. That will be very interesting to go through…http://publib.boulder.ibm.com/infocenter/ieduasst/v1r1m0/index.jsp?topic=/com.ibm.iea.was_v6/was/6.0.1/PD/WASv601_zOS_Heapdumps/player.html
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 29th, 2010 on 1:54 pm
Hi Jai,
I have configured -Xrunhprof:format=b,file=MyHeapDump.hprof and started the server. Heap dumps are generated fine and while stopping the server it is taking too long time to shutdown.
=====================================================
Dumping Threads..
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]
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]
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]
HPROF ERROR: Missing jclass when fields needed [hprof_class.c:647]
allocation sites … done.
‘script’ is not recognized as an internal or external command,
operable program or batch file.
=======================================================
This is the message I had seen in the dos prompt.
I tried to analyse the generated heap using jhat utility, got the below exception.
========================================================
C:beauser_projectsdomainswork>jhat -J-Xmx1024m MyHeapDump.hprof
Reading from MyHeapDump.hprof…
Dump file created Thu Jul 29 12:39:39 IST 2010
java.io.IOException: Unrecognized heap dump sub-record type: 235
at com.sun.tools.hat.internal.parser.HprofReader.readHeapDump(HprofReader.java:485)
at com.sun.tools.hat.internal.parser.HprofReader.read(HprofReader.java:222)
at com.sun.tools.hat.internal.parser.Reader.readFile(Reader.java:79)
at com.sun.tools.hat.Main.main(Main.java:143)
========================================================
Can you please advise what went wrong here.
Thanks in Advance
Rajendra
July 29th, 2010 on 2:37 pm
Hi Rajendra,
The two Issues which u pointed on “Jhat” as very common issues of this tool. There is no workaround or solution given by sun so far. This is the reason we dont use “jhat” tool to generate the Heap Dumps….
Reason1). We need to add an additional JAVA_OPTION on the Server start Script (So Server requires restart)
Reason2). Jhat is very slow …and some times when a server goes down it stops the process to get Killed …until the Heap Dump is generated completely….Which is very very time taking process.
Reason3). Many times we get an incorrect heapDump….as mentioned in the Issues-1 and issues-2 in the http://middlewaremagic.com/weblogic/2010/07/11/heap-dump-using-jhat-for-weblogic-server-heap-analysis/…
So now people dont use this utility anymore to generate the Heap Dump…. The best way is Use the jmap to generate the Heap Dump and then u can use “jhat” to analyze the Heap Dump…..That is areal best combination of Jhat (Analyzing heap Dump) and Jmap (Collecting heap Dump)…. http://middlewaremagic.com/weblogic/2010/07/12/weblogic-heap-dump-genration-using-jmap/
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
August 23rd, 2010 on 1:43 pm
Hi Jay,
I am using weblogic 8.1 sp5
I am receiving out of memory errors however only 20% of the heap is utilized. probably an issue with fragmentation. and i want to do a heap dump if the issue re-occurs
correct me if i am wrong.
1> Heap dump is to include “-XX:+HeapDumpOnOutOfMemoryError” in the weblogic startup?
2>However, there may be impact on production systems since heap dump is equivalent to performing profiling?
3>Is there any way we can manually generate a heap dump when JAVA OOM was discovered in the application log?
Thanks in Advance
Keshav
August 23rd, 2010 on 2:27 pm
Hi Keshav,
OutOfMemory can be separated in 2 Categories:
1). OutOfMemory in Heap Area: This occurs when the Heap gets filled up with Java Objects and GC becomes ineffective.
2). OutOfMemory in Native Area: This hsppens when the Native Area gets Filled up. Usually JNI codes, Libraries Loading, Thread Traces, Method Trace and ClassLoading kind of things happens in this area.
So if you see that your Heap Utilization is only 20% and still you are getting OutOfMemory then it means It should be “NativeOutOfMemory”. Please refer to some common causes of Native OutOfMemory: http://middlewaremagic.com/weblogic/2009/12/30/jvm-crash-and-native-outofmemory/
Answer 1). -XX:+HeapDumpOnOutOfMemoryError is useful to tell the JVM to generate the heapDump as soon as it encounters the OutOfMemory. Even you can specify the Heap Dump Generation Path: -XX:HeapDumpPath=C:/abc/
But this flag doesnt gurantee that always it will be generate the Heap Dump….Sometimes it may not generate the HeapDump.
Answer 2). There wont be much impact on production by applying this JAVA_OPTION because … this option will start functioning only when we encounter OutOfMemory… (Usually after OOM we must reboot the Servers ….).. Even performance wise there is no side effect seen so far with this JAVA_OPTION.
Answer 3). We can download utilities like “jmap” (which is better & faster than Jhat tool with good performance) to manually generate the HeapDumps whenever we want. Jmap tool comes bydefault along with the Latest JDKs ….You can download them as well.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
December 15th, 2010 on 6:51 am
Hi Jay,
How you will achive the same when some one using JRockit. Is it possible to generate heap dump using Jrockit and analyze using Jhat. If it is then please let me know.
I’ll suggest adding a new topic 😉
Thanks,
Sohel.
December 15th, 2010 on 4:45 pm
Hi Sohel,
I suppose below post would help you
Monitoring Using JRMC Remotely
Regards,
Ravish Mody
December 15th, 2010 on 7:58 pm
Hi Ravish,
Thanks for the reply.
The post is really usefull.
I am wondering how to generate heap dump in Jrockit like we did in SUN jdk using jmap.
Thanks & Regards,
Sohel.
December 15th, 2010 on 8:57 pm
Hi Sohel,
JRockit doesnot have any such feature which can generate a Heap Dump like *.hprof or *.bin or *.dump but may be in near future you can see similar feature in JRockit. But if you want to diagnose the JRockit JVM Activities then you can use JRCMD as described in the following link:
http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/ctrlbreakhndlr.html#wp1001781
Something similar you can achieve using the following commands as well:
jrcmd heap_diagnostics <PID>
jrcmd heapreport <PID>
jrcmd gcreport <PID>
jrcmd print_object_summary <PID>
jrcmd print_class_summary <PID>
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
December 15th, 2010 on 10:01 pm
Hi Jay/Ravish,
Got it. I heard that it isn’t possible using JRockit 😉 , but want to hear the same from an experts like you.
Thank you very much.
Keep posting 🙂
Cheers,
Sohel.
May 3rd, 2011 on 8:56 pm
Hi Guyz,
We’re using Weblogic 11g as a “windows service”. In that case I can only see a beasvcX64.exe process and can’t execute jmap on it.
What are the alternatives to get memory dump in such situation?
Thanks
May 3rd, 2011 on 11:12 pm
Hi fipnova51,
We developed an article based on your requirement….Please refer to : http://middlewaremagic.com/weblogic/?p=6624
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 3rd, 2011 on 11:37 pm
Hi fipnova51,
I must say that was a very good question and it was worth making an article on it, so that others can also get benefits out of it, hence we are pleased to share 20 Bonus Magic Points with you for asking this useful query.
Keep Posting 🙂
Regards,
Ravish Mody
May 4th, 2011 on 9:29 pm
Great, I’ll look at this article right now…
September 7th, 2011 on 5:26 pm
Hi Ravish/Jai,
Today one of our Tomcat web server started showing high memory utilization and i followed the same procdure which
you guys have mentioned. How can i read this binary file and make it to a user readble format using a third party tool.
September 7th, 2011 on 5:59 pm
Hi Sudheshpn,
The heap Dump is a Binary file and it cannot be converted as a text format file. But if you want to investigate the Heap Dump then it is very easy to open it in the “Eclipse Memory Analyzer tool” This tool provides various options to debug the Heap dump we need to just open the Heap Dump file inside Eclipse MAT tool to see the graphical representations of the heap and the consumed objects….
Please download the Eclipse Memory Analyzer from the following link:
http://www.eclipse.org/mat/
For reference: http://www.vogella.de/articles/EclipseMemoryAnalyser/article.html
http://memoryanalyzer.blogspot.com/
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
September 20th, 2011 on 3:45 pm
Hi Jay,
I followed your below link for leak Suspects using ECLIPSE MEMORY ANANLYSER,
http://weblogic-wonders.com/weblogic/2010/07/16/troubleshooting-out-of-memory-errors-in-weblogic-using-eclipse-memory-ananlyser/
it showed me the below Problem Suspect 1
One instance of “weblogic.jdbc.common.internal.GenericConnectionPool” loaded by “sun.misc.Launcher$AppClassLoader @ 0x866ba340″ occupies 335,917,304 (90.26%) bytes. The memory is accumulated in one instance of “java.util.LinkedList$Entry” loaded by “”.
Keywords
weblogic.jdbc.common.internal.GenericConnectionPool
sun.misc.Launcher$AppClassLoader @ 0x866ba340
java.util.LinkedList$Entry
Can you please tell me,how can i suspect which page is creating a page leak or which code is creating the problem..
Regards
Fabian
September 20th, 2011 on 5:06 pm
Hi Fabian,
Just looking at the above details it is not possible to investigate the root cause of this issue, because the complete heap dump need to be investigated properly in this case. It is also not possible to find out which JSP page is creating more such objects….because we will need to traverse the stack and some times we will need to run the OQL object query language queries as well in order to get more detailed information’s from the heap dump.
The above article just describes how to open Heap dump in the Memory Analyzer but not How to Analyze it. As heap dump analysis is a very huge topic. So if you are seeing that “weblogic.jdbc.common.internal.GenericConnectionPool” is consuming 90% of the heap space then you should file an Official Ticket with Oracle WebLogic Support team so that they can investigate your heap dump deeply and can point some issues.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
November 22nd, 2011 on 7:01 pm
Hi,
while trying to execute jmp in linux enviornment getting below error:
jmap -heap:format=b file=dump.bin 5772
Attaching to core 5772 from executable file=dump.bin, please wait…
Error attaching to core file: Can’t attach to the core file
java version :jdk150_11/bin
any help
November 22nd, 2011 on 11:22 pm
Hi Pavan,
Your command has a missing COMMA between “format=b” And “file=dump.bin” Correct command will be folllowing:
jmap -heap:format=b,file=dump.bin 5772
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
November 23rd, 2011 on 6:21 pm
Hi Jay thanks for your reply.
Please see below.
running form here : jdk/jdk150_11/bin
-bash-3.00# ./jmap -heap:format=b,file=dump.bin 19641
unknown heap format:b,file=dump.bin
-bash-3.00# uname -an
Linux test123 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 i686 i386 GNU/Linux
without comma getting below error
-bash-3.00# ./jmap -heap:format=b file=dump.bin 19641
Attaching to core 19641 from executable file=dump.bin, please wait…
Error attaching to core file: Can’t attach to the core file
Thanks
November 23rd, 2011 on 11:36 pm
Hi Pavan,
looks like “jmap” which comes with JDK1.5 does not have any attribute “file” so please try the below command:
./jmap -heap:format=b 4957
HELP Options for jmap in JDK 1.5
./jmap -help
Usage: jmap [option]
(to connect to a live java process)
or jmap [option]
(to connect to a core file)
or jmap [option] [server_id@]
(to connect to a remote debug server)
where option must be one of:
to print same info as Solaris pmap
-heap to print java heap summary
-heap:format=b to dump java heap in hprof binary format
-histo to print histogram of java object heap
-permstat to print permanent generation statistics
-h | -help to print this help message
=================================================
HELP Options for jmap in JDK 1.6
jmap -help
Usage:
jmap [option]
(to connect to running process)
jmap [option] <executable
(to connect to a core file)
jmap [option] [server_id@]
(to connect to remote debug server)
where is one of:
to print same info as Solaris pmap
-heap to print java heap summary
-histo[:live] to print histogram of java object heap; if the “live”
suboption is specified, only count live objects
-permstat to print permanent generation statistics
-finalizerinfo to print information on objects awaiting finalization
-dump: to dump java heap in hprof binary format
dump-options:
live dump only live objects; if not specified,
all objects in the heap are dumped.
format=b binary format
file= dump heap to
Example: jmap -dump:live,format=b,file=heap.bin
-F force. Use with -dump: or -histo
to force a heap dump or histogram when does not
respond. The “live” suboption is not supported
in this mode.
-h | -help to print this help message
-J to pass directly to the runtime system
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
November 24th, 2011 on 1:29 am
Hi Jay,
I want to take a heap dump in solaris the wls server is 10.0 version. jdk is 1.5.
How to do this….
Humble Regards,
Sandeep N.
November 24th, 2011 on 1:44 am
Hi Salam49,
may be you can try the sugestion mentioned in the following link: http://middlewaremagic.com/weblogic/?p=2241#comment-5480 to see if it works.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
November 25th, 2011 on 7:53 am
Thank you sir……
I have a question…we are using alsb with weblogic 10.0 both are combined together, but now we want to upgrade to osb can you help me out this how to install in production env… pls differentiate osb and SOA suite…what to choose…how to ahead..Pls give some suggestion.
Humble Regards,
Sandeep N.
November 25th, 2011 on 3:39 pm
Hi Sandeep,
I am not much familiar with OSB and SOA so i may not be very helpful here. I will give you an update if i can find some relevant document on this topic.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
November 25th, 2011 on 6:32 pm
Thanks Jay finally it works (./jmap -heap:format=b 4957)
November 30th, 2011 on 11:59 am
Hi jay,
If i am enabling the -XX:+HeapDumpOnOutOfMemoryError – it will create the hprof file in the default location
I wanted to change it by providing the path -XX:HeapDumpPath=/x/y/z/heap , here x, y and z directories are already there
will the WLS automatically create a new directory called heap and generate the hprof file there or do we have to create the directory heap?
To put in other words,
will the WLS automatically create the directory provided in -XX:HeapDumpPath if its not there?
your help is much appreciated, thanks in advance
November 30th, 2011 on 3:24 pm
Hi Aravindh,
Please check the following link:
http://middlewaremagic.com/weblogic/?p=4482#comment-5544
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
December 9th, 2011 on 7:12 pm
sorry i did a mistake while posting , below is the actual error
os:RHEL 6.0
Issue:while i am trying to take the heapdump
the command used is:
under java_home/bin
./jmap -heap:format=b
Attaching to process ID 5405, please wait…
sun.jvm.hotspot.debugger.NoSuchSymbolException: Could not find symbol “gHotSpotVMTypeEntryTypeNameOffset” in any of the known library names (libjvm.so, libjvm_g.so, gamma_g)
at sun.jvm.hotspot.HotSpotTypeDataBase.lookupInProcess(HotSpotTypeDataBase.java:388)
at sun.jvm.hotspot.HotSpotTypeDataBase.getLongValueFromProcess(HotSpotTypeDataBase.java:369)
at sun.jvm.hotspot.HotSpotTypeDataBase.readVMTypes(HotSpotTypeDataBase.java:102)
at sun.jvm.hotspot.HotSpotTypeDataBase.(HotSpotTypeDataBase.java:85)
at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:568)
at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:494)
at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:332)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:163)
at sun.jvm.hotspot.tools.HeapDumper.main(HeapDumper.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.tools.jmap.JMap.runTool(JMap.java:178)
at sun.tools.jmap.JMap.main(JMap.java:110)
Debugger attached successfully.
sun.jvm.hotspot.tools.HeapDumper requires a java VM process/core!
March 5th, 2012 on 3:15 pm
very useful information for beginners
Thank you for Jay sen sharma
June 12th, 2012 on 3:25 pm
i got a process id how to start the jmap?
June 17th, 2013 on 11:16 pm
Hi Jay,
Very often I am getting the below warning in one of my Production Weblogic server.
“One of the zones exceeded CPU or Memory threshold”
Please suggest.
Thanks in advance,
mek