Review Request JDK-8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mandy.chung at oracle.com
Fri Sep 22 22:18:20 UTC 2017
This patch proposes to replace the ClassLoader use of finalizer with
phantom reference, specifically Cleaner, for unloading native
libraries. It registers the class loader for cleanup only if it's not a
builtin class loader which will never be unloaded.
The spec for JNI_OnUnload  specifies that this function is called in
an unknown context whereas the hotspot implementation uses the class
loader being unloaded as the context, which I consider a bug. It
should not load a class defined to that class loader. The proposed spec
change for JNI_FindClass if called from JNI_OnUnload to use system class
loader (consistent with no caller context case).
Please see the spec change an behavioral change in this CSR. A native
library may fail to be reloaded if it is loaded immediately or soon
after a class loader is GC'ed but the cleaner thread doesn't yet have
the chance to handle the unloading of the native library. Likewise,
there is no guarantee regarding the timing of finalization and a native
library may fail to reload. It's believed that the compatibility risk
should be low.
I'm looking into adding a native jtreg test that will be added in the
More information about the hotspot-runtime-dev