Heap dump is
important when it’s come to performance testing.
Let’s start with
what is heap in an application.
Heap: Heap is dynamically collective amount of data /memory in partially binary
sorted tree structure.
But we need to
loop up on heap in term of memory.
Heap is part of memory where memory for objects assigned dynamically.
Heap dump: Heap Dump is snapshot of memory at certain
point which contains below mentioned information:
-information of
java objects
-information of
java classes
or we can define
as
A heap dump is a
textual or binary representation of the Java heap which is usually written to a
file.
Heap dump is
always helpful to analyze memory leak or high usage of memory of java application.
There are various tools which help us to generate the heap dump. We can also
generate heap dump without using tools. What we require is JVM (Java Virtual
Machine)on system.
There are various
vendors for JVM but let’s concentrate on Sun JVM.
Methods through which we can generate heap dump
with help of SUN JVM:
-
Automatically
when outofmemoryerror exception occurs
-
Using jmap
tool (command line tool)
1. Automatically
when outofmemoryerror exception occurs: Using below command on JVM command line , we
can generate heap dump whenever outofmemoryerror occurs in system:
- XX:+HeapDumpOnOutOfMemoryError
Note: it will make JVM to generate heap
dump when outofmemoryerror occurs in system and
save it in current directory.
2.
Using jmap
tool (command line tool): if jmap tool is available in JVM then using below
command, heap dump can be generated:
jmap -dump:file=path_to_file java_process_id
Note: The Java process id determines which local JVM should be dumped. The
process Id can be determined with the JVM Tool jps
But
if jmap is not available with JVM then we can use below mentioned command on
windows:
-XX:+HeapDumpOnCtrlBreak
In next post i will share how to analyze heap dump.
Happy Exploring !!!
Comments
Post a Comment