Memory Analysis Part 1–obtaining a Java heapdump

Source: Internet
Author: User
Tags jconsole

Transferred from: 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 are one of the most important analysis F Eatures. The advantage of heapdumps is so they can be produced in productive environments–the place where the problems most fre quently occur. All current Java Virtual machines support the generation of heapdumps without the need of additional tools. In this blog series I'll show you how to analyze and fix memory problems in production. I'll 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 an Alysis. The various JVM manufacturers (Sun,IBM, BEA) has different tools and formats to dumps the heap of the Jvm–this blog therefore focus on the Impleme Ntation 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 therefo Re you would has to implement a 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 if an outofmemoryerror are thrown you had to provide this JVM com Mand line parameter:

–xx:+heapdumponoutofmemoryerror

The parameter causes the JVM to dump a HPROF headump to the current directory if a outofmemoryerror OCCU Rs. 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 are not always useful. In some situations-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 was not avail Able on every platform and JVM version). You can alternatively use the JVM parameter -xx:+heapdumponctrlbreak and send a sigquit signal ( -3 kill F or Unix and ctrl-break for Windows) to the running Java process–the signal would 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 your 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 h Ave 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 would create a heapdump with the given name.

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

Information about Heapdump generation with the IBM JVM can is found in the IBM JVM Diagnosis documentation.

Information about BEA JRockit and the JRockit Memory Leak Detector can is found in the JRockit dokumentation.

Memory Analysis Part 1–obtaining a Java heapdump

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.