Fully featured low overhead profiler for Java EE and Java SE platforms.
Ultimate profiling and monitoring solution for Gradle, Maven, Ant, JUnit and TestNG.
Easy to use performance and memory profiler for .NET framework.

ClassValue memory leak detection

Moderators: Vladimir Kondratyev, Anton Katilin

ClassValue memory leak detection

Postby henryptung » Thu Nov 12, 2015 5:02 pm

Hi YourKit folks,

Not sure if this is the right place to report bugs, but here goes.

I recently worked on debugging a mem leak which (spoilers) was due to https://issues.apache.org/jira/browse/GROOVY-7591, and https://bugs.openjdk.java.net/browse/JDK-8136353. This occurred in the presence of dynamic classloading and unloading, so the issue was that this single strong reference prevented GC of the classloader, and subsequently of an in-memory byte-array-jar.

The strange thing here is that YourKit seemed unable to detect the issue, and insisted that the classloader was only weakly/softly reachable. By contrast, when I tried using MAT, it picked up the strong reference via Class.classValueMap immediately.

I really love YourKit here, the UI is miles ahead, but I hope issues like this don't lead other devs down rabbit holes like it did to me.

Thanks!
henryptung
 
Posts: 2
Joined: Thu Nov 12, 2015 4:49 pm

Re: ClassValue memory leak detection

Postby henryptung » Thu Nov 12, 2015 5:04 pm

Also, possibly useful notes:

Version: 2015 build 15074
JDK version: Oracle 8u66, OS X 64-bit
henryptung
 
Posts: 2
Joined: Thu Nov 12, 2015 4:49 pm

Re: ClassValue memory leak detection

Postby Anton Katilin » Thu Nov 12, 2015 8:58 pm

Hi,

Thank you for your kind words and for reporting this issue.

Could you please provide an example of HPROF dump demonstrating this problem. You can zip it, upload to DropBox or similar service and either put the download link here or, if you cannot publish it, send to support@yourkit.com

Best regards,
Anton
Anton Katilin
 
Posts: 5576
Joined: Wed Aug 11, 2004 8:37 am

Re: ClassValue memory leak detection

Postby Anton Katilin » Thu Nov 12, 2015 10:12 pm

Update: we have reproduced the problem, so no snapshot example is needed anymore.
Anton Katilin
 
Posts: 5576
Joined: Wed Aug 11, 2004 8:37 am

Re: ClassValue memory leak detection

Postby Anton Katilin » Fri Nov 13, 2015 1:23 pm

Update 2:

We have added special handling of ClassValueMap to the upcoming EAP build.

Some technical detail, if it's interesting:

1. It is possible to see these maps in HPROF snapshots only. The profiler format snapshots (.snapshot) are created with the help of JVMTI functionality, and it looks like for some reason JVM does not report all fields for the maps ClassValueMap. We're still investigating and perhaps will find a bug in the agent, but at this moment we tend to think this is due to a Java bug.

2. The upcoming EAP build will show these maps via a field reference "Class.classValueMap".

This works for Java 7 and Java 8. Although java.lang.Class's instance field values are not reported in HPROF format, we can identify which map belongs to which class by using the value of the field "type" of class ClassValue$ClassValueMap.

In recent Java 9 build the field "type" is absent (perhaps it's to fix the original bugs you've mentioned), and we do not know which class each ClassValueMap belongs to. As a workaround we show the maps as GC root of type "Held by JVM".
Anton Katilin
 
Posts: 5576
Joined: Wed Aug 11, 2004 8:37 am

Re: ClassValue memory leak detection

Postby Anton Katilin » Mon Nov 16, 2015 1:03 pm

Hi,

We've released EAP build 8:
https://www.yourkit.com/eap/

Please see the changes in build 8 for detail on how ClassValueMap is now supported.

Best regards,
Anton
Anton Katilin
 
Posts: 5576
Joined: Wed Aug 11, 2004 8:37 am

Re: ClassValue memory leak detection

Postby candrews » Mon Dec 28, 2015 5:04 am

The field "type" of class ClassValue$ClassValueMap. was removed in Java 9 because the field wasn't used for anything, see https://bugs.openjdk.java.net/browse/JDK-8032606 "ClassValue.ClassValueMap.type is unused"

Has anyone made progress on determine the root cause of https://bugs.openjdk.java.net/browse/JDK-8136353 or found a fix for it?
candrews
 
Posts: 1
Joined: Mon Dec 28, 2015 3:10 am

Re: ClassValue memory leak detection

Postby Anton Katilin » Mon Dec 28, 2015 6:52 am

Hi candrews,

The field "type" of class ClassValue$ClassValueMap. was removed in Java 9 because the field wasn't used for anything, see https://bugs.openjdk.java.net/browse/JDK-8032606 "ClassValue.ClassValueMap.type is unused"
Thank you for pointing this out. It's good that they have removed this field. Nevertheless, the special handling of ClassValueMap we've introduced still makes sense for Java 7 and Java 8 which are used in production nowadays, and will stay used for a long time after Java 9 release.

Has anyone made progress on determine the root cause of https://bugs.openjdk.java.net/browse/JDK-8136353 or found a fix for it?
I think it makes sense to ask this questions in JDK forums or add a comment directly to this bug.

Best regards,
Anton
Anton Katilin
 
Posts: 5576
Joined: Wed Aug 11, 2004 8:37 am


Return to Java Profiler

Who is online

Users browsing this forum: No registered users and 7 guests