Taking and using the heap dump information is very critical for successful career in Java Development. It will be very hard to believe that if you had done successful Java development, you had never taken or analyzed heap dump. In my career I had done many production deployments and solved many critical production and non production issues where I think without heap dump it will be very tough and some time almost next to impossible to solve certain issues. I had be approached by many how to take and analyse heap dump especially who are new or not mature to Java development. So this blog might help them to get some basic to some detail information about the heap dump in step by step order. Lets start with exactly what is heap dump ?.
What is Heap Dump:
Heap dump is a snapshot of the memory of a Java process at a certain point of time. It contains the information about objects loaded in memory, classes,
garbage collection roots, thread stack, local variables.
Using this information any body can get the following details:
1) How many classes loaded.
2) How many objects created.
3) How many heap space available and occupied.
4) What were the JVM parameters/options used for that run.
5) Heap used by each object type.
6) Thread status.
7) Thread call stack - exactly which method was getting evoked during that time.
8) Unreachable objects and many more. But this information is at the point of heap dump and it doesn't reflect the JVM past state.
When to take Heap Dump and why :
1) When your application seems hanging.
2) When there is sudden spike in memory.
3) When application crash due to out of memory issue.
4) When you want introspection into JVM at particular time or event.
Triggering of Heap Dump:
1) Triggering Heap Dump under live running application.
2) Triggering Heap Dump when the application goes out of memory.
Note: When you trigger the heap dump all the active threads are stopped (duration depends on the heap size) . This can lead to performance issue as many critical application cannot tolerate such activity.
Ways to Trigger Heap Dump:
Heap Dump on out of memory:
java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath= ....
or add to JAVA_OPTS if you are using tomcat etc.
Manually taking heap dump of running application:
Find the process id of the application:
jps -lv or ps aux | grep java. -- Recommended is jps
then take heap dump with jmap
jmap -dump:file=<> <>
jmap -dump:file=heap_dump.hprof 4208
Manually taking heap dump using the UI tool:
Start jvisualvm --> Navigate to the process --> go to monitor tab --> Click Heap Dump Button.
Knowing the object size and no of instances:
jmap -histo:live <>
jmap -histo:live 4208
Note you can also take the heap dump by enabling the JMX.
In next blog I will give the tips to analyze the Heap Dump
1) When your application seems hanging.
2) When there is sudden spike in memory.
3) When application crash due to out of memory issue.
4) When you want introspection into JVM at particular time or event.
Triggering of Heap Dump:
1) Triggering Heap Dump under live running application.
2) Triggering Heap Dump when the application goes out of memory.
Note: When you trigger the heap dump all the active threads are stopped (duration depends on the heap size) . This can lead to performance issue as many critical application cannot tolerate such activity.
Ways to Trigger Heap Dump:
Heap Dump on out of memory:
java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=
or add to JAVA_OPTS if you are using tomcat etc.
Manually taking heap dump of running application:
Find the process id of the application:
jps -lv or ps aux | grep java. -- Recommended is jps
then take heap dump with jmap
jmap -dump:file=<
jmap -dump:file=heap_dump.hprof 4208
Manually taking heap dump using the UI tool:
Start jvisualvm --> Navigate to the process --> go to monitor tab --> Click Heap Dump Button.
Knowing the object size and no of instances:
jmap -histo:live <
jmap -histo:live 4208
Note you can also take the heap dump by enabling the JMX.
In next blog I will give the tips to analyze the Heap Dump
No comments:
Post a Comment