Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect root cause in heap dumps in java

Tags:

java

heap-dump

In a java heap dump how do I know exactly where in the code/which thread caused the dump?

like image 238
Jim Avatar asked Jun 29 '26 00:06

Jim


2 Answers

For reading the memory dumps:

I would recommend you to try "eclipse memory analyzer" From here

Another option (free) would be opening this with JVisualVM (available at $JAVA_HOME/bin) jhat is cool too but was already recommended :)

Now, you're asking about the thread that caused memory heap-dump and not about how to proceed with memory dump... It depends on how did you obtain the memory dump. There are different ways to obtain the dump.

  1. On your process you can instruct the JVM to produce memory dump once OutOfMemory error is encountered, in this case I believe it will be the JVM itself.

  2. You can trigger the heap dump creation from the MBean given you have a JMX Server running along with your JVM Example

  3. You can even use system calls (on linux) externally to your application: kill -3 _YOUR_JAVA_PROCESS_ID_ will generation the heapdump.

But I hardly can imagine why would you need such an information. Later in comments you mention 'exact line of code' but these ways are usually external to your JVM... Are you sure you need a line of code that generated heap dump itself, or you're trying to identify the real issue?

Hope this helps

like image 165
Mark Bramnik Avatar answered Jul 01 '26 15:07

Mark Bramnik


In java you create object some where, use it in many places and the let GC to collect it back. There is no single line causing a leak.

What you should look for in tools like MAP is objects count and heap used by them. Pick each of the target class and see why they are not garbage collected. (some one is holding reference more than needed- say a static field )

You may find instructions from this page more useful - http://scn.sap.com/people/krum.tsvetkov/blog/2007/07/02/finding-memory-leaks-with-sap-memory-analyzer (also linked from MAT homepage)

like image 45
Jayan Avatar answered Jul 01 '26 15:07

Jayan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!