From 609a34073132d80ec5c7df333728335fb3d213f0 Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Mon, 4 Dec 2023 11:46:36 +0100 Subject: [PATCH 01/12] Fix missing headers in libchelper. (cherry picked from commit af68df34e8f61220e8aba171f8486a65d385f69a) --- .../src/com.oracle.svm.native.libchelper/src/getThreadId.c | 1 + .../src/com.oracle.svm.native.libchelper/src/getThreadUserTime.c | 1 + 2 files changed, 2 insertions(+) diff --git a/substratevm/src/com.oracle.svm.native.libchelper/src/getThreadId.c b/substratevm/src/com.oracle.svm.native.libchelper/src/getThreadId.c index 4e60f087cf81..48421bb1ff2a 100644 --- a/substratevm/src/com.oracle.svm.native.libchelper/src/getThreadId.c +++ b/substratevm/src/com.oracle.svm.native.libchelper/src/getThreadId.c @@ -28,6 +28,7 @@ #include #include +#include /* * Based on os::Linux::gettid() from jdk-20-ga, see diff --git a/substratevm/src/com.oracle.svm.native.libchelper/src/getThreadUserTime.c b/substratevm/src/com.oracle.svm.native.libchelper/src/getThreadUserTime.c index e33580a689ab..17836710b5bc 100644 --- a/substratevm/src/com.oracle.svm.native.libchelper/src/getThreadUserTime.c +++ b/substratevm/src/com.oracle.svm.native.libchelper/src/getThreadUserTime.c @@ -26,6 +26,7 @@ #ifdef __linux__ +#include #include #include #include From e386399d0e228a70166c68003b681cbdeb923632 Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Mon, 4 Dec 2023 11:46:58 +0100 Subject: [PATCH 02/12] Fix potentially pending JNI exceptions. (cherry picked from commit 944054914bcf734e07db5b2458230c57b651ece8) --- .../src/com.oracle.svm.native.jvm.posix/src/JvmFuncs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.native.jvm.posix/src/JvmFuncs.c b/substratevm/src/com.oracle.svm.native.jvm.posix/src/JvmFuncs.c index ad62c918051e..9f20147f7f55 100644 --- a/substratevm/src/com.oracle.svm.native.jvm.posix/src/JvmFuncs.c +++ b/substratevm/src/com.oracle.svm.native.jvm.posix/src/JvmFuncs.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -311,10 +311,15 @@ JNIEXPORT jobject JNICALL JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject acti return (*env)->CallObjectMethod(env, action, run); } } + + /* Some error occurred - clear pending exception and try to report the error. */ + (*env)->ExceptionClear(env); + jclass errorClass = (*env)->FindClass(env, "java/lang/InternalError"); if (errorClass != NULL && !(*env)->ExceptionCheck(env)) { (*env)->ThrowNew(env, errorClass, "Could not invoke PrivilegedAction"); } else { + (*env)->ExceptionClear(env); (*env)->FatalError(env, "PrivilegedAction could not be invoked and the error could not be reported"); } return NULL; From a8262f8180fb6da1f8a3e6854b52964dd7cdf47a Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 26 Sep 2023 08:40:34 +0200 Subject: [PATCH 03/12] svm: adopt "JDK-8312498 Thread::getState and JVM TI GetThreadState should return TIMED_WAITING virtual thread is timed parked" [GR-48899] (cherry picked from commit 421ff9926f7d6177f188cb698eaab1e27dbd980d) Adapted conditionals tot est for <= 21.0.3 as the corresponding upstream patches have been backported to 21.0.4 --- .../oracle/svm/core/jdk/JDK21u3OrEarlier.java | 40 +++++++++++++++++++ .../Target_java_lang_VirtualThread.java | 13 ++++-- 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java new file mode 100644 index 000000000000..9c8a0124255a --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, 2024, 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.jdk; + +import java.util.function.BooleanSupplier; + +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; + +public class JDK21u3OrEarlier implements BooleanSupplier { + + public static final boolean jdk21u3OrEarlier = JavaVersionUtil.JAVA_SPEC < 21 || + (JavaVersionUtil.JAVA_SPEC == 21 && Runtime.version().update() <= 3); + + @Override + public boolean getAsBoolean() { + return jdk21u3OrEarlier; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java index 9d9935dd0be6..1eb488c87645 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java @@ -43,6 +43,7 @@ import com.oracle.svm.core.jdk.JDK20OrEarlier; import com.oracle.svm.core.jdk.JDK20OrLater; import com.oracle.svm.core.jdk.JDK21OrLater; +import com.oracle.svm.core.jdk.JDK21u3OrEarlier; import com.oracle.svm.core.jdk.LoomJDK; import com.oracle.svm.core.jfr.HasJfrSupport; import com.oracle.svm.core.jfr.SubstrateJVM; @@ -62,8 +63,12 @@ public final class Target_java_lang_VirtualThread { @Alias static int PINNED; @Alias static int YIELDING; @Alias static int TERMINATED; - @Alias static int RUNNABLE_SUSPENDED; - @Alias static int PARKED_SUSPENDED; + @Alias // + @TargetElement(onlyWith = JDK21u3OrEarlier.class) // + static int RUNNABLE_SUSPENDED; + @Alias // + @TargetElement(onlyWith = JDK21u3OrEarlier.class) // + static int PARKED_SUSPENDED; @Alias static Target_jdk_internal_vm_ContinuationScope VTHREAD_SCOPE; // Checkstyle: resume @@ -164,7 +169,7 @@ Thread.State threadState() { } else { return Thread.State.RUNNABLE; } - } else if (state == RUNNABLE || state == RUNNABLE_SUSPENDED) { + } else if (state == RUNNABLE || (JDK21u3OrEarlier.jdk21u3OrEarlier && state == RUNNABLE_SUSPENDED)) { return Thread.State.RUNNABLE; } else if (state == RUNNING) { Object token = VirtualThreadHelper.acquireInterruptLockMaybeSwitch(this); @@ -179,7 +184,7 @@ Thread.State threadState() { return Thread.State.RUNNABLE; } else if (state == PARKING || state == YIELDING) { return Thread.State.RUNNABLE; - } else if (state == PARKED || state == PARKED_SUSPENDED || state == PINNED) { + } else if (state == PARKED || (JDK21u3OrEarlier.jdk21u3OrEarlier && state == PARKED_SUSPENDED) || state == PINNED) { int parkedThreadStatus = MonitorSupport.singleton().getParkedThreadStatus(asThread(this), false); switch (parkedThreadStatus) { case ThreadStatus.BLOCKED_ON_MONITOR_ENTER: From a238da5d9abfbf1e643519501003bab053319b12 Mon Sep 17 00:00:00 2001 From: Peter Hofer Date: Fri, 6 Oct 2023 19:19:22 +0200 Subject: [PATCH 04/12] [GR-48899] Support TIMED_WAITING for virtual threads. Changes needed to adopt to https://bugs.openjdk.org/browse/JDK-8312498 which got backported to 21 with https://bugs.openjdk.org/browse/JDK-8326966 (cherry picked from commit 4fad6c2661356dfd51afe82d88009b549bfdbedb) Adapted conditionals to test for <= 21.0.3 or >= 21.0.4 as the corresponding upstream patches have been backported to 21.0.4 --- .../oracle/svm/core/jdk/JDK21u4OrLater.java | 40 +++++++++++++++++++ .../Target_java_lang_VirtualThread.java | 23 ++++++----- 2 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java new file mode 100644 index 000000000000..c39b8758dc10 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, 2024, 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.jdk; + +import java.util.function.BooleanSupplier; + +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; + +public class JDK21u4OrLater implements BooleanSupplier { + + public static final boolean jdk21u4OrLater = JavaVersionUtil.JAVA_SPEC > 21 || + (JavaVersionUtil.JAVA_SPEC == 21 && Runtime.version().update() >= 4); + + @Override + public boolean getAsBoolean() { + return jdk21u4OrLater; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java index 1eb488c87645..6557b6883314 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java @@ -44,6 +44,7 @@ import com.oracle.svm.core.jdk.JDK20OrLater; import com.oracle.svm.core.jdk.JDK21OrLater; import com.oracle.svm.core.jdk.JDK21u3OrEarlier; +import com.oracle.svm.core.jdk.JDK21u4OrLater; import com.oracle.svm.core.jdk.LoomJDK; import com.oracle.svm.core.jfr.HasJfrSupport; import com.oracle.svm.core.jfr.SubstrateJVM; @@ -63,12 +64,10 @@ public final class Target_java_lang_VirtualThread { @Alias static int PINNED; @Alias static int YIELDING; @Alias static int TERMINATED; - @Alias // - @TargetElement(onlyWith = JDK21u3OrEarlier.class) // - static int RUNNABLE_SUSPENDED; - @Alias // - @TargetElement(onlyWith = JDK21u3OrEarlier.class) // - static int PARKED_SUSPENDED; + @Alias static int SUSPENDED; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PARKING; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PARKED; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PINNED; @Alias static Target_jdk_internal_vm_ContinuationScope VTHREAD_SCOPE; // Checkstyle: resume @@ -160,7 +159,7 @@ void unmount() { @Substitute Thread.State threadState() { - int state = state(); + int state = state() & ~SUSPENDED; if (state == NEW) { return Thread.State.NEW; } else if (state == STARTED) { @@ -169,7 +168,7 @@ Thread.State threadState() { } else { return Thread.State.RUNNABLE; } - } else if (state == RUNNABLE || (JDK21u3OrEarlier.jdk21u3OrEarlier && state == RUNNABLE_SUSPENDED)) { + } else if (state == RUNNABLE) { return Thread.State.RUNNABLE; } else if (state == RUNNING) { Object token = VirtualThreadHelper.acquireInterruptLockMaybeSwitch(this); @@ -184,7 +183,7 @@ Thread.State threadState() { return Thread.State.RUNNABLE; } else if (state == PARKING || state == YIELDING) { return Thread.State.RUNNABLE; - } else if (state == PARKED || (JDK21u3OrEarlier.jdk21u3OrEarlier && state == PARKED_SUSPENDED) || state == PINNED) { + } else if (state == PARKED || state == PINNED) { int parkedThreadStatus = MonitorSupport.singleton().getParkedThreadStatus(asThread(this), false); switch (parkedThreadStatus) { case ThreadStatus.BLOCKED_ON_MONITOR_ENTER: @@ -197,6 +196,12 @@ Thread.State threadState() { } } else if (state == TERMINATED) { return Thread.State.TERMINATED; + } else if (JDK21u4OrLater.jdk21u4OrLater) { + if (state == TIMED_PARKING) { + return Thread.State.RUNNABLE; + } else if (state == TIMED_PARKED || state == TIMED_PINNED) { + return Thread.State.TIMED_WAITING; + } } throw new InternalError(); } From ab3336bd647a44329d6070f1eae19a625a709337 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Sat, 9 Dec 2023 15:50:52 +0100 Subject: [PATCH 05/12] svm: adopt "JDK-8321270: Virtual Thread.yield consumes parking permit" [GR-50851] https://github.com/openjdk/jdk/commit/29d7a22348e43cba253d0483c4c05922368f6b8a (cherry picked from commit 595ac63036c8888330cc1f4eb4e381f5c70629f3) Adapted conditionals to test for <= 21.0.3 or >= 21.0.4 as the corresponding upstream patches have been backported to 21.0.4 --- .../svm/core/thread/Target_java_lang_VirtualThread.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java index 6557b6883314..6fe180ddb54d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java @@ -57,17 +57,20 @@ public final class Target_java_lang_VirtualThread { // Checkstyle: stop @Alias static int NEW; @Alias static int STARTED; - @Alias static int RUNNABLE; + @Alias // + @TargetElement(onlyWith = JDK21u3OrEarlier.class) static int RUNNABLE; @Alias static int RUNNING; @Alias static int PARKING; @Alias static int PARKED; @Alias static int PINNED; @Alias static int YIELDING; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int YIELDED; @Alias static int TERMINATED; @Alias static int SUSPENDED; @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PARKING; @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PARKED; @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PINNED; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int UNPARKED; @Alias static Target_jdk_internal_vm_ContinuationScope VTHREAD_SCOPE; // Checkstyle: resume @@ -168,7 +171,9 @@ Thread.State threadState() { } else { return Thread.State.RUNNABLE; } - } else if (state == RUNNABLE) { + } else if (JDK21u3OrEarlier.jdk21u3OrEarlier && state == RUNNABLE) { + return Thread.State.RUNNABLE; + } else if (JDK21u4OrLater.jdk21u4OrLater && (state == UNPARKED || state == YIELDED)) { return Thread.State.RUNNABLE; } else if (state == RUNNING) { Object token = VirtualThreadHelper.acquireInterruptLockMaybeSwitch(this); From ef898577f59b47d9445f920be3a09d0f3edaecee Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 11 Aug 2023 10:56:22 +0200 Subject: [PATCH 06/12] svm: adapt "Move ReferencedKeyMap to jdk.internal so it may be shared" [JDK-8310913] (cherry picked from commit 0f2c3c1e3ba6d44d53e77fac67ab1e81adee7c93) --- .../methodhandles/MethodHandleFeature.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java index efc47edece4d..25e48044eb7d 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java @@ -35,7 +35,9 @@ import java.util.Iterator; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; +import com.oracle.svm.core.jdk.JDK21u4OrLater; import org.graalvm.nativeimage.hosted.RuntimeReflection; import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; @@ -101,7 +103,7 @@ public class MethodHandleFeature implements InternalFeature { * equivalent image heap object is not part of the table and subsequently fails a comparison. */ private Object runtimeMethodTypeInternTable; - private Method concurrentWeakInternSetAdd; + private Method referencedKeySetAdd; private MethodHandleInvokerRenamingSubstitutionProcessor substitutionProcessor; @@ -122,9 +124,22 @@ public void duringSetup(DuringSetupAccess access) { Class arrayAccessorClass = access.findClassByName("java.lang.invoke.MethodHandleImpl$ArrayAccessor"); typedAccessors = ReflectionUtil.lookupField(arrayAccessorClass, "TYPED_ACCESSORS"); - Class concurrentWeakInternSetClass = access.findClassByName("java.lang.invoke.MethodType$ConcurrentWeakInternSet"); - runtimeMethodTypeInternTable = ReflectionUtil.newInstance(concurrentWeakInternSetClass); - concurrentWeakInternSetAdd = ReflectionUtil.lookupMethod(concurrentWeakInternSetClass, "add", Object.class); + if (JDK21u4OrLater.jdk21u4OrLater) { + try { + Class referencedKeySetClass = access.findClassByName("jdk.internal.util.ReferencedKeySet"); + Method create = ReflectionUtil.lookupMethod(referencedKeySetClass, "create", boolean.class, boolean.class, Supplier.class); + // The following call must match the static initializer of MethodType#internTable. + runtimeMethodTypeInternTable = create.invoke(null, + /* isSoft */ false, /* useNativeQueue */ true, (Supplier) () -> new ConcurrentHashMap<>(512)); + referencedKeySetAdd = ReflectionUtil.lookupMethod(referencedKeySetClass, "add", Object.class); + } catch (ReflectiveOperationException e) { + throw VMError.shouldNotReachHere(e); + } + } else { + Class concurrentWeakInternSetClass = access.findClassByName("java.lang.invoke.MethodType$ConcurrentWeakInternSet"); + runtimeMethodTypeInternTable = ReflectionUtil.newInstance(concurrentWeakInternSetClass); + referencedKeySetAdd = ReflectionUtil.lookupMethod(concurrentWeakInternSetClass, "add", Object.class); + } if (!SubstrateOptions.UseOldMethodHandleIntrinsics.getValue()) { /* @@ -322,7 +337,7 @@ private static void registerVarHandleMethodsForReflection(FeatureAccess access, public void registerHeapMethodType(MethodType methodType) { try { - concurrentWeakInternSetAdd.invoke(runtimeMethodTypeInternTable, methodType); + referencedKeySetAdd.invoke(runtimeMethodTypeInternTable, methodType); } catch (ReflectiveOperationException e) { throw VMError.shouldNotReachHere(e); } From 0edb942475a39226d5c68495433e3ea5049b2459 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 24 Apr 2024 15:13:07 +0300 Subject: [PATCH 07/12] Adopt "JDK-8324646: Avoid Class.forName in SecureRandom constructor" Fixes https://github.com/graalvm/mandrel/issues/716 (cherry picked from commit 39988d343d32ec99d86dbd57f2c55200233c9815) --- .../svm/hosted/SecurityServicesFeature.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 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..79e39b3a0e68 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 @@ -653,7 +653,15 @@ private static boolean isValid(Service s) { private static Function> getConstructorParameterClassAccessor(ImageClassLoader loader) { Map knownEngines = ReflectionUtil.readStaticField(Provider.class, "knownEngines"); Class clazz = loader.findClassOrFail("java.security.Provider$EngineDescription"); - Field consParamClassNameField = ReflectionUtil.lookupField(clazz, "constructorParameterClassName"); + Field consParamClassField; + + try { + consParamClassField = ReflectionUtil.lookupField(clazz, "constructorParameterClassName"); + } catch (ReflectionUtil.ReflectionUtilError e) { + consParamClassField = ReflectionUtil.lookupField(clazz, "constructorParameterClass"); + } + + final Field consParamClassFieldFinal = consParamClassField; /* * The returned lambda captures the value of the Provider.knownEngines map retrieved above @@ -678,10 +686,10 @@ private static Function> getConstructorParameterClassAccessor(I if (engineDescription == null) { return null; } - String constrParamClassName = (String) consParamClassNameField.get(engineDescription); - if (constrParamClassName != null) { - return loader.findClass(constrParamClassName).get(); + if (consParamClassFieldFinal.getName().equals("constructorParameterClassName")) { + return loader.findClass((String) consParamClassFieldFinal.get(engineDescription)).get(); } + return (Class) consParamClassFieldFinal.get(engineDescription); } catch (IllegalAccessException e) { VMError.shouldNotReachHere(e); } From dcecff795eb9c216bfea170c302b83bf9a43a035 Mon Sep 17 00:00:00 2001 From: Volker Simonis Date: Fri, 7 Jun 2024 12:03:43 +0200 Subject: [PATCH 08/12] Fix missing null check in 'Adopt "JDK-8324646: Avoid Class.forName in SecureRandom constructor"' --- .../com/oracle/svm/hosted/SecurityServicesFeature.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 79e39b3a0e68..136bb0e53d7d 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 @@ -686,10 +686,13 @@ private static Function> getConstructorParameterClassAccessor(I if (engineDescription == null) { return null; } - if (consParamClassFieldFinal.getName().equals("constructorParameterClassName")) { - return loader.findClass((String) consParamClassFieldFinal.get(engineDescription)).get(); + if (consParamClassFieldFinal.getName().equals("constructorParameterClass")) { + return (Class) consParamClassFieldFinal.get(engineDescription); + } + String constructorParameterClassName = (String) consParamClassFieldFinal.get(engineDescription); + if (constructorParameterClassName != null) { + return loader.findClass(constructorParameterClassName).get(); } - return (Class) consParamClassFieldFinal.get(engineDescription); } catch (IllegalAccessException e) { VMError.shouldNotReachHere(e); } From 16b61ffe0a99d6d2229470163bb238d394066a2b Mon Sep 17 00:00:00 2001 From: alina-yur Date: Tue, 30 Jul 2024 14:19:44 +0200 Subject: [PATCH 09/12] add MAINTAINING.md --- MAINTAINING.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 MAINTAINING.md diff --git a/MAINTAINING.md b/MAINTAINING.md new file mode 100644 index 000000000000..aeb6addc28c0 --- /dev/null +++ b/MAINTAINING.md @@ -0,0 +1,15 @@ +# GraalVM Community Backports Repositories Guidelines + +1. Commits to a GraalVM Community Edition (CE) release branch or maintenance repository are either a) replicas of existing commits applied to the `master` branch in the `oracle/graal` repository or b) specific to the maintained version. Such commits are intended to fix or improve existing features, must always keep release stability in mind, and ensure compatibility with published public APIs. + +2. Release branches shall be maintained by Oracle in `oracle/graal` for six months per GraalVM CE release. During that time, the community can request backports through pull requests against the corresponding release branch in `oracle/graal`. + +3. After six months and only for Java LTS releases that the community wants to support long term (e.g., 21), Oracle shall create a dedicated repository (e.g., `graalvm/graalvm-community-jdk21u`) to maintain community backports and version-specific bug fixes. + +4. Each repository shall be managed by one maintainer, appointed by Oracle, with the permission to approve and merge pull requests. + +5. The repositories shall not be used to ship new releases of GraalVM CE or any other GraalVM distribution, only to maintain source code. Distributors should use these repositories as their primary source for creating GraalVM CE-based builds. + +6. The creation of maintenance repositories for other GraalVM projects (e.g., LabsJDK or GraalJS) can also be requested by the community after six months. The same rules apply. + +7. Maven artifacts under the `org.graalvm` group that are used by both GraalVM CE-based distributions and Oracle GraalVM will be maintained by Oracle. \ No newline at end of file From d8cf3eefe86464caf679faaa3803766c3fd56e61 Mon Sep 17 00:00:00 2001 From: Alina Yurenko Date: Tue, 30 Jul 2024 15:42:10 +0300 Subject: [PATCH 10/12] Update MAINTAINING.md Co-authored-by: Fabio Niephaus --- MAINTAINING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINING.md b/MAINTAINING.md index aeb6addc28c0..22fb97bad5f2 100644 --- a/MAINTAINING.md +++ b/MAINTAINING.md @@ -4,7 +4,7 @@ 2. Release branches shall be maintained by Oracle in `oracle/graal` for six months per GraalVM CE release. During that time, the community can request backports through pull requests against the corresponding release branch in `oracle/graal`. -3. After six months and only for Java LTS releases that the community wants to support long term (e.g., 21), Oracle shall create a dedicated repository (e.g., `graalvm/graalvm-community-jdk21u`) to maintain community backports and version-specific bug fixes. +3. After six months and only for Java LTS releases that the community wants to support long-term (e.g., 21), Oracle shall create a dedicated repository (e.g., `graalvm/graalvm-community-jdk21u`) to maintain community backports and version-specific bug fixes. 4. Each repository shall be managed by one maintainer, appointed by Oracle, with the permission to approve and merge pull requests. From 49dcd17ea29079c9d3e58ba4455ccca7a1cd9a2e Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 12 Apr 2024 09:10:59 +0200 Subject: [PATCH 11/12] svm: adopt "JDK-8328366: Thread.setContextClassloader from thread in FJP commonPool task no longer works after JDK-8327501" (cherry picked from commit 10bb0c6797753cd21ceef3bd2228f66dc73969e0) --- .../src/com/oracle/svm/core/jdk/RecomputedFields.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecomputedFields.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecomputedFields.java index f587cd7aad17..c4e0c88ac1de 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecomputedFields.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecomputedFields.java @@ -33,6 +33,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.nio.charset.CharsetDecoder; +import java.security.AccessControlContext; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ForkJoinPool; @@ -386,6 +387,15 @@ private static synchronized ForkJoinPool initializeCommonPool() { } } +@TargetClass(value = java.util.concurrent.ForkJoinPool.class, innerClass = "DefaultForkJoinWorkerThreadFactory", onlyWith = JDK21OrLater.class) +@SuppressWarnings("removal") +final class Target_java_util_concurrent_ForkJoinPool_DefaultForkJoinWorkerThreadFactory { + @Alias @RecomputeFieldValue(kind = Reset) // + static AccessControlContext regularACC; + @Alias @RecomputeFieldValue(kind = Reset) // + static AccessControlContext commonACC; +} + /** Dummy class to have a class with the file's name. */ public final class RecomputedFields { } From dab7d02e67351339277a69ac325faff8da02fe88 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 20 Aug 2024 21:58:20 +0300 Subject: [PATCH 12/12] Fix style issues Style issues introduced by https://github.com/graalvm/graalvm-community-jdk21u/pull/4 --- .../src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java | 2 +- .../src/com/oracle/svm/core/jdk/JDK21u4OrLater.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java index 9c8a0124255a..a4275782a0b4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java @@ -31,7 +31,7 @@ public class JDK21u3OrEarlier implements BooleanSupplier { public static final boolean jdk21u3OrEarlier = JavaVersionUtil.JAVA_SPEC < 21 || - (JavaVersionUtil.JAVA_SPEC == 21 && Runtime.version().update() <= 3); + (JavaVersionUtil.JAVA_SPEC == 21 && Runtime.version().update() <= 3); @Override public boolean getAsBoolean() { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java index c39b8758dc10..f8e0115bd9a4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java @@ -31,7 +31,7 @@ public class JDK21u4OrLater implements BooleanSupplier { public static final boolean jdk21u4OrLater = JavaVersionUtil.JAVA_SPEC > 21 || - (JavaVersionUtil.JAVA_SPEC == 21 && Runtime.version().update() >= 4); + (JavaVersionUtil.JAVA_SPEC == 21 && Runtime.version().update() >= 4); @Override public boolean getAsBoolean() {