Question in understanding ClassValue better

Jochen Theodorou blackdrag at gmx.org
Thu May 19 14:27:02 UTC 2016


Hi,

at the beginning of this year I had an exchange with Peter Lavart about 
JDK-8136353 (see 
http://mail.openjdk.java.net/pipermail/mlvm-dev/2016-January/006563.html), 
and that is probably based on wrong assumptions. But I must confess I 
still have trouble understanding ClassValue semantics. And since the 
ClassValue problem in Groovy came up again, I though I make another try 
based on a list of assumptions and asking if they are wrong or right

1) ClassValue can be basically understood as a strong reference of a 
class to a class value
2) a ClassValue associated with a system class (for example 
Integer.TYPE) is never garbage collected
3) a ClassValue from a different loader than the system loader, 
associated with a system class, will prevent that loader to unload
4) a ClassValue referencing to the class it is associated with, does not 
prevent the collection of that class

Point 2 and 3 are kind of problematic for me and I wish them wrong, but 
they would follow from 1. The exchange with Peter makes me think 
assumption 4 is wrong... just I don't understand why.

If those assumptions are right, then I actually wonder in what cases I 
should use ClassValue without causing memory leaks. What I wanted to use 
it for is to associate a meta class with every class I need a meta class 
for. This includes system classes. If 3 is right, then doing so would 
prevent the Groovy runtime from being unloaded. Even if the meta classes 
are able to unload, the implementation of the ClassValue would still be 
there. And since that comes from the same loader, that loaded the 
runtime, that loader will stay. Now loading and (trying to) unload the 
Groovy runtime countless times would end up in a OOME at some point 
(permgen problem in older JDKs). And even if I would do something else 
for class from the standard loaders, I would still get into trouble on 
for example Tomcat. Not to forget that having two parallel structures 
for this raises the question as of why to use ClassValue at all.

I think what it boils down to in the end is: When (under what 
conditions) for what to use ClassValue at all.

bye Jochen


More information about the mlvm-dev mailing list