How can we analyze JAVA memory issues (java.lang.OutOfMemoryError: Java heap space) using ECLIPSE MAT and Jprofiler: II

Prabhash Dilhan Akmeemana
5 min readSep 19, 2023

--

In my previous article[1] I discussed how we can use ECLIPSE MAT to analyze the heap dumps and find the cause of the heap OOM issues. In this article, I’m going to talk about the Jprofiler features and how we can utilize the tool to analyze the heap dump.

First, you need to open the heap dump file(.hprof) using the Jprofiler and it will take some time to process and open the heap dump if the dump file is a large file.

MAT is a free tool and but you need to purchase a license key to use the full features of the Jprofiler.

If you are going to check memory leak/high memory issue, you need to click on the biggest object button. The biggest objects view shows a list of the most important objects in the current object set. “Biggest” in this context means the objects that would free most memory if they were removed from the heap. That size is called the retained size.

Just expanding the objects will show the outgoing references and you will be able to find the actual object that consumes the memory. Please refer to the attached screenshot below.

By looking at the object references and objects that consume the most of the memory, you will be able to find the culprit if you cross-check those reference objects with the code base. As we discussed in the previous article, let’s assume that a Byte array is shown as the biggest object in the heap. But it is a core java level object and you need to find the usage of that Byte array from your code. In order to do that, you need to check the incoming reference to the Byte array objects. From the Jprofiler, you can get incoming/outgoing references to a particular object by navigating right-click on the object > Use Selected object > References.

Let’s say you want to check the content of the Byte array object, In jprofiler you can’t see that. But using MAT, you will be able to check the content of the Byte array and copy its content to a file as below.

In Jprofile, it shows the byte[] content as below.

But in MAT, you can see the content and copy that into a file.

So these kinds of feature differences are there when comparing these two tools. Hence i always try to use both tools every time and try to get the best output from both tools.

Let’s discuss how we can search or filter particular objects based on criteria like, less than the assigned value of a variable, etc. In Jprofiler, we can easily do that. Let me share one of my experiences so that you can get a better understanding.

There was an OOM situation in WSO2 APIM and by looking at the heap dump, we saw that the org.apache.http.impl.nio.reactor.IOSessionImpl objects consume most of the memory and the object count is high. We knew that these objects were created per connection. Hence we thought that there could be a huge load on the server and that’s why we observed the OOM issue. In order to confirm the time frame we did the below analysis.

In the org.apache.http.impl.nio.reactor.IOSessionImpl object there is a variable that is used to store the started time.

We needed to check how many objects were created within 5 minutes. In order to do that, we just need to right-click -> Applying the filter By Restricting the selected value. Then another window will pop up and you just need to add the filter and get the outgoing references.

In MAT, if you are going to do such kind of filtering, you need to use OQL[2] which will be a bit hard for beginners. Object Query Language(OQL) is an SQL-like language used by Memory Analyzer for exploring a heap dump. (Near future, I will write a separate article to share some common OQL queries with you).

As mentioned earlier, these kinds of feature differences are there and it is better if you can use both the tools and compare the results to get a better analysis of the heap dump.

OK, That’s it for now. Next article, I will discuss java.lang.OutOfMemoryError: GC Overhead limit exceeded error and how we can analyze heap dumps to find the cause of that.

[1] https://medium.com/@prabhashdilhanakmeemana/how-can-we-analyze-java-memory-issues-java-lang-outofmemoryerror-cf41d3643ba5

[2] https://wiki.eclipse.org/MemoryAnalyzer/OQL

--

--