Review Request JDK-8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
Peter Levart
peter.levart at gmail.com
Mon Oct 9 10:47:31 UTC 2017
On 10/09/2017 10:20 AM, Alan Bateman wrote:
> On 06/10/2017 20:37, mandy chung wrote:
>> :
>>
>> The native libraries map is now created lazily with
>> synchronization. I keep the lazy initialization that will save to
>> create a CHM as many custom class loaders don't have native code. I
>> think it's a good saving. In addition, if we iniitialize the static
>> systemNativeLibraries at <clinit> time, it may want to avoid using
>> CHM as it changes the class initialization order.
>>
> Alternatively change nativeLibraries and systemNativeLibraries to
> volatile so the synchronization is only needed to initialize them.
> Otherwise this version (webrev.03) looks good to me.
>
> -Alan
Yes Mandy, you could use volatile fields + double checked locking for
initialization. In addition, the initializers to 'null' value are not
needed / are a waste of instructions (the default is guaranteed by JLS):
2695 // Native libraries belonging to system classes.
2696 private static Map<String, NativeLibrary> systemNativeLibraries
= null;
2697
2698 // Native libraries associated with the class loader.
2699 private Map<String, NativeLibrary> nativeLibraries = null;
Regards, Peter
More information about the core-libs-dev
mailing list