Bulk Emailing

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 4 May 2010

My Day with Eclipse MAT and Dominator Tree

Posted on 18:43 by Unknown

Eclipse MAT (Memory Analyzing Tool) is a feature rich Heap Dump analysis tool. This helps you to track down important pointers on MOB (Memory Out of Bound) Exception. Sun JVM (1.4.2 onwards) supports the feature of creating HPROF HeapDump. MAT parses heap dump file (i.e. .hprof) and gives graphics intuitive description of Memory Leak suspects.

The most important information of Heap Dump is “Dominator Tree”, in simple word, it lists the objects and the amount of memory space that they are holding. Before understanding “Dominator Tree”, you need to know 3 important concepts of Java Objects- Shallow Size, Retain Size and Retain Set. There is a nice article which explains this concept.

How to find out the Biggest Retain Set ?

The best possible approach to find out the biggest “Retain Set” and hence the maximum prospect of releasing heap storage on next Garbage Collection (GC), is “Dominator Tree” graph. Dominator Tree Algorithm converts the Object Reference Graph to Dominator Tree, the fastest way to find out the biggest “Retain Set”.

In the following section I'll try to explain how to analyze Dominator Tree with an example code where I have added multiple inter-dependent object references and an infinite loop to get MOB Exception.

Dominator Tree (Eclipse MAT)





Dominator Tree (java_pid1076.hprof)





Retained Heap = 96 (Shallow Heap of Data i.e. 32 + Retained Heap of A, B, C, D i.e. 48)

Shallow Size of Data = 32 {8 (header) + 4 (String header) + 4 (A header) + 4 (B header) + 4 (C header) + 4 (D header)}

Note:You need to set VM argument (-XX:+HeapDumpOnOutOfMemoryError) to get HPROF heap dump if there is any MOB Exception.

Object Reference graph to Dominator Tree Conversion



Object Reference Graph

Data-> {a, b, c, d}

b-> {c}

d-> {b, c}

Dominator Tree (Retain Set)

Data-> {Data, a, b, c, d}

a -> {a}

b -> {b}

c -> {c}

d -> {d}

Note: Here a, b, c, d are instances/objects of A, B, C and D classes.

Above example uses following classes-

public class HeapDemo {

public void eatUpMemo(){

// do some

ArrayList fatMan = new ArrayList();

for(;;){

Data d = new Data();

fatMan.add(d);

}

}

}

public class Data {

String title = "ABC";

A a = new A();

B b = new B();

C c = b.getC();

D d = new D(b);

}

public class A {

int x = 10;

}

public class B {

int y = 20;

C c = new C();

public C getC(){

return c;

}

}

public class C {

int z = 30;

}

public class D {

C c;

B b;

public D(B b){

this.b = b;

c = b.getC();

}

}



Reference:

  • Dominator Tree
  • Determining Shallow Size of Java Object

Email ThisBlogThis!Share to XShare to Facebook
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • CityWeather
    Update: Release 1.1 has been uploaded. It will now provide weekly forecast of your selected cities. Download   CityWeather is an Android...

Blog Archive

  • ►  2013 (6)
    • ►  September (2)
    • ►  May (1)
    • ►  April (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2012 (4)
    • ►  July (2)
    • ►  March (1)
    • ►  January (1)
  • ►  2011 (11)
    • ►  November (1)
    • ►  October (2)
    • ►  August (1)
    • ►  June (1)
    • ►  April (2)
    • ►  March (3)
    • ►  January (1)
  • ▼  2010 (27)
    • ►  December (2)
    • ►  November (3)
    • ►  September (2)
    • ►  August (4)
    • ►  July (4)
    • ►  June (7)
    • ▼  May (5)
      • Few Simple Steps to Setup TWiki
      • Android Custom TextView
      • My Day with Eclipse MAT and Dominator Tree
      • An effort to find out Angling spots in Delhi & NCR
      • A tiny Java connector for Facebook
Powered by Blogger.

About Me

Unknown
View my complete profile