Generate Heap Dump in Unix

Heap dump provides the insight into the JVM - shows live objects on the heap (reachable and unreachable) along with their types and values. In addition it also provides no of objects and their size as %age of total heap size.We have many ways to get the heap dump in Windows. Some are as follows:-

  1. jconsole
  2. jVisual VM
  3. Eclipse MAT ....and it goes on
Out of above , i like jVisualVM the most due to its monitoring capability, interactive display, and easy to use. But the problem comes with the unix. Even though we can monitor the application remotely  but we cannot see the live objects, their size and number i.e we cannot get the heap dump remotely.

To get the heap dump on Unix machine, we can use jmap. To use jmap, we need the process id of java application. At times, we have lot many java process running in unix and its difficult to identify. Java provides jps tool which list the JVM with the process Id which it got the access . The steps are as follows:-
  1. Type jps on unix. This will list down all java process running on Unix 
  2. Use jmap as  jmap -dump:file=<filename> <processid>                                                                      e.g. jmap -dump:file=heap1.hprof 6771
  3. File created would be read only. If you want to copy, you have the chnage the acess rights. to use we can use chmod as  :-                                                                                                                                  chmod 777 heap. hprof   
We can copy the dump to windows machine and run jvisualVM. Goto File --> Load



Browse the file in windows as shown and click ok.


Now the dump is loaded in jvisual VM. Next screem shows the summary, classes and instances. summary shows the objects,classes and instances loaded into JVM, classes shows all the classes loaded with no of instances and size as shown.

Summary View:-



Class View:- 



In my Next post, I will be discussing how to analyse heap dump in Eclipse MAT

Resource:-

Comments

Post a Comment

Popular posts from this blog

When to use getClass() and instanceOf in Java

Fix double check locking in Java 5