From 3347a52d9a4745231f98eec2fcbf7a49fb792b09 Mon Sep 17 00:00:00 2001 From: Jason Feng Date: Tue, 1 Oct 2024 18:19:43 -0400 Subject: [PATCH] keep Runnable r strongly reachable so that it is not reclaimable by GC The GC might occur before the second native library loading by another class loader, keep Runnable r strongly reachable so that it is not reclaimable by GC, and ensure UnsatisfiedLinkError. Signed-off-by: Jason Feng --- .../java/lang/ClassLoader/nativeLibrary/NativeLibraryTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/jdk/java/lang/ClassLoader/nativeLibrary/NativeLibraryTest.java b/test/jdk/java/lang/ClassLoader/nativeLibrary/NativeLibraryTest.java index 893c6151020..c6a4fb3f577 100644 --- a/test/jdk/java/lang/ClassLoader/nativeLibrary/NativeLibraryTest.java +++ b/test/jdk/java/lang/ClassLoader/nativeLibrary/NativeLibraryTest.java @@ -94,6 +94,8 @@ static void runTest() throws Exception { throw new RuntimeException("should fail to load the native library" + " by another class loader"); } catch (UnsatisfiedLinkError e) {} + // keep Runnable r strongly reachable so that it is not reclaimable by GC + java.lang.ref.Reference.reachabilityFence(r); } /*