On Wed, 13 Jul 2022 14:06:00 GMT, Roger Riggs <[email protected]> wrote:
>> The test `java/lang/ClassLoader/loadLibraryUnload/LoadLibraryUnloadTest.java`
>> Fails intermittently when expected output from a subprocess is not found.
>>
>> I suspect a race between the Cleaner that is going to call JNI_OnUnload (in
>> NativeLibraries.java:377) when the ClassLoader is no longer referenced and
>> the test code that exits as soon as it detects that the p.Class1 is no
>> longer referenced.
>>
>> The proposed fix is to create a canary object referenced by the native
>> library and released when the library is unloaded.
>> The Java side of the test provides the canary object and uses a
>> WeakReference to wait for it to be released.
>> When released the child process exits and the driver test will find all of
>> the output it expects.
>
> Roger Riggs has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Cleanup waiting for library unload
test/jdk/java/lang/ClassLoader/loadLibraryUnload/libloadLibraryUnload.c line 48:
> 46: if (ref == NULL) {
> 47: // Only create a single GlobalRef
> 48: ref = (*env)->NewGlobalRef(env, obj);
Hello Roger, do we not use any synchronization here because even if both
winning threads end up concurrently here, the `Object` instance they will be
setting as a global ref will be the same one? Ofcourse, there will then be two
calls to `NewGlobalRef` for the same instance. I am unaware what the semantics
of that call will be in such cases and if it is of any concern.
-------------
PR: https://git.openjdk.org/jdk/pull/9474