Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand Dominator Tree

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to understand Dominator Tree". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to understand Dominator Tree.

View & function 1, Overview#

Through File > Open Heap Dump... Open the dump file, the first display is the Overview overview interface, you can have a general understanding of Heap Dump, and provide some views, reports, portals, these views, reports are very helpful for the analysis of Heap Dump, will be introduced later.

If you move the mouse over an area of the pie chart, you will see the details of the object on the left, such as: object hashcode, class name, package name, Class object, parent class, class loader, shallow size, retained size, GC root type in the Inspector on the top left. Some attribute information and class-level information of the object are shown in the lower left.

2. Histogram View #

You can open the Histogram bar chart in the following ways:

(1) Click the "Histogram View" link in the Actions area of the Overview page

Histogram view:

This view shows the number of instances, [Shallow memory] and [Retained memory] of each Class class in the dimensions of the Class class, which can be sorted and displayed separately.

From the Histogram view, you can see which Class class has more object instances and takes up more memory. The difference between Shallow Heap and Retained Heap will be explained in the following concept introduction.

However, in most cases, classes with a large number of instance objects in the Histogram view are basic types, such as char [] (because they constitute String), String, and byte [], so it is impossible to determine the specific class or method that caused the memory leak, so you can continue to drill data using functions such as List objects or Merge Shortest Paths to GC roots. If the Histogram view shows a large number of instance objects that are not the base type, but a suspected class, such as the bean type in the project code, then focus on.

3. Dominator Tree (dominating Tree) View #

You can open the Dominator Tree view in the following ways:

(1) Click the "Dominator Tree View" link in the Actions area of the Overview page

(2) Click the "Dominator Tree button" of the toolbar to open a dominant tree view for the whole heap.

Dominator Tree (dominating tree) view:

This view shows the objects with the largest Retained Heap footprint in the current heap memory and the tree structure of the objects that depend on them to survive in the dimensions of the instance objects.

The view shows the instance object name, Shallow Heap size, Retained Heap size, and the percentage of the current object's Retained Heap in the heap

Clicking the "+" on the left side of the Dominator Tree instance object will show the next layer (next level). When all references to the current instance object are cleared, the objects listed in the next layer will be garbage collected.

This also clarifies the meaning of "domination": the collection of the parent node will cause the child node to be reclaimed, that is, the child node will survive because of the existence of the parent node.

The Dominator Tree domination tree can easily find out the objects that take up the most Retained Heap memory, and show which objects causes some objects to survive. Later on, the Dominator Tree concept section will give a more detailed explanation and examples of the domination tree.

4. Group grouping function #

The way to use the Group grouping function is to click the Group result by... of the toolbar in the Histogram view and Domiantor Tree view

You can choose to display it in another grouping way (default is No Grouping (objects), that is, grouping by object dimension)

For example, in the Histogram view or Dominator Tree view, select Group by package to better see which package of classes take up a lot of memory and easily locate your own application

5 、 Thread Overview#

The entrance to the Thread view, on the toolbar:

Thread Overview:

In the Thread Overview view, you can see: thread object / thread stack information, thread name, Shallow Heap, Retained Heap, class loader, whether Daemon thread and so on.

Thread stack information can also be seen in the MAT of analyzing memory Dump, which in itself is a powerful function, similar to the effect of the jstack command.

Moreover, combined with memory Dump analysis, you can see the local variables in the thread stack frame, and you can also see the properties of the local variables in the object properties area at the lower left, which is really convenient.

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

Public class TestThreadOverview {

Private String str1 = "str1"

Private String str2 = "str2"

Public static void main (String [] args) {

TestThreadOverview test = new TestThreadOverview ()

String local_str = "local_str"

LockSupport.park ()

}

}

In the Heap Dump analysis of the above code, you can see the information of the thread call stack, as well as the local variable TestThreadOverview and string local_str of the mainthread.

The first box in the figure above is the new TestThreadOverview () object (line 6 of code). The TestThreadOverview object has two properties, str1 and str2.

The second box is the string variable local_str in the main method (line 8 of the code)

Combined with the object attribute area on the left, it is more convenient to see the specific situation of the object in the thread.

6 、 List objects#

In the Histogram or Dominator Tree view, to see a reference diagram of an entry (object / class), you can use the List objects feature

(1) after selecting an entry, click Query Browser > List objects on the toolbar, and select with outgoing references or with incoming references

(2) right-click on an entry directly, or you can select List object.

List objects-- > with outgoing references: view the external object references held by the current object (the arrow pointing outward from the current object in the object diagram)

List objects-- > with incoming references

To see which external objects the current object is referenced by (the arrow pointing to the current object in the object diagram)

For example, in the example code in Thread Overview above, look at line 6 of the main method

TestThreadOverview test = new TestThreadOverview ()

The result of the outgoing references query is:

You can see that there are three references to the TestThreadOverview object. The first one is the Class class object of TestThreadOverview. Because all Java classes inherit from java.lang.Object, they all have references to class objects. The last two are member variables str1 and str2.

That is, it lists all external object references held by the local variable TestThreadOverview in the current main method

The result of the incoming references query is:

You can see that TestThreadOverview is a local variable of the main thread, the main thread itself is still a GC root, and the main thread is in a ThreadGroup

7. Paths to GC Roots (path from object to GC Roots) & Merge Shortest Paths to GC roots (common path from GC Roots to object) #

Paths to GC Roots: the path from the current object to GC roots, which explains why the current object is still alive and is useful for analyzing memory leaks. This query can only be used against a single object.

Merge Shortest Paths to GC roots

It means whether to include all references or exclude some types of references (such as soft references, weak references, virtual references) when querying the path to GC root. From the point of view of GC, an object cannot be GC because there must be strong references, and other reference types can be dropped by GC when needed by GC, so you can use exclude all phantom/weak/soft etc. References to only view strong references on the GC path.

The entry of Path to GC roots and Merge shortest Paths to GC roots is the same as List objects. You can enter it from the Query Browser of the toolbar, or by right-clicking on the entry.

It should be noted that Paths to GC roots is for a single object, so it cannot be used in the Histogram view, because the Histogram view is for classes and can only use Merge shortest Paths to GC roots queries

8. Leak Suspects Report (memory leak report) #

When you open a Dump file using MAT, a wizard window pops up. Keep the default option and click Finish, which will lead you to the Leak Suspects memory leak report page.

If you skip opening Dump, you can also enter it from other entrances, such as

(1) Run Expect System Test > Leak Suspects on the toolbar

(2) Reports part of the Overview page

Leak Suspects is a suspected memory leak that MAT analyzed for us, reflecting which objects are kept in memory and why they are not garbage collected.

MAT provides a very intimate function, the contents of the report will be compressed into a zip file, and placed in the original heap dump file directory, generally named "xxx_Leak_Suspects.zip", xxx is the name of the dump file, if you need to analyze this memory problem with colleagues, just send him this small zip package, do not need to send him the entire heap file. And the whole report is a file in HTML format, which can be easily opened with a browser.

The concept of memory leak:

1. These memory leaked objects are reachable from GC root and can be connected to them from the GC root existence path.

2. These objects are useless, that is, the program will no longer use these objects.

As for how to define objects that the program will no longer use, it depends on the specific program logic. To put it bluntly, the memory leak means that the memory that should be reclaimed has not been reclaimed.

Here is an example of how to use the Leak Suspects Report memory leak report

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

Public class OOMHeapTest {

Public static void main (String [] args) {

Oom ()

}

Private static void oom () {

Map map = new HashMap ()

Object [] array = new Object [1000000]

For (int I = 0; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report