How do I analyze a .hprof file?

I have a production server running with the following flag: -XX:+HeapDumpOnOutOfMemoryError

Last night it generated a java-38942.hprof file when our server encountered a heap error. It turns out that the developers of the system knew of the flag but no way to get any useful information from it.

Any ideas?

Asked by: Kelsey899 | Posted: 21-01-2022

Answer 1

If you want a fairly advanced tool to do some serious poking around, look at the Memory Analyzer project at Eclipse, contributed to them by SAP.

Some of what you can do is mind-blowingly good for finding memory leaks etc -- including running a form of limited SQL (OQL) against the in-memory objects, i.e.

SELECT toString(firstName) FROM com.yourcompany.somepackage.User

Totally brilliant.

Answered by: Andrew335 | Posted: 22-02-2022

Answer 2

You can use JHAT, The Java Heap Analysis Tool provided by default with the JDK. It's command line but starts a web server/browser you use to examine the memory. Not the most user friendly, but at least it's already installed most places you'll go. A very useful view is the "heap histogram" link at the very bottom.

ex: jhat -port 7401 -J-Xmx4G dump.hprof

jhat can execute OQL "these days" as well (bottom link "execute OQL")

Answered by: William521 | Posted: 22-02-2022

Answer 3

You can also use HeapWalker from the Netbeans Profiler or the Visual VM stand-alone tool. Visual VM is a good alternative to JHAT as it is stand alone, but is much easier to use than JHAT.

You need Java 6+ to fully use Visual VM.

Answered by: Kelsey727 | Posted: 22-02-2022

Answer 4

Just get the Eclipse Memory Analyzer. There's nothing better out there and it's free.

JHAT is only usable for "toy applications"

Answered by: Fiona421 | Posted: 22-02-2022

Answer 5

I personally prefer VisualVM. One of the features I like in VisualVM is heap dump comparison. When you are doing a heap dump analysis there are various ways to go about figuring out what caused the crash. One of the ways I have found useful is doing a comparison of healthy vs unhealthy heap dumps.

Following are the steps you can follow for it :

  1. Getting a heap dump of OutOfMemoryError let's call it "oome.hprof". You can get this via JVM parameter HeapDumpOnOutOfMemoryError.
  2. Restart the application let it run for a bit (minutes/hours) depending on your application. Get another heap dump while the application is still running. Let's call it "healthy.hprof".
  3. You can open both these dumps in VisualVM and do a heap dump comparison. You can do it on class or package level. This can often point you into the direction of the issue.

link :

Answered by: Daryl343 | Posted: 22-02-2022

Answer 6

YourKit Java Profiler seems to handle them too.

Answered by: Max829 | Posted: 22-02-2022

Answer 7

If you want to do a custom analysis of your heapdump then there's:

This library is fast but you will need to write your analysis code in Java.

From the docs:

  • Does not create any temporary files on disk to process heap dump
  • Can work directly GZ compressed heap dumps
  • HeapPath notation

Answered by: Catherine342 | Posted: 22-02-2022

Similar questions

java - How to analyze heap data from .hprof file and use it to reduce memory leaks?

In recent times, I have encountered java.lang.OutOfMemoryError exception while running an application. During one such instance, I was able to get the heap dump using jvisualvm. I am able to open the .hprof heap dump file obtained from the heap dump using NetBeans 8.1 IDE but I am not aware of how to analyze the data dump. I'd like to know how to read the ...

heap dump - Can I analyze .hprof file with Java code?

I just learned Java Mission Control. I thought about how to make Java Flight Recorder with Java code. I analyzed the heap file with lots of different tools, but this time I want to do it with code.

java - best way to analyze xml stanza from xmpp

i get stream of xml stanza from log. i want to understand the flow , currently what i can think of is get the spec from protocol and try to understanding each line. Is there any best prastice do you folks do to understand the xml stream? any easier way?

java - visual vm analyze memory leak

in my visual vm, i click on sample->memory, and i keep see "windowprincipal" class, instances stay at 25. even that right now nobody using the application. is this sign of memory leak?

java - How to analyze the heap dump using jhat

I ran the jhat on the heap dump, it has generated the reports. How do i use the report to analyze the heap.I couldn't understand completely other than the instance count. Is there any references or case studies on that. In short, i need to proceed furthur, How can i? Also what is object query language.

Best way to analyze http traffic sent by my java code?

I have some java code both new (using Apache commons http libraries) and old (strictly using java 1.4 API) and am trying to rewrite the old code using the newer apache commons libraries. However, it isn't working and I'm struggling to find out why. The requests are being sent, but my newer code times out on the receiving server which I don't have access to. Since the old code works, I must have mucked up the http request...

java - how to analyze an XML file?

Closed. This question does not meet Stack Overflow guid...

java - analyze text files

I have a noob question. My java project analyzes text files. There are three ways that the data can appear: 1. Search-term-A: data-to-collect-A 2. data-to-collect-B, search-term-B 3. data-to-collect-C@search-term-C I manage to collect all relevant lines by finding the search term inside. I did this by implementing grep in my app. But I ...

java - how to analyze jvm crash dump with .pdb file and .dll

I encountered java crash dump from running java process that using jni native library. I have a dll and a pdb file of native library emitting crash dump. but i don't get exact section where cause jvm crash dump. I read this blog.

How do I analyze volume, pitch and speed of a .wav file in Java?

So, I'm trying to remake Vib Ribbon: The input will be a .wav file, and I haven't the slightest idea of how to analyze it and create thresholds for volume and pitch that would create different obstacles- I've been pointed to Fourier transforms, which I don't understand. Can someone point me to a waveform analy...

Using JLayer (AKA JavaLayer) to analyze mp3 files in java?

I would like to perform a FFT on frames of an MP3 file using Java (think spectrum analyzer). I found JLayer which seems to fit the requirement of MP3 Decoding, but I'm not sure how to use it (Most examples are simply players that use the higher level helper, but that's not what I am looking for). FFT seems easy compared to decoding MP3 files ;)

java - How do you analyze fatal -javaagent errors?

I am trying to add a static method call to the java.lang.Object constructor using the java.lang.instrument API. I know I have the basics right because it works if I make the method call System.gc(). I verified this by running -verbosegc with and without the instrumentation. If I change the method call to a static class/method in my own package I get a fatal error: Exception in thread "main" FATAL ERROR in n...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)