Memory Dumps:
Most of the memory leaks result in the appserver or the java process crashing with an out of memory error. So just to be proactive and be able to get memory dump when that happens, it is a often a good idea to pass the following arguments to the JVM
 -XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/path to file for heapdump/
Prints a histogram of class instances on Ctrl-Break-XX:OnOutOfMemoryError="<cmd args>-XX:-PrintClassHistogram
Memory dumps can also be taken on live java processes using jmap command. There are subtle variations in the way it can be used on 1.5 and 1.6
-  Java 1.5: jmap -heap:format=b 
 Works intermittently and definitely doesn't work more than once on the same process due to the problems with jmap in java 1.5
- Java 1.6: jmap -dump:format=b,file=heap.bin or jmap -dump:live,format=b,file=heap.bin 
 Live option only gives the heap remained after running garbage collection. Jmap will create a file called heap.bin in the directoy jmap is run from
 Memory dumps can be taken from JConsole as well from 1.6.
Memory Dump Analysis:
Once we have the memory dumps, the next step is to analyze the dumps. One tool that was really useful for this purpose is
MAT: Eclipse based tool for analyzing the memory dumps.
http://www.eclipse.org/mat/
Thread Dump:
When applications result in any deadlocks , analyzing the threads will help us in getting to the root cause of the problem. Thread dumps can be take on linux using
1. kill -3
2. For Jboss process, we can take the thread dump from jmx-console as well (jboss.system->ServerInfo->listThreadDump operation)
3. Jstack
Analyzing Thread Dumps:
Once taking thread dumps , they can be analyzed and checked for deadlocks using Lockness
Lockness is a plugin for eclipse to analyze the thread dumps.
http://lockness.plugin.free.fr/home.php
-XX:-PrintConcurrentLocks
-XX:-TraceClassLoading
-XX:-TraceClassLoadingPreorder
 
 
No comments:
Post a Comment