转自: https://blog.codecentric.de/en/2008/07/memory-analysis-part-1-obtaining-a-java-heapdump/
For troubleshooting Java memory leaks and high memory usage problems, the heapdump is one of the most important analysis features. The advantage of heapdumps is that they can be produced in productive environments – the place where the problems most frequently occur. All current Java Virtual Machines support the generation of heapdumps without the need of additional tools.
In this blog series I will show you how to analyze and fix memory problems in production . I will also provide a list of common antipatterns and memory problems.
The first part of this series deals with the vital task of heapdump generation – the main precondition for a successful analysis. The various JVM manufacturers (SunIBMBEA) have different tools and formats to dump the heap of the JVM – this blog therefore focus on the implementation of Sun. The Sun Java Virtual Machine contains several options and tools to create a heapdump:
– Automatically when a java.lang.OutOfMemoryError occurs

– With the command line tool jmap

– By using a provided MBean (Java Management Extension – JMX) and the tooljconsole

Of course, there is the possibility to use the Java Virtual Machine Tool Interface (JVMTI) to produce a dump – but therefore you would have to implement an agent in C. Many Profiling Tools (like JProfiler) provide a JVMTI agent to create and evaluate a heapdump with a GUI.

To automatically generate a heap dump when an OutOfMemoryError is thrown you have to provide this JVM command line parameter:

– XX:+HeapDumpOnOutOfMemoryError

The parameter causes the JVM to dump a HPROF headump to the current directory if an OutOfMemoryError occurs. The name of the dump is by conventionjava_pid.hprof. To specify the directory and the name of the file by yourself, you can add the parameter -XX:HeapDumpPath=path_to_file to the JVM command line options.

The automatic production of dumps with these parameters is not always useful. In some situations you want to produce a heapdump at any given time during application execution. In this case Java version 1.4.2_09, 1.5.x and 1.6.x provide the tool jmap. A HPROF heapdump can be requested by executing the following command:

jmap -dump:file=path_to_file java_process_id.

The provided Java process id determines which local JVM should be dumped. The process Id can be determined with the JVM Tool jps (Note: The jmap tool is not available on every platform and JVM version). You can alternatively use the JVM parameter -XX:+HeapDumpOnCtrlBreak and send a SIGQUIT signal (-3 kill for Unix and Ctrl-Break for Windows) to the running Java process – the signal will also create a heapdump without aborting the JVM.

With Java 6, Sun introduced a JMX MBean which provides methods for generating a heapdump. To create a heapdump via JMX you first start the integrated JMX console with the command jconsole and connect it to the corresponding JVM. For a local connection you don’t need any additional configuration of the JVM – for a connection to a remote machine you have to configure JMX correctly.

You can use the MBean Explorer of jconsole to find the correct MBean within the JVM. The MBean com.sun.management.HotSpotDiagnostic contains the alluded method dumpHeap (String, boolean). With the help of the first method parameter you can set the path and the name of the Heapdump. The screenshot shows the view of the MBean. Pressing on the dumpHeap button will create a heapdump with the given name.

The next part of this series will get into more details how to analyse heapdumps and find memory leaks and common memory antipatterns.

Information about heapdump generation with the IBM JVM can be found in the IBM JVM Diagnosis Documentation.

Information about BEA JRockit and the JRockit Memory Leak Detector can be found in the JRockit Dokumentation.

Memory Analysis Part 1 – Obtaining a Java Heapdump的更多相关文章

  1. Diagnosing out of memory errors and memory leaks 内存泄露实例 C Java JavaScript 内存泄露

    小结: 1. 数据库连接池. JDBC语句和结果对象必须显式地关闭. 2. 电梯到目标楼层后地址是否被释放 When a button is pressed: Get some memory, whi ...

  2. Memory Analysis环境安装

    安装MAT(MAT在eclipse的页面:http://www.eclipse.org/mat/downloads.php) 显示饼图的时候,需要安装BIRT Chart Engine插件,通过Ins ...

  3. Automated Memory Analysis

    catalogue . 静态分析.动态分析.内存镜像分析对比 . Memory Analysis Approach . volatility: An advanced memory forensics ...

  4. Eclipse Memory Analysis进行堆转储文件分析

    生成堆转储文件 新建项目,设置Eclispe Java堆的大小: (1)限制Java堆大小:将最小值 -Xms参数与最大值-Xmx参数设置一样可避免堆的扩展         -Xmx20m -Xms2 ...

  5. jmap命令(Java Memory Map)(转)

    JDK内置工具使用 一.javah命令(C Header and Stub File Generator) 二.jps命令(Java Virtual Machine Process Status To ...

  6. JDK内置工具之一——JMap(java memory map)

    1.介绍 打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量). 可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本.使用方法 j ...

  7. 五、jdk工具之jmap(java memory map)、 mat之四--结合mat对内存泄露的分析、jhat之二--结合jmap生成的dump结果在浏览器上展示

    目录 一.jdk工具之jps(JVM Process Status Tools)命令使用 二.jdk命令之javah命令(C Header and Stub File Generator) 三.jdk ...

  8. On Memory Leaks in Java and in Android.

    from:http://chaosinmotion.com/blog/?p=696 Just because it's a garbage collected language doesn't mea ...

  9. DTrace to Troubleshoot Java Native Memory Problems

    How to Use DTrace to Troubleshoot Java Native Memory Problems on Oracle Solaris 11 Hands-On Labs of ...

随机推荐

  1. c++ 双向链表操作总结

    第一.包含DoubleLinkNode 模板类和DoubleLinkList 模板类 #pragma once #include<iostream> using namespace std ...

  2. linux-强制断开远程tcp连接

    最近在做日常维护,搭建了socks代理,但是socks代理服务已经关闭了,由于其他机器还在和我的服务器保持tcp长连接 e.g. tcp ESTAB Google了一下,没找到特别好的办法,例如ipt ...

  3. idea展现目录清晰方式

  4. 6、数据类型四:sets

    集合的基本特征:无序,唯一. 一个redis集合最多能存放232-1个集合元素.其强大之处在于它支持集合的“交.差.并”运算,而且能够快速的判断某个给定值是否在集合中. 1.基本命令: SADD ke ...

  5. 「小程序JAVA实战」Springboot版mybatis逆向生成工具(32)

    转自:https://idig8.com/2018/08/29/xiaochengxujavashizhanspringbootbanmybatisnixiangshengchenggongju32/ ...

  6. 黑暗之光 Day1

    1. 设置鼠标指针图标 Build Setting -> Player Setting 2. 添加雾的效果 Window->Lighting->Settings. 3. 任意键按下事 ...

  7. python 获取当前运行的类名函数名

    import inspect def get_current_function_name(): return inspect.stack()[1][3] class MyClass: def func ...

  8. 深入探究jvm之类装载器

    一.class装载验证流程 1.加载 1).取得类的二进制流. 2).转为方法区数据结构. 3).在Java堆中生成对应的java.lang.Class对象. 2.链接--验证(目的:保证Class流 ...

  9. 【jdbc】【c3p0】c3p0三种配置方式【整理】

    c3p0三种配置方式 c3p0的配置方式分为三种,分别是1.setters一个个地设置各个配置项2.类路径下提供一个c3p0.properties文件3.类路径下提供一个c3p0-config.xml ...

  10. 利用UUID 随机生成8位短号

    //获得8位短号 public static String[] chars = new String[] { "a", "b", "c", ...