From 379454278cc16bfabde405d162888485d16fb9ac Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Tue, 12 Sep 2023 13:08:44 -0700 Subject: [PATCH 1/8] Use CPUFeature.RDPID directly --- .../oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java index 0c971310952f..81874c919158 100644 --- a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java +++ b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java @@ -181,6 +181,7 @@ import com.oracle.svm.core.util.VMError; import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.amd64.AMD64.CPUFeature; import jdk.vm.ci.amd64.AMD64Kind; import jdk.vm.ci.code.CallingConvention; import jdk.vm.ci.code.CodeCacheProvider; @@ -754,8 +755,7 @@ public void emitConvertZeroToNull(AllocatableValue result, Value value) { @Override public void emitProcid(AllocatableValue dst) { - // GR-43733: Replace string by feature when we remove support for Java 17 - if (supportsCPUFeature("RDPID")) { + if (supportsCPUFeature(CPUFeature.RDPID)) { append(new AMD64ReadProcid(dst)); } else { AMD64ReadTimestampCounterWithProcid procid = new AMD64ReadTimestampCounterWithProcid(); From 91be1364facd40148f6bcb1eb73ce445c520c8c4 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 11 Sep 2023 11:10:03 -0700 Subject: [PATCH 2/8] JDK version cleanups for CPU types --- .../oracle/svm/hosted/util/CPUTypeAMD64.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java index a6dcd66f8242..00fea87390ca 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java @@ -40,11 +40,13 @@ import static jdk.vm.ci.amd64.AMD64.CPUFeature.CLWB; import static jdk.vm.ci.amd64.AMD64.CPUFeature.CMOV; import static jdk.vm.ci.amd64.AMD64.CPUFeature.CX8; +import static jdk.vm.ci.amd64.AMD64.CPUFeature.F16C; import static jdk.vm.ci.amd64.AMD64.CPUFeature.FLUSHOPT; import static jdk.vm.ci.amd64.AMD64.CPUFeature.FMA; import static jdk.vm.ci.amd64.AMD64.CPUFeature.FXSR; import static jdk.vm.ci.amd64.AMD64.CPUFeature.LZCNT; import static jdk.vm.ci.amd64.AMD64.CPUFeature.MMX; +import static jdk.vm.ci.amd64.AMD64.CPUFeature.PKU; import static jdk.vm.ci.amd64.AMD64.CPUFeature.POPCNT; import static jdk.vm.ci.amd64.AMD64.CPUFeature.SSE; import static jdk.vm.ci.amd64.AMD64.CPUFeature.SSE2; @@ -62,7 +64,6 @@ import org.graalvm.nativeimage.Platforms; import com.oracle.graal.pointsto.util.GraalAccess; -import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.option.SubstrateOptionsParser; import com.oracle.svm.core.util.UserError; import com.oracle.svm.hosted.NativeImageOptions; @@ -90,22 +91,13 @@ public enum CPUTypeAMD64 implements CPUType { X86_64("x86-64", CMOV, CX8, FXSR, MMX, SSE, SSE2), X86_64_V1("x86-64-v1", X86_64), X86_64_V2("x86-64-v2", X86_64_V1, POPCNT, SSE3, SSE4_1, SSE4_2, SSSE3), - /** - * F16C are not in {@link JDK17OrEarlier}. Leaving link here for cleanup purposes. - */ - X86_64_V3("x86-64-v3", X86_64_V2, AVX, AVX2, BMI1, BMI2, /* F16C, */ FMA, LZCNT), + X86_64_V3("x86-64-v3", X86_64_V2, AVX, AVX2, BMI1, BMI2, F16C, FMA, LZCNT), X86_64_V4("x86-64-v4", X86_64_V3, AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL), // Intel selection - /** - * F16C are not in {@link JDK17OrEarlier}. Leaving link here for cleanup purposes. - */ - HASWELL("haswell", X86_64, AES, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT, CLMUL, AVX, /* F16C, */ AVX2, BMI1, BMI2, LZCNT, FMA), + HASWELL("haswell", X86_64, AES, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT, CLMUL, AVX, F16C, AVX2, BMI1, BMI2, LZCNT, FMA), SKYLAKE("skylake", HASWELL, ADX, AMD_3DNOW_PREFETCH, FLUSHOPT), - /** - * PKU are not in {@link JDK17OrEarlier}. Leaving link here for cleanup purposes. - */ - SKYLAKE_AVX512("skylake-avx512", SKYLAKE, /* PKU, */ AVX512F, AVX512CD, AVX512VL, AVX512BW, AVX512DQ, CLWB), + SKYLAKE_AVX512("skylake-avx512", SKYLAKE, PKU, AVX512F, AVX512CD, AVX512VL, AVX512BW, AVX512DQ, CLWB), // Special symbols COMPATIBILITY(NativeImageOptions.MICRO_ARCHITECTURE_COMPATIBILITY, X86_64), From ae5c5820c21d3a924018395dfb8e92911b2b3471 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 11 Sep 2023 11:10:51 -0700 Subject: [PATCH 3/8] Deprecate JDK17OrEarlier --- .../src/com/oracle/svm/core/jdk/JDK17OrEarlier.java | 1 + 1 file changed, 1 insertion(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK17OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK17OrEarlier.java index 48d8487b98f0..3cfec6ed9238 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK17OrEarlier.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK17OrEarlier.java @@ -28,6 +28,7 @@ import org.graalvm.compiler.serviceprovider.JavaVersionUtil; +@Deprecated(since = "24.0.0", forRemoval = true) public class JDK17OrEarlier implements BooleanSupplier { @Override public boolean getAsBoolean() { From 2d4128a14beb2618470b1d2d556ff65797b5ba5d Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 11 Sep 2023 11:36:16 -0700 Subject: [PATCH 4/8] Remove flags for old JDK versions --- substratevm/mx.substratevm/mx_substratevm.py | 22 +++----------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index 3351c5bb86f0..39ce9b4c6a7d 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1884,30 +1884,14 @@ def config_file_update(self, file_path, lines, file_paths): # com.oracle.svm.driver.NativeImage.BuildConfiguration.getBuilderJavaArgs(). def compute_graal_compiler_flags_map(self): graal_compiler_flags_map = dict() - graal_compiler_flags_map['8'] = [ - '-d64', - '-XX:-UseJVMCIClassLoader' - ] - - graal_compiler_flags_map['11'] = [ - # Disable the check for JDK-8 graal version. - '-Dsubstratevm.IgnoreGraalVersionCheck=true', - ] # Packages to add-export distributions_transitive = mx.classpath_entries(self.buildDependencies) required_exports = mx_javamodules.requiredExports(distributions_transitive, get_jdk()) exports_flags = mx_sdk_vm.AbstractNativeImageConfig.get_add_exports_list(required_exports) - graal_compiler_flags_map['11'].extend(exports_flags) - # Currently JDK 17 and JDK 11 have the same flags - graal_compiler_flags_map['17'] = graal_compiler_flags_map['11'] - # Currently JDK 19 and JDK 17 have the same flags - graal_compiler_flags_map['19'] = graal_compiler_flags_map['17'] - graal_compiler_flags_map['19-ea'] = graal_compiler_flags_map['19'] - # Currently JDK 20 and JDK 19 have the same flags - graal_compiler_flags_map['20'] = graal_compiler_flags_map['19'] - # Currently JDK 22, JDK 21 and JDK 20 have the same flags - graal_compiler_flags_map['21'] = graal_compiler_flags_map['20'] + + graal_compiler_flags_map['21'] = exports_flags + # Currently JDK 22 has the same flags graal_compiler_flags_map['22'] = graal_compiler_flags_map['21'] # DO NOT ADD ANY NEW ADD-OPENS OR ADD-EXPORTS HERE! # From 9b81ea76466cfd100a581bb6aa64575a82488479 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 11 Sep 2023 12:01:25 -0700 Subject: [PATCH 5/8] Remove Java version checks in JNIVersion --- .../core/jni/functions/JNIFunctionTables.java | 8 ++- .../svm/core/jni/functions/JNIFunctions.java | 27 +++++++--- .../functions/JNIFunctionsJDK19OrLater.java | 52 ------------------- .../JNIHeaderDirectivesJDK19OrLater.java | 35 ------------- .../core/jni/headers/JNINativeInterface.java | 5 ++ .../JNINativeInterfaceJDK19OrLater.java | 40 -------------- .../svm/core/jni/headers/JNIVersion.java | 16 ++++-- .../jni/headers/JNIVersionJDK19OrLater.java | 42 --------------- .../jni/headers/JNIVersionJDK21OrLater.java | 50 ------------------ ...Later.java => JNIVersionJDK22OrLater.java} | 18 ++++--- .../hosted/jni/JNIFunctionTablesFeature.java | 18 +------ 11 files changed, 53 insertions(+), 258 deletions(-) delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionsJDK19OrLater.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIHeaderDirectivesJDK19OrLater.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterfaceJDK19OrLater.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK19OrLater.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK21OrLater.java rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/{JNIVersionJDK20OrLater.java => JNIVersionJDK22OrLater.java} (74%) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java index a79695eae0c4..33bb0c7201fb 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java @@ -24,7 +24,6 @@ */ package com.oracle.svm.core.jni.functions; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.compiler.word.Word; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.ImageSingletons; @@ -38,8 +37,6 @@ import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordBase; -import jdk.internal.misc.Unsafe; - import com.oracle.svm.core.FrameAccess; import com.oracle.svm.core.c.CIsolateData; import com.oracle.svm.core.c.CIsolateDataFactory; @@ -48,9 +45,10 @@ import com.oracle.svm.core.jni.headers.JNIInvokeInterface; import com.oracle.svm.core.jni.headers.JNIJavaVM; import com.oracle.svm.core.jni.headers.JNINativeInterface; -import com.oracle.svm.core.jni.headers.JNINativeInterfaceJDK19OrLater; import com.oracle.svm.core.util.VMError; +import jdk.internal.misc.Unsafe; + /** * Performs the initialization of the JNI function table structures at runtime. */ @@ -75,7 +73,7 @@ public static JNIFunctionTables singleton() { private final CIsolateData jniJavaVM = CIsolateDataFactory.createStruct("jniJavaVM", JNIJavaVM.class); private static int getFunctionTableSize() { - return JavaVersionUtil.JAVA_SPEC <= 17 ? SizeOf.get(JNINativeInterface.class) : SizeOf.get(JNINativeInterfaceJDK19OrLater.class); + return SizeOf.get(JNINativeInterface.class); } @Platforms(Platform.HOSTED_ONLY.class) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java index 7525f826e297..a8a2f40b8dc8 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java @@ -106,15 +106,14 @@ import com.oracle.svm.core.jni.headers.JNIObjectRefType; import com.oracle.svm.core.jni.headers.JNIValue; import com.oracle.svm.core.jni.headers.JNIVersion; -import com.oracle.svm.core.jni.headers.JNIVersionJDK19OrLater; -import com.oracle.svm.core.jni.headers.JNIVersionJDK20OrLater; -import com.oracle.svm.core.jni.headers.JNIVersionJDK21OrLater; +import com.oracle.svm.core.jni.headers.JNIVersionJDK22OrLater; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.monitor.MonitorInflationCause; import com.oracle.svm.core.monitor.MonitorSupport; import com.oracle.svm.core.snippets.KnownIntrinsics; import com.oracle.svm.core.stack.StackOverflowCheck; import com.oracle.svm.core.thread.JavaThreads; +import com.oracle.svm.core.thread.Target_java_lang_BaseVirtualThread; import com.oracle.svm.core.thread.VMThreads.SafepointBehavior; import com.oracle.svm.core.thread.VirtualThreads; import com.oracle.svm.core.util.Utf8; @@ -159,10 +158,14 @@ public final class JNIFunctions { @CEntryPointOptions(prologue = CEntryPointOptions.NoPrologue.class, epilogue = CEntryPointOptions.NoEpilogue.class) @Uninterruptible(reason = "No need to enter the isolate and also no way to report errors if unable to.") static int GetVersion(JNIEnvironment env) { - return JavaVersionUtil.JAVA_SPEC >= 21 ? JNIVersionJDK21OrLater.JNI_VERSION_21() - : JavaVersionUtil.JAVA_SPEC >= 20 ? JNIVersionJDK20OrLater.JNI_VERSION_20() - : JavaVersionUtil.JAVA_SPEC >= 19 ? JNIVersionJDK19OrLater.JNI_VERSION_19() - : JNIVersion.JNI_VERSION_10(); + switch (JavaVersionUtil.JAVA_SPEC) { + case 21: + return JNIVersion.JNI_VERSION_21(); + case 22: + return JNIVersionJDK22OrLater.JNI_VERSION_22(); + default: + throw VMError.shouldNotReachHere("Unsupported Java version " + JavaVersionUtil.JAVA_SPEC); + } } /* @@ -1122,6 +1125,16 @@ static JNIObjectHandle DefineClass(JNIEnvironment env, CCharPointer cname, JNIOb return JNIObjectHandles.createLocal(clazz); } + /* + * jboolean (JNICALL *IsVirtualThread) (JNIEnv *env, jobject obj); + */ + @CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnFalse.class, include = CEntryPoint.NotIncludedAutomatically.class, publishAs = Publish.NotPublished) + @CEntryPointOptions(prologue = JNIEnvEnterFatalOnFailurePrologue.class) + static boolean IsVirtualThread(JNIEnvironment env, JNIObjectHandle handle) { + Object obj = JNIObjectHandles.getObject(handle); + return obj instanceof Target_java_lang_BaseVirtualThread; + } + // Checkstyle: resume /** diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionsJDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionsJDK19OrLater.java deleted file mode 100644 index 8a01df0657ec..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionsJDK19OrLater.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022, 2022, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 com.oracle.svm.core.jni.functions; - -import org.graalvm.nativeimage.c.function.CEntryPoint; -import org.graalvm.nativeimage.c.function.CEntryPoint.Publish; - -import com.oracle.svm.core.c.function.CEntryPointOptions; -import com.oracle.svm.core.jni.JNIObjectHandles; -import com.oracle.svm.core.jni.functions.JNIFunctions.Support.JNIEnvEnterFatalOnFailurePrologue; -import com.oracle.svm.core.jni.functions.JNIFunctions.Support.JNIExceptionHandlerReturnFalse; -import com.oracle.svm.core.jni.headers.JNIEnvironment; -import com.oracle.svm.core.jni.headers.JNIObjectHandle; -import com.oracle.svm.core.thread.Target_java_lang_BaseVirtualThread; - -@SuppressWarnings("unused") -public final class JNIFunctionsJDK19OrLater { - - // Checkstyle: stop - - /* - * jboolean (JNICALL *IsVirtualThread) (JNIEnv *env, jobject obj); - */ - @CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnFalse.class, include = CEntryPoint.NotIncludedAutomatically.class, publishAs = Publish.NotPublished) - @CEntryPointOptions(prologue = JNIEnvEnterFatalOnFailurePrologue.class) - static boolean IsVirtualThread(JNIEnvironment env, JNIObjectHandle handle) { - Object obj = JNIObjectHandles.getObject(handle); - return obj instanceof Target_java_lang_BaseVirtualThread; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIHeaderDirectivesJDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIHeaderDirectivesJDK19OrLater.java deleted file mode 100644 index 18f3e031f553..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIHeaderDirectivesJDK19OrLater.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022, 2022, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 com.oracle.svm.core.jni.headers; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; - -public class JNIHeaderDirectivesJDK19OrLater extends JNIHeaderDirectives { - - @Override - public boolean isInConfiguration() { - return JavaVersionUtil.JAVA_SPEC >= 19; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterface.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterface.java index 5882fe50d8b3..42444829db92 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterface.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterface.java @@ -1470,4 +1470,9 @@ public interface JNINativeInterface extends PointerBase { @CField void setGetModule(CFunctionPointer p); + + // Virtual threads + + @CField + void setIsVirtualThread(CFunctionPointer p); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterfaceJDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterfaceJDK19OrLater.java deleted file mode 100644 index a433b4a14211..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNINativeInterfaceJDK19OrLater.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022, 2022, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 com.oracle.svm.core.jni.headers; - -import org.graalvm.nativeimage.c.CContext; -import org.graalvm.nativeimage.c.function.CFunctionPointer; -import org.graalvm.nativeimage.c.struct.CField; -import org.graalvm.nativeimage.c.struct.CStruct; - -@CContext(JNIHeaderDirectivesJDK19OrLater.class) -@CStruct(value = "JNINativeInterface_", addStructKeyword = true) -public interface JNINativeInterfaceJDK19OrLater extends JNINativeInterface { - - // Virtual threads - - @CField - void setIsVirtualThread(CFunctionPointer p); -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java index 932bccf718c6..163d3de47765 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java @@ -34,9 +34,10 @@ public final class JNIVersion { @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public static boolean isSupported(int version) { - return (JavaVersionUtil.JAVA_SPEC >= 21 && version == JNIVersionJDK21OrLater.JNI_VERSION_21()) || - (JavaVersionUtil.JAVA_SPEC >= 20 && version == JNIVersionJDK20OrLater.JNI_VERSION_20()) || - (JavaVersionUtil.JAVA_SPEC >= 19 && version == JNIVersionJDK19OrLater.JNI_VERSION_19()) || + return (JavaVersionUtil.JAVA_SPEC >= 22 && version == JNIVersionJDK22OrLater.JNI_VERSION_22()) || + version == JNI_VERSION_21() || + version == JNI_VERSION_20() || + version == JNI_VERSION_19() || version == JNI_VERSION_10() || version == JNI_VERSION_9() || version == JNI_VERSION_1_8() || @@ -69,6 +70,15 @@ public static boolean isSupported(int version) { @CConstant public static native int JNI_VERSION_10(); + @CConstant + public static native int JNI_VERSION_19(); + + @CConstant + public static native int JNI_VERSION_20(); + + @CConstant + public static native int JNI_VERSION_21(); + // Checkstyle: resume private JNIVersion() { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK19OrLater.java deleted file mode 100644 index 8317a35f6bdf..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK19OrLater.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022, 2022, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 com.oracle.svm.core.jni.headers; - -import org.graalvm.nativeimage.c.CContext; -import org.graalvm.nativeimage.c.constant.CConstant; - -@CContext(JNIHeaderDirectivesJDK19OrLater.class) -public final class JNIVersionJDK19OrLater { - - // Checkstyle: stop - - @CConstant - public static native int JNI_VERSION_19(); - - // Checkstyle: resume - - private JNIVersionJDK19OrLater() { - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK21OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK21OrLater.java deleted file mode 100644 index 1795d46c1be4..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK21OrLater.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2023, 2023, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 com.oracle.svm.core.jni.headers; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; -import org.graalvm.nativeimage.c.CContext; -import org.graalvm.nativeimage.c.constant.CConstant; - -final class JNIHeaderDirectivesJDK21OrLater extends JNIHeaderDirectives { - @Override - public boolean isInConfiguration() { - return JavaVersionUtil.JAVA_SPEC >= 21; - } -} - -@CContext(JNIHeaderDirectivesJDK21OrLater.class) -public final class JNIVersionJDK21OrLater { - - // Checkstyle: stop - - @CConstant - public static native int JNI_VERSION_21(); - - // Checkstyle: resume - - private JNIVersionJDK21OrLater() { - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK20OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK22OrLater.java similarity index 74% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK20OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK22OrLater.java index a697cd4f8a22..29f1aed99692 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK20OrLater.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDK22OrLater.java @@ -28,23 +28,27 @@ import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; -final class JNIHeaderDirectivesJDK20OrLater extends JNIHeaderDirectives { +final class JNIHeaderDirectivesJDK22OrLater extends JNIHeaderDirectives { @Override public boolean isInConfiguration() { - return JavaVersionUtil.JAVA_SPEC >= 20; + return JavaVersionUtil.JAVA_SPEC >= 22; } } -@CContext(JNIHeaderDirectivesJDK20OrLater.class) -public final class JNIVersionJDK20OrLater { +@CContext(JNIHeaderDirectivesJDK22OrLater.class) +public final class JNIVersionJDK22OrLater { // Checkstyle: stop - @CConstant - public static native int JNI_VERSION_20(); + /* + * GR-48572: there is not yet a JNI_VERSION_22 constant defined. As soon as it gets available, + * the "value" property of the CConstant annotation below must be removed. + */ + @CConstant(value = "JNI_VERSION_21") + public static native int JNI_VERSION_22(); // Checkstyle: resume - private JNIVersionJDK20OrLater() { + private JNIVersionJDK22OrLater() { } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java index 9d1b1b42a33d..ee420f5a973b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.stream.Stream; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.function.CEntryPoint; @@ -47,11 +46,9 @@ import com.oracle.svm.core.jni.functions.JNIFunctions; import com.oracle.svm.core.jni.functions.JNIFunctions.UnimplementedWithJNIEnvArgument; import com.oracle.svm.core.jni.functions.JNIFunctions.UnimplementedWithJavaVMArgument; -import com.oracle.svm.core.jni.functions.JNIFunctionsJDK19OrLater; import com.oracle.svm.core.jni.functions.JNIInvocationInterface; import com.oracle.svm.core.jni.headers.JNIInvokeInterface; import com.oracle.svm.core.jni.headers.JNINativeInterface; -import com.oracle.svm.core.jni.headers.JNINativeInterfaceJDK19OrLater; import com.oracle.svm.core.meta.MethodPointer; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl; @@ -90,7 +87,6 @@ public class JNIFunctionTablesFeature implements Feature { * for the Interface Function Table */ private StructInfo functionTableMetadata; - private StructInfo functionTableMetadataJDK19OrLater; /** * Metadata about the table pointed to by the {@code JavaVM*} C pointer. @@ -120,16 +116,12 @@ public void beforeAnalysis(BeforeAnalysisAccess arg) { invokeInterfaceMetadata = (StructInfo) nativeLibraries.findElementInfo(invokeInterface); AnalysisType functionTable = metaAccess.lookupJavaType(JNINativeInterface.class); functionTableMetadata = (StructInfo) nativeLibraries.findElementInfo(functionTable); - if (JavaVersionUtil.JAVA_SPEC > 17) { - functionTableMetadataJDK19OrLater = (StructInfo) nativeLibraries.findElementInfo(metaAccess.lookupJavaType(JNINativeInterfaceJDK19OrLater.class)); - } // Manually add functions as entry points so this is only done when JNI features are enabled AnalysisType invokes = metaAccess.lookupJavaType(JNIInvocationInterface.class); AnalysisType exports = metaAccess.lookupJavaType(JNIInvocationInterface.Exports.class); AnalysisType functions = metaAccess.lookupJavaType(JNIFunctions.class); - AnalysisType functionsJDK19OrLater = JavaVersionUtil.JAVA_SPEC <= 17 ? null : metaAccess.lookupJavaType(JNIFunctionsJDK19OrLater.class); - Stream analysisMethods = Stream.of(invokes, functions, functionsJDK19OrLater, exports).filter(type -> type != null).flatMap(type -> Stream.of(type.getDeclaredMethods(false))); + Stream analysisMethods = Stream.of(invokes, functions, exports).filter(type -> type != null).flatMap(type -> Stream.of(type.getDeclaredMethods(false))); Stream unimplementedMethods = Stream.of((AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJNIEnvArgument.class), (AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJavaVMArgument.class)); Stream.concat(analysisMethods, unimplementedMethods).forEach(method -> { @@ -229,14 +221,6 @@ private void fillJNIFunctionsTable(CompilationAccessImpl access) { int offset = field.getOffsetInfo().getProperty(); tables.initFunctionEntry(offset, getStubFunctionPointer(access, method)); } - if (JavaVersionUtil.JAVA_SPEC > 17) { - HostedType functionsJDK19OrLater = access.getMetaAccess().lookupJavaType(JNIFunctionsJDK19OrLater.class); - for (HostedMethod method : functionsJDK19OrLater.getDeclaredMethods(false)) { - StructFieldInfo field = findFieldFor(functionTableMetadataJDK19OrLater, method.getName()); - int offset = field.getOffsetInfo().getProperty(); - tables.initFunctionEntry(offset, getStubFunctionPointer(access, method)); - } - } for (ResolvedJavaMethod accessor : generatedMethods) { StructFieldInfo field = findFieldFor(functionTableMetadata, accessor.getName()); From f559e8a27fdbceeff76761b1a80364c030369c3f Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 11 Sep 2023 13:08:54 -0700 Subject: [PATCH 6/8] Remove unnecessary package name distinction --- ...ckage_jdk_incubator_concurrent_helper.java | 46 ------------------- .../Package_jdk_internal_vm_helper.java | 46 ------------------- .../thread/Target_java_lang_ScopedValue.java | 8 ++-- .../Target_jdk_internal_vm_Continuation.java | 4 +- ...get_jdk_internal_vm_ContinuationScope.java | 2 +- 5 files changed, 7 insertions(+), 99 deletions(-) delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_incubator_concurrent_helper.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_internal_vm_helper.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_incubator_concurrent_helper.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_incubator_concurrent_helper.java deleted file mode 100644 index 18a08dd5faf0..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_incubator_concurrent_helper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023, 2023, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 com.oracle.svm.core.thread; - -import java.util.function.Function; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; - -import com.oracle.svm.core.annotate.TargetClass; - -@Platforms(Platform.HOSTED_ONLY.class) -public class Package_jdk_incubator_concurrent_helper implements Function { - - @Override - public String apply(TargetClass annotation) { - if (JavaVersionUtil.JAVA_SPEC >= 21) { - return "java.lang." + annotation.className(); - } else { - return "jdk.incubator.concurrent." + annotation.className(); - } - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_internal_vm_helper.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_internal_vm_helper.java deleted file mode 100644 index 31673f297175..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_internal_vm_helper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022, 2022, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 com.oracle.svm.core.thread; - -import java.util.function.Function; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; - -import com.oracle.svm.core.annotate.TargetClass; - -@Platforms(Platform.HOSTED_ONLY.class) -public class Package_jdk_internal_vm_helper implements Function { - - @Override - public String apply(TargetClass annotation) { - if (JavaVersionUtil.JAVA_SPEC >= 19) { - return "jdk.internal.vm." + annotation.className(); - } else { - return "java.lang." + annotation.className(); - } - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_ScopedValue.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_ScopedValue.java index 5cfa65bd553b..0da2c3124d0f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_ScopedValue.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_ScopedValue.java @@ -45,7 +45,7 @@ public boolean getAsBoolean() { } } -@TargetClass(className = "ScopedValue", classNameProvider = Package_jdk_incubator_concurrent_helper.class, onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "java.lang.ScopedValue", onlyWith = ScopedValuesEnabled.class) final class Target_java_lang_ScopedValue { @Substitute static Target_java_lang_ScopedValue_Snapshot scopedValueBindings() { @@ -62,7 +62,7 @@ static Target_java_lang_ScopedValue_Snapshot scopedValueBindings() { * Substituted to directly call {@link Target_java_lang_Thread#setScopedValueBindings} for forced * inlining. */ -@TargetClass(className = "ScopedValue", classNameProvider = Package_jdk_incubator_concurrent_helper.class, innerClass = "Carrier", onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "java.lang.ScopedValue", innerClass = "Carrier", onlyWith = ScopedValuesEnabled.class) final class Target_java_lang_ScopedValue_Carrier { @Alias int bitmask; @@ -100,7 +100,7 @@ final class Target_jdk_internal_vm_ScopedValueContainer { static native void run(Runnable op); } -@TargetClass(className = "ScopedValue", classNameProvider = Package_jdk_incubator_concurrent_helper.class, innerClass = "Snapshot", onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "java.lang.ScopedValue", innerClass = "Snapshot", onlyWith = ScopedValuesEnabled.class) final class Target_java_lang_ScopedValue_Snapshot { // Checkstyle: stop @Alias // @@ -111,7 +111,7 @@ final class Target_java_lang_ScopedValue_Snapshot { Target_java_lang_ScopedValue_Snapshot prev; } -@TargetClass(className = "ScopedValue", classNameProvider = Package_jdk_incubator_concurrent_helper.class, innerClass = "Cache", onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "java.lang.ScopedValue", innerClass = "Cache", onlyWith = ScopedValuesEnabled.class) final class Target_java_lang_ScopedValue_Cache { @Alias static native void invalidate(int toClearBits); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java index 78ddc4b0d1e6..406fb1ee935e 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java @@ -39,7 +39,7 @@ import com.oracle.svm.core.stack.JavaFrameAnchors; import com.oracle.svm.core.util.VMError; -@TargetClass(className = "Continuation", classNameProvider = Package_jdk_internal_vm_helper.class, onlyWith = NotLoomJDK.class) +@TargetClass(className = "jdk.internal.vm.Continuation", onlyWith = NotLoomJDK.class) @Substitute @SuppressWarnings("unused") final class Target_jdk_internal_vm_Continuation__WithoutLoom { @@ -59,7 +59,7 @@ static void unpin() { } } -@TargetClass(className = "Continuation", classNameProvider = Package_jdk_internal_vm_helper.class, onlyWith = LoomJDK.class) +@TargetClass(className = "jdk.internal.vm.Continuation", onlyWith = LoomJDK.class) public final class Target_jdk_internal_vm_Continuation { @Substitute private static void registerNatives() { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ContinuationScope.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ContinuationScope.java index 8cd20f6da792..865761b9e42c 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ContinuationScope.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ContinuationScope.java @@ -26,6 +26,6 @@ import com.oracle.svm.core.annotate.TargetClass; -@TargetClass(className = "ContinuationScope", classNameProvider = Package_jdk_internal_vm_helper.class) +@TargetClass(className = "jdk.internal.vm.ContinuationScope") public final class Target_jdk_internal_vm_ContinuationScope { } From 298148a1d80ab0f9b1bff1f365d3eccf8a427fd9 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 11 Sep 2023 13:29:13 -0700 Subject: [PATCH 7/8] Simplify security provider verification cache cleaning --- .../svm/hosted/SecurityServicesFeature.java | 58 +++++-------------- 1 file changed, 13 insertions(+), 45 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java index 0a7b66da9b40..1f3fbd56ea58 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java @@ -31,6 +31,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.lang.ref.WeakReference; import java.lang.reflect.Executable; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -67,7 +68,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.Function; -import java.util.function.Predicate; import javax.crypto.Cipher; import javax.crypto.KeyAgreement; @@ -81,7 +81,6 @@ import javax.security.auth.login.Configuration; import org.graalvm.compiler.options.Option; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.hosted.RuntimeReflection; @@ -197,9 +196,6 @@ public static class Options { /** Providers marked as used by the user. */ private final Set manuallyMarkedUsedProviderClassNames = new HashSet<>(); - /** Provider verification cache cleaner that removes unused providers from the cache. */ - private Function verificationCacheCleaner; - /** Provider verification cache that contains only used providers. */ private Object filteredVerificationCache; @@ -307,7 +303,6 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { BeforeAnalysisAccessImpl access = (BeforeAnalysisAccessImpl) a; loader = access.getImageClassLoader(); jceSecurityClass = loader.findClassOrFail("javax.crypto.JceSecurity"); - verificationCacheCleaner = constructVerificationCacheCleaner(); /* Ensure sun.security.provider.certpath.CertPathHelper.instance is initialized. */ access.ensureInitialized("java.security.cert.TrustAnchor"); @@ -366,6 +361,9 @@ private void addManuallyConfiguredUsedProviders(DuringSetupAccess access) { } public boolean shouldRemoveProvider(Provider p) { + if (p == null) { + return true; + } if (usedProviders.contains(p)) { return false; } @@ -373,9 +371,17 @@ public boolean shouldRemoveProvider(Provider p) { } @Override + @SuppressWarnings("unchecked") public Object cleanVerificationCache(Object cache) { if (shouldFilterProviders) { - Object cleanedCache = verificationCacheCleaner.apply(cache); + /* + * The verification cache is an WeakIdentityWrapper -> Verification result + * ConcurrentHashMap. We do not care about the private WeakIdentityWrapper class, it + * extends WeakReference and so using WeakReference.get() is sufficient for us. + */ + var cleanedCache = new ConcurrentHashMap<>((ConcurrentHashMap, Object>) cache); + cleanedCache.keySet().removeIf(key -> shouldRemoveProvider(key.get())); + if (filteredVerificationCache == null || !filteredVerificationCache.equals(cleanedCache)) { filteredVerificationCache = cleanedCache; } @@ -829,44 +835,6 @@ private static void registerForReflection(Class clazz) { RuntimeReflection.register(clazz.getConstructors()); } - @SuppressWarnings("unchecked") - private Function constructVerificationCacheCleaner() { - /* - * The verification cache is an IdentityWrapper -> Verification result ConcurrentHashMap. - * The IdentityWrapper contains the actual provider in the 'obj' field. - */ - String className; - String fieldName; - if (JavaVersionUtil.JAVA_SPEC <= 20) { - className = "javax.crypto.JceSecurity$IdentityWrapper"; - fieldName = "obj"; - } else { - // JDK-8168469 - className = "java.lang.ref.Reference"; - fieldName = "referent"; - } - Class identityWrapper = loader.findClassOrFail(className); - Field providerField = ReflectionUtil.lookupField(identityWrapper, fieldName); - - Predicate listRemovalPredicate = wrapper -> { - try { - return shouldRemoveProvider((Provider) providerField.get(wrapper)); - } catch (IllegalAccessException e) { - throw VMError.shouldNotReachHere(e); - } - }; - - return obj -> { - Map original = (Map) obj; - Map verificationResults = new ConcurrentHashMap<>(original); - - verificationResults.keySet().removeIf(listRemovalPredicate); - - return verificationResults; - }; - - } - private static boolean isSignature(Service s) { return s.getType().equals(SIGNATURE_SERVICE); } From 7db4cecdd9ed4e1e3d0f4d34838cba76adb6e9e4 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 11 Sep 2023 13:33:02 -0700 Subject: [PATCH 8/8] Remove code for old JDK versions --- .../graalvm/compiler/java/LambdaUtils.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/java/LambdaUtils.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/java/LambdaUtils.java index fbda3673e36a..43f6706b5e7b 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/java/LambdaUtils.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/java/LambdaUtils.java @@ -51,26 +51,13 @@ public final class LambdaUtils { - private static final Pattern LAMBDA_PATTERN; + private static final Pattern LAMBDA_PATTERN = Pattern.compile("\\$\\$Lambda[/.][^/]+;"); private static final char[] HEX = "0123456789abcdef".toCharArray(); - public static final String LAMBDA_SPLIT_PATTERN; - public static final String LAMBDA_CLASS_NAME_SUBSTRING; + public static final String LAMBDA_SPLIT_PATTERN = "\\$\\$Lambda"; + public static final String LAMBDA_CLASS_NAME_SUBSTRING = "$$Lambda"; public static final String SERIALIZATION_TEST_LAMBDA_CLASS_SUBSTRING = "$$Lambda"; public static final String SERIALIZATION_TEST_LAMBDA_CLASS_SPLIT_PATTERN = "\\$\\$Lambda"; - static { - if (Runtime.version().feature() < 21) { - LAMBDA_PATTERN = Pattern.compile("\\$\\$Lambda\\$\\d+[/.][^/]+;"); - LAMBDA_SPLIT_PATTERN = "\\$\\$Lambda\\$"; - LAMBDA_CLASS_NAME_SUBSTRING = "$$Lambda$"; - } else { - // JDK-8292914 - LAMBDA_PATTERN = Pattern.compile("\\$\\$Lambda[/.][^/]+;"); - LAMBDA_SPLIT_PATTERN = "\\$\\$Lambda"; - LAMBDA_CLASS_NAME_SUBSTRING = "$$Lambda"; - } - } - private static GraphBuilderConfiguration buildLambdaParserConfig(ClassInitializationPlugin cip) { GraphBuilderConfiguration.Plugins plugins = new GraphBuilderConfiguration.Plugins(new InvocationPlugins()); plugins.setClassInitializationPlugin(cip);