#### What is heap dump

A heap dump is a snapshot of the memory used by a java process at a certain time. In other words, the memory of the java process is persisted to the disk in a certain format at a certain time. There are many formats for heap dump, and different formats may contain different information. But generally speaking, heap dump generally contains basic information such as Java objects and class in a heap. At the same time, when you perform a dump operation, a GC is often triggered, so the information contained in the file you dump is usually valid content (less or no garbage objects)

We can obtain the following basic information (one or more items, related to the format of dump file) in heap dump:

• All object information
Class information, field information, native value (int, long, etc.) and reference value of the object

• All class information
Class loader, class name, superclass and static field

• The root of the garbage collection object
The objects that can be touched directly are the virtual objects

• Thread stack and local variables
It contains the thread call stack information at dump time and local variable information in stack frame

A heap dump does not contain memory allocation information, which means that you can't tell who created these objects and where they were created.

However, by analyzing the reference relationship between objects, we can often infer the relevant information.

#### What is domino tree

The dominating tree is an object graph, which transforms the reference relationship of objects into a tree like object graph structure. Through it, we can easily see the reference relationship of objects and which largest memory use blocks.

If every path of an object y from its beginning (possibly GC roots) to its node must pass through X object, then x dominates y.

The object nearest to y is called the immediate dominator of Y.

In the dominator tree, each object is directly controlled by its child objects, so the reference relationship of the object is also well positioned.

The dominator tree contains the following features:

• All objects of the subtree of X are the retained sets of X.

• If x is the direct domination of Y, then the direct domination of X must also dominate y, and so on.

• The lines in the dominating tree do not directly correspond to the reference relationships of objects in the object graph, such as the relationship between D and F in the figure below.

#### Introduction to mat

Mat (memory analyzer tool), a memory analysis tool based on eclipse, is a fast and functional Java heap analysis tool. It can help us find memory leaks and reduce memory consumption. Use memory analysis tools to analyze many objects, quickly calculate the occupied size of objects in memory, and see who prevented the garbage collector's recycling work, and visually view the objects that may cause this result through reports.

The JVM can record part of the running state of the system when the problem occurs and store it in the heap dump file, which provides an important basis for us to analyze and diagnose the problem.

#### Select report type

After opening a dump with mat, we will select one of the report types.

Leak Suspects Report

Selection in general Leak Suspects Report After waiting for a period of time, a report will pop up automatically.

The report shows that about 11.3 GB of content is problematic. And part of the problem is "org.elasticsearch.common.cache.Cache" As follows:

Top Components Report

Enter the default overview

You can see most of its functions from the figure above. The main functions are action and report. We have already produced two kinds of reports.

Actions
1. Histogram: you can list the objects in memory, the number of objects, and the size
2. Domino tree: you can list which thread and the space occupied by those objects under the thread
3. Top consumers: list the largest objects by class name and package name by graph

Reports
1. Leak suspects: automatic analysis of leak reports and dump overview
2. Top components: analysis of the use of more than 1% of the components of each part of the report

#### Actions

Histogram Dominator Tree
Top consumers Duplicate Classes

#### Indicators of concern

The basic idea is to find the biggest part.

However, direct observation is not enough.

We need to use "top consumers" to find out the "big objects" according to the package / class name / class loader.

After finding out the "big objects", you can locate the specific contents of these "big" objects through the "locator tree", so as to better judge the problem points.

https://mingjunli.gitbooks.io/mat/content/

Responses
1. Blogger, your SSL certificate has expired, mainstream browsers can't access, QQ browser can

2. Can you comment freely?

3. Hello, how can I use your template? How can I display the next page if there are only 5 pages in my site? Big man, help

1. @Li Mu

Set read blog page display at most