`

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 (Sun, IBM, BEA) 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 tool jconsole

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 (JProfiler, dynaTrace Diagnostics) 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 convention java_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:

map -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.

分享到:
评论

相关推荐

    Obtaining a stack trace in C upon SIGSEGV

    然后,它包含了一系列标准头文件,比如 `<memory.h>` 和 `<signal.h>`,以及用于符号解析的 `<execinfo.h>` 和 `<dlfcn.h>`。 核心部分在于定义了一个信号处理函数,该函数会在接收到 `SIGSEGV` 信号时被调用。这个...

    Obtaining Absolute Encoder Position on a TMS320C240.pdf

    1. **硬件配置**:首先,确保绝对编码器正确连接到TMS320C240的输入端口。通常,这涉及到选择合适的引脚并进行必要的信号调理。 2. **初始化设置**:在软件层面,需要对DSP进行初始化,包括设置时钟频率、中断...

    abaqus Abaqus收敛培训教材Obtaining a Converged Solution with Abapdf

    "Obtaining a Converged Solution with Abaqus" 是一本专门针对Abaqus求解收敛问题的培训教材,旨在帮助用户理解和解决在进行有限元分析时遇到的收敛挑战。 教程分为两天的内容,涵盖了多个主题和工作坊,以理论...

    A Method for Obtaining Digital Signatures and Public-Key Cryptosystems

    #### 1. 数字签名概述 数字签名是一种用于验证电子信息来源的真实性及其完整性的一种方法。它利用了公钥加密技术,通过发送方使用自己的私钥对信息摘要进行加密,接收方则使用发送方的公钥解密来验证信息的真实性和...

    Learn.Java.for.Android.Development_Apress.2010+src

    Table of Contents Getting Started with Java Learning Language Fundamentals Learning Object-Oriented Language Features Mastering Advanced Language Features Part 1 Mastering Advanced Language Features ...

    uiautomatorviewer更新文件.rar

    解决uiautomatorviewer报错问题,分享给大家。 Unexpected error while obtaining UI hierarchy # 点击Details java.lang.reflect.InvocationTargetException

    简单的Java照相机源码

    * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without * ...

    电力潮流软件

    电力潮流计算, 经济调度,...visualization tool aids students in quickly obtaining a detailed understanding of the power system analysis problems when used as a supplement to traditional lecture approaches.

    domain user password obtaining

    domain user password obtaining

    Data Science with Java: Practical Methods for Scientists and Engineers

    With this practical book, Java software engineers looking to add data science skills will take a logical journey through the data science pipeline. Author Michael Brzustowicz explains the basic math ...

    基于Java的开源机器视觉算法库(源码)

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, ...

    ENHANCING SIMILARITY MATRICES FOR MUSIC AUDIO ANALYSIS

    analysis. However, the quadratic time and space complexity as well as the intricacy of extracting the desired structural information from these matrices are often prohibitive with regard to real-world...

    UNIX Network Programming Volume 2(Unix网络编程卷2英文版)

    part 1. introduction chapter 1. introduction 1.1 introduction 3 1.2 processes, threads, and the sharing of information 5 1.3 persistence of ipc objects 6 1.4 name spaces 7 1.5 effect of fork, ...

    万能脱壳工具 病毒分析工具 V1.4

    c.dump the memory with three mode(Dump Full、Dump Partial and Dump Region) v1.2 new features: ★support PEid plugins ★add a feature for rebuilding PE v1.1 new features: ★add ...

    JEDEC JEP 142-2023 GUIDELINE FOR OBTAINING AND A

    **JEDEC JEP 142-2023 概述** JEDEC JEP 142-2023 是一个针对混合多芯片模块(Hybrid MCM)产品中材料获取与验收的指导标准。该标准由JEDEC固态技术协会发布,并在2002年首次制定,2009年和2023年进行了重新确认。...

    英文原版-Becoming a Video Game Artist 1st Edition

    Despite this growth, the competition in obtaining a career in video games remains as arduous as ever. Becoming a Video Game Artist helps guide readers from their first steps of making a portfolio, to...

Global site tag (gtag.js) - Google Analytics