Acquiring Heap Dumps
Acquiring Heap Dumps
HPROF Binary Heap Dumps
Get Heap Dump on an OutOfMemoryError
One can get a HPROF binary heap dump on an OutOfMemoryError for Sun JVM (1.4.2_12 or higher and 1.5.0_07 or higher), Oracle JVMs, OpenJDK JVMs, HP-UX JVM (1.4.2_11 or higher) and SAP JVM (since 1.5.0) by setting the following JVM parameter:
-XX:+HeapDumpOnOutOfMemoryError
The heap dump is written to the work directory.
Interactively Trigger a Heap Dump
To get heap dump on demand one can add the following parameter to the JVM and press CTRL + BREAK in the preferred moment:
-XX:+HeapDumpOnCtrlBreak
HPROF agent
To use the HPROF agent to generate a dump on the end of execution, or on SIGQUIT signal use the following JVM parameter:
-agentlib:hprof=heap=dump,format=b
Alternatively, other tools can be used to acquire a heap dump:
- jmap -dump:format=b,file=<filename.hprof> <pid>
- JConsole (see sample usage in Basic Tutorial)
- Memory Analyzer (see bottom of page)
System Dumps and Heap Dumps from IBM Virtual Machines
- All known formats
- HPROF binary heap dumps
- IBM 1.4.2 SDFF
- IBM Javadumps
- IBM SDK for Java (J9) system dumps
- IBM SDK for Java Portable Heap Dumps
For a comparison of dump types, see Debugging from dumps. System dumps are simply operating system core dumps; therefore, they are a superset of portable heap dumps. System dumps are far superior than PHDs, particularly for more accurate GC roots, thread-based analysis, and unlike PHDs, system dumps contain memory contents like HPROFs.
Older versions of IBM Java (e.g. < 5.0SR12, < 6.0SR9) require running jextract on the operating system core dump which produced a zip file that contained the core dump, XML or SDFF file, and shared libraries. The IBM DTFJ feature still supports reading these jextracted zips; however, newer versions of IBM Java do not require jextract for use in MAT since DTFJ is able to directly read each supported operating system's core dump format. Simply ensure that the operating system core dump file ends with the .dmp suffix for visibility in the MAT Open Heap Dump selection. It is also common to zip core dumps because they are so large and compress very well. If a core dump is compressed with .zip, the IBM DTFJ feature in MAT is able to decompress the ZIP file and read the core from inside (just like a jextracted zip). The only significant downsides to system dumps over PHDs is that they are much larger, they usually take longer to produce, they may be useless if they are manually taken in the middle of an exclusive event that manipulates the underlying Java heap such as a garbage collection, and they sometimes require operating system configuration ( Linux, AIX) to ensure non-truncation.
-Xdump:system:events=systhrow,filter=java/lang/OutOfMemoryError,request=exclusive+prepwalk -Xdump:heap:none
In addition to an OutOfMemoryError, system dumps may be produced using operating system tools (e.g. gcore in gdb for Linux, gencore for AIX, Task Manager for Windows, SVCDUMP for z/OS, etc.), using the IBM Java APIs, using the various options of -Xdump, using Java Surgery, and more.
Versions of IBM Java older than IBM JDK 1.4.2 SR12, 5.0 SR8a and 6.0 SR2 are known to produce inaccurate GC root information.
Acquire Heap Dump from Memory Analyzer
If the Java process from which the heap dump is to be acquired is on the same machine as the Memory Analyzer, it is possible to acquire a heap dump directly from the Memory Analyzer. Dumps acquired this way are directly parsed and opened in the tool.
Acquiring the heap dump is VM specific. Memory Analyzer comes with several so called heap dump providers - for Oracle and Sun based VMs (needs a Oracle or Sun JDK with jmap) and for IBM VMs (needs an IBM JDK or JRE). Also extension points are provided for adopters to plug-in their own heap dump providers.
To trigger a heap dump from Memory Analyzer open the File > Acquire Heap Dump... menu item.
Depending on the concrete execution environment the pre-installed heap dump providers may work with their default settings and in this case a list of running Java processes should appear: To make selection easier, the order of the Java processes can be altered by clicking on the column titles for pid or Heap Dump Provider.

