Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Heap Dumps Java JRE7

Tags:

java

heap-dump

I'm trying to generate a heap dump from my java program, but no matter what I seem to try I can't seem to figure out how to do so.

I downloaded the Eclipse Memory Analyzer (Plugin and then Standalone) which is supposed to be able to aquire heat dumps from active jre processes.. yet it lists none. The documentation lists several otherways of generating them, but I can't seem to make any of them work, or they refer to something that just doesn't seem to exist on my system. Same applies from anything I've managed to find on the web...

The program isn't causing an out of memory exception, its just using far more resources then I'm expecting it too.

I'm just at a complete loss at how exactly its supposed to be done :/

Any help would be appreciated thanks.

like image 903
user2491165 Avatar asked Jun 16 '13 17:06

user2491165


People also ask

How do you get heap dump on OutOfMemoryError?

They are very useful to troubleshoot memory-leak problems and optimize memory usage in Java applications. In order to capture a heap dump automatically, we need to add the HeapDumpOnOutOfMemoryError command-line option that generates a heap dump when a java. lang. OutOfMemoryError is thrown.

Why heap dump is generated?

The JVM generates the Heap Dump file in the specified file path. Sometimes we might require Heap Dump in an on-demand basis. For example, during the peak load, an application may become slower and the memory consumption might be more. To troubleshoot the memory consumption, we require Heap Dump.


1 Answers

You can do it manually, using Java JDK's jmap.exe.

  • You get the PID of your process.
  • Navigate to %JAVA_HOME%/bin/ (JDK)
  • In the console (Command Prompt) type jmap.exe -dump:format=b,file=C:\dump\dump.bin PID
    • dump file is saved in the path you provide (in my example is C:\dump\dump.bin)

Then you can use NetBeans IDE to analyze this dump. It has an inbuilt tools, just import the dump.bin.

like image 149
darijan Avatar answered Oct 01 '22 12:10

darijan