Example explanation: Using IBM Heapanalyzer to analyze heap dump files step

Source: Internet
Author: User
Tags xms


Demand motivation: Solving OOM (Object out of Memory) problems and system tuning

1. How to generate Java heap dump

Java heap dump files are generated when there are too many objects in the JVM and the Java heap (Java heap) is depleted. Alternatively, you can use a tool or command to display the file. The ctrl+break can be generated by using the command line during program execution, with tools such as IBM Heapanalyzer, Sap Memory Analyzer, and Eclipse Memory Analyzer generating dump files in the specified state.

2. How to analyze Java heap dump files

Here is an example of using the IBM Heapanalyzer tool; Https://www14.software.ibm.com/webapp/iwm/web/reg/download.do?source=AW-0IN on the IBM website &s_pkg=0in&lang=en_us&cp=utf-8 Download the Ha395.zip file, and the following number is the version number. After decompression with the command line into the decompression directory, using such as Java–xmx800m–jar Ha395.jar startup tool, if the startup process found that the console has java.lang.OutOfMemoryError appear, can be appropriate to increase the number above (800), To give more space.

Then "open" generated by the dump file, open the screen like this, the file is very large words need to wait for some time

The IBM Heapanalyzer tool has done a basic analysis when it is opened, and the following results appear:

[-photo didnot display-]

In addition to displaying the result, a tree was generated. This screen is not closed until you no longer need this dump.

Basic terminology:

[-photo didnot display-]

Then do a simple introduction to the above interface.

[-photo didnot display-]

The size of each node tree occupies the total stack size, like 94%, then the size of this class in memory, followed by 5 child objects, note that this child object is not a subclass of an inheritance relationship, but is defined above: If a object refers to a B object, the B object is the object of object A.

The tool then displays the potentially leaking objects based on the results of the analysis. The following figure:

[-photo didnot display-]

The analysis is based primarily on the size difference between child object and parent object, and if the children object is small and the parent object is super large, it is likely that the parent object is a collection class (such as an array) that contains a large number of child objects as elements.

Tool bar:

[-photo didnot display-]

Click on the Analysis Toolbar table icon, display the following statistics table, you can click on the column headings to sort. The meaning of each heading is briefly described as follows:

TotalSize: The sum of the size of this object, and of all the child objects (and the child objects of the object, that is, all objects that can be referenced from this object), in bits;

Size: This object is sized, such as the first 56bits = 56/8bytes = 7b;

No.child: The number of child objects, excluding child objects;

No.parent: The number of parent objects, excluding objects of the parent object;

Name: The names of the objects.

Address: The addresses of objects in heap.

3. Analysis Results

3.1 A large array of java/util/hashmap$entry elements, occupying a total stack of 8%, a very high proportion.

3.2 A large number of java/util/hashtable$hashtableentry is an array of elements that occupy 5% of the total stack.

An array of 3.3 3.2 points to a large number of Java/util/hashtable$hashtablecachehashentry objects.

According to the analysis, the most suspected object should be java/util/hashmap$entry.

4. Other Experience Collection:

The use of the Heapdump tool is simple, the difficulty is to find "the true cause of the memory leak," generally need to pass The comparison of multiple heapdump files to find . ”

"Objectinputstream/objectoutputstream should be aware of memory leaks. Reset () "

"Because of the JDK problem, if you are using: J2re 5.0 IBM J9 2.3AIX ppc-32 build j9vmap3223-20070201, this SR4 version has the problem of qualifying the class loader can load the number of classes, default to 8192, if more than This limit, a outofmemory error is thrown. ”

For this problem, you can set up the number of classes that can be loaded by the ClassLoader to be resolved.

5. Introduction to Knowledge supplement

5.1 Heap (HEAP) and non-heap (non-heap) memory
According to the official statement: "Java virtual machines have a heap, the heap is the Run-time data region, all class instances and arrays of memory are allocated from here." The heap was created when the Java virtual machine was started. "" Memory outside the heap in the JVM is called Non heap memory (non-heap memory). You can see that the JVM mainly manages two types of memory: the heap and the non heap. Simply put, the heap is the memory that Java code can have, is reserved for developers, and not heaps are for the JVM to use, so the method area, JVM internal processing or optimization of required memory (such as JIT-compiled code caching), each class structure (such as running a constant pool, field and method data), and methods and the code to construct the method are in non heap memory.

5.2 Heap Memory Allocations
The initial memory allocated by the JVM is specified by-XMS, which defaults to the 1/64 of physical memory; The JVM's largest allocated memory is specified by-XMX, which defaults to 1/4 of physical memory. When the default free heap memory is less than 40%, the JVM increases the maximum limit for the heap until-xmx, and when the free heap memory is greater than 70%, the JVM reduces the heap until the minimum limit of-XMS. Therefore, the server generally sets-xms and-xmx equal to avoid resizing the heap after each GC.

5.3 Non-heap memory allocations
The JVM uses-xx:permsize to set a non heap memory initial value, which defaults to 1/64 of physical memory, and the maximum amount of non heap memory is set by Xx:maxpermsize, which defaults to 1/4 of physical memory.

5.4 JVM Memory limit (maximum)
First, JVM memory is limited to the actual maximum physical memory, and the maximum value of JVM memory is significantly related to the operating system, assuming that the physical memory is infinitely large. In simple terms, 32-bit processors although controllable memory space has 4GB, but the specific operating system will give a limit, this limit is generally 2GB-3GB (in general, Windows system is 1.5g-2g, Linux system under 2G-3G), and 64bit above the There is no limit to the device.

Yao Wen

2009-9-3

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.