One can now select from which process a heap dump should be acquired, provide a preferred location for the heap dump and press Finish to acquire the dump. Some of the heap dump providers may allow (or require) additional parameters (e.g. type of the heap dump) to be set. This can be done by using Next button to get to the Configuring Heap Dump Provider Arguments page of the wizard.
Configuring the Heap Dump Providers
If the process list is empty try to configure the available heap dump providers. To do this press Configure... , select a matching provider from the list and click on it. You can see then what are the required settings and specify them. Next will then apply any changed settings, and refresh the JVM list if any settings have been changed. Prev will return to the current JVM list without applying any changed settings. To then apply the changed settings reenter and exit the Configure Heap Dump Providers... page as follows: Configure... > Next
If a process is selected before pressing Configure... then the corresponding dump provider will be selected on entering the Configure Heap Dump Providers... page.
- HPROF jmp dump provider
- This provider uses the jps command supplied with an Oracle or OpenJDK based JDK to list the running JVMs on the system. The provider then uses the jmap command to get the chosen JVM to generate an HPROF dump. This provider requires a JDK (Java development kit), not a JRE (Java runtime environment) for those two commands. IBM JDKs do not have the jps or jmap commands. The commands on an OpenJ9 JDK may not work well enough for this provider to work with those JVMs.
- Attach API
- This uses the com.sun.tools.attach or com.ibm.tools.attach APIs to list the JVMs and then to attach to the chosen JVM to generate a dump. The Attach API is supplied as part of IBM JDKs and JREs, but is only supplied as part of Oracle or OpenJDK JDKs intools.jarand not as part of JREs. Therefore if Memory Analyzer is run with an Oracle JRE then this dump provider will not be available. The com.sun.tools.attach API is available on Oracle and OpenJDK JDKs, on OpenJ9 JDKs and JREs and IBM JDKs and JREs version Java 8 SR5 or later. The com.ibm.tools.attach API is available on earlier IBM JDKs and JREs. The Attach API dump provider automatically uses whichever Attach API is available, and loadstools.jarif required. The Attach API with Java 9 or later does not permit a Java process to connect to itself, so MemoryAnalyzer cannot generate a dump of itself using the Attach API dump provider. Use another dump provider instead.
- Attach API with helper JVM
- If Memory Analyzer is run with an Oracle JRE then this dump provider can be used with an Oracle JDK by providing a path to a java executable. The dump provider will load thetools.jarif required. so that the com.sun.tools.attach API is acessible. This provider can also be used to list JVMs of a different type from the JVM used to run Memory Analyzer. For example dumps from IBM JVMs can be generated by specifying a path to an IBM JVM java command even when Memory Analyzer is run with an Oracle JVM.
Options
- Dump Type
- System
- These process core dumps are generated using the com.ibm.jvm.Dump.SystemDump() method called by an agent library generated and loaded into the target JVM by Memory Analyzer. These dumps can be generated by IBM and OpenJ9 JVMs.
- Heap
- These Portable Heap Dumps are generated using the com.ibm.jvm.Dump.HeapDump() method called by an agent library generated and loaded into the target JVM by Memory Analyzer. These dumps can be generated by IBM and OpenJ9 JVMs.
- Java
- These Javacore dumps are generated using the com.ibm.jvm.Dump.JavaDump() method called by an agent library generated and loaded into the target JVM by Memory Analyzer. These dumps can be generated by IBM and OpenJ9 JVMs.
- HPROF
- These HPROF dumps are generated using the com.sun.management:type=HotSpotDiagnostic MXBean called in an agent library generated and loaded into the target JVM by Memory Analyzer. These dumps can be generated by Oracle and OpenJDK JVMs.
- Other options
- compress
- System dumps can be processed using jextract which compressed the dump and also adds extra system information so that the dump could be moved to another machine. Portable Heap Dump (PHD) files generated with the Heap option can be compressed using the gzip compressor to reduce the file size.
- live
- On IBM JVMs this forces a garbage collection before a dump is taken. This could affect the performance of the program running on the target JVM, but may reduce the size of PHD Heap dumps. On Oracle and OpenJDK JVMs this dumps only live objects into the HPROF file and should reduce its size. By default, Memory Analyzer removes the non-live objects from the dump as it indexes the dump and builds the snapshot, and puts information about those objects in the unreachable objects histogram. If this histogram is used or the 'keep unreachable objects' option is set then the live option should not be set as it will remove required information.
- listattach
- This is used when listing JVMs using the Attach API. The dump provider then attaches to each running JVM in the list and extracts more information to give a better description. This can take a little longer, so if the list operation is cancelled then this option is disabled so the next listing will be faster. The option can be reenabled if required.
- dumpdir
- IBM JVMs produce dumps in a directory specified by the target JVM, not by Memory Analyzer. Memory Analyzer needs to find the dump it caused to be generated, and looks in the target JVMuser.dirfor the dump files. If this is not the right place then Memory Analyzer will not find the gnerated dump, so the user would have to find it manually afterwards. If the user knows where the target JVM will produce dumps then it can be entered using this option.
- dumptemplate
- This gives an example file name to be used for the dump. The time and date is inserted into the name using substitution variable 0, for example{0,date,yyyyMMdd.HHmmss}. The process identifier is inserted using subsitution variable 1, for example{1,number,0}. The instance number, used to make the dump file unique, is inserted using subsitution variable 2, for example{2,number,0000}. The extra 0000 is a standard MessageFormat modifier giving the minimum number of digits to use.
Multiple snapshots in one heap dump
-agentlib:hprof=heap=dump,format=b
then if a heap dump is triggered multiple times all the heap dumps will be written to one file. An IBM z/OS system dump can contain data from multiple address spaces and processes. It is therefore possible that the dump file contains heap dump snapshots from multiple Java runtimes.
Memory Analyzer 1.2 and earlier handled this situation by choosing the first heap dump snapshot found unless another was selected via an environment variable or MAT DTFJ configuration option.
Memory Analyzer 1.3 handles this situation by detecting the multiple dumps, then presenting a dialog for the user to select the required snapshot.

