From 4a780bde3c5a6c76faa77800ecd916ba35d18710 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 30 Jun 2022 11:48:35 +0200 Subject: [PATCH 01/44] svm: ignore unlikely-arg-type warnings related to CPU features --- .../oracle/svm/core/graal/amd64/AMD64CalleeSavedRegisters.java | 3 +++ .../com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java | 1 + .../oracle/svm/core/cpufeature/RuntimeCPUFeatureCheckImpl.java | 1 + 3 files changed, 5 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/AMD64CalleeSavedRegisters.java b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/AMD64CalleeSavedRegisters.java index 6ac577331720..ccca90e0a89c 100644 --- a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/AMD64CalleeSavedRegisters.java +++ b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/AMD64CalleeSavedRegisters.java @@ -257,6 +257,7 @@ private final class XMMSaverRestorer { this.hostedCPUFeatures = ImageSingletons.lookup(CPUFeatureAccess.class).buildtimeCPUFeatures(); } + @SuppressWarnings("unlikely-arg-type") public void emit() { assert isRuntimeCompilationEnabled == DeoptimizationSupport.enabled() : "JIT compilation enabled after registering singleton?"; if (isRuntimeCompilationEnabled && AMD64CPUFeatureAccess.canUpdateCPUFeatures()) { @@ -326,6 +327,7 @@ public void emit() { * Emits a {@linkplain #emitRuntimeFeatureTest runtime feature check} if the {@code feature} * is not statically available. */ + @SuppressWarnings("unlikely-arg-type") private void testFeature(CPUFeature feature, Label falseLabel) { if (!hostedCPUFeatures.contains(feature)) { emitRuntimeFeatureTest(feature, falseLabel); @@ -338,6 +340,7 @@ private void testFeature(CPUFeature feature, Label falseLabel) { * was {@linkplain #enterAvxRegion(CPUFeature) entered}, it must be * {@linkplain #leaveAvxRegion(CPUFeature) left} before calling this method. */ + @SuppressWarnings("unlikely-arg-type") private void jumpToEndOrReturn(CPUFeature feature, Label end) throws StaticFeatureException { if (hostedCPUFeatures.contains(feature)) { throw new StaticFeatureException(); 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 f2437b780e13..30100bbbcac5 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 @@ -195,6 +195,7 @@ public SubstrateAMD64Backend(Providers providers) { * Returns {@code true} if a call from run-time compiled code to AOT compiled code is an AVX-SSE * transition. For AOT compilations, this always returns {@code false}. */ + @SuppressWarnings("unlikely-arg-type") public static boolean runtimeToAOTIsAvxSseTransition(TargetDescription target) { if (SubstrateUtil.HOSTED) { // hosted does not need to care about this diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/cpufeature/RuntimeCPUFeatureCheckImpl.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/cpufeature/RuntimeCPUFeatureCheckImpl.java index e6183acbdf3a..e0a211ae0f0b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/cpufeature/RuntimeCPUFeatureCheckImpl.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/cpufeature/RuntimeCPUFeatureCheckImpl.java @@ -326,6 +326,7 @@ public static ResolvedJavaField getMaskField(MetaAccessProvider metaAccess) { * available at image build time. */ @Fold + @SuppressWarnings("unlikely-arg-type") public static EnumSet removeStaticFeatures(EnumSet features) { EnumSet copy = EnumSet.copyOf(features); EnumSet featuresToBeRemoved = getStaticFeatures(); From f722fe10053b8b582beb13082f7a624306110b11 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 30 Jun 2022 08:52:50 +0200 Subject: [PATCH 02/44] svm: ignore Thread.getId deprecation for JDK 19 --- .../src/com/oracle/svm/core/VMInspection.java | 1 + .../src/com/oracle/svm/core/jfr/JfrThreadRepository.java | 1 + .../src/com/oracle/svm/core/jfr/SubstrateJVM.java | 1 + .../src/com/oracle/svm/core/thread/JavaThreadsFeature.java | 1 + .../src/com/oracle/svm/core/thread/PlatformThreads.java | 2 ++ .../src/com/oracle/svm/core/thread/SubstrateVirtualThread.java | 2 ++ .../src/com/oracle/svm/core/thread/Target_java_lang_Thread.java | 2 +- 7 files changed, 9 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java index 6ddff48d2f3f..17d1b9fd801a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java @@ -132,6 +132,7 @@ protected void operate() { log.flush(); } + @SuppressWarnings("deprecation") private static void dumpStack(Log log, IsolateThread vmThread) { Thread javaThread = PlatformThreads.fromVMThread(vmThread); if (javaThread != null) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java index 271346b83420..1362e15c24aa 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java @@ -96,6 +96,7 @@ public void registerThread(Thread thread) { } @Uninterruptible(reason = "Epoch must not change while in this method.") + @SuppressWarnings("deprecation") private void registerThread0(Thread thread) { assert SubstrateJVM.isRecording(); JfrThreadEpochData epochData = getEpochData(false); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java index a882f3db4be4..48093d29d197 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java @@ -255,6 +255,7 @@ public long getStackTraceId(int skipCount) { } /** See {@link JVM#getThreadId}. */ + @SuppressWarnings("deprecation") public static long getThreadId(Thread thread) { if (HasJfrSupport.get()) { return thread.getId(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java index e3fdf0dbb712..325d8fc96568 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java @@ -130,6 +130,7 @@ public void afterAnalysis(AfterAnalysisAccess access) { JavaThreads.threadInitNumber.set(maxAutonumber); } + @SuppressWarnings("deprecation") static long threadId(Thread thread) { return thread == PlatformThreads.singleton().mainThread ? 1 : thread.getId(); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java index a469e2916394..50ce01911648 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java @@ -170,6 +170,7 @@ protected PlatformThreads() { mainGroupThreadsArray[0] = mainThread; } + @SuppressWarnings("deprecation") @Uninterruptible(reason = "Thread locks/holds the THREAD_MUTEX.") public static long getThreadAllocatedBytes(long javaThreadId) { // Accessing the value for the current thread is fast. @@ -195,6 +196,7 @@ public static long getThreadAllocatedBytes(long javaThreadId) { } } + @SuppressWarnings("deprecation") @Uninterruptible(reason = "Thread locks/holds the THREAD_MUTEX.") public static void getThreadAllocatedBytes(long[] javaThreadIds, long[] result) { VMThreads.lockThreadMutexInNativeCode(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java index d3b3080c1865..17620ec32cde 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java @@ -566,6 +566,7 @@ public Thread.State getState() { } } + @SuppressWarnings("deprecation") @Override public String toString() { StringBuilder sb = new StringBuilder("VirtualThread[#"); @@ -601,6 +602,7 @@ public String toString() { } @Override + @SuppressWarnings("deprecation") public int hashCode() { return (int) getId(); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index 9e7e7778ab9e..0debacef048f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -330,7 +330,7 @@ private Target_java_lang_Thread(String name, int characteristics) { this.contextClassLoader = Thread.currentThread().getContextClassLoader(); } - @SuppressWarnings("hiding") + @SuppressWarnings({"hiding", "deprecation"}) @Substitute private void start0() { if (!SubstrateOptions.MultiThreaded.getValue()) { From 9806235724a2cadd57cfdf39c9b00af1d3c3064a Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 30 Jun 2022 09:09:41 +0200 Subject: [PATCH 03/44] svm: ignore serial warnings --- .../src/com/oracle/graal/pointsto/util/AnalysisError.java | 1 + .../oracle/graal/pointsto/util/ParallelExecutionException.java | 1 + .../src/com/oracle/objectfile/BuildDependency.java | 1 + .../src/com/oracle/svm/core/util/UserError.java | 1 + 4 files changed, 4 insertions(+) diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/AnalysisError.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/AnalysisError.java index e70501a18922..06b8a1724d3a 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/AnalysisError.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/AnalysisError.java @@ -38,6 +38,7 @@ import jdk.vm.ci.meta.ResolvedJavaType; @Platforms(Platform.HOSTED_ONLY.class) +@SuppressWarnings("serial") public class AnalysisError extends Error { private static final long serialVersionUID = -4489048906003856416L; diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/ParallelExecutionException.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/ParallelExecutionException.java index b4af6ccbdec0..3a4d7ea42599 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/ParallelExecutionException.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/ParallelExecutionException.java @@ -31,6 +31,7 @@ /** * Bundles all exceptions from on parallel execution so they can be reported properly. */ +@SuppressWarnings("serial") public class ParallelExecutionException extends RuntimeException { private static final long serialVersionUID = -8477198165297173951L; diff --git a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/BuildDependency.java b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/BuildDependency.java index 5699d4066b1e..eef40789cda8 100644 --- a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/BuildDependency.java +++ b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/BuildDependency.java @@ -28,6 +28,7 @@ /** * A build dependency is a pair of LayoutDecisions (a, b), such that a depends on b. */ +@SuppressWarnings("serial") public final class BuildDependency implements Comparable { private static class DuplicateDependencyException extends Exception { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/UserError.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/UserError.java index bcdc7ef73315..a12f03ba01c8 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/UserError.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/UserError.java @@ -37,6 +37,7 @@ * SVM mechanism for handling user errors and warnings that should be reported to the command line. */ @Platforms(Platform.HOSTED_ONLY.class) +@SuppressWarnings("serial") public class UserError { /** From 5f26f6b35177e42c08f9ed6d3b3b4f23b543b53e Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 30 Jun 2022 09:28:24 +0200 Subject: [PATCH 04/44] svm: more deprecation for JDK 19 --- .../src/com/oracle/svm/core/heap/AbstractMemoryMXBean.java | 1 + .../oracle/svm/core/jdk/localization/LocalizationSupport.java | 1 + 2 files changed, 2 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/AbstractMemoryMXBean.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/AbstractMemoryMXBean.java index bc31ffe3f9c1..b9150c8f1428 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/AbstractMemoryMXBean.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/AbstractMemoryMXBean.java @@ -64,6 +64,7 @@ public ObjectName getObjectName() { } @Override + @SuppressWarnings("deprecation") public int getObjectPendingFinalizationCount() { // SVM does not have any finalization support. return 0; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationSupport.java index 01fdd24b8087..d91bd2073c10 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationSupport.java @@ -133,6 +133,7 @@ public void prepareNonCompliant(Class clazz) { /** * @return locale for given tag or null for invalid ones */ + @SuppressWarnings("deprecation") public static Locale parseLocaleFromTag(String tag) { try { return new Locale.Builder().setLanguageTag(tag).build(); From 605606a0ce4b5324de9455cb93d9f9b09dd83554 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 15:36:35 +0200 Subject: [PATCH 05/44] svm: update graal_compiler_flags_map for JDK 19 --- substratevm/mx.substratevm/mx_substratevm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index b3a567dfafee..a8a6a6246c92 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1665,6 +1665,8 @@ def compute_graal_compiler_flags_map(self): 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] # DO NOT ADD ANY NEW ADD-OPENS OR ADD-EXPORTS HERE! # # Instead provide the correct requiresConcealed entries in the moduleInfo From e2ef358c669b0a6fc5c822f793a7ead08ab45186 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 27 Jun 2022 14:16:41 +0200 Subject: [PATCH 06/44] svm: SVM_STATIC_LIBRARIES_SUPPORT is jdk dependent --- substratevm/mx.substratevm/mx_substratevm.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index a8a6a6246c92..b267181e8c28 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1577,7 +1577,13 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi layout = { './': ['file:' + join(base_jdk_home, 'lib', lib_prefix + '*' + lib_suffix)] } - register_distribution(mx.LayoutTARDistribution(suite, 'SVM_STATIC_LIBRARIES_SUPPORT', [], layout, None, True, None)) + register_distribution(JDKLayoutTARDistribution(suite, 'SVM_STATIC_LIBRARIES_SUPPORT', [], layout, None, True, None)) + + +class JDKLayoutTARDistribution(mx.LayoutTARDistribution): + def isJDKDependent(self): + return True + class SubstrateCompilerFlagsBuilder(mx.ArchivableProject): From beea0abe669d38e2e620da92d0b11071f2105fae Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 15:07:47 +0200 Subject: [PATCH 07/44] svm: add JDK19OrLater and JDK17OrEarlier --- .../oracle/svm/core/jdk/JDK17OrEarlier.java | 36 +++++++++++++++++++ .../com/oracle/svm/core/jdk/JDK19OrLater.java | 36 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK17OrEarlier.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrLater.java 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 new file mode 100644 index 000000000000..48d8487b98f0 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK17OrEarlier.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019, 2019, 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 JDK17OrEarlier implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return JavaVersionUtil.JAVA_SPEC <= 17; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrLater.java new file mode 100644 index 000000000000..fb32c832d2d4 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrLater.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020, 2020, 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 JDK19OrLater implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return JavaVersionUtil.JAVA_SPEC >= 19; + } +} From 14c00737928f502d4b7b10e33c8ad7d660e28caa Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 15:19:58 +0200 Subject: [PATCH 08/44] svm: add SubstrateMethodAccessor#invoke with caller argument --- .../svm/core/reflect/SubstrateMethodAccessor.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/SubstrateMethodAccessor.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/SubstrateMethodAccessor.java index 04c0db33c536..b0d413f9badb 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/SubstrateMethodAccessor.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/SubstrateMethodAccessor.java @@ -49,8 +49,12 @@ import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaField; +interface MethodAccessorJDK19 { + Object invoke(Object obj, Object[] args, Class caller); +} + @InternalVMMethod -public final class SubstrateMethodAccessor extends SubstrateAccessor implements MethodAccessor { +public final class SubstrateMethodAccessor extends SubstrateAccessor implements MethodAccessor, MethodAccessorJDK19 { public static final int STATICALLY_BOUND = -1; public static final int OFFSET_NOT_YET_COMPUTED = 0xdead0001; @@ -106,6 +110,12 @@ public Object invoke(Object obj, Object[] args) { return ((MethodInvokeFunctionPointer) expandSignature).invoke(obj, args, target); } + @Override + public Object invoke(Object obj, Object[] args, Class caller) { + // FIXME ignore caller + return invoke(obj, args); + } + public Object invokeSpecial(Object obj, Object[] args) { preInvoke(obj); From de10e6abe6cc7a72182e4b0005a3c89219ea6a31 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 16:27:19 +0200 Subject: [PATCH 09/44] svm: Classloader JDK 19 --- ...et_java_lang_ClassLoader_JDK17OrLater.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java index 1fc90500645c..95eca2003d11 100644 --- a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java +++ b/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java @@ -32,7 +32,10 @@ import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.jdk.JDK17OrLater; +import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.NativeLibrarySupport; import jdk.internal.loader.NativeLibraries; @@ -65,11 +68,18 @@ final class Target_jdk_internal_loader_NativeLibraries_JDK17OrLater { * not need an instance for now. */ @SuppressWarnings("unused") - @Substitute + @Substitute// + @TargetElement(onlyWith = JDK17OrEarlier.class) public static NativeLibraries jniNativeLibraries(ClassLoader loader) { return null; } + @SuppressWarnings("unused") + @Substitute// + @TargetElement(onlyWith = JDK19OrLater.class) + public static NativeLibraries newInstance(ClassLoader loader) { + return null; + } /* * Fields capturing state from the image generator that must not leak into the image heap. */ @@ -79,6 +89,7 @@ public static NativeLibraries jniNativeLibraries(ClassLoader loader) { @Delete // private static Set loadedLibraryNames; @Delete // + @TargetElement(onlyWith = JDK17OrEarlier.class)// private static Deque nativeLibraryContext; /* @@ -93,16 +104,33 @@ public static NativeLibraries jniNativeLibraries(ClassLoader loader) { private static native boolean load(Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl_JDK17OrLater impl, String name, boolean isBuiltin, boolean isJNI, boolean throwExceptionIfFail); */ - @Delete + @Delete// + @TargetElement(onlyWith = JDK17OrEarlier.class) private static native void unload(String name, boolean isBuiltin, boolean isJNI, long handle); + @Delete// + @TargetElement(onlyWith = JDK19OrLater.class) + private static native void unload(String name, boolean isBuiltin, long handle); + @Delete private static native String findBuiltinLib(String name); - @Delete + @Delete// + @TargetElement(onlyWith = JDK17OrEarlier.class) private static native long findEntry0(Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl_JDK17OrLater lib, String name); } +@TargetClass(value = jdk.internal.loader.NativeLibrary.class, onlyWith = JDK19OrLater.class) +final class Target_jdk_internal_loader_NativeLibrary_JDK19OrLater { + @Delete + private static native long findEntry0(long handle, String name); +} + @TargetClass(value = jdk.internal.loader.NativeLibraries.class, innerClass = "NativeLibraryImpl", onlyWith = JDK17OrLater.class) final class Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl_JDK17OrLater { } + +@Delete// +@TargetClass(value = jdk.internal.loader.NativeLibraries.class, innerClass = "NativeLibraryContext", onlyWith = JDK19OrLater.class) +final class Target_jdk_internal_loader_NativeLibraries_NativeLibraryContext_JDK19OrLater { +} From 2fb55f9ea77d43f07fec22436e2cad90ed5ac00e Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 16:28:12 +0200 Subject: [PATCH 10/44] svm: RecomputedFields JDK 19 --- .../src/com/oracle/svm/core/jdk/RecomputedFields.java | 2 ++ 1 file changed, 2 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 4d7a5f28fbe7..49cf2b91cf3e 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 @@ -57,6 +57,7 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; @@ -328,6 +329,7 @@ public static int getCommonPoolParallelism() { /* Delete the original static field for common parallelism. */ @Delete // + @TargetElement(onlyWith = JDK17OrEarlier.class)// static int COMMON_PARALLELISM; @Alias // From c980954d33d2ba395f0b2627c1074887f9ddc4a8 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 16:28:38 +0200 Subject: [PATCH 11/44] svm: ReferenceQueue$Lock gone in JDK 19 --- .../svm/core/monitor/MultiThreadedMonitorSupport.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java index 1a32abacb6e7..27cb528787c3 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java @@ -54,6 +54,7 @@ import com.oracle.svm.core.annotate.Uninterruptible; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.hub.DynamicHubCompanion; +import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; import com.oracle.svm.core.stack.StackOverflowCheck; import com.oracle.svm.core.thread.ThreadStatus; @@ -119,7 +120,9 @@ public class MultiThreadedMonitorSupport extends MonitorSupport { * class Lock for all its locking needs. */ HashSet> monitorTypes = new HashSet<>(); - monitorTypes.add(Class.forName("java.lang.ref.ReferenceQueue$Lock")); + if (JavaVersionUtil.JAVA_SPEC <= 17) { + monitorTypes.add(Class.forName("java.lang.ref.ReferenceQueue$Lock")); + } /* The WeakIdentityHashMap also synchronizes on its internal ReferenceQueue field. */ monitorTypes.add(java.lang.ref.ReferenceQueue.class); @@ -580,7 +583,7 @@ final class Target_java_util_concurrent_locks_AbstractQueuedSynchronizer_Conditi @Alias Target_java_util_concurrent_locks_AbstractQueuedSynchronizer this$0; } -@TargetClass(value = ReferenceQueue.class, innerClass = "Lock") +@TargetClass(value = ReferenceQueue.class, innerClass = "Lock", onlyWith = JDK17OrEarlier.class) final class Target_java_lang_ref_ReferenceQueue_Lock { } // Checkstyle: resume From 3eeeb56bc7bc3f37f5f150b95223d81e02e7ffe1 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 17:21:01 +0200 Subject: [PATCH 12/44] svm: Field JDK 19 --- .../Target_java_lang_reflect_Field.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.reflect/src/com/oracle/svm/reflect/target/Target_java_lang_reflect_Field.java b/substratevm/src/com.oracle.svm.reflect/src/com/oracle/svm/reflect/target/Target_java_lang_reflect_Field.java index 91b3114d11bc..83fa05ba740d 100644 --- a/substratevm/src/com.oracle.svm.reflect/src/com/oracle/svm/reflect/target/Target_java_lang_reflect_Field.java +++ b/substratevm/src/com.oracle.svm.reflect/src/com/oracle/svm/reflect/target/Target_java_lang_reflect_Field.java @@ -32,7 +32,6 @@ import java.util.Map; import org.graalvm.nativeimage.ImageSingletons; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; @@ -45,11 +44,14 @@ import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.jdk.JDK11OrEarlier; +import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.jdk.JDK17OrLater; +import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.image.NativeImageCodeCache; import com.oracle.svm.reflect.hosted.FieldOffsetComputer; import com.oracle.svm.reflect.hosted.ReflectionMetadataComputer; +import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaField; @@ -87,8 +89,17 @@ public final class Target_java_lang_reflect_Field { native Target_java_lang_reflect_Field copy(); @Alias + @TargetElement(onlyWith = JDK17OrEarlier.class) native Target_jdk_internal_reflect_FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck); + @Alias// + @TargetElement(onlyWith = JDK19OrLater.class) + native Target_jdk_internal_reflect_FieldAccessor acquireFieldAccessor(); + + @Alias// + @TargetElement(onlyWith = JDK19OrLater.class) + native Target_jdk_internal_reflect_FieldAccessor acquireOverrideFieldAccessor(); + @Alias @TargetElement(name = CONSTRUCTOR_NAME, onlyWith = JDK17OrLater.class) @SuppressWarnings("hiding") @@ -101,6 +112,7 @@ public final class Target_java_lang_reflect_Field { /** @see com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor#deleteErrorMessage */ @Substitute + @TargetElement(onlyWith = JDK17OrEarlier.class) Target_jdk_internal_reflect_FieldAccessor getFieldAccessor(@SuppressWarnings("unused") Object obj) { boolean ov = override; Target_jdk_internal_reflect_FieldAccessor accessor = (ov) ? overrideFieldAccessor : fieldAccessor; @@ -115,6 +127,38 @@ Target_jdk_internal_reflect_FieldAccessor getFieldAccessor(@SuppressWarnings("un return acquireFieldAccessor(ov); } + /** @see com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor#deleteErrorMessage */ + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + Target_jdk_internal_reflect_FieldAccessor getFieldAccessor() { + Target_jdk_internal_reflect_FieldAccessor accessor = fieldAccessor; + if (accessor != null) { + return accessor; + } + if (deletedReason != null) { + Field field = SubstrateUtil.cast(this, Field.class); + throw VMError.unsupportedFeature("Unsupported field " + field.getDeclaringClass().getTypeName() + + "." + field.getName() + " is reachable: " + deletedReason); + } + return acquireFieldAccessor(); + } + + /** @see com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor#deleteErrorMessage */ + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + Target_jdk_internal_reflect_FieldAccessor getOverrideFieldAccessor() { + Target_jdk_internal_reflect_FieldAccessor accessor = overrideFieldAccessor; + if (accessor != null) { + return accessor; + } + if (deletedReason != null) { + Field field = SubstrateUtil.cast(this, Field.class); + throw VMError.unsupportedFeature("Unsupported field " + field.getDeclaringClass().getTypeName() + + "." + field.getName() + " is reachable: " + deletedReason); + } + return acquireOverrideFieldAccessor(); + } + @Substitute private byte[] getTypeAnnotationBytes0() { return SubstrateUtil.cast(this, Target_java_lang_reflect_AccessibleObject.class).typeAnnotations; From 41d1d4799247fd92a348d0bd4955a453ec62858f Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 21 Jun 2022 11:15:19 +0200 Subject: [PATCH 13/44] svm: PlainSocketImpl removed in JDK 19 [JDK-8253119] --- .../hosted/jdk/JNIRegistrationJavaNet.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java index 993df4b68813..1cdd26b6c99e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java @@ -60,23 +60,35 @@ public void duringSetup(DuringSetupAccess a) { hasPlatformSocketOptions = a.findClassByName("jdk.net.ExtendedSocketOptions$PlatformSocketOptions") != null; rerunClassInit(a, "java.net.DatagramPacket", "java.net.InetAddress", "java.net.NetworkInterface", - "java.net.SocketInputStream", "java.net.SocketOutputStream", - /* Caches networking properties. */ - "java.net.DefaultDatagramSocketImplFactory", /* Stores a default SSLContext in a static field. */ "javax.net.ssl.SSLContext"); + if (JavaVersionUtil.JAVA_SPEC <= 17) { + /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ + rerunClassInit(a, "java.net.SocketInputStream", "java.net.SocketOutputStream", + /* Caches networking properties. */ + "java.net.DefaultDatagramSocketImplFactory"); + } if (isWindows()) { rerunClassInit(a, "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl"); - /* Caches networking properties. */ - rerunClassInit(a, "java.net.PlainSocketImpl"); + if (JavaVersionUtil.JAVA_SPEC <= 17) { + /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ + /* Caches networking properties. */ + rerunClassInit(a, "java.net.PlainSocketImpl"); + } } else { assert isPosix(); - rerunClassInit(a, "java.net.PlainDatagramSocketImpl", "java.net.PlainSocketImpl"); + if (JavaVersionUtil.JAVA_SPEC <= 17) { + /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ + rerunClassInit(a, "java.net.PlainDatagramSocketImpl", "java.net.PlainSocketImpl"); + } if (hasExtendedOptionsImpl) { rerunClassInit(a, "sun.net.ExtendedOptionsImpl"); } - rerunClassInit(a, "java.net.AbstractPlainDatagramSocketImpl", "java.net.AbstractPlainSocketImpl"); + if (JavaVersionUtil.JAVA_SPEC <= 17) { + /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ + rerunClassInit(a, "java.net.AbstractPlainDatagramSocketImpl", "java.net.AbstractPlainSocketImpl"); + } if (hasPlatformSocketOptions) { /* From 9a3d04938cf84d84e823743a49cbcaf259302326 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 21 Jun 2022 11:23:15 +0200 Subject: [PATCH 14/44] svm: remove AccessControlContext exceptions for removed fields in JDK 19 --- .../svm/hosted/jdk/AccessControlContextReplacerFeature.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/AccessControlContextReplacerFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/AccessControlContextReplacerFeature.java index f914ed444e95..c16bc134832e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/AccessControlContextReplacerFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/AccessControlContextReplacerFeature.java @@ -84,7 +84,9 @@ public void duringSetup(DuringSetupAccess access) { if (JavaVersionUtil.JAVA_SPEC >= 11) { allowContextIfExists("java.security.AccessController$AccHolder", "innocuousAcc"); - allowContextIfExists("java.util.concurrent.ForkJoinPool$DefaultForkJoinWorkerThreadFactory", "ACC"); + if (JavaVersionUtil.JAVA_SPEC < 19) { + allowContextIfExists("java.util.concurrent.ForkJoinPool$DefaultForkJoinWorkerThreadFactory", "ACC"); + } } if (JavaVersionUtil.JAVA_SPEC < 17) { allowContextIfExists("java.util.concurrent.ForkJoinWorkerThread", "INNOCUOUS_ACC"); @@ -92,7 +94,7 @@ public void duringSetup(DuringSetupAccess access) { if (JavaVersionUtil.JAVA_SPEC >= 11 && JavaVersionUtil.JAVA_SPEC < 17) { allowContextIfExists("java.util.concurrent.ForkJoinPool$InnocuousForkJoinWorkerThreadFactory", "ACC"); } - if (JavaVersionUtil.JAVA_SPEC >= 17) { + if (JavaVersionUtil.JAVA_SPEC >= 17 && JavaVersionUtil.JAVA_SPEC < 19) { allowContextIfExists("java.util.concurrent.ForkJoinPool$WorkQueue", "INNOCUOUS_ACC"); allowContextIfExists("java.util.concurrent.ForkJoinPool$DefaultCommonPoolForkJoinWorkerThreadFactory", "ACC"); } From f554a37f46db3429487d3e5d5378f7d879364a7b Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 21 Jun 2022 12:31:02 +0200 Subject: [PATCH 15/44] svm: sync with AMD64.CPUFeature in JDK 19 --- .../svm/core/amd64/AMD64LibCHelper.java | 24 ++++++++++++++++++ .../include/amd64cpufeatures.h | 6 +++++ .../include/amd64hotspotcpuinfo.h | 16 +++++++++--- .../src/cpuid.c | 25 +++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/amd64/AMD64LibCHelper.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/amd64/AMD64LibCHelper.java index 01239268a8c9..2bc9423b628f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/amd64/AMD64LibCHelper.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/amd64/AMD64LibCHelper.java @@ -242,6 +242,30 @@ public interface CPUFeatures extends PointerBase { @AllowNarrowingCast @CField boolean fHV(); + + @AllowNarrowingCast + @CField + boolean fSERIALIZE(); + + @AllowNarrowingCast + @CField + boolean fRDTSCP(); + + @AllowNarrowingCast + @CField + boolean fRDPID(); + + @AllowNarrowingCast + @CField + boolean fFSRM(); + + @AllowNarrowingCast + @CField + boolean fGFNI(); + + @AllowNarrowingCast + @CField + boolean fAVX512_BITALG(); } // Checkstyle: resume } diff --git a/substratevm/src/com.oracle.svm.native.libchelper/include/amd64cpufeatures.h b/substratevm/src/com.oracle.svm.native.libchelper/include/amd64cpufeatures.h index 3e8bf16e5027..865744445316 100644 --- a/substratevm/src/com.oracle.svm.native.libchelper/include/amd64cpufeatures.h +++ b/substratevm/src/com.oracle.svm.native.libchelper/include/amd64cpufeatures.h @@ -71,4 +71,10 @@ typedef struct { char fAVX512_VBMI2; char fAVX512_VBMI; char fHV; + char fSERIALIZE; + char fRDTSCP; + char fRDPID; + char fFSRM; + char fGFNI; + char fAVX512_BITALG; } CPUFeatures; diff --git a/substratevm/src/com.oracle.svm.native.libchelper/include/amd64hotspotcpuinfo.h b/substratevm/src/com.oracle.svm.native.libchelper/include/amd64hotspotcpuinfo.h index 89921a36343b..71f86ec7bcfd 100644 --- a/substratevm/src/com.oracle.svm.native.libchelper/include/amd64hotspotcpuinfo.h +++ b/substratevm/src/com.oracle.svm.native.libchelper/include/amd64hotspotcpuinfo.h @@ -156,7 +156,10 @@ typedef union { mmx_amd : 1, mmx : 1, fxsr : 1, - : 4, + fxsr_opt : 1, + pdpe1gb : 1, + rdtscp : 1, + : 1, long_mode : 1, tdnow2 : 1, tdnow : 1; @@ -243,7 +246,11 @@ typedef union { avx512_bitalg : 1, : 1, avx512_vpopcntdq : 1, - : 17; + : 1, + : 1, + mawau : 5, + rdpid : 1, + : 9; } bits; } SefCpuid7Ecx; @@ -253,7 +260,10 @@ typedef union { uint32_t : 2, avx512_4vnniw : 1, avx512_4fmaps : 1, - : 28; + fast_short_rep_mov : 1, + : 9, + serialize : 1, + : 17; } bits; } SefCpuid7Edx; diff --git a/substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c b/substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c index 571ed8a8ba93..0f326c8808b4 100644 --- a/substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c +++ b/substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c @@ -444,8 +444,12 @@ static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_info) features->fAVX512_VPCLMULQDQ = 1; if (_cpuid_info->sef_cpuid7_ecx.bits.vaes != 0) features->fAVX512_VAES = 1; + if (_cpuid_info->sef_cpuid7_ecx.bits.gfni != 0) + features->fGFNI = 1; if (_cpuid_info->sef_cpuid7_ecx.bits.avx512_vnni != 0) features->fAVX512_VNNI = 1; + if (_cpuid_info->sef_cpuid7_ecx.bits.avx512_bitalg != 0) + features->fAVX512_BITALG = 1; if (_cpuid_info->sef_cpuid7_ecx.bits.avx512_vbmi != 0) features->fAVX512_VBMI = 1; if (_cpuid_info->sef_cpuid7_ecx.bits.avx512_vbmi2 != 0) @@ -464,6 +468,8 @@ static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_info) features->fAES = 1; if (_cpuid_info->sef_cpuid7_ebx.bits.erms != 0) features->fERMS = 1; + if (_cpuid_info->sef_cpuid7_edx.bits.fast_short_rep_mov != 0) + features->fFSRM = 1; if (_cpuid_info->std_cpuid1_ecx.bits.clmul != 0) features->fCLMUL = 1; if (_cpuid_info->sef_cpuid7_ebx.bits.rtm != 0) @@ -478,6 +484,10 @@ static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_info) features->fFMA = 1; if (_cpuid_info->sef_cpuid7_ebx.bits.clflushopt != 0) features->fFLUSHOPT = 1; + if (_cpuid_info->ext_cpuid1_edx.bits.rdtscp != 0) + features->fRDTSCP = 1; + if (_cpuid_info->sef_cpuid7_ecx.bits.rdpid != 0) + features->fRDPID = 1; // AMD|Hygon features. if (is_amd_family(_cpuid_info)) @@ -505,6 +515,10 @@ static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_info) { features->fCLWB = 1; } + if (_cpuid_info->sef_cpuid7_edx.bits.serialize != 0) + { + features->fSERIALIZE = 1; + } } // ZX features. @@ -553,6 +567,17 @@ void determineCPUFeatures(CPUFeatures *features) features->fVZEROUPPER = 0; features->fAVX512BW = 0; features->fAVX512VL = 0; + features->fAVX512DQ = 0; + features->fAVX512_VNNI = 0; + features->fAVX512_VAES = 0; + features->fAVX512_VPOPCNTDQ = 0; + features->fAVX512_VPCLMULQDQ = 0; + features->fAVX512_VBMI = 0; + features->fAVX512_VBMI2 = 0; + features->fCLWB = 0; + features->fFLUSHOPT = 0; + features->fGFNI = 0; + features->fAVX512_BITALG = 0; } } } From fe8cf7b5e48a2d81056a72c86043ea9995adf4e9 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 21 Jun 2022 12:53:07 +0200 Subject: [PATCH 16/44] svm: adopt JNI registration for JDK 19 --- .../hosted/jdk/JNIRegistrationJavaNet.java | 75 +++++++++++-------- .../hosted/jdk/JNIRegistrationJavaNio.java | 6 +- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java index 1cdd26b6c99e..332738447b86 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java @@ -129,47 +129,62 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { * InetAddress, Inet4Address, and Inet6Address are registered from many places in the JDK, * so it does not make sense to separate them. */ - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInitInetAddressIDs, - method(a, "java.net.InetAddress", "init"), - /* The next two methods call initInetAddressIDs directly. */ - method(a, "java.net.Inet4AddressImpl", "lookupAllHostAddr", String.class), - method(a, "java.net.Inet6AddressImpl", "lookupAllHostAddr", String.class)); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInetAddressLoadImpl, - method(a, "java.net.InetAddress", "loadImpl", String.class)); + if (JavaVersionUtil.JAVA_SPEC < 19) { + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInitInetAddressIDs, + method(a, "java.net.InetAddress", "init"), + /* The next two methods call initInetAddressIDs directly. */ + method(a, "java.net.Inet4AddressImpl", "lookupAllHostAddr", String.class), + method(a, "java.net.Inet6AddressImpl", "lookupAllHostAddr", String.class)); + } else { + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInitInetAddressIDs, + method(a, "java.net.InetAddress", "init"), + /* The next two methods call initInetAddressIDs directly. */ + method(a, "java.net.Inet4AddressImpl", "lookupAllHostAddr", String.class), + method(a, "java.net.Inet6AddressImpl", "lookupAllHostAddr", String.class, int.class)); + } + if (JavaVersionUtil.JAVA_SPEC < 19) { + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInetAddressLoadImpl, + method(a, "java.net.InetAddress", "loadImpl", String.class)); + } a.registerReachabilityHandler(JNIRegistrationJavaNet::registerNetworkInterfaceInit, method(a, "java.net.NetworkInterface", "init")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDatagramPacketInit, - method(a, "java.net.DatagramPacket", "init")); + if (JavaVersionUtil.JAVA_SPEC < 19) { + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDatagramPacketInit, + method(a, "java.net.DatagramPacket", "init")); + } if (JavaVersionUtil.JAVA_SPEC <= 11) { a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDatagramSocketCheckOldImpl, method(a, "java.net.DatagramSocket", "checkOldImpl")); } - String plainDatagramSocketImpl = isWindows() ? "TwoStacksPlainDatagramSocketImpl" : "PlainDatagramSocketImpl"; - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainDatagramSocketImplInit, - method(a, "java.net." + plainDatagramSocketImpl, "init")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainDatagramSocketImplSocketGetOption, - method(a, "java.net." + plainDatagramSocketImpl, "socketGetOption", int.class)); - - if (isPosix()) { - String plainSocketImpl = isWindows() ? "TwoStacksPlainSocketImpl" : "PlainSocketImpl"; - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainSocketImplInitProto, - method(a, "java.net." + plainSocketImpl, "initProto")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainSocketImplSocketGetOption, - method(a, "java.net." + plainSocketImpl, "socketGetOption", int.class, Object.class)); + if (JavaVersionUtil.JAVA_SPEC < 19) { + /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ + String plainDatagramSocketImpl = isWindows() ? "TwoStacksPlainDatagramSocketImpl" : "PlainDatagramSocketImpl"; + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainDatagramSocketImplInit, + method(a, "java.net." + plainDatagramSocketImpl, "init")); + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainDatagramSocketImplSocketGetOption, + method(a, "java.net." + plainDatagramSocketImpl, "socketGetOption", int.class)); + + if (isPosix()) { + String plainSocketImpl = isWindows() ? "TwoStacksPlainSocketImpl" : "PlainSocketImpl"; + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainSocketImplInitProto, + method(a, "java.net." + plainSocketImpl, "initProto")); + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainSocketImplSocketGetOption, + method(a, "java.net." + plainSocketImpl, "socketGetOption", int.class, Object.class)); + } + if (isWindows()) { + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainDatagramSocketImplInitIDs, + method(a, "java.net.DualStackPlainDatagramSocketImpl", "initIDs")); + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainSocketImplInitIDs, + method(a, "java.net.PlainSocketImpl", "initIDs")); + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainSocketImplLocalAddress, + method(a, "java.net.PlainSocketImpl", "localAddress", int.class, clazz(a, "java.net.InetAddressContainer"))); + } } - if (isWindows()) { - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainDatagramSocketImplInitIDs, - method(a, "java.net.DualStackPlainDatagramSocketImpl", "initIDs")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainSocketImplInitIDs, - method(a, "java.net.PlainSocketImpl", "initIDs")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainSocketImplLocalAddress, - method(a, "java.net.PlainSocketImpl", "localAddress", int.class, clazz(a, "java.net.InetAddressContainer"))); - } else { - assert isPosix(); + if (isPosix()) { if (hasExtendedOptionsImpl) { a.registerReachabilityHandler(JNIRegistrationJavaNet::registerExtendedOptionsImplInit, method(a, "sun.net.ExtendedOptionsImpl", "init")); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java index a633e29e088d..e83ffc94705e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java @@ -91,7 +91,9 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { // JDK-8220738 a.registerReachabilityHandler(JNIRegistrationJavaNio::registerNetInitIDs, method(a, "sun.nio.ch.Net", "initIDs")); } - a.registerReachabilityHandler(JNIRegistrationJavaNio::registerFileChannelImplInitIDs, method(a, "sun.nio.ch.FileChannelImpl", "initIDs")); + if (JavaVersionUtil.JAVA_SPEC <= 17) { + a.registerReachabilityHandler(JNIRegistrationJavaNio::registerFileChannelImplInitIDs, method(a, "sun.nio.ch.FileChannelImpl", "initIDs")); + } a.registerReachabilityHandler(JNIRegistrationJavaNio::registerFileKeyInitIDs, method(a, "sun.nio.ch.FileKey", "initIDs")); if (isPosix()) { @@ -114,7 +116,7 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { * Starting with support for JDK 17, all of the Buffer classes require MemorySegmentProxy * which is accessed via reflection. */ - if (JavaVersionUtil.JAVA_SPEC >= 17) { + if (JavaVersionUtil.JAVA_SPEC == 17) { RuntimeReflection.register(clazz(a, "jdk.internal.access.foreign.MemorySegmentProxy")); } } From 182791f89e11d18f713ece752cd457285cf79dbb Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 23 Jun 2022 07:29:34 +0200 Subject: [PATCH 17/44] svm: ClassLoaderAccessors for Class.classLoader for JDK 19 In JDK 19, `Class.classLoader` is references directly inside of `Class` instead of only via `getClassLoader0`. Thus, add an accessor for the field. --- .../src/com/oracle/svm/core/hub/DynamicHub.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index b3bcd1e82c0e..8be30c58f1a3 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -313,6 +313,9 @@ public void setModule(Module module) { private String signature; + @Substitute @InjectAccessors(ClassLoaderAccessors.class) // + private ClassLoader classLoader; + @Substitute @InjectAccessors(ReflectionDataAccessors.class) // private SoftReference> reflectionData; @@ -732,10 +735,8 @@ public InputStream getResourceAsStream(String resourceName) { @KeepOriginal private native ClassLoader getClassLoader(); - @Substitute - private ClassLoader getClassLoader0() { - return companion.getClassLoader(); - } + @KeepOriginal + private native ClassLoader getClassLoader0(); public boolean isLoaded() { return companion.hasClassLoader(); @@ -1552,6 +1553,13 @@ private static SoftReference> getReflec } } + private static class ClassLoaderAccessors { + @SuppressWarnings("unused") + private static ClassLoader getClassLoader(DynamicHub that) { + return that.companion.getClassLoader(); + } + } + private static class AnnotationDataAccessors { @SuppressWarnings("unused") private static Target_java_lang_Class_AnnotationData getAnnotationData(DynamicHub that) { From 8748c31c07ccaa1e3f718347822732194e36d51d Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 23 Jun 2022 07:52:29 +0200 Subject: [PATCH 18/44] svm: InetAddress.preferIPv6Address removed in JDK 19 --- .../com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java index 332738447b86..1297637e0030 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java @@ -205,7 +205,10 @@ static void registerInitInetAddressIDs(DuringAnalysisAccess a) { } /* Java_java_net_InetAddress_init */ - JNIRuntimeAccess.register(fields(a, "java.net.InetAddress", "holder", "preferIPv6Address")); + JNIRuntimeAccess.register(fields(a, "java.net.InetAddress", "holder")); + if (JavaVersionUtil.JAVA_SPEC <= 17) { + JNIRuntimeAccess.register(fields(a, "java.net.InetAddress", "preferIPv6Address")); + } JNIRuntimeAccess.register(fields(a, "java.net.InetAddress$InetAddressHolder", "address", "family", "hostName", "originalHostName")); /* Java_java_net_Inet4Address_init */ From 79cfb738f65420b4004110484791d73f04167895 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 23 Jun 2022 10:34:51 +0200 Subject: [PATCH 19/44] svm: mark jdk.internal.misc.VM.toThreadState as Uninterruptible --- .../com/oracle/svm/core/jdk/Target_jdk_internal_misc_VM.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_misc_VM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_misc_VM.java index 1edc96b02493..e62b6ac6e336 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_misc_VM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_misc_VM.java @@ -30,6 +30,7 @@ import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.AnnotateOriginal; import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.InjectAccessors; import com.oracle.svm.core.annotate.NeverInline; @@ -37,6 +38,7 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.Uninterruptible; import com.oracle.svm.core.snippets.KnownIntrinsics; import jdk.internal.misc.Unsafe; @@ -52,7 +54,8 @@ public static String getSavedProperty(String name) { return ImageSingletons.lookup(SystemPropertiesSupport.class).getSavedProperties().get(name); } - @Alias + @AnnotateOriginal + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public static native Thread.State toThreadState(int threadStatus); @Substitute From b93e50e0d6ba6987897eae608d9676839379807e Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 23 Jun 2022 15:15:44 +0200 Subject: [PATCH 20/44] svm: ignore permitted subclasses that have been deleted --- .../reflect/hosted/ReflectionMetadataEncoderImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.reflect/src/com/oracle/svm/reflect/hosted/ReflectionMetadataEncoderImpl.java b/substratevm/src/com.oracle.svm.reflect/src/com/oracle/svm/reflect/hosted/ReflectionMetadataEncoderImpl.java index 95cd5f5cf185..a08d51f4f8a9 100644 --- a/substratevm/src/com.oracle.svm.reflect/src/com/oracle/svm/reflect/hosted/ReflectionMetadataEncoderImpl.java +++ b/substratevm/src/com.oracle.svm.reflect/src/com/oracle/svm/reflect/hosted/ReflectionMetadataEncoderImpl.java @@ -288,9 +288,13 @@ private static Class[] getPermittedSubclasses(MetaAccessProvider metaAccess, } Set> reachablePermittedSubclasses = new HashSet<>(); for (Class permittedSubclass : permittedSubclasses) { - HostedType hostedType = ((HostedMetaAccess) metaAccess).optionalLookupJavaType(permittedSubclass).orElse(null); - if (hostedType != null && hostedType.getWrapped().isReachable()) { - reachablePermittedSubclasses.add(permittedSubclass); + try { + HostedType hostedType = ((HostedMetaAccess) metaAccess).optionalLookupJavaType(permittedSubclass).orElse(null); + if (hostedType != null && hostedType.getWrapped().isReachable()) { + reachablePermittedSubclasses.add(permittedSubclass); + } + } catch (DeletedElementException dee) { + // permitted subclass has been deleted -> ignore } } return reachablePermittedSubclasses.toArray(new Class[0]); From c08817de00b50a3d407b41a56faf97627dcafcd7 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 27 Jun 2022 09:40:49 +0200 Subject: [PATCH 21/44] svm: InnocuousThread in JDK 19 --- .../com/oracle/svm/core/thread/SubstrateVirtualThread.java | 3 ++- .../com/oracle/svm/hosted/jdk/JDKInitializationFeature.java | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java index 17620ec32cde..6bfec7b9fee5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java @@ -40,6 +40,7 @@ import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.jdk.ContinuationsSupported; +import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.jdk.NotLoomJDK; import com.oracle.svm.core.monitor.MonitorSupport; import com.oracle.svm.core.stack.JavaFrameAnchor; @@ -693,7 +694,7 @@ private static ScheduledExecutorService createDelayedTaskScheduler() { } } -@TargetClass(className = "jdk.internal.misc.InnocuousThread", onlyWith = {ContinuationsSupported.class, NotLoomJDK.class}) +@TargetClass(className = "jdk.internal.misc.InnocuousThread", onlyWith = {ContinuationsSupported.class, NotLoomJDK.class, JDK17OrEarlier.class}) final class Target_jdk_internal_misc_InnocuousThread { @Alias static native Thread newThread(String name, Runnable target); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java index fb1facc52306..49b87c3069e6 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java @@ -24,6 +24,7 @@ */ package com.oracle.svm.hosted.jdk; +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.hosted.Feature; @@ -168,5 +169,9 @@ public void afterRegistration(AfterRegistrationAccess access) { rci.rerunInitialization("java.lang.StrictMath$RandomNumberGeneratorHolder", "Contains random seeds"); rci.rerunInitialization("jdk.internal.misc.InnocuousThread", "Contains a thread group INNOCUOUSTHREADGROUP."); + + if (JavaVersionUtil.JAVA_SPEC >= 19) { + rci.rerunInitialization("sun.nio.ch.Poller", "Contains an InnocuousThread."); + } } } From e769c6b6a35ebcc03837bb51c6ac889dd77f7708 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 16:56:50 +0200 Subject: [PATCH 22/44] svm: Thread related changes in JDK 19 --- .../JavaLangThreadGroupSubstitutions.java | 12 +-- .../oracle/svm/core/thread/JavaThreads.java | 2 +- .../oracle/svm/core/thread/LoomSupport.java | 31 ++++--- .../Package_jdk_internal_vm_helper.java | 46 ++++++++++ .../svm/core/thread/PlatformThreads.java | 10 ++- .../thread/Target_java_lang_Continuation.java | 31 ++++++- .../core/thread/Target_java_lang_Thread.java | 88 ++++++++++++------- .../Target_java_lang_VirtualThread.java | 26 +++++- 8 files changed, 190 insertions(+), 56 deletions(-) create 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/JavaLangThreadGroupSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaLangThreadGroupSubstitutions.java index 6e8b223fa112..c13000ce596e 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaLangThreadGroupSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaLangThreadGroupSubstitutions.java @@ -39,7 +39,7 @@ import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.annotate.Uninterruptible; import com.oracle.svm.core.heap.Heap; -import com.oracle.svm.core.jdk.NotLoomJDK; +import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.jdk.UninterruptibleUtils; import jdk.vm.ci.meta.MetaAccessProvider; @@ -48,14 +48,14 @@ @TargetClass(ThreadGroup.class) final class Target_java_lang_ThreadGroup { - @Alias @TargetElement(onlyWith = NotLoomJDK.class)// + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadGroupNUnstartedThreadsRecomputation.class, disableCaching = true)// private int nUnstartedThreads; - @Alias @TargetElement(onlyWith = NotLoomJDK.class)// + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadGroupNThreadsRecomputation.class)// private int nthreads; - @Alias @TargetElement(onlyWith = NotLoomJDK.class) // + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class) // @InjectAccessors(ThreadGroupThreadsAccessor.class) // private Thread[] threads; @@ -82,11 +82,11 @@ final class Target_java_lang_ThreadGroup { long injectedId; @Alias - @TargetElement(onlyWith = NotLoomJDK.class)// + @TargetElement(onlyWith = JDK17OrEarlier.class)// native void addUnstarted(); @Alias - @TargetElement(onlyWith = NotLoomJDK.class)// + @TargetElement(onlyWith = JDK17OrEarlier.class)// native void add(Thread t); @AnnotateOriginal diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java index c115adfcbd48..b7a105c4a3c8 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java @@ -276,7 +276,7 @@ static void initializeNewThread( } LoomSupport.CompatibilityUtil.initThreadFields(tjlt, group, target, stackSize, priority, daemon, ThreadStatus.NEW); - if (!LoomSupport.isEnabled() && !(VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(fromTarget(tjlt)))) { + if (!(LoomSupport.isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) && !(VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(fromTarget(tjlt)))) { JavaThreads.toTarget(group).addUnstarted(); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/LoomSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/LoomSupport.java index e0f1dcba0178..ebfe9415d870 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/LoomSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/LoomSupport.java @@ -27,6 +27,7 @@ import java.lang.reflect.Field; import org.graalvm.compiler.api.replacements.Fold; +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.IsolateThread; @@ -105,19 +106,23 @@ public static Target_java_lang_Continuation getContinuation(Target_java_lang_Thr } public static class CompatibilityUtil { - private static final Field FIELDHOLDER_STATUS_FIELD = (ImageInfo.inImageCode() && isEnabled()) ? ReflectionUtil.lookupField(Target_java_lang_Thread_FieldHolder.class, "threadStatus") : null; - private static final Field THREAD_STATUS_FIELD = (ImageInfo.inImageCode() && !isEnabled()) ? ReflectionUtil.lookupField(Target_java_lang_Thread.class, "threadStatus") : null; + private static final Field FIELDHOLDER_STATUS_FIELD = (ImageInfo.inImageCode() && (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19)) + ? ReflectionUtil.lookupField(Target_java_lang_Thread_FieldHolder.class, "threadStatus") + : null; + private static final Field THREAD_STATUS_FIELD = (ImageInfo.inImageCode() && !(isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19)) + ? ReflectionUtil.lookupField(Target_java_lang_Thread.class, "threadStatus") + : null; static long getStackSize(Target_java_lang_Thread tjlt) { - return isEnabled() ? tjlt.holder.stackSize : tjlt.stackSize; + return isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19 ? tjlt.holder.stackSize : tjlt.stackSize; } static int getThreadStatus(Target_java_lang_Thread tjlt) { - return isEnabled() ? tjlt.holder.threadStatus : tjlt.threadStatus; + return isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19 ? tjlt.holder.threadStatus : tjlt.threadStatus; } static void setThreadStatus(Target_java_lang_Thread tjlt, int threadStatus) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { tjlt.holder.threadStatus = threadStatus; } else { tjlt.threadStatus = threadStatus; @@ -125,7 +130,7 @@ static void setThreadStatus(Target_java_lang_Thread tjlt, int threadStatus) { } static boolean compareAndSetThreadStatus(Target_java_lang_Thread tjlt, int expectedStatus, int newStatus) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { return Unsafe.getUnsafe().compareAndSetInt(tjlt.holder, Unsafe.getUnsafe().objectFieldOffset(FIELDHOLDER_STATUS_FIELD), expectedStatus, newStatus); } else { return Unsafe.getUnsafe().compareAndSetInt(tjlt, Unsafe.getUnsafe().objectFieldOffset(THREAD_STATUS_FIELD), expectedStatus, newStatus); @@ -133,7 +138,7 @@ static boolean compareAndSetThreadStatus(Target_java_lang_Thread tjlt, int expec } static int getPriority(Target_java_lang_Thread tjlt) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { return tjlt.holder.priority; } else { return tjlt.priority; @@ -141,7 +146,7 @@ static int getPriority(Target_java_lang_Thread tjlt) { } static void setPriority(Target_java_lang_Thread tjlt, int priority) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { tjlt.holder.priority = priority; } else { tjlt.priority = priority; @@ -149,7 +154,7 @@ static void setPriority(Target_java_lang_Thread tjlt, int priority) { } static void setStackSize(Target_java_lang_Thread tjlt, long stackSize) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { tjlt.holder.stackSize = stackSize; } else { tjlt.stackSize = stackSize; @@ -157,7 +162,7 @@ static void setStackSize(Target_java_lang_Thread tjlt, long stackSize) { } static void setDaemon(Target_java_lang_Thread tjlt, boolean isDaemon) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { tjlt.holder.daemon = isDaemon; } else { tjlt.daemon = isDaemon; @@ -165,7 +170,7 @@ static void setDaemon(Target_java_lang_Thread tjlt, boolean isDaemon) { } static void setGroup(Target_java_lang_Thread tjlt, ThreadGroup group) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { tjlt.holder.group = group; } else { tjlt.group = group; @@ -173,7 +178,7 @@ static void setGroup(Target_java_lang_Thread tjlt, ThreadGroup group) { } static void setTarget(Target_java_lang_Thread tjlt, Runnable target) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { tjlt.holder.task = target; } else { tjlt.target = target; @@ -181,7 +186,7 @@ static void setTarget(Target_java_lang_Thread tjlt, Runnable target) { } static void initThreadFields(Target_java_lang_Thread tjlt, ThreadGroup group, Runnable target, long stackSize, int priority, boolean daemon, int threadStatus) { - if (isEnabled()) { + if (isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { tjlt.holder = new Target_java_lang_Thread_FieldHolder(null, null, 0, 0, false); } setGroup(tjlt, group); 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 new file mode 100644 index 000000000000..31673f297175 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Package_jdk_internal_vm_helper.java @@ -0,0 +1,46 @@ +/* + * 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/PlatformThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java index 50ce01911648..d1febc0428df 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java @@ -48,6 +48,7 @@ import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.compiler.core.common.SuppressFBWarnings; +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Isolate; @@ -420,8 +421,10 @@ public static void assignCurrent(Thread thread, boolean manuallyStarted) { /* If the thread was manually started, finish initializing it. */ if (manuallyStarted) { final ThreadGroup group = thread.getThreadGroup(); - toTarget(group).addUnstarted(); - toTarget(group).add(thread); + if (!(LoomSupport.isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) && !(VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(thread))) { + toTarget(group).addUnstarted(); + toTarget(group).add(thread); + } if (!thread.isDaemon()) { nonDaemonThreads.incrementAndGet(); @@ -529,7 +532,8 @@ private static boolean tearDownPlatformThreads() { set.add(pool); } } else { - Runnable target = toTarget(thread).target; + Target_java_lang_Thread tjlt = toTarget(thread); + Runnable target = JavaVersionUtil.JAVA_SPEC >= 19 ? tjlt.holder.task : tjlt.target; if (Target_java_util_concurrent_ThreadPoolExecutor_Worker.class.isInstance(target)) { ThreadPoolExecutor executor = SubstrateUtil.cast(target, Target_java_util_concurrent_ThreadPoolExecutor_Worker.class).executor; if (executor != null && (executor.getClass() == ThreadPoolExecutor.class || executor.getClass() == ScheduledThreadPoolExecutor.class)) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Continuation.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Continuation.java index 64a0bf68a5ec..0ac31297cf45 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Continuation.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Continuation.java @@ -32,48 +32,61 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.LoomJDK; -@TargetClass(className = "java.lang.Continuation", onlyWith = LoomJDK.class) +@TargetClass(className = "Continuation", classNameProvider = Package_jdk_internal_vm_helper.class, onlyWith = JDK19OrLater.class) public final class Target_java_lang_Continuation { @Alias// + @TargetElement(onlyWith = LoomJDK.class)// Runnable target; @Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// + @TargetElement(onlyWith = LoomJDK.class)// public Continuation internal; @Alias// + @TargetElement(onlyWith = LoomJDK.class)// short cs; @Alias// + @TargetElement(onlyWith = LoomJDK.class)// Object yieldInfo; @Alias// + @TargetElement(onlyWith = LoomJDK.class)// byte flags; @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true)// + @TargetElement(onlyWith = LoomJDK.class)// // Checkstyle: stop static byte FLAG_SAFEPOINT_YIELD = 1 << 1; // Checkstyle: resume @SuppressWarnings("unused") @Alias + @TargetElement(onlyWith = LoomJDK.class) public Target_java_lang_Continuation(Target_java_lang_ContinuationScope scope, Runnable target) { } @Alias + @TargetElement(onlyWith = LoomJDK.class) public static native boolean yield(Target_java_lang_ContinuationScope scope); @Alias// + @TargetElement(onlyWith = LoomJDK.class)// boolean done; @Substitute + @TargetElement(onlyWith = LoomJDK.class) private boolean isEmpty() { return internal.isEmpty(); } @Alias + @TargetElement(onlyWith = LoomJDK.class) public native Target_java_lang_ContinuationScope getScope(); @Alias + @TargetElement(onlyWith = LoomJDK.class) public native Target_java_lang_Continuation getParent(); /** @@ -85,6 +98,7 @@ private boolean isEmpty() { * {@link Target_java_lang_Continuation#postYieldCleanup(int)}. */ @Alias + @TargetElement(onlyWith = LoomJDK.class) public native void run(); /** @@ -92,29 +106,36 @@ private boolean isEmpty() { * {@link Target_java_lang_Continuation#doYield(int)}. */ @Alias + @TargetElement(onlyWith = LoomJDK.class) native boolean yield0(Target_java_lang_ContinuationScope scope, Target_java_lang_Continuation child); @Alias + @TargetElement(onlyWith = LoomJDK.class) private native void setMounted(boolean mounted); @Alias + @TargetElement(onlyWith = LoomJDK.class) private native void postYieldCleanup(int origRefSP); @Substitute + @TargetElement(onlyWith = LoomJDK.class) private void mount() { setMounted(true); } @Substitute + @TargetElement(onlyWith = LoomJDK.class) private void unmount() { setMounted(false); } @Alias + @TargetElement(onlyWith = LoomJDK.class) public native boolean isPreempted(); @SuppressWarnings("unused") @Substitute + @TargetElement(onlyWith = LoomJDK.class) @NeverInline("access stack pointer") private static int isPinned0(Target_java_lang_ContinuationScope scope) { return LoomSupport.isPinned( @@ -123,11 +144,13 @@ private static int isPinned0(Target_java_lang_ContinuationScope scope) { } @Substitute + @TargetElement(onlyWith = LoomJDK.class) boolean isStarted() { return internal.isStarted(); } @Alias + @TargetElement(onlyWith = LoomJDK.class) native boolean isDone(); @Alias @@ -135,6 +158,7 @@ boolean isStarted() { public static native Target_java_lang_Continuation getCurrentContinuation(Target_java_lang_ContinuationScope scope); @Substitute + @TargetElement(onlyWith = LoomJDK.class) static void enterSpecial(Target_java_lang_Continuation cont, boolean isContinue) { enter(cont, isContinue); } @@ -143,6 +167,7 @@ static void enterSpecial(Target_java_lang_Continuation cont, boolean isContinue) * Yields to nth continuation as the nth nearest enterSpecial returns. */ @Substitute + @TargetElement(onlyWith = LoomJDK.class) private static int doYield(int scopes) { assert scopes == 0; Target_java_lang_Thread tjlt = SubstrateUtil.cast(Thread.currentThread(), Target_java_lang_Thread.class); @@ -157,12 +182,14 @@ private static int doYield(int scopes) { } @Substitute + @TargetElement(onlyWith = LoomJDK.class) private void finish() { done = true; assert isEmpty(); } @Substitute + @TargetElement(onlyWith = LoomJDK.class) private static void enter(Target_java_lang_Continuation cont, boolean isContinue) { if (!isContinue) { assert cont.internal == null; @@ -173,6 +200,7 @@ private static void enter(Target_java_lang_Continuation cont, boolean isContinue } @Substitute + @TargetElement(onlyWith = LoomJDK.class) private void enter0() { try { target.run(); @@ -182,6 +210,7 @@ private void enter0() { } @Substitute + @TargetElement(onlyWith = LoomJDK.class) private int tryForceYield0(Target_java_lang_Thread thread) { Target_java_lang_Continuation cont = thread.getContinuation(); Target_java_lang_Continuation innermost = cont; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index 0debacef048f..a777a194625a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -45,9 +45,10 @@ import com.oracle.svm.core.jdk.ContinuationsNotSupported; import com.oracle.svm.core.jdk.ContinuationsSupported; import com.oracle.svm.core.jdk.JDK11OrEarlier; +import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.jdk.JDK17OrLater; +import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.LoomJDK; -import com.oracle.svm.core.jdk.NotLoomJDK; import com.oracle.svm.core.monitor.MonitorSupport; import com.oracle.svm.core.util.VMError; @@ -94,19 +95,19 @@ public final class Target_java_lang_Thread { @Alias// volatile String name; - @Alias @TargetElement(onlyWith = NotLoomJDK.class)// + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// int priority; /* Whether or not the thread is a daemon . */ - @Alias @TargetElement(onlyWith = NotLoomJDK.class)// + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// boolean daemon; /* What will be run. */ - @Alias @TargetElement(onlyWith = NotLoomJDK.class)// + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// Runnable target; /* The group of this thread */ - @Alias @TargetElement(onlyWith = NotLoomJDK.class)// + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// ThreadGroup group; @Alias// @@ -116,10 +117,10 @@ public final class Target_java_lang_Thread { * The requested stack size for this thread, or 0 if the creator did not specify a stack size. * It is up to the VM to do whatever it likes with this number; some VMs will ignore it. */ - @Alias @TargetElement(onlyWith = NotLoomJDK.class)// + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// long stackSize; - @Alias @TargetElement(onlyWith = LoomJDK.class)// + @Alias @TargetElement(onlyWith = JDK19OrLater.class)// Target_java_lang_Thread_FieldHolder holder; /* Thread ID */ @@ -127,10 +128,11 @@ public final class Target_java_lang_Thread { long tid; /** We have our own atomic number in {@link JavaThreads#threadSeqNumber}. */ - @Delete @TargetElement(onlyWith = NotLoomJDK.class)// + @Delete @TargetElement(onlyWith = JDK17OrEarlier.class)// static long threadSeqNumber; /** We have our own atomic number in {@link JavaThreads#threadInitNumber}. */ @Delete// + @TargetElement(onlyWith = JDK17OrEarlier.class) // static int threadInitNumber; /* @@ -140,16 +142,16 @@ public final class Target_java_lang_Thread { @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // public AccessControlContext inheritedAccessControlContext; - @Alias @TargetElement(onlyWith = NotLoomJDK.class) // + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class) // @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadStatusRecomputation.class) // volatile int threadStatus; - @Alias @TargetElement(onlyWith = NotLoomJDK.class) // + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class) // /* private */ /* final */ Object blockerLock; - @Alias @TargetElement(onlyWith = LoomJDK.class) // + @Alias @TargetElement(onlyWith = JDK19OrLater.class) // Object interruptLock; - @Alias @TargetElement(onlyWith = NotLoomJDK.class) // + @Alias @TargetElement(onlyWith = JDK17OrEarlier.class) // volatile Target_sun_nio_ch_Interruptible blocker; /** @see JavaThreads#setCurrentThreadLockHelper */ @@ -172,19 +174,21 @@ public void setContextClassLoader(ClassLoader cl) { /** Replace "synchronized" modifier with delegation to an atomic increment. */ @Substitute - @TargetElement(onlyWith = NotLoomJDK.class) // + @TargetElement(onlyWith = JDK17OrEarlier.class) // static long nextThreadID() { return JavaThreads.threadSeqNumber.incrementAndGet(); } /** Replace "synchronized" modifier with delegation to an atomic increment. */ @Substitute + @TargetElement(onlyWith = JDK17OrEarlier.class) // private static int nextThreadNum() { return JavaThreads.threadInitNumber.incrementAndGet(); } - @Alias - @TargetElement(onlyWith = LoomJDK.class) + @AnnotateOriginal + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @TargetElement(onlyWith = JDK19OrLater.class) public native boolean isVirtual(); @Alias @@ -202,7 +206,7 @@ private static int nextThreadNum() { null, 0, Thread.NORM_PRIORITY, asDaemon, ThreadStatus.RUNNABLE); - if (LoomSupport.isEnabled()) { + if (LoomSupport.isEnabled() || JavaVersionUtil.JAVA_SPEC >= 19) { tid = Target_java_lang_Thread_ThreadIdentifiers.next(); } else { tid = nextThreadID(); @@ -226,11 +230,24 @@ public long getId() { @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public native ThreadGroup getThreadGroup(); + @AnnotateOriginal @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - @Substitute - public boolean isDaemon() { - return daemon; - } + @TargetElement(onlyWith = JDK19OrLater.class) + static native ThreadGroup virtualThreadGroup(); + + @AnnotateOriginal + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @TargetElement(onlyWith = JDK19OrLater.class) + native boolean isTerminated(); + + @AnnotateOriginal + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @TargetElement(onlyWith = JDK19OrLater.class) + native Thread.State threadState(); + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @AnnotateOriginal + public native boolean isDaemon(); @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) @Substitute @@ -250,6 +267,15 @@ private static Thread currentThread0() { return thread; } + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + static Thread currentCarrierThread() { + // FIXME support for VirtualThreads + Thread thread = PlatformThreads.currentThread.get(); + assert thread != null : "Thread has not been set yet"; + return thread; + } + @Inject @TargetElement(onlyWith = ContinuationsSupported.class)// @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// Thread vthread = null; @@ -276,7 +302,7 @@ void setCurrentThread(Thread thread) { @Substitute @SuppressWarnings({"unused"}) - @TargetElement(onlyWith = NotLoomJDK.class) + @TargetElement(onlyWith = JDK17OrEarlier.class) private Target_java_lang_Thread( ThreadGroup g, Runnable target, @@ -294,7 +320,7 @@ private Target_java_lang_Thread( @Substitute @SuppressWarnings({"unused"}) - @TargetElement(onlyWith = LoomJDK.class) + @TargetElement(onlyWith = JDK19OrLater.class) private Target_java_lang_Thread( ThreadGroup g, String name, @@ -307,7 +333,7 @@ private Target_java_lang_Thread( /* Injected Target_java_lang_Thread instance field initialization. */ this.threadData = new ThreadData(); - checkCharacteristics(characteristics); + // FIXME: checkCharacteristics(characteristics); // TODO: derive from characteristics bitset boolean inheritThreadLocals = false; @@ -461,38 +487,38 @@ private int countStackFrames() { private static native Thread[] getThreads(); @Substitute - @TargetElement(onlyWith = NotLoomJDK.class) + @TargetElement(onlyWith = JDK17OrEarlier.class) private boolean isAlive() { return JavaThreads.isAlive(JavaThreads.fromTarget(this)); } @Substitute - @TargetElement(onlyWith = LoomJDK.class) + @TargetElement(onlyWith = JDK19OrLater.class) private boolean isAlive0() { return PlatformThreads.isAlive(JavaThreads.fromTarget(this)); } @Substitute - @TargetElement(onlyWith = NotLoomJDK.class) + @TargetElement(onlyWith = JDK17OrEarlier.class) private static void yield() { JavaThreads.yieldCurrent(); } @Substitute - @TargetElement(onlyWith = LoomJDK.class) + @TargetElement(onlyWith = JDK19OrLater.class) private static void yield0() { // Loom virtual threads are handled in yield() JavaThreads.yieldCurrent(); } @Substitute - @TargetElement(onlyWith = NotLoomJDK.class) + @TargetElement(onlyWith = JDK17OrEarlier.class) private static void sleep(long millis) throws InterruptedException { JavaThreads.sleep(millis); } @Substitute - @TargetElement(onlyWith = LoomJDK.class) + @TargetElement(onlyWith = JDK19OrLater.class) private static void sleep0(long millis) throws InterruptedException { // Loom virtual threads are handled in sleep() JavaThreads.sleep(millis); @@ -568,7 +594,7 @@ static void setScopedCache(Object[] cache) { } -@TargetClass(value = Thread.class, innerClass = "FieldHolder", onlyWith = LoomJDK.class) +@TargetClass(value = Thread.class, innerClass = "FieldHolder", onlyWith = JDK19OrLater.class) final class Target_java_lang_Thread_FieldHolder { @Alias // ThreadGroup group; @@ -607,7 +633,7 @@ static long next() { } } -@TargetClass(value = Thread.class, innerClass = "VirtualThreads", onlyWith = LoomJDK.class) +@TargetClass(value = Thread.class, innerClass = "VirtualThreads", onlyWith = {LoomJDK.class, JDK17OrEarlier.class}) final class Target_java_lang_Thread_VirtualThreads { } 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 73790f0fea48..53001c1a96f0 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 @@ -28,30 +28,39 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.LoomJDK; +import com.oracle.svm.core.util.VMError; /** * `VirtualThread` is implemented in Java, so we do not need to modify this class very much. */ -@TargetClass(className = "java.lang.VirtualThread", onlyWith = LoomJDK.class) +@TargetClass(className = "java.lang.VirtualThread", onlyWith = JDK19OrLater.class) public final class Target_java_lang_VirtualThread { @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// + @TargetElement(onlyWith = LoomJDK.class)// private static boolean notifyJvmtiEvents; @Substitute + @TargetElement(onlyWith = LoomJDK.class) private static void registerNatives() { } @Alias + @TargetElement(onlyWith = LoomJDK.class) public static native Target_java_lang_ContinuationScope continuationScope(); @Alias// + @TargetElement(onlyWith = LoomJDK.class)// Target_java_lang_Continuation cont; @Alias// + @TargetElement(onlyWith = LoomJDK.class)// Thread carrierThread; @Substitute// + @TargetElement(onlyWith = LoomJDK.class) StackTraceElement[] asyncGetStackTrace() { if (carrierThread != null) { return carrierThread.getStackTrace(); @@ -60,8 +69,23 @@ StackTraceElement[] asyncGetStackTrace() { } @Alias// + @TargetElement(onlyWith = LoomJDK.class) private native StackTraceElement[] tryGetStackTrace(); @Alias + @TargetElement(onlyWith = LoomJDK.class) native boolean joinNanos(long nanos) throws InterruptedException; + + @Substitute + @TargetElement(name = "continuationScope", onlyWith = JDK19OrLater.class) + static Object continuationScopeJDK19() { + throw VMError.unimplemented("JDK 19 continuations not yet supported"); + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + @SuppressWarnings("static-method") + private boolean yieldContinuation() { + throw VMError.unimplemented("JDK 19 continuations not yet supported"); + } } From 8f1f4d5092ab15b898f1339924c5de4c4bccadbb Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 27 Jun 2022 10:28:58 +0200 Subject: [PATCH 23/44] svm: initialize Continuation at runtime for now --- .../com/oracle/svm/hosted/jdk/JDKInitializationFeature.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java index 49b87c3069e6..25468f55c7a1 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java @@ -173,5 +173,8 @@ public void afterRegistration(AfterRegistrationAccess access) { if (JavaVersionUtil.JAVA_SPEC >= 19) { rci.rerunInitialization("sun.nio.ch.Poller", "Contains an InnocuousThread."); } + if (JavaVersionUtil.JAVA_SPEC >= 19) { + rci.initializeAtRunTime("jdk.internal.vm.Continuation", "Not yet supported"); + } } } From 354cbafc11ebc8220081a63fa73af899a31d64f6 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 28 Jun 2022 12:07:04 +0200 Subject: [PATCH 24/44] svm: adopt JFR EventHandler removal in JDK 19 https://bugs.openjdk.org/browse/JDK-8282420 --- substratevm/mx.substratevm/suite.py | 2 + .../svm/core/jfr/JfrEventWriterAccess.java | 41 ++++++++++++----- .../com/oracle/svm/core/jfr/JfrFeature.java | 3 +- .../oracle/svm/core/jfr/JfrThreadLocal.java | 4 +- ...Package_jdk_jfr_internal_event_helper.java | 46 +++++++++++++++++++ .../com/oracle/svm/core/jfr/SubstrateJVM.java | 3 +- ..._jdk_jfr_internal_EventHandlerCreator.java | 7 ++- .../Target_jdk_jfr_internal_EventWriter.java | 2 +- .../core/jfr/Target_jdk_jfr_internal_JVM.java | 13 ++---- ...dk_jfr_internal_handlers_EventHandler.java | 32 +++++++++++++ .../svm/hosted/jfr/JfrEventSubstitution.java | 4 +- 11 files changed, 124 insertions(+), 33 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Package_jdk_jfr_internal_event_helper.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_handlers_EventHandler.java diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 47bbaa788fab..6a587cda2c76 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -230,6 +230,8 @@ "jdk.jfr.events", "jdk.jfr.internal", "jdk.jfr.internal.jfc", + ], + "jdk.jfr@11..18": [ "jdk.jfr.internal.handlers", ], }, diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEventWriterAccess.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEventWriterAccess.java index 6a23f51e502d..215cc50ffb26 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEventWriterAccess.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEventWriterAccess.java @@ -26,6 +26,7 @@ import java.lang.reflect.Field; +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -33,7 +34,6 @@ import com.oracle.svm.util.ReflectionUtil; import jdk.internal.misc.Unsafe; -import jdk.jfr.internal.EventWriter; /** * Used to access the Java event writer class, see {@link jdk.jfr.internal.EventWriter}. @@ -41,38 +41,57 @@ public final class JfrEventWriterAccess { private static final Unsafe UNSAFE = Unsafe.getUnsafe(); - private static final Field startPosition = ReflectionUtil.lookupField(EventWriter.class, "startPosition"); - private static final Field startPositionAddress = ReflectionUtil.lookupField(EventWriter.class, "startPositionAddress"); - private static final Field currentPosition = ReflectionUtil.lookupField(EventWriter.class, "currentPosition"); - private static final Field maxPosition = ReflectionUtil.lookupField(EventWriter.class, "maxPosition"); - private static final Field valid = ReflectionUtil.lookupField(EventWriter.class, "valid"); + private static final Field startPosition; + private static final Field startPositionAddress; + private static final Field currentPosition; + private static final Field maxPosition; + private static final Field valid; + static { + Class declaringClass = getEventWriterClass(); + startPosition = ReflectionUtil.lookupField(declaringClass, "startPosition"); + startPositionAddress = ReflectionUtil.lookupField(declaringClass, "startPositionAddress"); + currentPosition = ReflectionUtil.lookupField(declaringClass, "currentPosition"); + maxPosition = ReflectionUtil.lookupField(declaringClass, "maxPosition"); + valid = ReflectionUtil.lookupField(declaringClass, "valid"); + } + + @Platforms(Platform.HOSTED_ONLY.class) + public static Class getEventWriterClass() { + String className; + if (JavaVersionUtil.JAVA_SPEC >= 19) { + className = "jdk.jfr.internal.event.EventWriter"; + } else { + className = "jdk.jfr.internal.EventWriter"; + } + return ReflectionUtil.lookupClass(false, className); + } @Platforms(Platform.HOSTED_ONLY.class) private JfrEventWriterAccess() { } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void setStartPosition(EventWriter writer, long value) { + public static void setStartPosition(Target_jdk_jfr_internal_EventWriter writer, long value) { UNSAFE.putLong(writer, UNSAFE.objectFieldOffset(startPosition), value); } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void setStartPositionAddress(EventWriter writer, long value) { + public static void setStartPositionAddress(Target_jdk_jfr_internal_EventWriter writer, long value) { UNSAFE.putLong(writer, UNSAFE.objectFieldOffset(startPositionAddress), value); } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void setCurrentPosition(EventWriter writer, long value) { + public static void setCurrentPosition(Target_jdk_jfr_internal_EventWriter writer, long value) { UNSAFE.putLong(writer, UNSAFE.objectFieldOffset(currentPosition), value); } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void setMaxPosition(EventWriter writer, long value) { + public static void setMaxPosition(Target_jdk_jfr_internal_EventWriter writer, long value) { UNSAFE.putLong(writer, UNSAFE.objectFieldOffset(maxPosition), value); } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void setValid(EventWriter writer, boolean value) { + public static void setValid(Target_jdk_jfr_internal_EventWriter writer, boolean value) { UNSAFE.putBooleanVolatile(writer, UNSAFE.objectFieldOffset(valid), value); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrFeature.java index 33ba62456492..a3f7145708ef 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrFeature.java @@ -49,7 +49,6 @@ import jdk.jfr.Configuration; import jdk.jfr.Event; -import jdk.jfr.internal.EventWriter; import jdk.jfr.internal.JVM; import jdk.jfr.internal.jfc.JFC; @@ -61,7 +60,7 @@ *
    *
  • Java-level events are defined by a Java class that extends {@link Event} and that is * annotated with JFR-specific annotations. Those events are typically triggered by the Java - * application and a Java {@link EventWriter} object is used when writing the event to a + * application and a Java {@code EventWriter} object is used when writing the event to a * buffer.
  • *
  • Native events are triggered by the JVM itself and are defined in the JFR metadata.xml file. * For writing such an event to a buffer, we call into {@link JfrNativeEventWriter} and pass a diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadLocal.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadLocal.java index 4e057b0d2edb..c0dd3488ebc1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadLocal.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadLocal.java @@ -48,15 +48,13 @@ import com.oracle.svm.core.threadlocal.FastThreadLocalWord; import com.oracle.svm.core.util.VMError; -import jdk.jfr.internal.EventWriter; - /** * This class holds various JFR-specific thread local values. * * Each thread uses both a Java and a native {@link JfrBuffer}: *
      *
    • The Java buffer is accessed by JFR events that are implemented as Java classes and written - * using {@link EventWriter}.
    • + * using {@code EventWriter}. *
    • The native buffer is accessed when {@link JfrNativeEventWriter} is used to write an * event.
    • *
    diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Package_jdk_jfr_internal_event_helper.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Package_jdk_jfr_internal_event_helper.java new file mode 100644 index 000000000000..b4e07bbc24fc --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Package_jdk_jfr_internal_event_helper.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020, 2020, 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.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_jfr_internal_event_helper implements Function { + + @Override + public String apply(TargetClass annotation) { + if (JavaVersionUtil.JAVA_SPEC >= 19) { + return "jdk.jfr.internal.event." + annotation.className(); + } else { + return "jdk.jfr.internal." + annotation.className(); + } + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java index 48093d29d197..b8ff90734b1a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java @@ -45,7 +45,6 @@ import com.oracle.svm.core.util.VMError; import jdk.jfr.Configuration; -import jdk.jfr.internal.EventWriter; import jdk.jfr.internal.JVM; import jdk.jfr.internal.LogTag; @@ -415,7 +414,7 @@ public void setThreadBufferSize(long size) { /** See {@link JVM#flush}. */ @Uninterruptible(reason = "Accesses a JFR buffer.") - public boolean flush(EventWriter writer, int uncommittedSize, int requestedSize) { + public boolean flush(Target_jdk_jfr_internal_EventWriter writer, int uncommittedSize, int requestedSize) { assert writer != null; assert uncommittedSize >= 0; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventHandlerCreator.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventHandlerCreator.java index d535640f0889..7a037f67c40a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventHandlerCreator.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventHandlerCreator.java @@ -26,15 +26,14 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.util.VMError; -import jdk.jfr.internal.handlers.EventHandler; - -@TargetClass(className = "jdk.jfr.internal.EventHandlerCreator", onlyWith = HasJfrSupport.class) +@TargetClass(className = "jdk.jfr.internal.EventHandlerCreator", onlyWith = {HasJfrSupport.class, JDK17OrEarlier.class}) public final class Target_jdk_jfr_internal_EventHandlerCreator { @Substitute @SuppressWarnings("static-method") - public Class makeEventHandlerClass() { + public Class makeEventHandlerClass() { throw VMError.shouldNotReachHere(); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventWriter.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventWriter.java index 444bd628a704..ca315170add7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventWriter.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventWriter.java @@ -27,7 +27,7 @@ import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.TargetClass; -@TargetClass(value = jdk.jfr.internal.EventWriter.class, onlyWith = HasJfrSupport.class) +@TargetClass(className = "EventWriter", classNameProvider = Package_jdk_jfr_internal_event_helper.class, onlyWith = HasJfrSupport.class) public final class Target_jdk_jfr_internal_EventWriter { @Alias @SuppressWarnings("unused") boolean notified; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java index 830949d80e9f..7ce4cc99cced 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java @@ -26,10 +26,8 @@ import java.util.List; -import com.oracle.svm.core.jfr.traceid.JfrTraceId; import org.graalvm.nativeimage.ProcessProperties; -import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; @@ -37,13 +35,12 @@ import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.jdk.JDK11OrEarlier; import com.oracle.svm.core.jdk.JDK17OrLater; +import com.oracle.svm.core.jfr.traceid.JfrTraceId; import com.oracle.svm.core.util.VMError; import jdk.jfr.Event; -import jdk.jfr.internal.EventWriter; import jdk.jfr.internal.JVM; import jdk.jfr.internal.LogTag; -import jdk.jfr.internal.handlers.EventHandler; @SuppressWarnings({"static-method", "unused"}) @TargetClass(value = jdk.jfr.internal.JVM.class, onlyWith = HasJfrSupport.class) @@ -291,7 +288,7 @@ public long getChunkStartNanos() { @Substitute @TargetElement(onlyWith = JDK17OrLater.class) - public boolean setHandler(Class eventClass, EventHandler handler) { + public boolean setHandler(Class eventClass, Target_jdk_jfr_internal_handlers_EventHandler handler) { // eventHandler fields should all be set at compile time so this method // should never be reached at runtime throw VMError.shouldNotReachHere("eventHandler does not exist for: " + eventClass); @@ -318,13 +315,13 @@ public static Object getEventWriter() { /** See {@link JVM#newEventWriter}. */ @Substitute - public static EventWriter newEventWriter() { - return SubstrateUtil.cast(SubstrateJVM.get().newEventWriter(), EventWriter.class); + public static Target_jdk_jfr_internal_EventWriter newEventWriter() { + return SubstrateJVM.get().newEventWriter(); } /** See {@link JVM#flush}. */ @Substitute - public static boolean flush(EventWriter writer, int uncommittedSize, int requestedSize) { + public static boolean flush(Target_jdk_jfr_internal_EventWriter writer, int uncommittedSize, int requestedSize) { return SubstrateJVM.get().flush(writer, uncommittedSize, requestedSize); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_handlers_EventHandler.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_handlers_EventHandler.java new file mode 100644 index 000000000000..9e93c8450018 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_handlers_EventHandler.java @@ -0,0 +1,32 @@ +/* + * 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.jfr; + +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.JDK17OrEarlier; + +@TargetClass(className = "jdk.jfr.internal.handlers.EventHandler", onlyWith = JDK17OrEarlier.class) +final class Target_jdk_jfr_internal_handlers_EventHandler { +} diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java index 5590922a3d74..b7b42f921973 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java @@ -35,12 +35,12 @@ import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor; import com.oracle.graal.pointsto.util.GraalAccess; +import com.oracle.svm.core.jfr.JfrEventWriterAccess; import com.oracle.svm.core.jfr.JfrJavaEvents; import com.oracle.svm.core.util.VMError; import jdk.internal.misc.Unsafe; import jdk.jfr.Event; -import jdk.jfr.internal.EventWriter; import jdk.jfr.internal.JVM; import jdk.jfr.internal.SecuritySupport; import jdk.vm.ci.meta.MetaAccessProvider; @@ -63,7 +63,7 @@ public class JfrEventSubstitution extends SubstitutionProcessor { JfrEventSubstitution(MetaAccessProvider metaAccess) { jdkJfrEvent = metaAccess.lookupJavaType(Event.class); - ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(EventWriter.class); + ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(JfrEventWriterAccess.getEventWriterClass()); changeWriterResetMethod(jdkJfrEventWriter); typeSubstitution = new ConcurrentHashMap<>(); methodSubstitutions = new ConcurrentHashMap<>(); From 9b89ce209c04d3eba5bbc593338d81e333d084d3 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 28 Jun 2022 16:59:39 +0200 Subject: [PATCH 25/44] svm: handle MemorySegmentProxy JDK 19 --- ...ava_nio_DirectByteBuffer_JDK17OrLater.java | 20 +++-- ...ava_nio_DirectByteBuffer_JDK19OrLater.java | 74 +++++++++++++++++++ 2 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17OrLater.java index 122b63bccbed..44a4bf7efc81 100644 --- a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17OrLater.java +++ b/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17OrLater.java @@ -29,32 +29,38 @@ 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.JDK17OrEarlier; import com.oracle.svm.core.jdk.JDK17OrLater; -import jdk.internal.access.foreign.MemorySegmentProxy; +@TargetClass(className = "jdk.internal.access.foreign.MemorySegmentProxy", onlyWith = {JDK17OrLater.class, JDK17OrEarlier.class}) +@SuppressWarnings("unused") +final class Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17OrLater { +} -@TargetClass(className = "java.nio.DirectByteBuffer", onlyWith = JDK17OrLater.class) +@TargetClass(className = "java.nio.DirectByteBuffer", onlyWith = {JDK17OrLater.class, JDK17OrEarlier.class}) @SuppressWarnings("unused") final class Target_java_nio_DirectByteBuffer_JDK17OrLater { @Alias - protected Target_java_nio_DirectByteBuffer_JDK17OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, MemorySegmentProxy segment) { + protected Target_java_nio_DirectByteBuffer_JDK17OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, + Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17OrLater segment) { } } -@TargetClass(className = "java.nio.DirectByteBufferR", onlyWith = JDK17OrLater.class) +@TargetClass(className = "java.nio.DirectByteBufferR", onlyWith = {JDK17OrLater.class, JDK17OrEarlier.class}) @SuppressWarnings("unused") final class Target_java_nio_DirectByteBufferR_JDK17OrLater { @Alias - protected Target_java_nio_DirectByteBufferR_JDK17OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, MemorySegmentProxy segment) { + protected Target_java_nio_DirectByteBufferR_JDK17OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, + Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17OrLater segment) { } } -@TargetClass(className = "sun.nio.ch.Util", onlyWith = JDK17OrLater.class) -final class Target_sun_nio_ch_Util { +@TargetClass(className = "sun.nio.ch.Util", onlyWith = {JDK17OrLater.class, JDK17OrEarlier.class}) +final class Target_sun_nio_ch_Util_JDK17 { @Substitute private static Target_java_nio_DirectByteBuffer_JDK17OrLater newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java b/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java new file mode 100644 index 000000000000..1b5df9894b48 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019, 2019, 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.jdk17; + +import java.io.FileDescriptor; + +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.JDK19OrLater; + +@TargetClass(className = "java.lang.foreign.MemorySegment", onlyWith = JDK19OrLater.class) +@SuppressWarnings("unused") +final class Target_java_lang_foreign_MemorySegment_JDK19OrLater { +} + +@TargetClass(className = "java.nio.DirectByteBuffer", onlyWith = JDK19OrLater.class) +@SuppressWarnings("unused") +final class Target_java_nio_DirectByteBuffer_JDK19OrLater { + + @Alias + protected Target_java_nio_DirectByteBuffer_JDK19OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, + Target_java_lang_foreign_MemorySegment_JDK19OrLater segment) { + } + +} + +@TargetClass(className = "java.nio.DirectByteBufferR", onlyWith = JDK19OrLater.class) +@SuppressWarnings("unused") +final class Target_java_nio_DirectByteBufferR_JDK19OrLater { + + @Alias + protected Target_java_nio_DirectByteBufferR_JDK19OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, + Target_java_lang_foreign_MemorySegment_JDK19OrLater segment) { + } + +} + +@TargetClass(className = "sun.nio.ch.Util", onlyWith = JDK19OrLater.class) +final class Target_sun_nio_ch_Util_JDK17OrLater { + + @Substitute + private static Target_java_nio_DirectByteBuffer_JDK19OrLater newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { + return new Target_java_nio_DirectByteBuffer_JDK19OrLater(size, addr, fd, unmapper, isSync, null); + } + + @Substitute + static Target_java_nio_DirectByteBufferR_JDK19OrLater newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { + return new Target_java_nio_DirectByteBufferR_JDK19OrLater(size, addr, fd, unmapper, isSync, null); + } + +} From d6580e3cc1ee876f1b4135666640f3a6d440d706 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 28 Jun 2022 17:56:05 +0200 Subject: [PATCH 26/44] svm: Perf support JDK 19 --- .../core/jvmstat/Target_jdk_internal_perf_Perf.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java index cc1e9440bba6..12fd25c0031d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java @@ -30,15 +30,25 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK17OrEarlier; +import com.oracle.svm.core.jdk.JDK19OrLater; @TargetClass(className = "jdk.internal.perf.Perf") @SuppressWarnings({"unused", "static-method"}) public final class Target_jdk_internal_perf_Perf { @Substitute - public ByteBuffer attach(String user, int lvmid, int mode) { + @TargetElement(name = "attach", onlyWith = JDK17OrEarlier.class) + public ByteBuffer attachJDK17(String user, int lvmid, int mode) { return ImageSingletons.lookup(PerfDataSupport.class).attach(user, lvmid, mode); } + @Substitute + @TargetElement(name = "attach", onlyWith = JDK19OrLater.class) + public ByteBuffer attachJDK19(int lvmid) { + return ImageSingletons.lookup(PerfDataSupport.class).attach(null, lvmid, 0); + } + @Substitute public void detach(ByteBuffer bb) { ImageSingletons.lookup(PerfDataSupport.class).detach(bb); From 8d24e095bd8d1310b23a1e1222cf242eceacbe87 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 29 Jun 2022 09:00:49 +0200 Subject: [PATCH 27/44] svm: StaticProperty for JDK 19 --- ...rget_jdk_internal_util_StaticProperty.java | 79 ++++++++++++++++--- .../Target_java_nio_charset_Charset.java | 10 ++- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java index 68ed4fe114a3..503abf0d7d75 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java @@ -24,14 +24,17 @@ */ package com.oracle.svm.core.jdk; +import java.lang.reflect.Method; +import java.nio.charset.Charset; +import java.util.function.BooleanSupplier; + +import org.graalvm.nativeimage.ImageSingletons; + import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.localization.substitutions.Target_java_nio_charset_Charset; import com.oracle.svm.util.ReflectionUtil; -import org.graalvm.nativeimage.ImageSingletons; - -import java.lang.reflect.Method; -import java.util.function.BooleanSupplier; /** * This class provides JDK-internal access to values that are also available via system properties. @@ -95,18 +98,20 @@ private static String jdkSerialFilterFactory() { return ImageSingletons.lookup(SystemPropertiesSupport.class).savedProperties.get("jdk.serialFilterFactory"); } - /* - * Method jdkSerialFilterFactory is present in some versions of the JDK11 and not in the other. - * It is always present in the JDK17. We need to check if this method should be substituted by - * checking if it exists in the running JDK version. - */ - private static class StaticPropertyJdkSerialFilterFactoryAvailable implements BooleanSupplier { + private abstract static class StaticPropertyMethodAvailable implements BooleanSupplier { + + private final String methodName; + + protected StaticPropertyMethodAvailable(String methodName) { + this.methodName = methodName; + } + @Override public boolean getAsBoolean() { Method method; try { method = ReflectionUtil.lookupMethod(true, Class.forName("jdk.internal.util.StaticProperty"), - "jdkSerialFilterFactory"); + methodName); } catch (ClassNotFoundException e) { return false; } @@ -114,4 +119,56 @@ public boolean getAsBoolean() { } } + /* + * Method jdkSerialFilterFactory is present in some versions of the JDK11 and not in the other. + * It is always present in the JDK17. We need to check if this method should be substituted by + * checking if it exists in the running JDK version. + */ + private static class StaticPropertyJdkSerialFilterFactoryAvailable extends StaticPropertyMethodAvailable { + protected StaticPropertyJdkSerialFilterFactoryAvailable() { + super("jdkSerialFilterFactory"); + } + } + + @Substitute + @TargetElement(onlyWith = StaticPropertyNativeEncodingAvailable.class) + public static String nativeEncoding() { + return ImageSingletons.lookup(SystemPropertiesSupport.class).savedProperties.get("native.encoding"); + } + + /* + * Method nativeEncoding is present in some versions of the JDK17 and not in the other. We need + * to check if this method should be substituted by checking if it exists in the running JDK + * version. + */ + private static class StaticPropertyNativeEncodingAvailable extends StaticPropertyMethodAvailable { + protected StaticPropertyNativeEncodingAvailable() { + super("nativeEncoding"); + } + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + public static String fileEncoding() { + return ImageSingletons.lookup(SystemPropertiesSupport.class).savedProperties.get("file.encoding"); + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + public static String javaPropertiesDate() { + return ImageSingletons.lookup(SystemPropertiesSupport.class).savedProperties.getOrDefault("java.properties.date", null); + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + public static String jnuEncoding() { + return ImageSingletons.lookup(SystemPropertiesSupport.class).savedProperties.get("sun.jnu.encoding"); + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + public static Charset jnuCharset() { + String jnuEncoding = ImageSingletons.lookup(SystemPropertiesSupport.class).savedProperties.get("sun.jnu.encoding"); + return Target_java_nio_charset_Charset.forName(jnuEncoding, Charset.defaultCharset()); + } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java index 5dcb37722841..cc3e1bb21be4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java @@ -30,17 +30,19 @@ import java.util.SortedMap; import java.util.TreeMap; -import com.oracle.svm.core.annotate.RecomputeFieldValue; import org.graalvm.nativeimage.ImageSingletons; import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.localization.LocalizationSupport; @TargetClass(java.nio.charset.Charset.class) @SuppressWarnings({"unused"}) -final class Target_java_nio_charset_Charset { +public final class Target_java_nio_charset_Charset { @Alias // @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // private static volatile Object[] cache1; @@ -64,6 +66,10 @@ private static SortedMap availableCharsets() { return Collections.unmodifiableSortedMap(result); } + @Alias + @TargetElement(onlyWith = JDK19OrLater.class) + public static native Charset forName(String charsetName, Charset fallback); + @Substitute private static Charset lookup2(String charsetName) { Object[] a; From 3cf9b7181fc74f6302afc0139222564027c0f166 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 29 Jun 2022 15:04:23 +0200 Subject: [PATCH 28/44] svm: don't complain about Proxies that are run-time initialzed --- .../hosted/classinitialization/ClassInitializationFeature.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationFeature.java index 76cd8fdda63e..0ea99e2ae91f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationFeature.java @@ -29,6 +29,7 @@ import static com.oracle.svm.hosted.classinitialization.InitKind.RUN_TIME; import java.io.PrintWriter; +import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -40,6 +41,7 @@ import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.util.Providers; +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException; import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; @@ -186,6 +188,7 @@ public void afterAnalysis(AfterAnalysisAccess access) { if (ClassInitializationOptions.AssertInitializationSpecifiedForAllClasses.getValue()) { List unspecifiedClasses = classInitializationSupport.classesWithKind(RUN_TIME).stream() .filter(c -> classInitializationSupport.specifiedInitKindFor(c) == null) + .filter(c -> JavaVersionUtil.JAVA_SPEC < 19 || !Proxy.isProxyClass(c)) .map(Class::getTypeName) .collect(Collectors.toList()); if (!unspecifiedClasses.isEmpty()) { From 2eacc221147227050b9301b98878678fe696b87b Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 20 Jun 2022 15:37:04 +0200 Subject: [PATCH 29/44] svm: temporary support for JDK 19 EA Revert as soon as labsjdk-19 is available. --- substratevm/mx.substratevm/mx_substratevm.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index b267181e8c28..a67fa41caec2 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -69,7 +69,7 @@ def get_jdk(): def graal_compiler_flags(): version_tag = get_jdk().javaCompliance.value compiler_flags = mx.dependency('substratevm:svm-compiler-flags-builder').compute_graal_compiler_flags_map() - if version_tag not in compiler_flags: + if str(version_tag) not in compiler_flags: missing_flags_message = 'Missing graal-compiler-flags for {0}.\n Did you forget to run "mx build"?' mx.abort(missing_flags_message.format(version_tag)) def adjusted_exports(line): @@ -84,7 +84,8 @@ def adjusted_exports(line): return before + sep + 'ALL-UNNAMED' else: return line - return [adjusted_exports(line) for line in compiler_flags[version_tag]] + + return [adjusted_exports(line) for line in compiler_flags[str(version_tag)]] def svm_unittest_config_participant(config): vmArgs, mainClass, mainClassArgs = config @@ -1654,12 +1655,12 @@ 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] = [ + graal_compiler_flags_map['8'] = [ '-d64', '-XX:-UseJVMCIClassLoader' ] - graal_compiler_flags_map[11] = [ + graal_compiler_flags_map['11'] = [ # Disable the check for JDK-8 graal version. '-Dsubstratevm.IgnoreGraalVersionCheck=true', ] @@ -1668,11 +1669,12 @@ def compute_graal_compiler_flags_map(self): 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) + 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] + 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'] = graal_compiler_flags_map['17'] + graal_compiler_flags_map['19-ea'] = graal_compiler_flags_map['19'] # DO NOT ADD ANY NEW ADD-OPENS OR ADD-EXPORTS HERE! # # Instead provide the correct requiresConcealed entries in the moduleInfo From 5204b1c4c0d5f8621afd76997d9228bceda5d9ee Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 30 Jun 2022 10:43:31 +0200 Subject: [PATCH 30/44] ci: temporarily add JDK 19 EA --- common.json | 12 +++++++++++- common.jsonnet | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/common.json b/common.json index bfff718de015..afc16143e8cb 100644 --- a/common.json +++ b/common.json @@ -15,7 +15,17 @@ "labsjdk-ce-17-llvm": {"name": "labsjdk", "version": "ce-17.0.4+7-jvmci-22.2-b04-sulong", "platformspecific": true }, "labsjdk-ee-17": {"name": "labsjdk", "version": "ee-17.0.4+10-jvmci-22.2-b04", "platformspecific": true }, "labsjdk-ee-17Debug": {"name": "labsjdk", "version": "ee-17.0.4+10-jvmci-22.2-b04-debug", "platformspecific": true }, - "labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.4+10-jvmci-22.2-b04-sulong", "platformspecific": true } + "labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.4+10-jvmci-22.2-b04-sulong", "platformspecific": true }, + + "jdk-19-ea": { + "build_id": "jdk-19+28", + "name": "jpg-jdk", + "version": "19", + "extrabundles": [ + "static_libs" + ], + "platformspecific": true + } }, "COMMENT.devkits" : "The devkits versions reflect those used to build the JVMCI JDKs (e.g., see devkit_platform_revisions in /make/conf/jib-profiles.js)", diff --git a/common.jsonnet b/common.jsonnet index 8f4d574f1e53..673c2c561564 100644 --- a/common.jsonnet +++ b/common.jsonnet @@ -79,6 +79,7 @@ # jdk_version is an hidden field that can be used to generate job names local jdk11 = { jdk_version:: 11}, local jdk17 = { jdk_version:: 17}, + local jdk19 = { jdk_version:: 19}, oraclejdk11:: jdk11 + { downloads+: { JAVA_HOME : jdks.oraclejdk11 }}, oraclejdk17:: jdk17 + { downloads+: { JAVA_HOME : jdks.oraclejdk17 }}, @@ -95,9 +96,13 @@ "labsjdk-ce-17-llvm":: jdk17 + { downloads+: { LLVM_JAVA_HOME : jdks["labsjdk-ce-17-llvm"] }}, "labsjdk-ee-17-llvm":: jdk17 + { downloads+: { LLVM_JAVA_HOME : jdks["labsjdk-ee-17-llvm"] }}, + "labsjdk-ce-19":: jdk19 + { downloads+: { JAVA_HOME : jdks["jdk-19-ea"] + { open: true} }}, + "labsjdk-ee-19":: jdk19 + { downloads+: { JAVA_HOME : jdks["jdk-19-ea"] }}, + # Aliases to edition specific labsjdks labsjdk11:: self["labsjdk-" + repo_config.graalvm_edition + "-11"], labsjdk17:: self["labsjdk-" + repo_config.graalvm_edition + "-17"], + labsjdk19:: self["labsjdk-" + repo_config.graalvm_edition + "-19"], labsjdk11Debug:: self["labsjdk-" + repo_config.graalvm_edition + "-11Debug"], labsjdk17Debug:: self["labsjdk-" + repo_config.graalvm_edition + "-17Debug"], labsjdk11LLVM:: self["labsjdk-" + repo_config.graalvm_edition + "-11-llvm"], From ca75ff4ebc9443179c8bcf070c07ddd417e0cc38 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 30 Jun 2022 10:44:07 +0200 Subject: [PATCH 31/44] ci: add libgraal quickbuild job for JDK 19 --- vm/ci_common/common.jsonnet | 2 ++ vm/ci_includes/vm.jsonnet | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/vm/ci_common/common.jsonnet b/vm/ci_common/common.jsonnet index 6a6b17a20e3a..877531333896 100644 --- a/vm/ci_common/common.jsonnet +++ b/vm/ci_common/common.jsonnet @@ -703,6 +703,8 @@ local devkits = common_json.devkits; self.gate_vm_linux_amd64 + self.libgraal_compiler_quickbuild + vm.vm_java_17 + { name: 'gate-vm-libgraal-compiler-quickbuild-17-linux-amd64' }, self.gate_vm_linux_amd64 + self.libgraal_truffle_quickbuild + vm.vm_java_17 + { name: 'gate-vm-libgraal-truffle-quickbuild-17-linux-amd64' }, + self.gate_vm_linux_amd64 + self.libgraal_compiler_quickbuild + vm.vm_java_19 + { name: 'gate-vm-libgraal-compiler-quickbuild-19-linux-amd64' }, + vm.vm_java_17 + self.svm_common_linux_amd64 + self.sulong_linux + vm.custom_vm_linux + self.gate_vm_linux_amd64 + vm.vm_unittest + { run: [ ['export', 'SVM_SUITE=' + vm.svm_suite], diff --git a/vm/ci_includes/vm.jsonnet b/vm/ci_includes/vm.jsonnet index ae544f22fe00..581017c201bf 100644 --- a/vm/ci_includes/vm.jsonnet +++ b/vm/ci_includes/vm.jsonnet @@ -24,6 +24,14 @@ local jdks = common_json.jdks; }, }, + vm_java_19:: graal_common.labsjdk19 + { + environment+: { + BASE_JDK_NAME: jdks['jdk-19-ea'].name, + BASE_JDK_VERSION: jdks['jdk-19-ea'].version, + BASE_JDK_SHORT_VERSION: '19', + }, + }, + vm_java_11_llvm:: self.vm_java_11 + { downloads+: { LLVM_JAVA_HOME: jdks['labsjdk-ce-11-llvm'], From 6569245e0d371ed5de006418c3fcff29ebe15c7a Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 28 Jun 2022 07:53:17 +0200 Subject: [PATCH 32/44] ci: use closed jpg-jdk for both ce and ee --- common.jsonnet | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common.jsonnet b/common.jsonnet index 673c2c561564..561e78e04d0e 100644 --- a/common.jsonnet +++ b/common.jsonnet @@ -96,8 +96,8 @@ "labsjdk-ce-17-llvm":: jdk17 + { downloads+: { LLVM_JAVA_HOME : jdks["labsjdk-ce-17-llvm"] }}, "labsjdk-ee-17-llvm":: jdk17 + { downloads+: { LLVM_JAVA_HOME : jdks["labsjdk-ee-17-llvm"] }}, - "labsjdk-ce-19":: jdk19 + { downloads+: { JAVA_HOME : jdks["jdk-19-ea"] + { open: true} }}, - "labsjdk-ee-19":: jdk19 + { downloads+: { JAVA_HOME : jdks["jdk-19-ea"] }}, + "labsjdk-ce-19":: jdk19 + { downloads+: { JAVA_HOME : jdks["jdk-19-ea"] + { open: false} }}, + "labsjdk-ee-19":: jdk19 + { downloads+: { JAVA_HOME : jdks["jdk-19-ea"] + { open: false} }}, # Aliases to edition specific labsjdks labsjdk11:: self["labsjdk-" + repo_config.graalvm_edition + "-11"], From 38707053c9766f3ab761d88de94791f4448866b3 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 30 Jun 2022 09:48:44 +0200 Subject: [PATCH 33/44] ci: add JDK 19 svm build gate --- substratevm/ci.jsonnet | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/substratevm/ci.jsonnet b/substratevm/ci.jsonnet index 71a718f2eb87..d81bd64fde53 100644 --- a/substratevm/ci.jsonnet +++ b/substratevm/ci.jsonnet @@ -63,6 +63,7 @@ local linux_amd64_jdk11 = common.linux_amd64 + common.labsjdk11, local linux_amd64_jdk17 = common.linux_amd64 + common.labsjdk17, + local linux_amd64_jdk19 = common.linux_amd64 + common.labsjdk19, local darwin_jdk17 = common.darwin_amd64 + common.labsjdk17, local windows_jdk17 = common.windows_amd64 + common.labsjdk17 + common.devkits["windows-jdk17"], @@ -73,6 +74,14 @@ linux_amd64_jdk11 + gate("build-ce", "build,helloworld,test,nativeimagehelp,muslcbuild,debuginfotest") + maven + svm_unittest + t("35:00") + musl_toolchain + gdb("10.2"), linux_amd64_jdk11 + gate("modules-basic", "build,hellomodule,test") + maven + svm_unittest + t("30:00"), linux_amd64_jdk17 + gate("style-fullbuild", "style,fullbuild,helloworld,test,svmjunit,debuginfotest") + common.eclipse + common.jdt + maven + svm_unittest + t("50:00") + mx_build_exploded + gdb("10.2"), + linux_amd64_jdk19 + gate("build-ce", "build") + { + run: [ + # cannot yet use mx gate --tag build due to compile errors in /compiler + ["mx", "build"], + # cannot yet use mx gate --tag hello world due to missing JFR support in JDK 19 + ["mx", "helloworld"], + ] + } + maven + svm_unittest + t("35:00"), windows_jdk17 + gate("basics", "build,helloworld,test,svmjunit") + svm_unittest + t("1:30:00"), windows_jdk17 + gate("basics-quickbuild", "build,helloworld_quickbuild,test_quickbuild,svmjunit_quickbuild") + svm_unittest + t("1:30:00"), ], From 49aeb528bc3f3a95db248ed402c1bae62cf6f11e Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 30 Jun 2022 09:12:57 +0000 Subject: [PATCH 34/44] ci: disable JDK 19 libgraal gate for now --- vm/ci_common/common.jsonnet | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vm/ci_common/common.jsonnet b/vm/ci_common/common.jsonnet index 877531333896..2ba8c124f130 100644 --- a/vm/ci_common/common.jsonnet +++ b/vm/ci_common/common.jsonnet @@ -703,7 +703,8 @@ local devkits = common_json.devkits; self.gate_vm_linux_amd64 + self.libgraal_compiler_quickbuild + vm.vm_java_17 + { name: 'gate-vm-libgraal-compiler-quickbuild-17-linux-amd64' }, self.gate_vm_linux_amd64 + self.libgraal_truffle_quickbuild + vm.vm_java_17 + { name: 'gate-vm-libgraal-truffle-quickbuild-17-linux-amd64' }, - self.gate_vm_linux_amd64 + self.libgraal_compiler_quickbuild + vm.vm_java_19 + { name: 'gate-vm-libgraal-compiler-quickbuild-19-linux-amd64' }, + # requires compiler changes GR-39169 + # self.gate_vm_linux_amd64 + self.libgraal_compiler_quickbuild + vm.vm_java_19 + { name: 'gate-vm-libgraal-compiler-quickbuild-19-linux-amd64' }, vm.vm_java_17 + self.svm_common_linux_amd64 + self.sulong_linux + vm.custom_vm_linux + self.gate_vm_linux_amd64 + vm.vm_unittest + { run: [ From 03f0ba18dcfc27258a2fbc329c76496e30fb4439 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 07:25:51 +0000 Subject: [PATCH 35/44] svm: update comment in SubstrateMethodAccessor --- .../com/oracle/svm/core/reflect/SubstrateMethodAccessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/SubstrateMethodAccessor.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/SubstrateMethodAccessor.java index b0d413f9badb..57842bd83644 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/SubstrateMethodAccessor.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/SubstrateMethodAccessor.java @@ -112,7 +112,7 @@ public Object invoke(Object obj, Object[] args) { @Override public Object invoke(Object obj, Object[] args, Class caller) { - // FIXME ignore caller + // Handle caller sensitive invokes (GR-39586) return invoke(obj, args); } From d79c8b30ebe576feeda7b663850003d3ca70c289 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 07:26:43 +0000 Subject: [PATCH 36/44] svm: update comment in Thread.currentCarrierThread substitution --- .../src/com/oracle/svm/core/thread/Target_java_lang_Thread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index a777a194625a..e2dc97c89ff6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -270,7 +270,7 @@ private static Thread currentThread0() { @Substitute @TargetElement(onlyWith = JDK19OrLater.class) static Thread currentCarrierThread() { - // FIXME support for VirtualThreads + // missing support for VirtualThreads (GR-39563) Thread thread = PlatformThreads.currentThread.get(); assert thread != null : "Thread has not been set yet"; return thread; From e46edfe6bb02c5679da478c23954c0ddb296a771 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 09:30:58 +0200 Subject: [PATCH 37/44] svm: rearrange comments in MultiThreadedMonitorSupport for JDK 19 --- .../svm/core/monitor/MultiThreadedMonitorSupport.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java index 27cb528787c3..ab12636ffb0f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java @@ -116,11 +116,14 @@ public class MultiThreadedMonitorSupport extends MonitorSupport { /* * The com.oracle.svm.core.WeakIdentityHashMap used to model the * com.oracle.svm.core.monitor.MultiThreadedMonitorSupport#additionalMonitors map uses - * java.lang.ref.ReferenceQueue internally. The ReferenceQueue uses the inner static - * class Lock for all its locking needs. + * java.lang.ref.ReferenceQueue internally. */ HashSet> monitorTypes = new HashSet<>(); if (JavaVersionUtil.JAVA_SPEC <= 17) { + /* + * Until JDK 17, the ReferenceQueue uses the inner static class Lock for all its + * locking needs. + */ monitorTypes.add(Class.forName("java.lang.ref.ReferenceQueue$Lock")); } /* The WeakIdentityHashMap also synchronizes on its internal ReferenceQueue field. */ From b7c879dc06e17c8919329c4477a73eca4e4beb90 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 09:31:34 +0200 Subject: [PATCH 38/44] svm: remove outdated FIXME in Thread substitution --- .../src/com/oracle/svm/core/thread/Target_java_lang_Thread.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index e2dc97c89ff6..b9b66b2605f4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -333,8 +333,6 @@ private Target_java_lang_Thread( /* Injected Target_java_lang_Thread instance field initialization. */ this.threadData = new ThreadData(); - // FIXME: checkCharacteristics(characteristics); - // TODO: derive from characteristics bitset boolean inheritThreadLocals = false; /* Initialize the rest of the Thread object, ignoring `characteristics`. */ From cd5de05fb1319f2eca9e5d0cbe2a3643d5773b06 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 09:31:58 +0200 Subject: [PATCH 39/44] svm: update comment in JNIRegistrationJavaNio to address MemorySegmentProxy removal in JDK 19 --- .../src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java index e83ffc94705e..05c055c4273a 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java @@ -113,8 +113,8 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { a.registerReachabilityHandler(registerInitInetAddressIDs, method(a, "sun.nio.ch.Net", "initIDs")); /* - * Starting with support for JDK 17, all of the Buffer classes require MemorySegmentProxy - * which is accessed via reflection. + * In JDK 17, all of the Buffer classes require MemorySegmentProxy which is accessed via + * reflection. */ if (JavaVersionUtil.JAVA_SPEC == 17) { RuntimeReflection.register(clazz(a, "jdk.internal.access.foreign.MemorySegmentProxy")); From e08b782620e7e280418f0cf6228c978899ff9593 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 09:48:49 +0200 Subject: [PATCH 40/44] svm: remove user and mode from PerfDataSupport.attach() --- .../src/com/oracle/svm/core/jvmstat/PerfDataSupport.java | 4 ++-- .../svm/core/jvmstat/Target_jdk_internal_perf_Perf.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java index 9d337292aa48..81c1c6961ed2 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java @@ -34,7 +34,7 @@ import com.oracle.svm.core.annotate.AutomaticFeature; public interface PerfDataSupport { - ByteBuffer attach(String user, int lvmid, int mode); + ByteBuffer attach(int lvmid); void detach(ByteBuffer bb); @@ -53,7 +53,7 @@ class NoPerfDataSupport implements PerfDataSupport { } @Override - public ByteBuffer attach(String user, int lvmid, int mode) { + public ByteBuffer attach(int lvmid) { throw new IllegalArgumentException("Performance data is not supported."); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java index 12fd25c0031d..76f6edf313f8 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java @@ -40,13 +40,13 @@ public final class Target_jdk_internal_perf_Perf { @Substitute @TargetElement(name = "attach", onlyWith = JDK17OrEarlier.class) public ByteBuffer attachJDK17(String user, int lvmid, int mode) { - return ImageSingletons.lookup(PerfDataSupport.class).attach(user, lvmid, mode); + return ImageSingletons.lookup(PerfDataSupport.class).attach(lvmid); } @Substitute @TargetElement(name = "attach", onlyWith = JDK19OrLater.class) public ByteBuffer attachJDK19(int lvmid) { - return ImageSingletons.lookup(PerfDataSupport.class).attach(null, lvmid, 0); + return ImageSingletons.lookup(PerfDataSupport.class).attach(lvmid); } @Substitute From 71ff0dcbfcd791018c04198c19a521c44e8ea356 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 09:54:05 +0200 Subject: [PATCH 41/44] svm: fix assertion in MultiThreadedMonitorSupport --- .../oracle/svm/core/monitor/MultiThreadedMonitorSupport.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java index ab12636ffb0f..e767cfe423ac 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java @@ -456,7 +456,8 @@ protected JavaMonitor getOrCreateMonitorFromObject(Object obj, boolean createIfN } protected JavaMonitor getOrCreateMonitorFromMap(Object obj, boolean createIfNotExisting) { - assert obj.getClass() != Target_java_lang_ref_ReferenceQueue_Lock.class : "ReferenceQueue.Lock must have a monitor field or we can deadlock accessing WeakIdentityHashMap below"; + assert JavaVersionUtil.JAVA_SPEC > 19 || + obj.getClass() != Target_java_lang_ref_ReferenceQueue_Lock.class : "ReferenceQueue.Lock must have a monitor field or we can deadlock accessing WeakIdentityHashMap below"; VMError.guarantee(!additionalMonitorsLock.isHeldByCurrentThread(), "Recursive manipulation of the additionalMonitors map can lead to table corruptions and double insertion of a monitor for the same object"); From cbcdf268dd8f5c54a7d79724df2295d09dc9aa9c Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 10:46:44 +0200 Subject: [PATCH 42/44] Revert "svm: ignore Thread.getId deprecation for JDK 19" This reverts commit 2bc010a44e825cda8cb7a33ccf1721a77a773754. --- .../src/com/oracle/svm/core/VMInspection.java | 1 - .../src/com/oracle/svm/core/jfr/JfrThreadRepository.java | 1 - .../src/com/oracle/svm/core/jfr/SubstrateJVM.java | 1 - .../src/com/oracle/svm/core/thread/JavaThreadsFeature.java | 1 - .../src/com/oracle/svm/core/thread/PlatformThreads.java | 2 -- .../src/com/oracle/svm/core/thread/SubstrateVirtualThread.java | 2 -- .../src/com/oracle/svm/core/thread/Target_java_lang_Thread.java | 2 +- 7 files changed, 1 insertion(+), 9 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java index 17d1b9fd801a..6ddff48d2f3f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java @@ -132,7 +132,6 @@ protected void operate() { log.flush(); } - @SuppressWarnings("deprecation") private static void dumpStack(Log log, IsolateThread vmThread) { Thread javaThread = PlatformThreads.fromVMThread(vmThread); if (javaThread != null) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java index 1362e15c24aa..271346b83420 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java @@ -96,7 +96,6 @@ public void registerThread(Thread thread) { } @Uninterruptible(reason = "Epoch must not change while in this method.") - @SuppressWarnings("deprecation") private void registerThread0(Thread thread) { assert SubstrateJVM.isRecording(); JfrThreadEpochData epochData = getEpochData(false); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java index b8ff90734b1a..e935904dd4d6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java @@ -254,7 +254,6 @@ public long getStackTraceId(int skipCount) { } /** See {@link JVM#getThreadId}. */ - @SuppressWarnings("deprecation") public static long getThreadId(Thread thread) { if (HasJfrSupport.get()) { return thread.getId(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java index 325d8fc96568..e3fdf0dbb712 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java @@ -130,7 +130,6 @@ public void afterAnalysis(AfterAnalysisAccess access) { JavaThreads.threadInitNumber.set(maxAutonumber); } - @SuppressWarnings("deprecation") static long threadId(Thread thread) { return thread == PlatformThreads.singleton().mainThread ? 1 : thread.getId(); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java index d1febc0428df..b0b0a774bab6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java @@ -171,7 +171,6 @@ protected PlatformThreads() { mainGroupThreadsArray[0] = mainThread; } - @SuppressWarnings("deprecation") @Uninterruptible(reason = "Thread locks/holds the THREAD_MUTEX.") public static long getThreadAllocatedBytes(long javaThreadId) { // Accessing the value for the current thread is fast. @@ -197,7 +196,6 @@ public static long getThreadAllocatedBytes(long javaThreadId) { } } - @SuppressWarnings("deprecation") @Uninterruptible(reason = "Thread locks/holds the THREAD_MUTEX.") public static void getThreadAllocatedBytes(long[] javaThreadIds, long[] result) { VMThreads.lockThreadMutexInNativeCode(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java index 6bfec7b9fee5..9f9c0a1f32e6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java @@ -567,7 +567,6 @@ public Thread.State getState() { } } - @SuppressWarnings("deprecation") @Override public String toString() { StringBuilder sb = new StringBuilder("VirtualThread[#"); @@ -603,7 +602,6 @@ public String toString() { } @Override - @SuppressWarnings("deprecation") public int hashCode() { return (int) getId(); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index b9b66b2605f4..dddfadb228f5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -354,7 +354,7 @@ private Target_java_lang_Thread(String name, int characteristics) { this.contextClassLoader = Thread.currentThread().getContextClassLoader(); } - @SuppressWarnings({"hiding", "deprecation"}) + @SuppressWarnings("hiding") @Substitute private void start0() { if (!SubstrateOptions.MultiThreaded.getValue()) { From 927a4c6d79928e21b1a65aedd4b4035bb40306c2 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 11:02:47 +0200 Subject: [PATCH 43/44] svm: introduce JavaThreads.getThreadId() --- .../src/com/oracle/svm/core/VMInspection.java | 3 ++- .../com/oracle/svm/core/jfr/JfrThreadRepository.java | 11 ++++++----- .../src/com/oracle/svm/core/jfr/SubstrateJVM.java | 3 ++- .../src/com/oracle/svm/core/thread/JavaThreads.java | 9 ++++++++- .../oracle/svm/core/thread/JavaThreadsFeature.java | 2 +- .../com/oracle/svm/core/thread/PlatformThreads.java | 6 +++--- .../svm/core/thread/SubstrateVirtualThread.java | 4 ++-- .../svm/core/thread/Target_java_lang_Thread.java | 2 +- 8 files changed, 25 insertions(+), 15 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java index 6ddff48d2f3f..73e0ddb9b905 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspection.java @@ -47,6 +47,7 @@ import com.oracle.svm.core.log.Log; import com.oracle.svm.core.stack.JavaStackWalker; import com.oracle.svm.core.stack.ThreadStackPrinter.StackFramePrintVisitor; +import com.oracle.svm.core.thread.JavaThreads; import com.oracle.svm.core.thread.JavaVMOperation; import com.oracle.svm.core.thread.PlatformThreads; import com.oracle.svm.core.thread.VMThreads; @@ -136,7 +137,7 @@ private static void dumpStack(Log log, IsolateThread vmThread) { Thread javaThread = PlatformThreads.fromVMThread(vmThread); if (javaThread != null) { log.character('"').string(javaThread.getName()).character('"'); - log.string(" #").signed(javaThread.getId()); + log.string(" #").signed(JavaThreads.getThreadId(javaThread)); if (javaThread.isDaemon()) { log.string(" daemon"); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java index 271346b83420..5bc269179794 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrThreadRepository.java @@ -39,6 +39,7 @@ import com.oracle.svm.core.jfr.traceid.JfrTraceIdEpoch; import com.oracle.svm.core.locks.VMMutex; import com.oracle.svm.core.thread.JavaLangThreadGroupSubstitutions; +import com.oracle.svm.core.thread.JavaThreads; import com.oracle.svm.core.thread.PlatformThreads; import com.oracle.svm.core.thread.VMOperation; import com.oracle.svm.core.thread.VMThreads; @@ -105,8 +106,8 @@ private void registerThread0(Thread thread) { } JfrVisited visitedThread = StackValue.get(JfrVisited.class); - visitedThread.setId(thread.getId()); - visitedThread.setHash((int) thread.getId()); + visitedThread.setId(JavaThreads.getThreadId(thread)); + visitedThread.setHash((int) JavaThreads.getThreadId(thread)); if (!epochData.visitedThreads.putIfAbsent(visitedThread)) { return; } @@ -114,11 +115,11 @@ private void registerThread0(Thread thread) { JfrNativeEventWriterData data = StackValue.get(JfrNativeEventWriterData.class); JfrNativeEventWriterDataAccess.initialize(data, epochData.threadBuffer); - JfrNativeEventWriter.putLong(data, thread.getId()); // JFR trace id + JfrNativeEventWriter.putLong(data, JavaThreads.getThreadId(thread)); // JFR trace id JfrNativeEventWriter.putString(data, thread.getName()); // Java or native thread name - JfrNativeEventWriter.putLong(data, thread.getId()); // OS thread id + JfrNativeEventWriter.putLong(data, JavaThreads.getThreadId(thread)); // OS thread id JfrNativeEventWriter.putString(data, thread.getName()); // Java thread name - JfrNativeEventWriter.putLong(data, thread.getId()); // Java thread id + JfrNativeEventWriter.putLong(data, JavaThreads.getThreadId(thread)); // Java thread id ThreadGroup threadGroup = thread.getThreadGroup(); if (threadGroup != null) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java index e935904dd4d6..bb641aa862e8 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/SubstrateJVM.java @@ -40,6 +40,7 @@ import com.oracle.svm.core.heap.VMOperationInfos; import com.oracle.svm.core.jfr.events.ExecutionSampleEvent; import com.oracle.svm.core.jfr.logging.JfrLogging; +import com.oracle.svm.core.thread.JavaThreads; import com.oracle.svm.core.thread.JavaVMOperation; import com.oracle.svm.core.thread.ThreadListener; import com.oracle.svm.core.util.VMError; @@ -256,7 +257,7 @@ public long getStackTraceId(int skipCount) { /** See {@link JVM#getThreadId}. */ public static long getThreadId(Thread thread) { if (HasJfrSupport.get()) { - return thread.getId(); + return JavaThreads.getThreadId(thread); } return 0; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java index b7a105c4a3c8..5fa7372c4c6f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java @@ -30,12 +30,12 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -import com.oracle.svm.core.SubstrateUtil; import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.compiler.core.common.SuppressFBWarnings; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.IsolateThread; +import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.AlwaysInline; import com.oracle.svm.core.annotate.NeverInline; import com.oracle.svm.core.annotate.Uninterruptible; @@ -98,6 +98,13 @@ static Thread.State getThreadState(Thread thread) { return Target_jdk_internal_misc_VM.toThreadState(getThreadStatus(thread)); } + @SuppressWarnings("deprecation") + @AlwaysInline("handle Thread.getId deprecation") + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + public static long getThreadId(Thread thread) { + return thread.getId(); + } + /** * Safe method to check whether a thread has been interrupted. * diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java index e3fdf0dbb712..b713a589483b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java @@ -131,7 +131,7 @@ public void afterAnalysis(AfterAnalysisAccess access) { } static long threadId(Thread thread) { - return thread == PlatformThreads.singleton().mainThread ? 1 : thread.getId(); + return thread == PlatformThreads.singleton().mainThread ? 1 : JavaThreads.getThreadId(thread); } private static final String AUTONUMBER_PREFIX = "Thread-"; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java index b0b0a774bab6..98489c0f4fc0 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java @@ -175,7 +175,7 @@ protected PlatformThreads() { public static long getThreadAllocatedBytes(long javaThreadId) { // Accessing the value for the current thread is fast. Thread curThread = PlatformThreads.currentThread.get(); - if (curThread != null && curThread.getId() == javaThreadId) { + if (curThread != null && JavaThreads.getThreadId(curThread) == javaThreadId) { return Heap.getHeap().getThreadAllocatedMemory(CurrentIsolate.getCurrentThread()); } @@ -185,7 +185,7 @@ public static long getThreadAllocatedBytes(long javaThreadId) { IsolateThread isolateThread = VMThreads.firstThread(); while (isolateThread.isNonNull()) { Thread javaThread = PlatformThreads.currentThread.get(isolateThread); - if (javaThread != null && javaThread.getId() == javaThreadId) { + if (javaThread != null && JavaThreads.getThreadId(javaThread) == javaThreadId) { return Heap.getHeap().getThreadAllocatedMemory(isolateThread); } isolateThread = VMThreads.nextThread(isolateThread); @@ -205,7 +205,7 @@ public static void getThreadAllocatedBytes(long[] javaThreadIds, long[] result) Thread javaThread = PlatformThreads.currentThread.get(isolateThread); if (javaThread != null) { for (int i = 0; i < javaThreadIds.length; i++) { - if (javaThread.getId() == javaThreadIds[i]) { + if (JavaThreads.getThreadId(javaThread) == javaThreadIds[i]) { result[i] = Heap.getHeap().getThreadAllocatedMemory(isolateThread); break; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java index 9f9c0a1f32e6..379da0d5c462 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/SubstrateVirtualThread.java @@ -570,7 +570,7 @@ public Thread.State getState() { @Override public String toString() { StringBuilder sb = new StringBuilder("VirtualThread[#"); - sb.append(getId()); + sb.append(JavaThreads.getThreadId(this)); String name = getName(); if (!name.isEmpty() && !name.equals("")) { sb.append(","); @@ -603,7 +603,7 @@ public String toString() { @Override public int hashCode() { - return (int) getId(); + return (int) JavaThreads.getThreadId(this); } @Override diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index dddfadb228f5..633193862042 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -361,7 +361,7 @@ private void start0() { throw VMError.unsupportedFeature("Single-threaded VM cannot create new threads"); } - parentThreadId = Thread.currentThread().getId(); + parentThreadId = JavaThreads.getThreadId(Thread.currentThread()); long stackSize = PlatformThreads.getRequestedStackSize(JavaThreads.fromTarget(this)); try { PlatformThreads.singleton().startThread(JavaThreads.fromTarget(this), stackSize); From e06f3e51ba5f2858f309002268e7855f53c859cb Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 1 Jul 2022 14:40:35 +0200 Subject: [PATCH 44/44] svm: use JDK17 suffix for DirectByteBuffer substitution --- ...rget_java_nio_DirectByteBuffer_JDK17.java} | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) rename substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/{Target_java_nio_DirectByteBuffer_JDK17OrLater.java => Target_java_nio_DirectByteBuffer_JDK17.java} (70%) diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java similarity index 70% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17OrLater.java rename to substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java index 44a4bf7efc81..4440f01eea49 100644 --- a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17OrLater.java +++ b/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java @@ -34,27 +34,27 @@ @TargetClass(className = "jdk.internal.access.foreign.MemorySegmentProxy", onlyWith = {JDK17OrLater.class, JDK17OrEarlier.class}) @SuppressWarnings("unused") -final class Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17OrLater { +final class Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17 { } @TargetClass(className = "java.nio.DirectByteBuffer", onlyWith = {JDK17OrLater.class, JDK17OrEarlier.class}) @SuppressWarnings("unused") -final class Target_java_nio_DirectByteBuffer_JDK17OrLater { +final class Target_java_nio_DirectByteBuffer_JDK17 { @Alias - protected Target_java_nio_DirectByteBuffer_JDK17OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, - Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17OrLater segment) { + protected Target_java_nio_DirectByteBuffer_JDK17(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, + Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17 segment) { } } @TargetClass(className = "java.nio.DirectByteBufferR", onlyWith = {JDK17OrLater.class, JDK17OrEarlier.class}) @SuppressWarnings("unused") -final class Target_java_nio_DirectByteBufferR_JDK17OrLater { +final class Target_java_nio_DirectByteBufferR_JDK17 { @Alias - protected Target_java_nio_DirectByteBufferR_JDK17OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, - Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17OrLater segment) { + protected Target_java_nio_DirectByteBufferR_JDK17(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, + Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17 segment) { } } @@ -63,13 +63,13 @@ protected Target_java_nio_DirectByteBufferR_JDK17OrLater(int cap, long addr, Fil final class Target_sun_nio_ch_Util_JDK17 { @Substitute - private static Target_java_nio_DirectByteBuffer_JDK17OrLater newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return new Target_java_nio_DirectByteBuffer_JDK17OrLater(size, addr, fd, unmapper, isSync, null); + private static Target_java_nio_DirectByteBuffer_JDK17 newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { + return new Target_java_nio_DirectByteBuffer_JDK17(size, addr, fd, unmapper, isSync, null); } @Substitute - static Target_java_nio_DirectByteBufferR_JDK17OrLater newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return new Target_java_nio_DirectByteBufferR_JDK17OrLater(size, addr, fd, unmapper, isSync, null); + static Target_java_nio_DirectByteBufferR_JDK17 newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { + return new Target_java_nio_DirectByteBufferR_JDK17(size, addr, fd, unmapper, isSync, null); } }