From fb88acfe74239d8fb0670cb8a7fc6f7906cfa6c1 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Fri, 10 Oct 2025 11:44:37 +0000 Subject: [PATCH 01/14] fix and test --- src/hotspot/share/code/nmethod.cpp | 2 +- .../TestNativeWrapperCollection.java | 100 ++++++++++++++++++ .../libnativeWrapperCollection.c | 47 ++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java create mode 100644 test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c diff --git a/src/hotspot/share/code/nmethod.cpp b/src/hotspot/share/code/nmethod.cpp index 7274b627f3e6b..6dc23ad2ba366 100644 --- a/src/hotspot/share/code/nmethod.cpp +++ b/src/hotspot/share/code/nmethod.cpp @@ -2596,7 +2596,7 @@ void nmethod::metadata_do(MetadataClosure* f) { // Main purpose is to reduce code cache pressure and get rid of // nmethods that don't seem to be all that relevant any longer. bool nmethod::is_cold() { - if (!MethodFlushing || is_native_method() || is_not_installed()) { + if (!MethodFlushing || is_not_installed()) { // No heuristic unloading at all return false; } diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java new file mode 100644 index 0000000000000..4318c39f043bb --- /dev/null +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package gc.NativeWrapperCollection; + +/* + * @test TestNativeWrapperCollection + * @summary TODO + * @library /test/lib + * @build jdk.test.whitebox.WhiteBox + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox + * @run main/othervm/native -ea -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseSerialGC + * gc.NativeWrapperCollection.TestNativeWrapperCollection + */ + +import java.lang.reflect.Method; +import java.util.Iterator; +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.dcmd.JMXExecutor; +import jdk.test.lib.dcmd.CommandExecutor; +import jdk.test.whitebox.WhiteBox; + +public class TestNativeWrapperCollection { + + static { + System.loadLibrary("nativeWrapperCollection"); + } + + private static final WhiteBox WB = WhiteBox.getWhiteBox(); + + static native void method(); + static native void callRegisterNatives(int index); + + public static void main(String... args) throws Exception { + Method method = TestNativeWrapperCollection.class.getDeclaredMethod("method"); + + callRegisterNatives(0); + + WB.enqueueMethodForCompilation(method, 1 /* compLevel */); + while (WB.isMethodQueuedForCompilation(method)) { + Thread.onSpinWait(); + } + + callRegisterNatives(1); + + WB.enqueueMethodForCompilation(method, 1 /* compLevel */); + while (WB.isMethodQueuedForCompilation(method)) { + Thread.onSpinWait(); + } + + WB.fullGC(); + System.gc(); // TODO: Why is this needed? + + assert(checkOneOccurrence()) : "CodeCache entry wasn't collected"; + } + + private static boolean checkOneOccurrence() { + // Get output from dcmd (diagnostic command) + OutputAnalyzer output = new JMXExecutor().execute("Compiler.codelist"); + Iterator lines = output.asLines().iterator(); + + int count = 0; + while (lines.hasNext()) { + String line = lines.next(); + if (!line.contains("TestNativeWrapperCollection.method")) { + continue; + } + if (++count > 1) { + return false; + } + + String[] parts = line.split(" "); + int codeState = Integer.parseInt(parts[2]); + if (codeState == 1 /* not_entrant */) { + return false; + } + } + return true; + } +} diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c b/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c new file mode 100644 index 0000000000000..29d0939a89da9 --- /dev/null +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include + +#include "jni.h" + +static void method0(JNIEnv* env, jclass cls) { + printf("method0\n"); +} + +static void method1(JNIEnv* env, jclass cls) { + printf("method1\n"); +} + +JNIEXPORT void JNICALL +Java_gc_NativeWrapperCollection_TestNativeWrapperCollection_callRegisterNatives +(JNIEnv *env, jclass cls, jint index) { + JNINativeMethod nativeMethods[] = { + { + (char*) "method", // name + (char*) "()V", // sig + (void*) (index == 0 ? method0 : method1) // native method ptr + } + }; + (*env)->RegisterNatives(env, cls, nativeMethods, 1); +} From 273c5142e760ab6d91ccec4f5f8d029742dcde92 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 10:49:22 +0000 Subject: [PATCH 02/14] fix check --- src/hotspot/share/code/nmethod.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/code/nmethod.cpp b/src/hotspot/share/code/nmethod.cpp index 6dc23ad2ba366..eec9618c18e02 100644 --- a/src/hotspot/share/code/nmethod.cpp +++ b/src/hotspot/share/code/nmethod.cpp @@ -2596,7 +2596,7 @@ void nmethod::metadata_do(MetadataClosure* f) { // Main purpose is to reduce code cache pressure and get rid of // nmethods that don't seem to be all that relevant any longer. bool nmethod::is_cold() { - if (!MethodFlushing || is_not_installed()) { + if (!MethodFlushing || (is_native_method() && is_in_use()) || is_not_installed()) { // No heuristic unloading at all return false; } From 5358cc0db5156d99b92fd855a738efdad0e1234d Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 11:30:53 +0000 Subject: [PATCH 03/14] cc --- .../TestNativeWrapperCollection.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java index 4318c39f043bb..5da64d8a04192 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java @@ -29,7 +29,9 @@ * @library /test/lib * @build jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox - * @run main/othervm/native -ea -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseSerialGC + * @run main/othervm/native -ea -Xbootclasspath/a:. + * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI + * -XX:+UseSerialGC * gc.NativeWrapperCollection.TestNativeWrapperCollection */ @@ -69,32 +71,29 @@ public static void main(String... args) throws Exception { } WB.fullGC(); - System.gc(); // TODO: Why is this needed? + WB.forceSafepoint(); - assert(checkOneOccurrence()) : "CodeCache entry wasn't collected"; - } - - private static boolean checkOneOccurrence() { // Get output from dcmd (diagnostic command) OutputAnalyzer output = new JMXExecutor().execute("Compiler.codelist"); Iterator lines = output.asLines().iterator(); - int count = 0; + boolean foundOne = false; while (lines.hasNext()) { String line = lines.next(); if (!line.contains("TestNativeWrapperCollection.method")) { continue; } - if (++count > 1) { - return false; + if (foundOne) { + throw new AssertionError("Expected one CodeCache entry for " + + "'TestNativeWrapperCollection.method', found at least 2"); } String[] parts = line.split(" "); int codeState = Integer.parseInt(parts[2]); if (codeState == 1 /* not_entrant */) { - return false; + throw new AssertionError("Unexpected not-entrant entry for " + + "'TestNativeWrapperCollection.method'"); } } - return true; } } From a5ec01e2fd9fa9dfdf48774a447947412c6332d6 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 13:10:34 +0000 Subject: [PATCH 04/14] comments and fix test --- .../NativeWrapperCollection/TestNativeWrapperCollection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java index 5da64d8a04192..27f03c4396ee5 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java @@ -70,8 +70,8 @@ public static void main(String... args) throws Exception { Thread.onSpinWait(); } - WB.fullGC(); - WB.forceSafepoint(); + WB.fullGC(); // mark the nmethod as not on stack + WB.fullGC(); // reclaim the nmethod // Get output from dcmd (diagnostic command) OutputAnalyzer output = new JMXExecutor().execute("Compiler.codelist"); From 867af272d61475a2d7a91ca468fa6f5b1841f6eb Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 13:18:57 +0000 Subject: [PATCH 05/14] stuff --- .../TestNativeWrapperCollection.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java index 27f03c4396ee5..daafb2e494265 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java @@ -25,14 +25,13 @@ /* * @test TestNativeWrapperCollection - * @summary TODO + * @summary Test that nmethod for native methods are collected after becoming not entrant + * @requires vm.compiler1.enabled * @library /test/lib * @build jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox - * @run main/othervm/native -ea -Xbootclasspath/a:. - * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI - * -XX:+UseSerialGC - * gc.NativeWrapperCollection.TestNativeWrapperCollection + * @run main/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI + * gc.NativeWrapperCollection.TestNativeWrapperCollection */ import java.lang.reflect.Method; From 8b88b550000e6cc119a0ca60a5ad0509adf3408e Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 13:22:38 +0000 Subject: [PATCH 06/14] othervm --- .../NativeWrapperCollection/TestNativeWrapperCollection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java index daafb2e494265..c7d9ae8307cc5 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java @@ -30,8 +30,8 @@ * @library /test/lib * @build jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox - * @run main/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI - * gc.NativeWrapperCollection.TestNativeWrapperCollection + * @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI + * gc.NativeWrapperCollection.TestNativeWrapperCollection */ import java.lang.reflect.Method; From 38e8a7b34fe79b7f6ecf3fc66a1c759d5acb2322 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 13:31:54 +0000 Subject: [PATCH 07/14] nn --- .../NativeWrapperCollection/TestNativeWrapperCollection.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java index c7d9ae8307cc5..e41ceb7be08d1 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java @@ -52,7 +52,7 @@ public class TestNativeWrapperCollection { static native void method(); static native void callRegisterNatives(int index); - public static void main(String... args) throws Exception { + public static void main(String[] args) throws Exception { Method method = TestNativeWrapperCollection.class.getDeclaredMethod("method"); callRegisterNatives(0); @@ -72,7 +72,6 @@ public static void main(String... args) throws Exception { WB.fullGC(); // mark the nmethod as not on stack WB.fullGC(); // reclaim the nmethod - // Get output from dcmd (diagnostic command) OutputAnalyzer output = new JMXExecutor().execute("Compiler.codelist"); Iterator lines = output.asLines().iterator(); From ab6b8051f9a7cc6e4840fc87f159de091289f695 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 14:52:07 +0000 Subject: [PATCH 08/14] trigger From b3eae89321897c608881351e886aadac3c104d0f Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 14:59:07 +0000 Subject: [PATCH 09/14] nn --- .../libnativeWrapperCollection.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c b/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c index 29d0939a89da9..b82ea79da0693 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c @@ -21,17 +21,10 @@ * questions. */ -#include - #include "jni.h" -static void method0(JNIEnv* env, jclass cls) { - printf("method0\n"); -} - -static void method1(JNIEnv* env, jclass cls) { - printf("method1\n"); -} +static void method0(JNIEnv* env, jclass cls) {} +static void method1(JNIEnv* env, jclass cls) {} JNIEXPORT void JNICALL Java_gc_NativeWrapperCollection_TestNativeWrapperCollection_callRegisterNatives From 6bba7687840c1d7f7499506bb9bdd52f3db7f7ce Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 15:37:09 +0000 Subject: [PATCH 10/14] fix summary --- .../gc/NativeWrapperCollection/TestNativeWrapperCollection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java index e41ceb7be08d1..deee1824a87ba 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java @@ -25,7 +25,7 @@ /* * @test TestNativeWrapperCollection - * @summary Test that nmethod for native methods are collected after becoming not entrant + * @summary Test that native wrappers are collected after becoming not entrant * @requires vm.compiler1.enabled * @library /test/lib * @build jdk.test.whitebox.WhiteBox From 8ea13b6ec69ef5bfcd5f2719363b0a0596b55800 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sat, 11 Oct 2025 18:20:23 +0000 Subject: [PATCH 11/14] update foundOne --- .../NativeWrapperCollection/TestNativeWrapperCollection.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java index deee1824a87ba..0f2666462020b 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java @@ -92,6 +92,10 @@ public static void main(String[] args) throws Exception { throw new AssertionError("Unexpected not-entrant entry for " + "'TestNativeWrapperCollection.method'"); } + + // Found one TestNativeWrapperCollection.method, exactly one is + // expected + foundOne = true; } } } From 98754ee8a3e26f771cdc806bd29e097df720b546 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 22 Oct 2025 20:53:34 +0000 Subject: [PATCH 12/14] nn --- src/hotspot/share/code/nmethod.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/code/nmethod.cpp b/src/hotspot/share/code/nmethod.cpp index eec9618c18e02..6dc23ad2ba366 100644 --- a/src/hotspot/share/code/nmethod.cpp +++ b/src/hotspot/share/code/nmethod.cpp @@ -2596,7 +2596,7 @@ void nmethod::metadata_do(MetadataClosure* f) { // Main purpose is to reduce code cache pressure and get rid of // nmethods that don't seem to be all that relevant any longer. bool nmethod::is_cold() { - if (!MethodFlushing || (is_native_method() && is_in_use()) || is_not_installed()) { + if (!MethodFlushing || is_not_installed()) { // No heuristic unloading at all return false; } From b6d94cf8fffbc29c8e5ffc02c0663fa649296358 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Thu, 23 Oct 2025 08:41:05 +0000 Subject: [PATCH 13/14] cc --- ...lection.java => NativeWrapperCollection.java} | 16 ++++++++-------- ...llection.c => libnativeWrapperCollection.cpp} | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) rename test/hotspot/jtreg/gc/NativeWrapperCollection/{TestNativeWrapperCollection.java => NativeWrapperCollection.java} (85%) rename test/hotspot/jtreg/gc/NativeWrapperCollection/{libnativeWrapperCollection.c => libnativeWrapperCollection.cpp} (91%) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/NativeWrapperCollection.java similarity index 85% rename from test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java rename to test/hotspot/jtreg/gc/NativeWrapperCollection/NativeWrapperCollection.java index 0f2666462020b..469acd58bdb2f 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/TestNativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/NativeWrapperCollection.java @@ -24,14 +24,14 @@ package gc.NativeWrapperCollection; /* - * @test TestNativeWrapperCollection + * @test NativeWrapperCollection * @summary Test that native wrappers are collected after becoming not entrant * @requires vm.compiler1.enabled * @library /test/lib * @build jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI - * gc.NativeWrapperCollection.TestNativeWrapperCollection + * gc.NativeWrapperCollection.NativeWrapperCollection */ import java.lang.reflect.Method; @@ -41,7 +41,7 @@ import jdk.test.lib.dcmd.CommandExecutor; import jdk.test.whitebox.WhiteBox; -public class TestNativeWrapperCollection { +public class NativeWrapperCollection { static { System.loadLibrary("nativeWrapperCollection"); @@ -53,7 +53,7 @@ public class TestNativeWrapperCollection { static native void callRegisterNatives(int index); public static void main(String[] args) throws Exception { - Method method = TestNativeWrapperCollection.class.getDeclaredMethod("method"); + Method method = NativeWrapperCollection.class.getDeclaredMethod("method"); callRegisterNatives(0); @@ -78,22 +78,22 @@ public static void main(String[] args) throws Exception { boolean foundOne = false; while (lines.hasNext()) { String line = lines.next(); - if (!line.contains("TestNativeWrapperCollection.method")) { + if (!line.contains("NativeWrapperCollection.method")) { continue; } if (foundOne) { throw new AssertionError("Expected one CodeCache entry for " + - "'TestNativeWrapperCollection.method', found at least 2"); + "'NativeWrapperCollection.method', found at least 2"); } String[] parts = line.split(" "); int codeState = Integer.parseInt(parts[2]); if (codeState == 1 /* not_entrant */) { throw new AssertionError("Unexpected not-entrant entry for " + - "'TestNativeWrapperCollection.method'"); + "'NativeWrapperCollection.method'"); } - // Found one TestNativeWrapperCollection.method, exactly one is + // Found one NativeWrapperCollection.method, exactly one is // expected foundOne = true; } diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c b/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.cpp similarity index 91% rename from test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c rename to test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.cpp index b82ea79da0693..0626cf8d401e0 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.c +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/libnativeWrapperCollection.cpp @@ -26,8 +26,10 @@ static void method0(JNIEnv* env, jclass cls) {} static void method1(JNIEnv* env, jclass cls) {} +extern "C" { + JNIEXPORT void JNICALL -Java_gc_NativeWrapperCollection_TestNativeWrapperCollection_callRegisterNatives +Java_gc_NativeWrapperCollection_NativeWrapperCollection_callRegisterNatives (JNIEnv *env, jclass cls, jint index) { JNINativeMethod nativeMethods[] = { { @@ -36,5 +38,7 @@ Java_gc_NativeWrapperCollection_TestNativeWrapperCollection_callRegisterNatives (void*) (index == 0 ? method0 : method1) // native method ptr } }; - (*env)->RegisterNatives(env, cls, nativeMethods, 1); + env->RegisterNatives(cls, nativeMethods, 1); +} + } From 5d0c70562614c5a3cd3391f5191bf60c5b51e82c Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Fri, 24 Oct 2025 13:59:10 +0000 Subject: [PATCH 14/14] sleep --- .../gc/NativeWrapperCollection/NativeWrapperCollection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/gc/NativeWrapperCollection/NativeWrapperCollection.java b/test/hotspot/jtreg/gc/NativeWrapperCollection/NativeWrapperCollection.java index 469acd58bdb2f..d963b25e331ae 100644 --- a/test/hotspot/jtreg/gc/NativeWrapperCollection/NativeWrapperCollection.java +++ b/test/hotspot/jtreg/gc/NativeWrapperCollection/NativeWrapperCollection.java @@ -59,14 +59,14 @@ public static void main(String[] args) throws Exception { WB.enqueueMethodForCompilation(method, 1 /* compLevel */); while (WB.isMethodQueuedForCompilation(method)) { - Thread.onSpinWait(); + Thread.sleep(50 /* ms */); } callRegisterNatives(1); WB.enqueueMethodForCompilation(method, 1 /* compLevel */); while (WB.isMethodQueuedForCompilation(method)) { - Thread.onSpinWait(); + Thread.sleep(50 /* ms */); } WB.fullGC(); // mark the nmethod as not on stack