Monday, August 6, 2018

Java - Heap Dump, Core Dump




Heap dump - Collection of objects that are in memory (JVM)
Thread dump - Shows what each thread in a process is doing at a given point in time along with the stack trace.
Core dump - O/S level dump file which has O/S level info in addition to the heap dump.

Heap dump - is useful to
analyse OOM situations.
Thread dump - To troubleshoot slow running of your application.
Core dump - When your
JVM has crashed abruptly. To find details about native calls and so on.
Core dump will be generated automatically if a program crashed due to segmentation fault or some other reason. But core dump will not be generated if an application halt and been terminate by control+c or conventional way of kill or pkill.

In order to force a core dump generation you could run kill -6 <
PID>

You should also make sure that you have enabled it and have provided enough space and permissions for it to get generated.

For Linux, the
coredump is turned off by default on all systems. For RedHat Advanced Server 2.1, it should be under /etc/security. There should be a self-explanatory file called limits.conf and look for the word "core". If set to "0", then coredump is disabled.

For Solaris, you can also make sure core files are enabled with the
coreadm command.

Check
ulimit -a to see whether your environment allows core files to be produced.
ulimit -c (This is the size limit of the core file. Fix it with ulimit -c unlimited).
Kernel limitation (hard limit for
ulimit -c).
Available disk space for the user (e.g., is there disk quota?).
          jmap -dump:file=path_to_file java_process_id





Heapdump can be taken in number of ways:

Via Java VM parameters:
-XX:+
HeapDumpOnOutOfMemoryError writes heap dump on OutOfMemoryError (recommended)
-XX:+
HeapDumpOnCtrlBreak writes heap dump together with thread dump on CTRL+BREAK

Using
JRockit:

-
jrcmd pid hprofdump filename=name_of_dump_file

Using
Jmap:

-
jmap -heap:format=b pid

Note: use -J-d64
jvm option if your JVM is 64 Bit Jvmjmap -J-d64 -heap pid

You can also manually generate a heap dump with tool
VisualVM.

Using HPROF:

You can use HPROF: Heap and CPU Profiling Agent.
A complete dump of the current live objects in the heap can be obtained with:

-java -
agentlib:hprof=heap=dump,format=b -jar application

This will automatically dump heap when java application is terminated. You can also force heap dump by sending QUIT signal to java process with kill -QUIT
pid command.

Analysing Heapdump file using Jhat

You can use
jhat (Java Heap Analysis Tool) to read the generated file:

-
jhat [ options ] <heap-dump-file>

The
jhat command parses a java heap dump file and launches a webserver. jhat enables you to browse heap dumps using your favorite webbrowser.
Note that you should have a
hprof binary format output to be able to parse it with jhat. You can useformat=b option to generate the dump in this format.





No comments:

Post a Comment

Hyderabad Trip - Best Places to visit

 Best Places to Visit  in Hyderabad 1.        1. Golconda Fort Maps Link :   https://www.google.com/maps/dir/Aparna+Serene+Park,+Masj...