On Thu, 14 Jul 2022 12:54:43 GMT, Jaikiran Pai <j...@openjdk.org> wrote:
>> 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. Its a racy bug, each NewGlobalRef will have a reference to the object and only the global ref in the last call to `setRef` will be cleared. The easiest fix is to synchronize on `Class1.class` in Class1.loadLibrary(). ------------- PR: https://git.openjdk.org/jdk/pull/9474