heap dump analysis - aem: real world issues

16
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. AEM | Heap Dump Analysis Kanika Gera

Upload: kanika-gera

Post on 13-Apr-2017

26 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

AEM | Heap Dump Analysis Kanika Gera

Page 2: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Heap Dump Analysis

• Java Heap Size & Concepts• Concepts of Heap Dumps• Memory Analyzer tools• MAT • Demo

Page 3: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Java Heap Size & Concepts When a Java program starts, Java Virtual Machine gets some

memory from Operating System. Java Virtual Machine or JVM uses this memory for all its need and part of this memory is call java heap memory.

The flag Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms specifies the initial memory allocation pool. This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory.

JVM also run garbage collector periodically to reclaim memory back from dead objects. JVM expands Heap in Java some where near to Maximum Heap Size specified by -Xmx and if there is no more memory left for creating new object in java heap , JVM throws java.lang.OutOfMemoryError and your application/AEM dies by throwing OOM.

3

Page 4: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

What is a HeapDump?

4

• A snapshot of the memory of a Java process

• It contains information about the java objects and classes in the heap:

All Objects - Class, fields, primitive values and referencesAll Classes - Classloader, name, super class, static fieldsGarbage Collection Roots - Objects defined to be reachable by the JVMThread Stacks and Local Variables - The call-stacks of threads at the moment of the snapshot, and per frame information about local objects

To generate heap dump we have to execute a JVM with the following parameters in eclipse -XX:+HeapDumpOnOutOfMemoryError writes heap dump on first OutOfMemoryError Here the heap dump will be generated in the “current directory” of the JVM by default. It can be explicitly redirected with -XX:HeapDumpPath= for example -XX: HeapDumpPath=/disk/myFolder.

Page 5: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Shallow, Retained Heap Shallow heap is the memory consumed by one object. An object needs 32 or 64 bits

(depending on the OS architecture) per reference, 4 bytes per Integer, 8 bytes per Long, etc. Depending on the heap dump format the size may be adjusted (e.g. aligned to 8, etc...) to model better the real consumption of the VM.

Retained set of X is the set of objects which would be removed by GC when X is garbage collected.

Retained heap of X is the sum of shallow sizes of all objects in the retained set of X, i.e. memory kept alive by X.

Page 6: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Shallow vs Retained Heap The retained set for a leading set of objects, such as all objects of a particular class or all

objects of all classes loaded by a particular class loader or simply a bunch of arbitrary objects, is the set of objects that is released if all objects of that leading set become unaccessible. The retained set includes these objects as well as all other objects only accessible through these objects. The retained size is the total heap size of all objects contained in the retained set.

Page 7: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Object Reference Graph

Page 8: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Dominator Tree An object x dominates an object y if every path in the object graph from the start (or the root) node to y

must go through x. The immediate dominator x of some object y is the dominator closest to the object y. A dominator tree is built out of the object graph. In the dominator tree each object is the immediate

dominator of its children, so dependencies between the objects are easily identified.

The dominator tree has the following important properties: The objects belonging to the sub-tree of x (i.e. the objects dominated by x ) represent the

retained set of x . If x is the immediate dominator of y , then the immediate dominator of x also dominates y , and so on. The edges in the dominator tree do not directly correspond to object references from the object graph.

Page 9: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Object graph to Dominator Tree

Page 10: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Heap Analysis using MAT

Page 11: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Heap Dump – Biggest Objects

11

Page 12: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Heap Dump – Histogram

12

Page 13: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Heap Dump – Histogram

13

Page 14: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Analyzing Threads

14

Page 15: Heap Dump Analysis - AEM: Real World Issues

© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

THANK YOU !

Page 16: Heap Dump Analysis - AEM: Real World Issues