From e00edebb58153ebf0f1a113174af2e180a750753 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Mon, 24 Jun 2024 19:12:26 +0200 Subject: [PATCH] Backport https://github.com/oracle/graal/pull/9078 Backports the following commits: ceaac5f6f8009c05a78a756c2e9fa1370691c3b2 Automatic merge of master into galahad f1a2d954b2ea8b67b3b06c85e30e1d1dfcd6493f Automatic merge of master into galahad 59a170e007341f4eb74047fa27dd555377d95d3f compiler: adopt "JDK-8332826: Make hashCode methods in ArraysSupport friendlier" 2b2754d3d45b2580e07dd482f68463e306becd3c svm: adopt "JDK-8331189: Implementation of Scoped Values (Third Preview)" 07d3bc2503303731fe3717e70626af8903caf155 update galahad-jdk 90def08290974ffffc79c4c9577f8896bfe7d2bd compiler: no more JDK 21 style gate in galahad 2a04ddeebfbfbe97cee550a601a921e5412c9602 Automatic merge of master into galahad d2f6535c41cc04a4e78bfc9a8c17515eadc7d54a Automatic merge of master into galahad e1771d1dc2128dde2cf813e86341cc62757c6402 Automatic merge of master into galahad 268aa8d94d0c9c33c1f8e6433ec280500deae1d5 reduce galahad gate to bare minimum 3bd87540c4bf81f13885fdb34632866b9199a697 [JDK-8333292] Fix libgraal build broken by JDK-8331189. 188f35a8cf2493e6132a7d406b5dd13dcd5c96ae Fix libgraal build broken by JDK-8331877. 95415adb721ff438aed193c9f138de3f1802c343 [JDK-8333362] Fix libgraal build broken by JDK-8331877. 3fbd87a25953b25441bac00a66fb3ca459c18dd8 Automatic merge of master into galahad 93923e4454c8273669907ccb72a3c6af54fca0b4 Automatic merge of master into galahad a29b4da35d60dbd4852a4a272ec0e6bb2ec0283d Automatic merge of master into galahad ee5cef44f0064d1daf623085092b14b5ca291dbd Automatic merge of master into galahad 8b40a6a9c96726db8c2bdbb58376cec5ea5001ac Automatic merge of master into galahad 4d34880dc0676a975af0954357fde2782eff6bb7 Merge master into galahad 414d874be3af1a21a3c8ebfd9cbd163b985a0a68 [GR-54472] Resolve merge conflits. 78ec64e7517491dc296903d30d247398248853d4 Automatic merge of master into galahad 768bab8ead8824a93da337d9547c647b6232dcfa Automatic merge of master into galahad ca7c3ca212ad0a431c9e2d7b2cc2de16f863eaff Automatic merge of master into galahad 4ce7fe8a1963d27240def2514fbd1e3e52417526 Automatic merge of master into galahad 02a83e93dbb70349d5bd1f2a94702f0e209c6fc0 Automatic merge of master into galahad b6f336516c0bb6cba0a7089cd2f1c934cff61530 Automatic merge of master into galahad 859ea9d815684a210545e0895a93067d8d106f87 Fix incorrect resolution of merge conflicts for VectorizedHashCodeTest 8f4c2145361fdd57a7db90181f05a829c08eecc3 Automatic merge of master into galahad bdedb09ebdd60f7b0b91d1c5b416dae78aa85bec Automatic merge of master into galahad 103dbcaf104957bf24b3c88de5d2f24f462d0270 Automatic merge of master into galahad --- common.json | 16 +++--- .../jdk23/test/VectorizedHashCodeTest.java | 42 ++++++++++------ .../compiler/hotspot/JVMCIVersionCheck.java | 4 +- .../core/windows/WindowsPlatformThreads.java | 4 +- .../windows/WindowsThreadCpuTimeSupport.java | 2 +- .../oracle/svm/core/windows/WindowsUtils.java | 4 +- .../core/jdk/JDKContainerSubstitutions.java | 5 +- ...ame_jdk_jfr_internal_JDKEvents_helper.java | 47 +++++++++++++++++ ...jdk_jfr_internal_instrument_JDKEvents.java | 10 ++-- .../thread/Target_java_lang_ScopedValue.java | 50 ++++++++++++------- 10 files changed, 130 insertions(+), 54 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Name_jdk_jfr_internal_JDKEvents_helper.java diff --git a/common.json b/common.json index d811baf1cf2e..c075ba2ca0bb 100644 --- a/common.json +++ b/common.json @@ -8,7 +8,7 @@ "COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet", "jdks": { - "galahad-jdk": {"name": "jpg-jdk", "version": "23", "build_id": "jdk-23+25-2038", "platformspecific": true, "extrabundles": ["static-libs"]}, + "galahad-jdk": {"name": "jpg-jdk", "version": "23", "build_id": "jdk-23+26-2139", "platformspecific": true, "extrabundles": ["static-libs"]}, "oraclejdk11": {"name": "jpg-jdk", "version": "11.0.11", "build_id": "jdk-11.0.11+9", "platformspecific": true, "extrabundles": ["static-libs"] }, @@ -45,13 +45,13 @@ "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21.0.2+13-jvmci-23.1-b33-sulong", "platformspecific": true }, "graalvm-ee-21": {"name": "graalvm-java21", "version": "23.1.3", "platformspecific": true }, - "oraclejdk-latest": {"name": "jpg-jdk", "version": "23", "build_id": "jdk-23+25", "platformspecific": true, "extrabundles": ["static-libs"]}, - "labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-23+25-jvmci-b01", "platformspecific": true }, - "labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-23+25-jvmci-b01-debug", "platformspecific": true }, - "labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-23+25-jvmci-b01-sulong", "platformspecific": true }, - "labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-23+25-jvmci-b01", "platformspecific": true }, - "labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-23+25-jvmci-b01-debug", "platformspecific": true }, - "labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-23+25-jvmci-b01-sulong", "platformspecific": true } + "oraclejdk-latest": {"name": "jpg-jdk", "version": "23", "build_id": "jdk-23+26", "platformspecific": true, "extrabundles": ["static-libs"]}, + "labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-23+26-jvmci-b01", "platformspecific": true }, + "labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-23+26-jvmci-b01-debug", "platformspecific": true }, + "labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-23+26-jvmci-b01-sulong", "platformspecific": true }, + "labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-23+26-jvmci-b01", "platformspecific": true }, + "labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-23+26-jvmci-b01-debug", "platformspecific": true }, + "labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-23+26-jvmci-b01-sulong", "platformspecific": true } }, "eclipse": { diff --git a/compiler/src/jdk.graal.compiler.hotspot.jdk23.test/src/jdk/graal/compiler/hotspot/jdk23/test/VectorizedHashCodeTest.java b/compiler/src/jdk.graal.compiler.hotspot.jdk23.test/src/jdk/graal/compiler/hotspot/jdk23/test/VectorizedHashCodeTest.java index b84312aefabf..65ebce73b493 100644 --- a/compiler/src/jdk.graal.compiler.hotspot.jdk23.test/src/jdk/graal/compiler/hotspot/jdk23/test/VectorizedHashCodeTest.java +++ b/compiler/src/jdk.graal.compiler.hotspot.jdk23.test/src/jdk/graal/compiler/hotspot/jdk23/test/VectorizedHashCodeTest.java @@ -24,6 +24,7 @@ */ package jdk.graal.compiler.hotspot.jdk23.test; +import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Set; @@ -40,20 +41,31 @@ @AddExports({"java.base/jdk.internal.util"}) public class VectorizedHashCodeTest extends GraalCompilerTest { + private static int getField(String name) { + try { + var arraysSupport = Class.forName("jdk.internal.util.ArraysSupport"); + Field f = arraysSupport.getDeclaredField(name); + f.setAccessible(true); + return f.getInt(null); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + @Test public void testJDKConstantValue() { - Assert.assertEquals(ArraysSupport.T_BOOLEAN, VectorizedHashCodeInvocationPlugin.T_BOOLEAN); - Assert.assertEquals(ArraysSupport.T_CHAR, VectorizedHashCodeInvocationPlugin.T_CHAR); - Assert.assertEquals(ArraysSupport.T_BYTE, VectorizedHashCodeInvocationPlugin.T_BYTE); - Assert.assertEquals(ArraysSupport.T_SHORT, VectorizedHashCodeInvocationPlugin.T_SHORT); - Assert.assertEquals(ArraysSupport.T_INT, VectorizedHashCodeInvocationPlugin.T_INT); + Assert.assertEquals(getField("T_BOOLEAN"), VectorizedHashCodeInvocationPlugin.T_BOOLEAN); + Assert.assertEquals(getField("T_CHAR"), VectorizedHashCodeInvocationPlugin.T_CHAR); + Assert.assertEquals(getField("T_BYTE"), VectorizedHashCodeInvocationPlugin.T_BYTE); + Assert.assertEquals(getField("T_SHORT"), VectorizedHashCodeInvocationPlugin.T_SHORT); + Assert.assertEquals(getField("T_INT"), VectorizedHashCodeInvocationPlugin.T_INT); } // @formatter:off private static String[] tests = {"", " ", "a", "abcdefg", - "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way- in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only. -- Charles Dickens, Tale of Two Cities", - "C'était le meilleur des temps, c'était le pire des temps, c'était l'âge de la sagesse, c'était l'âge de la folie, c'était l'époque de la croyance, c'était l'époque de l'incrédulité, c'était la saison de la Lumière, c'était C'était la saison des Ténèbres, c'était le printemps de l'espoir, c'était l'hiver du désespoir, nous avions tout devant nous, nous n'avions rien devant nous, nous allions tous directement au Ciel, nous allions tous directement dans l'autre sens bref, la période ressemblait tellement à la période actuelle, que certaines de ses autorités les plus bruyantes ont insisté pour qu'elle soit reçue, pour le bien ou pour le mal, au degré superlatif de la comparaison seulement. -- Charles Dickens, Tale of Two Cities (in French)", - "禅道修行を志した雲水は、一般に参禅のしきたりを踏んだうえで一人の師につき、各地にある専門道場と呼ばれる養成寺院に入門し、与えられた公案に取り組むことになる。公案は、師家(老師)から雲水が悟りの境地へと進んで行くために手助けとして課す問題であり、悟りの境地に達していない人には容易に理解し難い難問だが、屁理屈や詭弁が述べられているわけではなく、頓知や謎かけとも異なる。" + "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way- in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only. -- Charles Dickens, Tale of Two Cities", + "C'était le meilleur des temps, c'était le pire des temps, c'était l'âge de la sagesse, c'était l'âge de la folie, c'était l'époque de la croyance, c'était l'époque de l'incrédulité, c'était la saison de la Lumière, c'était C'était la saison des Ténèbres, c'était le printemps de l'espoir, c'était l'hiver du désespoir, nous avions tout devant nous, nous n'avions rien devant nous, nous allions tous directement au Ciel, nous allions tous directement dans l'autre sens bref, la période ressemblait tellement à la période actuelle, que certaines de ses autorités les plus bruyantes ont insisté pour qu'elle soit reçue, pour le bien ou pour le mal, au degré superlatif de la comparaison seulement. -- Charles Dickens, Tale of Two Cities (in French)", + "禅道修行を志した雲水は、一般に参禅のしきたりを踏んだうえで一人の師につき、各地にある専門道場と呼ばれる養成寺院に入門し、与えられた公案に取り組むことになる。公案は、師家(老師)から雲水が悟りの境地へと進んで行くために手助けとして課す問題であり、悟りの境地に達していない人には容易に理解し難い難問だが、屁理屈や詭弁が述べられているわけではなく、頓知や謎かけとも異なる。" }; // @formatter:on @@ -89,7 +101,7 @@ private void testHash(String method, Function f, Function a, a -> a.length / 2); } - public static int hashBooleanArray(Object array, int fromIndex, int length, int initialValue) { - return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_BOOLEAN); + public static int hashBooleanArray(byte[] array, int fromIndex, int length, int initialValue) { + return ArraysSupport.hashCode(array, fromIndex, length, initialValue); } @Test @@ -124,7 +136,7 @@ public void testHashBooleanArray() { } public static int hashCharArray(char[] array, int fromIndex, int length, int initialValue) { - return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_CHAR); + return ArraysSupport.hashCode(array, fromIndex, length, initialValue); } @Test @@ -139,7 +151,7 @@ public void testHashCharArray() { } public static int hashShortArray(short[] array, int fromIndex, int length, int initialValue) { - return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_SHORT); + return ArraysSupport.hashCode(array, fromIndex, length, initialValue); } @Test @@ -154,7 +166,7 @@ public void testHashShortArray() { } public static int hashIntArray(int[] array, int fromIndex, int length, int initialValue) { - return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_INT); + return ArraysSupport.hashCode(array, fromIndex, length, initialValue); } @Test diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/JVMCIVersionCheck.java index 247aa12d2e95..f73391fbd8a0 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/JVMCIVersionCheck.java @@ -55,8 +55,8 @@ public final class JVMCIVersionCheck { private static final Map> JVMCI_MIN_VERSIONS = Map.of( "21", Map.of(DEFAULT_VENDOR_ENTRY, createLegacyVersion(23, 1, 33)), "23", Map.of( - "Oracle Corporation", createLabsJDKVersion("23+25", 1), - DEFAULT_VENDOR_ENTRY, createLabsJDKVersion("23+25", 1))); + "Oracle Corporation", createLabsJDKVersion("23+26", 1), + DEFAULT_VENDOR_ENTRY, createLabsJDKVersion("23+26", 1))); private static final int NA = 0; /** * Minimum Java release supported by Graal. diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsPlatformThreads.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsPlatformThreads.java index a842822bcb84..43ef7cb0b02c 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsPlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsPlatformThreads.java @@ -208,7 +208,7 @@ protected void reset() { } @Override - @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+10/src/hotspot/os/windows/os_windows.cpp#L5457-L5499") + @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+26/src/hotspot/os/windows/os_windows.cpp#L5672-L5714") protected void park(boolean isAbsolute, long time) { assert time >= 0 && !(isAbsolute && time == 0) : "must not be called otherwise"; @@ -256,7 +256,7 @@ private static int toDword(long value) { } @Override - @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+10/src/hotspot/os/windows/os_windows.cpp#L5501-L5504") + @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+26/src/hotspot/os/windows/os_windows.cpp#L5716-L5719") protected void unpark() { StackOverflowCheck.singleton().makeYellowZoneAvailable(); try { diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsThreadCpuTimeSupport.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsThreadCpuTimeSupport.java index 49c4273397ba..50544324bce2 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsThreadCpuTimeSupport.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsThreadCpuTimeSupport.java @@ -55,7 +55,7 @@ public long getThreadCpuTime(IsolateThread isolateThread, boolean includeSystemT return getThreadCpuTime(hThread, includeSystemTime); } - @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+10/src/hotspot/os/windows/os_windows.cpp#L4722-L4738") + @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+26/src/hotspot/os/windows/os_windows.cpp#L4960-L4976") @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private static long getThreadCpuTime(HANDLE hThread, boolean includeSystemTime) { FILETIME create = StackValue.get(FILETIME.class); diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java index 9c823502a4cc..f9ec40546b45 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java @@ -171,8 +171,8 @@ static void writeBytes(FileDescriptor descriptor, byte[] bytes, int off, int len /** Retrieve a nanosecond counter for elapsed time measurement. */ @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-22+22/src/hotspot/os/windows/os_windows.cpp#L976-L983") - @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-22+22/src/hotspot/os/windows/os_windows.cpp#L1081-L1087") + @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+26/src/hotspot/os/windows/os_windows.cpp#L1089-L1096") + @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+26/src/hotspot/os/windows/os_windows.cpp#L1194-L1200") public static long getNanoCounter() { if (performanceFrequency == 0L) { CLongPointer count = StackValue.get(CLongPointer.class); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java index e7771fee6b0e..c1b39b19bce1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java @@ -35,10 +35,11 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jfr.Name_jdk_jfr_internal_JDKEvents_helper; -@TargetClass(className = "jdk.jfr.internal.instrument.JDKEvents") +@TargetClass(classNameProvider = Name_jdk_jfr_internal_JDKEvents_helper.class) @Platforms(LINUX.class) -final class Target_jdk_jfr_internal_instrument_JDKEvents { +final class Target_jdk_jfr_internal_JDKEvents { @Alias // @RecomputeFieldValue(kind = Kind.Reset) // private static Target_jdk_internal_platform_Metrics containerMetrics; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Name_jdk_jfr_internal_JDKEvents_helper.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Name_jdk_jfr_internal_JDKEvents_helper.java new file mode 100644 index 000000000000..0bf0117657fb --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Name_jdk_jfr_internal_JDKEvents_helper.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024, 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.jfr; + +import java.util.function.Function; + +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; + +import com.oracle.svm.core.annotate.TargetClass; + +import jdk.graal.compiler.serviceprovider.JavaVersionUtil; + +@Platforms(Platform.HOSTED_ONLY.class) +public final class Name_jdk_jfr_internal_JDKEvents_helper implements Function { + + @Override + public String apply(TargetClass annotation) { + if (JavaVersionUtil.JAVA_SPEC >= 23) { + return "jdk.jfr.internal.JDKEvents"; + } else { + return "jdk.jfr.internal.instrument.JDKEvents"; + } + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_instrument_JDKEvents.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_instrument_JDKEvents.java index a18d50e941c0..f6cb76b489b2 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_instrument_JDKEvents.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_instrument_JDKEvents.java @@ -33,16 +33,20 @@ import jdk.jfr.events.ActiveRecordingEvent; import jdk.jfr.events.ActiveSettingEvent; -@TargetClass(className = "jdk.jfr.internal.instrument.JDKEvents", onlyWith = HasJfrSupport.class) +@TargetClass(classNameProvider = Name_jdk_jfr_internal_JDKEvents_helper.class, onlyWith = HasJfrSupport.class) final class Target_jdk_jfr_internal_instrument_JDKEvents { - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) private static Class[] eventClasses = { + @Alias // + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) // + private static Class[] eventClasses = { ActiveSettingEvent.class, ActiveRecordingEvent.class }; // This is a list of the classes with instrumentation code that should be applied. - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) private static Class[] instrumentationClasses = new Class[]{}; + @Alias // + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) // + @TargetElement(onlyWith = JDK21OrEarlier.class) private static Class[] instrumentationClasses = new Class[]{}; @Alias // @TargetElement(onlyWith = JDK21OrEarlier.class) // 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 2aaf4cbab947..f90898ed1777 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 @@ -25,27 +25,16 @@ package com.oracle.svm.core.thread; import java.util.concurrent.Callable; -import java.util.function.BooleanSupplier; - -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.ModuleNative; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK21OrEarlier; +import com.oracle.svm.core.jdk.JDK23OrLater; -@Platforms(Platform.HOSTED_ONLY.class) -final class ScopedValuesEnabled implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return JavaVersionUtil.JAVA_SPEC >= 21 || (JavaVersionUtil.JAVA_SPEC >= 20 && ModuleNative.bootLayerContainsModule("jdk.incubator.concurrent")); - } -} - -@TargetClass(className = "java.lang.ScopedValue", onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "java.lang.ScopedValue") final class Target_java_lang_ScopedValue { @Substitute static Target_java_lang_ScopedValue_Snapshot scopedValueBindings() { @@ -58,15 +47,20 @@ static Target_java_lang_ScopedValue_Snapshot scopedValueBindings() { } } +@TargetClass(className = "java.lang.ScopedValue", innerClass = "CallableOp", onlyWith = JDK23OrLater.class) +final class Target_java_lang_ScopedValue_CallableOp { +} + /** * Substituted to directly call {@link Target_java_lang_Thread#setScopedValueBindings} for forced * inlining. */ -@TargetClass(className = "java.lang.ScopedValue", innerClass = "Carrier", onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "java.lang.ScopedValue", innerClass = "Carrier") final class Target_java_lang_ScopedValue_Carrier { @Alias int bitmask; @Substitute + @TargetElement(onlyWith = JDK21OrEarlier.class) @Uninterruptible(reason = "Ensure no safepoint actions can disrupt reverting scoped value bindings.", calleeMustBe = false) private R runWith(Target_java_lang_ScopedValue_Snapshot newSnapshot, Callable op) throws Exception { Target_java_lang_Thread.setScopedValueBindings(newSnapshot); @@ -78,6 +72,19 @@ private R runWith(Target_java_lang_ScopedValue_Snapshot newSnapshot, Callabl } } + @Substitute + @TargetElement(onlyWith = JDK23OrLater.class) + @Uninterruptible(reason = "Ensure no safepoint actions can disrupt reverting scoped value bindings.", calleeMustBe = false) + private R runWith(Target_java_lang_ScopedValue_Snapshot newSnapshot, Target_java_lang_ScopedValue_CallableOp op) throws Exception { + Target_java_lang_Thread.setScopedValueBindings(newSnapshot); + try { + return Target_jdk_internal_vm_ScopedValueContainer.call(op); + } finally { + Target_java_lang_Thread.setScopedValueBindings(newSnapshot.prev); + Target_java_lang_ScopedValue_Cache.invalidate(bitmask); + } + } + @Substitute @Uninterruptible(reason = "Ensure no safepoint actions can disrupt reverting scoped value bindings.", calleeMustBe = false) private void runWith(Target_java_lang_ScopedValue_Snapshot newSnapshot, Runnable op) { @@ -91,16 +98,21 @@ private void runWith(Target_java_lang_ScopedValue_Snapshot newSnapshot, Runnable } } -@TargetClass(className = "jdk.internal.vm.ScopedValueContainer", onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "jdk.internal.vm.ScopedValueContainer") final class Target_jdk_internal_vm_ScopedValueContainer { @Alias + @TargetElement(onlyWith = JDK21OrEarlier.class) static native V call(Callable op) throws Exception; + @Alias + @TargetElement(onlyWith = JDK23OrLater.class) + static native V call(Target_java_lang_ScopedValue_CallableOp op) throws Exception; + @Alias static native void run(Runnable op); } -@TargetClass(className = "java.lang.ScopedValue", innerClass = "Snapshot", onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "java.lang.ScopedValue", innerClass = "Snapshot") final class Target_java_lang_ScopedValue_Snapshot { // Checkstyle: stop @Alias // @@ -111,7 +123,7 @@ final class Target_java_lang_ScopedValue_Snapshot { Target_java_lang_ScopedValue_Snapshot prev; } -@TargetClass(className = "java.lang.ScopedValue", innerClass = "Cache", onlyWith = ScopedValuesEnabled.class) +@TargetClass(className = "java.lang.ScopedValue", innerClass = "Cache") final class Target_java_lang_ScopedValue_Cache { @Alias static native void invalidate(int toClearBits);