The index files generated have a component in the file name from the snapshot identifier, so the index files from each snapshot can be distinguished. This means that multiple snapshots from one heap dump file can be examined in Memory Analyzer simultaneously. The heap dump history for the file remembers the last snapshot selected for that file, though when the snapshot is reopened via the history the index file is also shown in the history. To open another snapshot in the dump, close the first snapshot, then reopen the heap dump file using the File menu and another snapshot can be chosen to be parsed. The first snapshot can then be reopened using the index file in the history, and both snapshots can be viewed at once.
Summary
The following table shows the availability of VM options and tools on the various platforms:
| Vendor | Release | VM Parameter | Sun Tools | SAP Tool | Attach | MAT | |||
|---|---|---|---|---|---|---|---|---|---|
| On out of memory | On Ctrl+Break | Agent | JMap | JConsole | JVMMon | API | acquire heap dump | ||
| Sun, HP | 1.4.2_12 | Yes | Yes | Yes | No | ||||
| 1.5.0_07 | Yes | Yes (Since 1.5.0_15) | Yes | Yes (Only Solaris and Linux) | com.sun.tools.attach | Yes (Only Solaris and Linux) | |||
| 1.6.0_00 | Yes | No | Yes | Yes | Yes | com.sun.tools.attach | Yes | ||
| Oracle, OpenJDK, HP | 1.7.0 | Yes | No | Yes | Yes | Yes | com.sun.tools.attach | Yes | |
| 1.8.0 | Yes | No | Yes | Yes | Yes | com.sun.tools.attach | Yes | ||
| SAP | Any 1.5.0 | Yes | Yes | Yes | Yes (Only Solaris and Linux) | Yes | |||
| IBM | 1.4.2 SR12 | Yes | Yes | No | No | No | No | No | |
| 1.5.0 SR8a | Yes | Yes | No | No | No | No | com.ibm.tools.attach | No | |
| 1.6.0 SR2 | Yes | Yes | No | No | No | No | com.ibm.tools.attach | No | |
| 1.6.0 SR6 | Yes | Yes | No | No | No | No | com.ibm.tools.attach | Yes | |
| 1.7.0 | Yes | Yes | No | No | No | No | com.ibm.tools.attach | Yes | |
| 1.8.0 | Yes | Yes | No | No | No | No | com.ibm.tools.attach | Yes | |
| 1.8.0 SR5 | Yes | Yes | No | No | No | No | com.sun.tools.attach | Yes | |
| OpenJ9 | 1.8.0 | Yes | Yes | No | No | Yes (PHD only) | No | com.sun.tools.attach | Yes |
Acquiring Heap Dumps的更多相关文章
- Android内存管理(10)MAT: 基本教程
原文: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Fgettingstarted%2Fbasic ...
- 使用VisualVM查看Java Heap Dump
浏览Heap Dump 可以使用VisualVM浏览heap dump文件的内容,从而快速查看在堆中分配的对象.Heap dumps在主窗口的heap dump子标签页中显示.你可以打开保存在本地的h ...
- How to Analyze Java Thread Dumps
When there is an obstacle, or when a Java based Web application is running much slower than expected ...
- (转)使用MAT比较多个heap dump文件
使用MAT比较多个heap dump文件 调试内存泄露时,有时候适时比较2个或多个heap dump文件是很有用的.这时需要生成多个单独的HPROF文件. 下面是一些关于如何在MAT里比较多个heap ...
- [MAT]使用MAT比較多个heap dump文件
使用MAT比較多个heap dump文件 调试内存泄露时,有时候适时比較2个或多个heap dump文件是非常实用的.这时须要生成多个单独的HPROF文件. 以下是一些关于怎样在MAT里比較多个hea ...
- Android内存管理(9)*MAT:Heap Dump,Shallow Heap,Retained Heap,Dominating Tree,GC Roots等的含义
原文: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Fconcepts%2Fheapdump.ht ...
- Java Heap dump文件分析工具jhat简介
jhat 是Java堆分析工具(Java heap Analyzes Tool). 在JDK6u7之后成为标配. 使用该命令需要有一定的Java开发经验,官方不对此工具提供技术支持和客户服务. 用法: ...
- 性能监控之常见 Java Heap Dump 方法
一.前言 在本文中,我们总结下抓 Java dump 的几种不同方法. Java Heap Dump 是特定时刻 JVM 内存中所有对象的快照.它们对于解决内存泄漏问题和分析 Java 应用程序中的内 ...
- jvm系列(四):jvm调优-命令大全(jps jstat jmap jhat jstack jinfo)
文章同步发布于github博客地址,阅读效果更佳,欢迎品尝 运用jvm自带的命令可以方便的在生产监控和打印堆栈的日志信息帮忙我们来定位问题!虽然jvm调优成熟的工具已经有很多:jconsole.大名鼎 ...
随机推荐
- 程序编译是出现"field has incomplete type"问题的解决
在编译程序是出现了如下错误, 类或结构体的前向声明只能用来定义指针对象或引用,因为编译到这里时还没有发现定义,不知道该类或者结构的内部成员,没有办法具体的构造一个对象,所以会报错. 将类成员改成指针就 ...
- PostgreSql 合并多行记录
需求描述: A表有如下数据 id 1 2 3 4 B表有如下数据 id name 1 aaa 1 bbb 1 ccc 2 aa 2 bb 3 c A表和B表通过id关联,需要查询结果如下: id na ...
- Microsoft Visual C++ 14.0 is required问题的解决或warning: Debugger speedups using cython not found
今天在下载了 python3.64版本的安装后运行爬虫程序报错: warning: Debugger speedups using cython not found. Run '"C:\Py ...
- Hibernate 延迟载入
一.延迟载入定义 延迟载入,也叫懒载入,它是Hibernate为提高程序运行效率而提供的一种机制,即当仅仅有真正使用该对象的数据时才会创建. 说白了,所谓的延迟载入不是 ...
- PHP登入网站抓取并且抓取数据
有时候需要登入网站,然后去抓取一些有用的信息,人工做的话,太累了.有的人可以很快的做到登入,但是需要在登入后再去访问其他页面始终都访问不了,因为他们没有带Cookie进去而被当做是两次会话.下面看看代 ...
- mahout之canopy算法简单理解
canopy是聚类算法的一种实现 它是一种快速,简单,但是不太准确的聚类算法 canopy通过两个人为确定的阈值t1,t2来对数据进行计算,可以达到将一堆混乱的数据分类成有一定规则的n个数据堆 由于c ...
- 如何在Visual Studio(VS)2012里使用libsvm工具箱
原文:http://blog.csdn.net/u014691453/article/details/40393137 软件版本: Visual Studio版本:VS2012 (注:使用方法在 VS ...
- [Grunt] grunt.template
/** * Created by Answer1215 on 11/15/2014. */ module.exports = function(grunt){ grunt.initConfig({ f ...
- XPath查找节点值示例
下面一个XML文档,需要找到粗体部分文字: <?xml version='1.0' encoding='utf-8'?> <rep sts="OK" a=&quo ...
- 最短路+状态压缩dp(旅行商问题)hdu-4568-Hunter
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4568 题目大意: 给一个矩阵 n*m (n m<=200),方格里如果是0~9表示通过它时要花 ...