Questions about JDK-8136353 "ClassValue preventing class unloading"
Jochen Theodorou
blackdrag at gmx.org
Thu Jan 7 14:05:04 UTC 2016
Hi Peter,
Am 06.01.2016 um 21:34 schrieb Peter Levart:
[...]
> Currently the cached instance of type T is reachable from Class<?>
> instance and you are using Integer.TYPE in your example. Which means
> that the cached instance of T is never going to be released if
> ClassValue<T> instance is reachable from cached instance of T. In your
> example, it is: (Dummy instance -> Dummy.class -> MyClassValue
> instance). So you get this reachability chain: Integer.TYPE ->
> ClassValueMap instance -> ClassValueMap.Entry[] -> ClassValueMap.Entry
> -> Dummy instance -> Dummy.class -> MyClassValue instance.
>
> Integer.TYPE is a Class<?> instance representing int type which is
> loaded by bootstrap class loader, which never goes away.
So in other words, this is supposed to work if I used for example Dummy
instead of Integer.TYPE? Because this is not the case (just tested with
1.8.0_66). Which means we are not talking only about bootstrap classes,
but about basically any class.
> ClassValue API could use a different strategy and reference the cached
> instance of type T from ClassValue<T> instance instead, but then you
> would have a problem with ClassValue instances reachable from other
> class loaders than the cached instances of type T.
yes, that is what I tried as well... I used my own map directly in
ClassValue and avoided the map ClassValue uses natively.
So the solution for this case is basically using a Soft- or
Weak-Reference in Dummy, right?
bye Jochen
More information about the mlvm-dev
mailing list