MAT Dump Analysis Program memory

Source: Internet
Author: User

First, Introduction

A real application system can inevitably cause problems. The JVM is able to record the operating state of the JVM in real-time when a problem occurs, and it is stored in a heap dump file, which provides an important basis for system analysis. But the original dump file is plain text, difficult to understand, in order to reduce the complexity of dump file analysis, MAT (Eclipse Memory Analyzer) came into being. Mat, a powerful, "fool-type" heap dump file analysis tool. Detailed introduction See http://www.eclipse.org/mat/

Second, get Mat

Mat now offers two ways to install the Eclipse IDE plug-in (integrated) and Eclipse RCP (standalone version).

This article uses the time Eclipse RCP version, which can be downloaded to http://www.eclipse.org/mat/downloads.php. Unzip the operation as shown below

Third, get the dump file

Dump files can be obtained in several ways, mainly in interactive and event-based ways.

1. Interactive

1), using Ctrl+break: If the JVM runtime parameter is added

-xrunhprof:format=b,file=heapdump.hprof

Parameters. When the Java process receives the sigquit signal (kill-3), it generates a dump file in hprof format.

2), using the Jmap tool: Jmap is a utility that comes with the JDK, and JAVA6 can get a dump file of a running Java process with the following command

Jmap-dump:format=b,file=filename PID

2. Event-Based approach

It is often too late to get the dump file interactively in a production environment when problems occur. Therefore, the actual production environment uses the event-based approach. The JVM supports automatic heap dumps when outofmemoryerror occur, generating dump files. You need to include the following parameters in the application JVM startup parameters:

-xx:+heapdumponoutofmemoryerror

Iv. Document Analysis

Open the Get dump file at the mat clock, and the folder automatically generates an analysis report after completion, as shown in the figure

The main workspace shows an overview of file analysis, and you can see the main class occupancy (biggest Objects) and optional operations, action,reports, etc.

The Inspector area on the left can view the domain information for each class, as shown in the figure is a Com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate class instance, including the values of its individual fields.

How far outofmemoryerror Small example

1. Write a clearly OutOfMemoryError applet

Import Java.util.Date;

Import java.util.List;

Import java.util.ArrayList;

public class test{

public static void Main (string[] args) {

list<date> list = new arraylist<date> ();

while (true) {

Date date = new Date ();

List.add (date);

Date=null;

}

}

}

2. Setting the Startup parameters

$ java-xx:+heapdumponoutofmemoryerror Test

3. If it gets an exception

The generated dump file is Java_pid4931.hprof

4. Import the dump file using the mat

It is clear from the analysis report that a class thread occupies 99% of the memory, which is loaded by Java.lang.ClassLoader.

Clearer memory leaks can be seen by viewing the leak suspects report

Click Detail to view more information

The shortest path to the memory consumption point

Objects consumed by memory

At this point it should be possible to analyze the situation, memory overflow mainly because there are a large number of date objects. Then view the thread stack

Can also be the basic location of the problem. The problem code is:

while (true) {

Date date = new Date ();

List.add (date);

Date=null;

}

Vi. Summary

Mat is a powerful memory analysis tool, the current introduction is just a few basic features, more information please refer to

http://memoryanalyzer.blogspot.com/

http://www.ibm.com/developerworks/cn/java/j-memoryanalyzer/index.html?ca=drs-

Http://www.vogella.de/articles/EclipseMemoryAnalyser/article.html


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.