In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the use of MAT, a sharp tool for Java memory analysis". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Java memory analysis of the sharp tool MAT use detailed explanation" it!
The dump file contains:
1, all objects: classes, fields, native values and references
2, all classes: classloader, class name, superclass, static domain
3Gray GC root: reachable objects defined by JVM
4, thread stack and local variables: call stack of the thread, information of the local object per frame.
The dump file does not contain memory allocation information, so it is not possible to query information such as who created which objects.
Shallow heap is the memory space occupied by an object, and an object needs 32 or 64bits.
Retained set of X is a group of object in which X is recycled by jvm gc and then remove.
Retained heap of X is the sum of the shallow heap size of all objects in retained set of X. In other words, the memory space needed to keep X alive.
Generally speaking, shallow heap is the actual space of an object in memory, while retained heap is the space released by memory after an object is reclaimed by gc.
This picture can see what is leading set and what is retained set.
Dominator tree: defines an object x dominate object y, when every path from root to y passes through x. To put it bluntly, as long as there is a y object alive, then there must be an x object. Dominator tree is the tree structure that converts the object reference graph into a tree structure. Helps to find alive dependencies between objects, while also recognizing the chunk of retained memory. Immediate dominator x of y is the nearest dominator to y.
Dominator tree has several properties:
1. The subtree of object x contains objects (the set of objects of x dominate), which represents the retained set of x
2, if x is the immediate dominator of y, then the immediate dominator of x is also dominate y, and so on
3The edges in tree dominate do not represent the corresponding edges in the object reference graph, and are not strictly direct object references.
This diagram reflects an example of an object reference graph converted to dominator tree.
Gc root: a gc root is an object that can be accessed and read from outside the heap. Here are some ways to make an object the gc root.
1Query system class: classes loaded by Bootstrap or system classloaders, such as java.util.* in rt.jar
2 local variables in JNI local:native code, such as user-defined JNI code and JVM internal code
3The global variable in the JNI global:native code
4Thread block: objects referenced in the currently active thread block
5Jing Thread: threads that have been started and do not have stop
6 wait monitor: objects that are called wait () or notify () or synchronized by synchronized. If they are synchronized methods, then static methods refer to classes, and non-static methods refer to objects.
7 Java local:local variables, such as input parameters of the method and variables created within the method
8 entry and exit parameters in the native stack:native code, such as file/net/IO method and reflection parameters
9 finalizer finalizable: an object waiting in a queue for its finalizable to run
10 unfinalized: an object with a finalize method that has not been finalize and has not entered the finalizer queue to wait for finalize
11J unreachable: objects that will not be touched are marked as root for retain object in MAT, otherwise they will not appear in the analysis
The 12recoverjava stack frame:java stack frame contains local variables, which are generated when the dump is parsed and the stack frame is set as an object in the preferences.
13The root type of the location.
Here are some ways to get dump:
1. Dump:JVM parameter:-XX:+HeapDumpOnOutOfMemoryError in oom
2. Dump in interactive environment:
1) JVM parameter:-XX:+HeapDumpOnCtrlBreak
2) use external tools:jmap-dump:format=b,file=
3) use external tools:jconsole
4) use external tools: MAT
5) kill-3
6) jstack-l >
Some troubleshooting methods:
1. Find large objects through top consumers, and you can group by according to class, classloader and package.
2. Finding responsible objects through immediate dominator is very useful for quickly locating the holders of a group of objects. This operation directly solves the problem of "who makes these objects alive" rather than "who has references to these objects", which is more direct and efficient.
3. Run classloader analysis. This importance is reflected in the highlights: *, applications use different classloader loading classes. Second, classes loaded by different classloader are stored in different * * generations, which can also be recycled in theory. When a class is loaded by a different classloader, it is necessary to determine which loader is more important according to the number of instance under the respective loader, thus recycling the other.
4. Analyze threads. The heap dump itself contains thread information. You can use MAT to view the heap memory information of threads in overview and detail,detail of threads, as well as thread stacks, as well as operating system local stacks. Suppose we do not do heap dump, we check that there is a problem with the system, how to troubleshoot it from the perspective of threads? First of all, top-H-p looks at the operation of the java application in thread mode, finds the thread that takes up cpu or memory, records the thread id, then converts printf% x to hexadecimal, and then jstack-l > thread.log puts the thread dump of the java process out, finds the tid inside, and analyzes which thread occupies the system resources.
5. Analyze the java container class. Because the java container class is the most commonly used to store objects, there is theoretically a risk of memory leakage. It can be seen from several angles: 1) array fill rate query (fill rate fill ratio is the proportion of non-empty elements in the array), print the fill rate frequency distribution of non-primitive type arrays, so as to check the array utilization in the system; 2) the array is grouped according to size query, printing a histogram grouped by size; 3) collection fill rate query, ArrayList/HashMap/Hashtable/Properties / Vector/WeakHashMap/ConcurrentHashMap$Segment;4) collection grouping histogram according to size 5) View all objects in a list; 6) View all objects in hashmap; 7) View objects in hashset; 8) check the collision rate of map; 9) check all array with only one constant.
6, analyze Finalizer,1) query the objects being processed by finalizer; 2) query the objects that finalizer is going to process; 3) directly view the finalizer thread; 4) view the thread local object of the finalizer thread.
At this point, I believe that everyone on the "Java memory analysis of the use of MAT," have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.