From 49f4c88b90aeeb107d81cc87336ffaf624bcbdbd Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 10 Apr 2026 10:47:46 +0200 Subject: [PATCH 1/7] 7904172: JTReg should add --enable-native-access=ALL-UNNAMED in /native actions --- .../com/sun/javatest/regtest/exec/MainAction.java | 10 +++++++++- test/nativepath/NativesOK.java | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java b/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java index 722a1f040..784534c83 100644 --- a/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java +++ b/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2026, 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 @@ -188,6 +188,7 @@ void init(Map opts, List args, String reason, othervmOverrideReasons.add("test or library uses bootclasspath"); } + boolean seenEnableNativeAccess = false; boolean seenEnablePreview = false; // separate the arguments into the options to java, the // classname and the parameters to the named class @@ -195,6 +196,9 @@ void init(Map opts, List args, String reason, String arg = args.get(i); if (testClassName == null) { if (arg.startsWith("-")) { + if (arg.startsWith("--enable-native-access")) { + seenEnableNativeAccess = true; + } if (arg.equals("--enable-preview")) { seenEnablePreview = true; } @@ -231,6 +235,10 @@ void init(Map opts, List args, String reason, throw new ParseException(PARSE_SECURE_OTHERVM); } + if (nativeCode && !seenEnableNativeAccess) { + testJavaArgs.add("--enable-native-access=ALL-UNNAMED"); + } + if (!script.disablePreview()) { // test with explicit `@enablePreview false` take precedence boolean needsEnablePreview = script.enablePreview(); if (needsEnablePreview && !seenEnablePreview) { diff --git a/test/nativepath/NativesOK.java b/test/nativepath/NativesOK.java index eacc9c4f0..00d9a1816 100644 --- a/test/nativepath/NativesOK.java +++ b/test/nativepath/NativesOK.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2026, 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 @@ -23,6 +23,7 @@ /* * @test + * @bug 7901983 7904172 * @run main/native NativesOK */ @@ -47,5 +48,8 @@ public static void main(String[] args) { String[] paths = j_l_path.split("\\"+File.pathSeparator); if (!Arrays.asList(paths).contains(t_native)) throw new Error("System property 'test.nativepath' is not part of 'java.library.path'"); + + if (!NativesOK.class.getClassLoader().getUnnamedModule().isNativeAccessEnabled()) + throw new Error("ALL-UNNAMED modules should have native access enabled"); } } From b558caede689cb06b9922728f3622e3649cf94a1 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 10 Apr 2026 13:14:30 +0200 Subject: [PATCH 2/7] Force othervm mode for /native tests --- .../classes/com/sun/javatest/regtest/exec/MainAction.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java b/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java index 784534c83..eb28e9c59 100644 --- a/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java +++ b/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java @@ -237,6 +237,9 @@ void init(Map opts, List args, String reason, if (nativeCode && !seenEnableNativeAccess) { testJavaArgs.add("--enable-native-access=ALL-UNNAMED"); + if (!othervm) { + othervmOverrideReasons.add("/native test requires --enable-native-access=ALL-UNNAMED"); + } } if (!script.disablePreview()) { // test with explicit `@enablePreview false` take precedence From 98813cc35ff2115aa12bc87faccbd2955c068ad7 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Sat, 11 Apr 2026 15:53:46 +0200 Subject: [PATCH 3/7] Run `NativeAccessEnabled` only on Java 22+ --- .../sun/javatest/regtest/exec/MainAction.java | 1 + test/nativepath/NativeAccessEnabled.java | 37 +++++++++++++++++++ test/nativepath/NativesOK.java | 6 +-- test/nativepath/TestNativePath.gmk | 19 +++++++++- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 test/nativepath/NativeAccessEnabled.java diff --git a/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java b/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java index eb28e9c59..5623c5815 100644 --- a/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java +++ b/src/share/classes/com/sun/javatest/regtest/exec/MainAction.java @@ -236,6 +236,7 @@ void init(Map opts, List args, String reason, } if (nativeCode && !seenEnableNativeAccess) { + // TODO Only add argument on Test JDK 17 or higher testJavaArgs.add("--enable-native-access=ALL-UNNAMED"); if (!othervm) { othervmOverrideReasons.add("/native test requires --enable-native-access=ALL-UNNAMED"); diff --git a/test/nativepath/NativeAccessEnabled.java b/test/nativepath/NativeAccessEnabled.java new file mode 100644 index 000000000..bd5ebc6a7 --- /dev/null +++ b/test/nativepath/NativeAccessEnabled.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2026, 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. + */ + +/* + * @test + * @bug 7904172 + * @requires jdk.version.major >= 22 + * @run main/native NativeAccessEnabled + */ + +public class NativeAccessEnabled { + public static void main(String[] args) { + var module = NativeAccessEnabled.class.getClassLoader().getUnnamedModule(); + if (!module.isNativeAccessEnabled()) // Module#isNativeAccessEnabled requires Java 22+ + throw new Error("ALL-UNNAMED modules should have native access enabled"); + } +} diff --git a/test/nativepath/NativesOK.java b/test/nativepath/NativesOK.java index 00d9a1816..eacc9c4f0 100644 --- a/test/nativepath/NativesOK.java +++ b/test/nativepath/NativesOK.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -23,7 +23,6 @@ /* * @test - * @bug 7901983 7904172 * @run main/native NativesOK */ @@ -48,8 +47,5 @@ public static void main(String[] args) { String[] paths = j_l_path.split("\\"+File.pathSeparator); if (!Arrays.asList(paths).contains(t_native)) throw new Error("System property 'test.nativepath' is not part of 'java.library.path'"); - - if (!NativesOK.class.getClassLoader().getUnnamedModule().isNativeAccessEnabled()) - throw new Error("ALL-UNNAMED modules should have native access enabled"); } } diff --git a/test/nativepath/TestNativePath.gmk b/test/nativepath/TestNativePath.gmk index 6da78a051..bed9d4e00 100644 --- a/test/nativepath/TestNativePath.gmk +++ b/test/nativepath/TestNativePath.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2014, 2026, 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 @@ -139,6 +139,23 @@ $(BUILDTESTDIR)/TestRelativeNativePath.ok: \ echo "$@ test passed at `date`" > $@ +# verify that --enable-native-access=ALL-UNNAMED is added +# for a test with the /native argument +$(BUILDTESTDIR)/TestNativeAccessEnabled.ok: \ + $(JTREG_IMAGEDIR)/lib/javatest.jar \ + $(JTREG_IMAGEDIR)/lib/jtreg.jar \ + $(JTREG_IMAGEDIR)/bin/jtreg + + cd $(BUILDTESTDIR); $(JTREG_IMAGEDIR)/bin/jtreg $(JTREG_OPTS) \ + -jdk:$(JDKHOME) \ + -nativepath:$(NATIVEPATH) \ \ + -w:$(@:%.ok=%nativeaccessenabled)/work \ + -r:$(@:%.ok=%nativeaccessenabled)/report \ + -verbose:fail \ + $(ABS_TESTDIR)/nativepath/NativeAccessEnabled.java + + echo "$@ test passed at `date`" > $@ + TESTS.jtreg += \ $(BUILDTESTDIR)/TestNativePath.ok \ $(BUILDTESTDIR)/TestNativePath.agentvm.ok \ From 4418ef5497d372f610233b0c5c4587cebbe00417 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Sat, 11 Apr 2026 15:08:14 +0000 Subject: [PATCH 4/7] Include new test in makefile --- test/nativepath/TestNativePath.gmk | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/nativepath/TestNativePath.gmk b/test/nativepath/TestNativePath.gmk index bed9d4e00..baa747c65 100644 --- a/test/nativepath/TestNativePath.gmk +++ b/test/nativepath/TestNativePath.gmk @@ -148,7 +148,7 @@ $(BUILDTESTDIR)/TestNativeAccessEnabled.ok: \ cd $(BUILDTESTDIR); $(JTREG_IMAGEDIR)/bin/jtreg $(JTREG_OPTS) \ -jdk:$(JDKHOME) \ - -nativepath:$(NATIVEPATH) \ \ + -nativepath:$(NATIVEPATH) \ -w:$(@:%.ok=%nativeaccessenabled)/work \ -r:$(@:%.ok=%nativeaccessenabled)/report \ -verbose:fail \ @@ -160,10 +160,12 @@ TESTS.jtreg += \ $(BUILDTESTDIR)/TestNativePath.ok \ $(BUILDTESTDIR)/TestNativePath.agentvm.ok \ $(BUILDTESTDIR)/TestNativePath.othervm.ok \ - $(BUILDTESTDIR)/TestRelativeNativePath.ok + $(BUILDTESTDIR)/TestRelativeNativePath.ok \ + $(BUILDTESTDIR)/TestNativeAccessEnabled.ok testnativepath: \ $(BUILDTESTDIR)/TestNativePath.ok \ $(BUILDTESTDIR)/TestNativePath.agentvm.ok \ $(BUILDTESTDIR)/TestNativePath.othervm.ok \ - $(BUILDTESTDIR)/TestRelativeNativePath.ok + $(BUILDTESTDIR)/TestRelativeNativePath.ok \ + $(BUILDTESTDIR)/TestNativeAccessEnabled.ok From 634643f56455f9a7c8ded40b0021b3dd493c102a Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Sat, 11 Apr 2026 17:33:55 +0200 Subject: [PATCH 5/7] Include `NativeAccessEnabled` test only when Java 25 is available --- test/nativepath/TestNativePath.gmk | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/nativepath/TestNativePath.gmk b/test/nativepath/TestNativePath.gmk index baa747c65..0f1a746f4 100644 --- a/test/nativepath/TestNativePath.gmk +++ b/test/nativepath/TestNativePath.gmk @@ -139,6 +139,20 @@ $(BUILDTESTDIR)/TestRelativeNativePath.ok: \ echo "$@ test passed at `date`" > $@ +TESTS.jtreg += \ + $(BUILDTESTDIR)/TestNativePath.ok \ + $(BUILDTESTDIR)/TestNativePath.agentvm.ok \ + $(BUILDTESTDIR)/TestNativePath.othervm.ok \ + $(BUILDTESTDIR)/TestRelativeNativePath.ok + +testnativepath: \ + $(BUILDTESTDIR)/TestNativePath.ok \ + $(BUILDTESTDIR)/TestNativePath.agentvm.ok \ + $(BUILDTESTDIR)/TestNativePath.othervm.ok \ + $(BUILDTESTDIR)/TestRelativeNativePath.ok + +ifdef JDK25HOME + # verify that --enable-native-access=ALL-UNNAMED is added # for a test with the /native argument $(BUILDTESTDIR)/TestNativeAccessEnabled.ok: \ @@ -156,16 +170,7 @@ $(BUILDTESTDIR)/TestNativeAccessEnabled.ok: \ echo "$@ test passed at `date`" > $@ -TESTS.jtreg += \ - $(BUILDTESTDIR)/TestNativePath.ok \ - $(BUILDTESTDIR)/TestNativePath.agentvm.ok \ - $(BUILDTESTDIR)/TestNativePath.othervm.ok \ - $(BUILDTESTDIR)/TestRelativeNativePath.ok \ - $(BUILDTESTDIR)/TestNativeAccessEnabled.ok +TESTS.jtreg += $(BUILDTESTDIR)/TestNativeAccessEnabled.ok +testnativepath += $(BUILDTESTDIR)/TestNativeAccessEnabled.ok -testnativepath: \ - $(BUILDTESTDIR)/TestNativePath.ok \ - $(BUILDTESTDIR)/TestNativePath.agentvm.ok \ - $(BUILDTESTDIR)/TestNativePath.othervm.ok \ - $(BUILDTESTDIR)/TestRelativeNativePath.ok \ - $(BUILDTESTDIR)/TestNativeAccessEnabled.ok +endif From 897d68239fc7c584149f77deec0d616d99ab283e Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Sat, 11 Apr 2026 17:46:35 +0200 Subject: [PATCH 6/7] Use Java 25 to select and run the new test --- test/nativepath/TestNativePath.gmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/nativepath/TestNativePath.gmk b/test/nativepath/TestNativePath.gmk index 0f1a746f4..c8062e455 100644 --- a/test/nativepath/TestNativePath.gmk +++ b/test/nativepath/TestNativePath.gmk @@ -161,7 +161,7 @@ $(BUILDTESTDIR)/TestNativeAccessEnabled.ok: \ $(JTREG_IMAGEDIR)/bin/jtreg cd $(BUILDTESTDIR); $(JTREG_IMAGEDIR)/bin/jtreg $(JTREG_OPTS) \ - -jdk:$(JDKHOME) \ + -jdk:$(JDK25HOME) \ -nativepath:$(NATIVEPATH) \ -w:$(@:%.ok=%nativeaccessenabled)/work \ -r:$(@:%.ok=%nativeaccessenabled)/report \ From 7250d428858d627d350df18f5665b0c4a9f863e1 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 7 May 2026 12:37:05 +0200 Subject: [PATCH 7/7] Add note to the `/native` tag description --- src/share/doc/javatest/regtest/tag-spec.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/share/doc/javatest/regtest/tag-spec.html b/src/share/doc/javatest/regtest/tag-spec.html index 47c3ce0df..7e1eea7d4 100644 --- a/src/share/doc/javatest/regtest/tag-spec.html +++ b/src/share/doc/javatest/regtest/tag-spec.html @@ -52,7 +52,7 @@

The JDK Test Framework: Tag Language Specification

Comments and questions to: jtreg-use@openjdk.org.
-1.48, 20 February, 2026 +1.49, 7 May 2026

This is a specification document, not a tutorial. For more basic information @@ -498,6 +498,10 @@

ACTION OPTIONS

The test uses native code, which must be provided separately, in a precompiled library, when the test is run. +The jtreg tool adds --enable-native-access=ALL-UNNAMED to the list of Java test +runtime command-line arguments for actions with /native tag -- unless +there is one or more explicit custom --enable-native-access argument(s) present +in the list of test runtime arguments.