The indexes that need to be paid attention to in mat analysis of heap dump

in Tutorials with 30 comments

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:

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:

 1536823826319_ c2d70adf_ 70f8_ 4d2f_ 8f02_ fa970216fc45_ Image.png

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.

 1536821966656_ 0410c9e6_ 26a6_ 4a0e_ b0a3_ 5eb595d049be_ image_ resized.png

Leak Suspects Report

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

 1536822238019_ e25a1c83_ 30a6_ 4e5c_ 87fd_ 0534e7980373_ image_ resized.png

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:

 1536822275094_ 9dbd2c4a_ 99cb_ 47a5_ a4a7_ 6c76781e3658_ image_ resized.png

Top Components Report

 1536823194039_ 807f93db_ 9112_ 4abe_ 96c3_ c26b88942e57_ image_ resized.png

 1536823226935_ e24abbde_ c3fe_ 4bb0_ a612_ d2da799b410e_ image_ resized.png

Advanced Usage

Enter the default overview

 1536822507761_ 0bf779c8_ 2619_ 4d28_ a26c_ a5ea402d5064_ image_ resized.png

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
4. Duplicate classes: analyze class loader through class loader

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
 1536823536190_ 43c1ff15_ eaba_ 4ed7_ bcb7_ 30f15d6c7c07_ image_ resized.png 1536823576321_ 60002d45_ 9505_ 45e6_ adb7_ bfb63ee13af2_ image_ resized.png
Top consumers Duplicate Classes
 1536823615087_ 1e7fa2a8_ a903_ 456d_ 9a15_ c7fc4df4055f_ image_ resized.png 1536823646462_ ffd1d196_ cb98_ 43c9_ bf6a_ 8184947b4732_ image_ resized.png

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.

Link reference

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

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

    Reply
  2. Can you comment freely?

    Reply
  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

    Reply
    1. @Li Mu

      Set read blog page display at most

      Reply
  4. dsa

    Ha ha, ha, ha, ha, ha, dsadsa

    Reply
  5. Such a comprehensive tutorial, the blogger is really good

    Reply
  6. Learning for the big man

    Reply