Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java heap dump analysis for lambda expressions

My Java application heap dump shows that a specific lambda used in my class has locked up some amount of memory and its not being released during GC.

Heap shows the specific anonymous lambda class as ParentClass$$Lambda$ID and in current case, the ID is 79(image attached). This ID does not seem to have any relation with the number of lambdas that exist in the class and hence we cannot conclude on which lambda is represented. I'm interested to point at the exact lambda expression as it helps in analyzing, fixing and testing the scenarios related.

Decompiling the class file with DJ did not help as it recreates the lambda expressions to a readable code. Let me know if any ideas on this.

enter image description here

like image 216
Pavan Kumar Avatar asked Jun 19 '15 09:06

Pavan Kumar


People also ask

How do you analyze a heap dump in Java?

We will first start the Memory Analyzer Tool and open the heap dump file. In Eclipse MAT, two types of object sizes are reported: Shallow heap size: The shallow heap of an object is its size in the memory. Retained heap size: Retained heap is the amount of memory that will be freed when an object is garbage collected.

How do you analyze a heap dump for out of memory?

If you are trying to test memory leakage in your application all you have to do is to identify the object which gets accumulated in the heap every time you access the application. To effectively identify the objects first take and initial heap. Then perform some action in your application.

How do you take the heap dump of a Java process?

Right-click on one of the Java process. Click on the 'Heap Dump' option on the drop-down menu. Heap dump will be generated. File path where heap dump is generated will be specified in the Summary Tab > Basic Info > File section.

What is Java heap dump?

A heap dump is a snapshot of all the objects that are in memory in the JVM at a certain moment. They are very useful to troubleshoot memory-leak problems and optimize memory usage in Java applications. Heap dumps are usually stored in binary format hprof files.


1 Answers

Try defining the system property

jdk.internal.lambda.dumpProxyClasses=/path/to/dir

when invoking the JVM. This will cause the runtime to write the dynamically generated lambda classes to disk, where you can inspect them with javap. This will enable you to see what fields (captured variables) they hold, and what lambda body method the lambda corresponds to.

like image 196
Brian Goetz Avatar answered Nov 15 '22 07:11

Brian Goetz