From d346806df4d9c324fdca999108399e9875468afa Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 9 Aug 2023 14:47:59 +0200 Subject: [PATCH 01/10] svm: Thread.sleep cleanup [JDK-8309408] --- .../svm/core/thread/Target_java_lang_Thread.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 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 d5c78c08ccb5..8222169e81de 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 @@ -32,7 +32,6 @@ import java.util.Objects; import java.util.concurrent.ThreadFactory; -import com.oracle.svm.core.jdk.JDK21OrEarlier; import org.graalvm.compiler.api.directives.GraalDirectives; import org.graalvm.compiler.replacements.ReplacementsUtil; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; @@ -59,7 +58,9 @@ import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.JDK20OrEarlier; import com.oracle.svm.core.jdk.JDK20OrLater; +import com.oracle.svm.core.jdk.JDK21OrEarlier; import com.oracle.svm.core.jdk.JDK21OrLater; +import com.oracle.svm.core.jdk.JDK22OrLater; import com.oracle.svm.core.jdk.LoomJDK; import com.oracle.svm.core.jdk.NotLoomJDK; import com.oracle.svm.core.monitor.MonitorSupport; @@ -595,12 +596,19 @@ private static void sleep0JDK20(long millis) throws InterruptedException { } @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) + @TargetElement(onlyWith = {JDK21OrLater.class, JDK21OrEarlier.class}) private static void sleep0(long nanos) throws InterruptedException { // Virtual threads are handled in sleep() PlatformThreads.sleep(nanos); } + @Substitute + @TargetElement(onlyWith = JDK22OrLater.class) + private static void sleepNanos0(long nanos) throws InterruptedException { + // Virtual threads are handled in sleep() + PlatformThreads.sleep(nanos); + } + @Substitute @TargetElement public void join(long millis) throws InterruptedException { From 0483f33682444d6759d3563ecf0d85be6696acc4 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 9 Aug 2023 14:50:12 +0200 Subject: [PATCH 02/10] svm: JFR: Refactor after 'view' command [JDK-8310266] --- .../core/jdk/JDKContainerSubstitutions.java | 2 +- .../svm/core/jfr/JfrJdkCompatibility.java | 85 +++++++++++++++++++ .../com/oracle/svm/core/jfr/JfrManager.java | 5 +- 3 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java index b49dcef27a19..1896966d38bc 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java @@ -92,7 +92,7 @@ final class Target_jdk_jfr_internal_periodic_JVMEventTask { // Only present in JDKs without JDK-8268398 @TargetClass(className = "jdk.jfr.internal.Utils", onlyWith = JDK17OrEarlier.class) @Platforms(LINUX.class) -final class Target_jdk_jfr_internal_Utils { +final class Target_jdk_jfr_internal_Utils_JDK17 { @Alias // @RecomputeFieldValue(kind = Kind.Reset) // private static Target_jdk_internal_platform_Metrics[] metrics; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java new file mode 100644 index 000000000000..5d6d0a15c1c0 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jfr; + +import java.time.Duration; + +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.JDK21OrEarlier; +import com.oracle.svm.core.jdk.JDK22OrLater; + +import jdk.jfr.Recording; + +/** + * Compatibility class to handle incompatible changes between JDK 21 and JDK 22. Once support for + * JDKs prior to 22 is dropped, these the methods can be called directly and the substitutions can + * go away. + */ +@SuppressWarnings("unused") + +final class JfrJdkCompatibility { + private JfrJdkCompatibility() { + } + + public static String makeFilename(Recording recording) { + if (JavaVersionUtil.JAVA_SPEC >= 22) { + return Target_jdk_jfr_internal_JVMSupport.makeFilename(recording); + } else { + return Target_jdk_jfr_internal_Utils.makeFilename(recording); + } + } + + public static String formatTimespan(Duration dValue, String separation) { + if (JavaVersionUtil.JAVA_SPEC >= 22) { + return Target_jdk_jfr_internal_util_ValueFormatter.formatTimespan(dValue, separation); + } else { + return Target_jdk_jfr_internal_Utils.formatTimespan(dValue, separation); + } + } +} + +@TargetClass(className = "jdk.jfr.internal.Utils", onlyWith = {JDK21OrEarlier.class, HasJfrSupport.class}) +final class Target_jdk_jfr_internal_Utils { + @Alias + public static native String makeFilename(Recording recording); + + @Alias + public static native String formatTimespan(Duration dValue, String separation); +} + +@TargetClass(className = "jdk.jfr.internal.JVMSupport", onlyWith = {JDK22OrLater.class, HasJfrSupport.class}) +final class Target_jdk_jfr_internal_JVMSupport { + @Alias + public static native String makeFilename(Recording recording); +} + +@TargetClass(className = "jdk.jfr.internal.util.ValueFormatter", onlyWith = {JDK22OrLater.class, HasJfrSupport.class}) +final class Target_jdk_jfr_internal_util_ValueFormatter { + @Alias + public static native String formatTimespan(Duration dValue, String separation); +} \ No newline at end of file diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrManager.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrManager.java index 86249befb3f7..6c68552a8b98 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrManager.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrManager.java @@ -57,7 +57,6 @@ import jdk.jfr.internal.OldObjectSample; import jdk.jfr.internal.PrivateAccess; import jdk.jfr.internal.SecuritySupport; -import jdk.jfr.internal.Utils; import jdk.jfr.internal.jfc.JFC; /** @@ -240,7 +239,7 @@ private static void initRecording() { recording.scheduleStart(dDelay); msg.append("Recording " + recording.getId() + " scheduled to start in "); - msg.append(Utils.formatTimespan(dDelay, " ")); + msg.append(JfrJdkCompatibility.formatTimespan(dDelay, " ")); msg.append("."); } else { recording.start(); @@ -276,7 +275,7 @@ private static SecuritySupport.SafePath resolvePath(Recording recording, String } private static SecuritySupport.SafePath makeGenerated(Recording recording, Path directory) { - return new SecuritySupport.SafePath(directory.toAbsolutePath().resolve(Utils.makeFilename(recording)).normalize()); + return new SecuritySupport.SafePath(directory.toAbsolutePath().resolve(JfrJdkCompatibility.makeFilename(recording)).normalize()); } private static String getPath(SecuritySupport.SafePath path) { From 239a58d31ea79dafcc01d205d004164efa8166d9 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 9 Aug 2023 15:02:17 +0200 Subject: [PATCH 03/10] Update to JDK 22+3 --- common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.json b/common.json index c86aac8c4e34..68ab10e27c6d 100644 --- a/common.json +++ b/common.json @@ -42,7 +42,7 @@ "labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-debug", "platformspecific": true }, "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-sulong", "platformspecific": true }, - "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "2", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} + "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "3", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} }, "eclipse": { From 0f9258150513be88f11c4357dab43f01e190122c Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 10 Aug 2023 14:12:35 +0200 Subject: [PATCH 04/10] Update to JDK 22+4 --- common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.json b/common.json index 68ab10e27c6d..f55f6ed63539 100644 --- a/common.json +++ b/common.json @@ -42,7 +42,7 @@ "labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-debug", "platformspecific": true }, "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-sulong", "platformspecific": true }, - "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "3", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} + "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "4", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} }, "eclipse": { From dc02e6ac6bc601450d4250ec1c38955f2074cea1 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 11 Aug 2023 09:53:01 +0200 Subject: [PATCH 05/10] svm: adapt "JFR: Replace JVM.getJVM() with JVM" [JDK-8310661] --- .../com/oracle/svm/core/jfr/JfrFeature.java | 3 +- .../svm/core/jfr/JfrJdkCompatibility.java | 52 ++- .../core/jfr/Target_jdk_jfr_internal_JVM.java | 178 +++++--- .../Target_jdk_jfr_internal_JVM_JDK21.java | 409 ++++++++++++++++++ .../svm/hosted/jfr/JfrEventFeature.java | 3 +- .../svm/hosted/jfr/JfrEventSubstitution.java | 3 +- 6 files changed, 575 insertions(+), 73 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_JDK21.java 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 aa3db1d157ed..7de9d64a2c49 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 @@ -52,7 +52,6 @@ import com.sun.management.internal.PlatformMBeanProviderImpl; import jdk.jfr.Configuration; -import jdk.jfr.internal.JVM; import jdk.jfr.internal.jfc.JFC; /** @@ -158,7 +157,7 @@ public void afterRegistration(AfterRegistrationAccess access) { // Initialize some parts of JFR/JFC at image build time. List knownConfigurations = JFC.getConfigurations(); - JVM.getJVM().createNativeJFR(); + JfrJdkCompatibility.createNativeJFR(); ImageSingletons.add(JfrManager.class, new JfrManager(HOSTED_ENABLED)); ImageSingletons.add(SubstrateJVM.class, new SubstrateJVM(knownConfigurations)); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java index 5d6d0a15c1c0..674aea0415b4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java @@ -24,16 +24,24 @@ */ package com.oracle.svm.core.jfr; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.time.Duration; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.jdk.JDK21OrEarlier; import com.oracle.svm.core.jdk.JDK22OrLater; +import com.oracle.svm.core.util.VMError; +import com.oracle.svm.util.ReflectionUtil; import jdk.jfr.Recording; +import jdk.jfr.internal.JVM; +import jdk.jfr.internal.JVMSupport; /** * Compatibility class to handle incompatible changes between JDK 21 and JDK 22. Once support for @@ -42,7 +50,7 @@ */ @SuppressWarnings("unused") -final class JfrJdkCompatibility { +public final class JfrJdkCompatibility { private JfrJdkCompatibility() { } @@ -61,6 +69,46 @@ public static String formatTimespan(Duration dValue, String separation) { return Target_jdk_jfr_internal_Utils.formatTimespan(dValue, separation); } } + + @Platforms(Platform.HOSTED_ONLY.class) + public static void createNativeJFR() { + try { + if (JavaVersionUtil.JAVA_SPEC >= 22) { + Method createJFR = ReflectionUtil.lookupMethod(JVMSupport.class, "createJFR"); + createJFR.invoke(null); + } else { + Method createNativeJFR = ReflectionUtil.lookupMethod(JVM.class, "createNativeJFR"); + createNativeJFR.invoke(getJVMOrNull()); + } + } catch (ReflectiveOperationException | ClassCastException e) { + throw VMError.shouldNotReachHere(e); + } + } + + @Platforms(Platform.HOSTED_ONLY.class) + public static void retransformClasses(Class[] classes) { + try { + // call JVM.retransformClasses(classes) + Method retransformClasses = ReflectionUtil.lookupMethod(JVM.class, "retransformClasses", Class[].class); + retransformClasses.invoke(getJVMOrNull(), (Object) classes); + } catch (ReflectiveOperationException | ClassCastException e) { + throw VMError.shouldNotReachHere(e); + } + } + + /** + * Gets a {@link JVM} object or {@code null} in case of JDK 22+, where the methods of + * {@link JVM} are static (JDK-8310661). + */ + @Platforms(Platform.HOSTED_ONLY.class) + public static JVM getJVMOrNull() throws IllegalAccessException, InvocationTargetException { + if (JavaVersionUtil.JAVA_SPEC >= 22) { + return null; + } else { + Method getJVM = ReflectionUtil.lookupMethod(JVM.class, "getJVM"); + return (JVM) getJVM.invoke(null); + } + } } @TargetClass(className = "jdk.jfr.internal.Utils", onlyWith = {JDK21OrEarlier.class, HasJfrSupport.class}) @@ -82,4 +130,4 @@ final class Target_jdk_jfr_internal_JVMSupport { final class Target_jdk_jfr_internal_util_ValueFormatter { @Alias public static native String formatTimespan(Duration dValue, String separation); -} \ No newline at end of file +} 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 feba8cfa07cb..a36047cee2ea 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 @@ -27,8 +27,6 @@ import java.util.List; import java.util.function.BooleanSupplier; -import com.oracle.svm.core.jdk.JDK20OrEarlier; -import com.oracle.svm.core.jdk.JDK21OrLater; import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -42,8 +40,9 @@ 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; -import com.oracle.svm.core.jdk.JDK20OrLater; +import com.oracle.svm.core.jdk.JDK20OrEarlier; +import com.oracle.svm.core.jdk.JDK21OrLater; +import com.oracle.svm.core.jdk.JDK22OrLater; import com.oracle.svm.core.jfr.traceid.JfrTraceId; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; @@ -66,7 +65,8 @@ public final class Target_jdk_jfr_internal_JVM { @Alias // @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // - private volatile boolean nativeOK; + @TargetElement(onlyWith = JDK22OrLater.class) // + private static volatile boolean nativeOK; /** See {@link JVM#registerNatives}. */ @Substitute @@ -74,26 +74,30 @@ private static void registerNatives() { } @Substitute - public void markChunkFinal() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void markChunkFinal() { SubstrateJVM.get().markChunkFinal(); } /** See {@link JVM#beginRecording}. */ @Substitute - public void beginRecording() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void beginRecording() { SubstrateJVM.get().beginRecording(); } /** See {@link JVM#isRecording}. */ @Substitute @Uninterruptible(reason = "Needed for calling SubstrateJVM.isRecording().") - public boolean isRecording() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean isRecording() { return SubstrateJVM.get().isRecording(); } /** See {@link JVM#endRecording}. */ @Substitute - public void endRecording() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void endRecording() { SubstrateJVM.get().endRecording(); } @@ -105,19 +109,22 @@ public static long counterTime() { /** See {@link JVM#emitEvent}. */ @Substitute - public boolean emitEvent(long eventTypeId, long timestamp, long when) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean emitEvent(long eventTypeId, long timestamp, long when) { return false; } /** See {@link JVM#getAllEventClasses}. */ @Substitute - public List> getAllEventClasses() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static List> getAllEventClasses() { return JfrJavaEvents.getAllEventClasses(); } /** See {@link JVM#getUnloadedEventClassCount}. */ @Substitute - public long getUnloadedEventClassCount() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static long getUnloadedEventClassCount() { return 0; } @@ -134,7 +141,8 @@ public static long getClassId(Class clazz) { /** See {@link JVM#getPid}. */ @Substitute - public String getPid() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static String getPid() { long id = ProcessProperties.getProcessID(); return String.valueOf(id); } @@ -142,7 +150,8 @@ public String getPid() { /** See {@link JVM#getStackTraceId}. */ @Substitute @Uninterruptible(reason = "Needed for SubstrateJVM.getStackTraceId().") - public long getStackTraceId(int skipCount) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static long getStackTraceId(int skipCount) { /* * The result is only valid until the epoch changes but this is fine because EventWriter * instances are invalidated when the epoch changes. @@ -152,13 +161,15 @@ public long getStackTraceId(int skipCount) { /** See {@link JVM#getThreadId}. */ @Substitute - public long getThreadId(Thread t) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static long getThreadId(Thread t) { return SubstrateJVM.getThreadId(t); } /** See {@link JVM#getTicksFrequency}. */ @Substitute - public long getTicksFrequency() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static long getTicksFrequency() { return JfrTicks.getTicksFrequency(); } @@ -182,37 +193,43 @@ public static void subscribeLogLevel(LogTag lt, int tagSetId) { /** See {@link JVM#retransformClasses}. */ @Substitute - public synchronized void retransformClasses(Class[] classes) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static synchronized void retransformClasses(Class[] classes) { // Not supported but this method is called during JFR startup, so we can't throw an error. } /** See {@link JVM#setEnabled}. */ @Substitute - public void setEnabled(long eventTypeId, boolean enabled) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setEnabled(long eventTypeId, boolean enabled) { SubstrateJVM.get().setEnabled(eventTypeId, enabled); } /** See {@link JVM#setFileNotification}. */ @Substitute - public void setFileNotification(long delta) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setFileNotification(long delta) { SubstrateJVM.get().setFileNotification(delta); } /** See {@link JVM#setGlobalBufferCount}. */ @Substitute - public void setGlobalBufferCount(long count) throws IllegalArgumentException, IllegalStateException { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setGlobalBufferCount(long count) throws IllegalArgumentException, IllegalStateException { SubstrateJVM.get().setGlobalBufferCount(count); } /** See {@link JVM#setGlobalBufferSize}. */ @Substitute - public void setGlobalBufferSize(long size) throws IllegalArgumentException { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setGlobalBufferSize(long size) throws IllegalArgumentException { SubstrateJVM.get().setGlobalBufferSize(size); } /** See {@link JVM#setMemorySize}. */ @Substitute - public void setMemorySize(long size) throws IllegalArgumentException { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setMemorySize(long size) throws IllegalArgumentException { SubstrateJVM.get().setMemorySize(size); } @@ -225,20 +242,22 @@ public void setMethodSamplingInterval(long type, long intervalMillis) { /** See {@code JVM#setMethodSamplingPeriod}. */ @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) - public void setMethodSamplingPeriod(long type, long intervalMillis) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setMethodSamplingPeriod(long type, long intervalMillis) { SubstrateJVM.get().setMethodSamplingInterval(type, intervalMillis); } /** See {@link JVM#setOutput}. */ @Substitute - public void setOutput(String file) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setOutput(String file) { SubstrateJVM.get().setOutput(file); } /** See {@link JVM#setForceInstrumentation}. */ @Substitute - public void setForceInstrumentation(boolean force) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setForceInstrumentation(boolean force) { } @Substitute @@ -249,67 +268,78 @@ public void setSampleThreads(boolean sampleThreads) throws IllegalStateException /** See {@link JVM#setCompressedIntegers}. */ @Substitute - public void setCompressedIntegers(boolean compressed) throws IllegalStateException { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setCompressedIntegers(boolean compressed) throws IllegalStateException { SubstrateJVM.get().setCompressedIntegers(compressed); } /** See {@link JVM#setStackDepth}. */ @Substitute - public void setStackDepth(int depth) throws IllegalArgumentException, IllegalStateException { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setStackDepth(int depth) throws IllegalArgumentException, IllegalStateException { SubstrateJVM.get().setStackDepth(depth); } /** See {@link JVM#setStackTraceEnabled}. */ @Substitute - public void setStackTraceEnabled(long eventTypeId, boolean enabled) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setStackTraceEnabled(long eventTypeId, boolean enabled) { SubstrateJVM.get().setStackTraceEnabled(eventTypeId, enabled); } /** See {@link JVM#setThreadBufferSize}. */ @Substitute - public void setThreadBufferSize(long size) throws IllegalArgumentException, IllegalStateException { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setThreadBufferSize(long size) throws IllegalArgumentException, IllegalStateException { SubstrateJVM.get().setThreadBufferSize(size); } /** See {@link JVM#setThreshold}. */ @Substitute - public boolean setThreshold(long eventTypeId, long ticks) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean setThreshold(long eventTypeId, long ticks) { return SubstrateJVM.get().setThreshold(eventTypeId, ticks); } /** See {@link JVM#storeMetadataDescriptor}. */ @Substitute - public void storeMetadataDescriptor(byte[] bytes) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void storeMetadataDescriptor(byte[] bytes) { SubstrateJVM.get().storeMetadataDescriptor(bytes); } /** See {@link JVM#getAllowedToDoEventRetransforms}. */ @Substitute - public boolean getAllowedToDoEventRetransforms() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean getAllowedToDoEventRetransforms() { return false; } /** See {@link JVM#createJFR}. */ @Substitute - private boolean createJFR(boolean simulateFailure) throws IllegalStateException { + @TargetElement(onlyWith = JDK22OrLater.class) + private static boolean createJFR(boolean simulateFailure) throws IllegalStateException { return SubstrateJVM.get().createJFR(simulateFailure); } /** See {@link JVM#destroyJFR}. */ @Substitute - private boolean destroyJFR() { + @TargetElement(onlyWith = JDK22OrLater.class) + private static boolean destroyJFR() { return SubstrateJVM.get().destroyJFR(); } /** See {@link JVM#isAvailable}. */ @Substitute - public boolean isAvailable() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean isAvailable() { return true; } /** See {@link JVM#getTimeConversionFactor}. */ @Substitute - public double getTimeConversionFactor() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static double getTimeConversionFactor() { return 1; } @@ -330,7 +360,8 @@ public Object getHandler(Class eventClass) { /** See {@link JVM#getTypeId(Class)}. */ @Substitute - public long getTypeId(Class clazz) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static long getTypeId(Class clazz) { return JfrTraceId.getTraceId(clazz); } @@ -363,7 +394,8 @@ public static void flush(Target_jdk_jfr_internal_EventWriter writer, int uncommi } @Substitute - public void flush() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void flush() { SubstrateJVM.get().flush(); } @@ -375,27 +407,29 @@ public static long commit(long nextPosition) { /** See {@link JVM#setRepositoryLocation}. */ @Substitute - public void setRepositoryLocation(String dirText) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setRepositoryLocation(String dirText) { SubstrateJVM.get().setRepositoryLocation(dirText); } /** See {@code JVM#setDumpPath(String)}. */ @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) - public void setDumpPath(String dumpPathText) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void setDumpPath(String dumpPathText) { SubstrateJVM.get().setDumpPath(dumpPathText); } /** See {@code JVM#getDumpPath()}. */ @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) - public String getDumpPath() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static String getDumpPath() { return SubstrateJVM.get().getDumpPath(); } /** See {@link JVM#abort}. */ @Substitute - public void abort(String errorMsg) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void abort(String errorMsg) { SubstrateJVM.get().abort(errorMsg); } @@ -407,98 +441,108 @@ public static boolean addStringConstant(long id, String s) { /** See {@link JVM#uncaughtException}. */ @Substitute - public void uncaughtException(Thread thread, Throwable t) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void uncaughtException(Thread thread, Throwable t) { // Would be used to determine the emergency dump filename if an exception happens during // shutdown. } /** See {@link JVM#setCutoff}. */ @Substitute - public boolean setCutoff(long eventTypeId, long cutoffTicks) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean setCutoff(long eventTypeId, long cutoffTicks) { return SubstrateJVM.get().setCutoff(eventTypeId, cutoffTicks); } @Substitute - public boolean setThrottle(long eventTypeId, long eventSampleSize, long periodMs) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean setThrottle(long eventTypeId, long eventSampleSize, long periodMs) { // Not supported but this method is called during JFR startup, so we can't throw an error. return true; } /** See {@link JVM#emitOldObjectSamples}. */ @Substitute - public void emitOldObjectSamples(long cutoff, boolean emitAll, boolean skipBFS) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void emitOldObjectSamples(long cutoff, boolean emitAll, boolean skipBFS) { // Not supported but this method is called during JFR shutdown, so we can't throw an error. } /** See {@link JVM#shouldRotateDisk}. */ @Substitute - public boolean shouldRotateDisk() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean shouldRotateDisk() { return SubstrateJVM.get().shouldRotateDisk(); } @Substitute - public void include(Thread thread) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void include(Thread thread) { SubstrateJVM.get().setExcluded(thread, false); } @Substitute - public void exclude(Thread thread) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static void exclude(Thread thread) { SubstrateJVM.get().setExcluded(thread, true); } @Substitute - public boolean isExcluded(Thread thread) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static boolean isExcluded(Thread thread) { return SubstrateJVM.get().isExcluded(thread); } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) // - public boolean isExcluded(Class eventClass) { + @TargetElement(onlyWith = JDK22OrLater.class) // + public static boolean isExcluded(Class eventClass) { // Temporarily always include. return false; } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) // - public boolean isInstrumented(Class eventClass) { + @TargetElement(onlyWith = JDK22OrLater.class) // + public static boolean isInstrumented(Class eventClass) { // This should check for blessed commit methods in the event class [GR-41200] return true; } /** See {@link SubstrateJVM#getChunkStartNanos}. */ @Substitute - public long getChunkStartNanos() { + @TargetElement(onlyWith = JDK22OrLater.class) + public static long getChunkStartNanos() { return SubstrateJVM.get().getChunkStartNanos(); } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) // - public boolean setConfiguration(Class eventClass, Target_jdk_jfr_internal_event_EventConfiguration configuration) { + @TargetElement(onlyWith = JDK22OrLater.class) // + public static boolean setConfiguration(Class eventClass, Target_jdk_jfr_internal_event_EventConfiguration configuration) { return SubstrateJVM.get().setConfiguration(eventClass, configuration); } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) // - public Object getConfiguration(Class eventClass) { + @TargetElement(onlyWith = JDK22OrLater.class) // + public static Object getConfiguration(Class eventClass) { return SubstrateJVM.get().getConfiguration(eventClass); } /** See {@link JVM#getTypeId(String)}. */ @Substitute - public long getTypeId(String name) { + @TargetElement(onlyWith = JDK22OrLater.class) + public static long getTypeId(String name) { /* Not implemented at the moment. */ return -1; } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) // - public boolean isContainerized() { + @TargetElement(onlyWith = JDK22OrLater.class) // + public static boolean isContainerized() { return Containers.isContainerized(); } @Substitute - @TargetElement(onlyWith = JDK20OrLater.class) // - public long hostTotalMemory() { + @TargetElement(onlyWith = JDK22OrLater.class) // + public static long hostTotalMemory() { /* Not implemented at the moment. */ return 0; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_JDK21.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_JDK21.java new file mode 100644 index 000000000000..4bbc17d9ef89 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_JDK21.java @@ -0,0 +1,409 @@ +/* + * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jfr; + +import java.util.List; + +import org.graalvm.nativeimage.ProcessProperties; + +import com.oracle.svm.core.Containers; +import com.oracle.svm.core.Uninterruptible; +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.JDK17OrEarlier; +import com.oracle.svm.core.jdk.JDK19OrLater; +import com.oracle.svm.core.jdk.JDK20OrLater; +import com.oracle.svm.core.jdk.JDK21OrEarlier; +import com.oracle.svm.core.jfr.traceid.JfrTraceId; +import com.oracle.svm.core.util.VMError; + +import jdk.jfr.internal.JVM; + +@SuppressWarnings({"static-method", "unused"}) +@TargetClass(value = JVM.class, onlyWith = {JDK21OrEarlier.class, HasJfrSupport.class}) +final class Target_jdk_jfr_internal_JVM_JDK21 { + + @Alias // + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // + private volatile boolean nativeOK; + + @Substitute + public void markChunkFinal() { + SubstrateJVM.get().markChunkFinal(); + } + + /** See {@link JVM#beginRecording}. */ + @Substitute + public void beginRecording() { + SubstrateJVM.get().beginRecording(); + } + + /** See {@link JVM#isRecording}. */ + @Substitute + @Uninterruptible(reason = "Needed for calling SubstrateJVM.isRecording().") + public boolean isRecording() { + return SubstrateJVM.get().isRecording(); + } + + /** See {@link JVM#endRecording}. */ + @Substitute + public void endRecording() { + SubstrateJVM.get().endRecording(); + } + + /** See {@link JVM#emitEvent}. */ + @Substitute + public boolean emitEvent(long eventTypeId, long timestamp, long when) { + return false; + } + + /** See {@link JVM#getAllEventClasses}. */ + @Substitute + public List> getAllEventClasses() { + return JfrJavaEvents.getAllEventClasses(); + } + + /** See {@link JVM#getUnloadedEventClassCount}. */ + @Substitute + public long getUnloadedEventClassCount() { + return 0; + } + + /** See {@link JVM#getPid}. */ + @Substitute + public String getPid() { + long id = ProcessProperties.getProcessID(); + return String.valueOf(id); + } + + /** See {@link JVM#getStackTraceId}. */ + @Substitute + @Uninterruptible(reason = "Needed for SubstrateJVM.getStackTraceId().") + public long getStackTraceId(int skipCount) { + /* + * The result is only valid until the epoch changes but this is fine because EventWriter + * instances are invalidated when the epoch changes. + */ + return SubstrateJVM.get().getStackTraceId(skipCount); + } + + /** See {@link JVM#getThreadId}. */ + @Substitute + public long getThreadId(Thread t) { + return SubstrateJVM.getThreadId(t); + } + + /** See {@link JVM#getTicksFrequency}. */ + @Substitute + public long getTicksFrequency() { + return JfrTicks.getTicksFrequency(); + } + + /** See {@link JVM#retransformClasses}. */ + @Substitute + public synchronized void retransformClasses(Class[] classes) { + // Not supported but this method is called during JFR startup, so we can't throw an error. + } + + /** See {@link JVM#setEnabled}. */ + @Substitute + public void setEnabled(long eventTypeId, boolean enabled) { + SubstrateJVM.get().setEnabled(eventTypeId, enabled); + } + + /** See {@link JVM#setFileNotification}. */ + @Substitute + public void setFileNotification(long delta) { + SubstrateJVM.get().setFileNotification(delta); + } + + /** See {@link JVM#setGlobalBufferCount}. */ + @Substitute + public void setGlobalBufferCount(long count) throws IllegalArgumentException, IllegalStateException { + SubstrateJVM.get().setGlobalBufferCount(count); + } + + /** See {@link JVM#setGlobalBufferSize}. */ + @Substitute + public void setGlobalBufferSize(long size) throws IllegalArgumentException { + SubstrateJVM.get().setGlobalBufferSize(size); + } + + /** See {@link JVM#setMemorySize}. */ + @Substitute + public void setMemorySize(long size) throws IllegalArgumentException { + SubstrateJVM.get().setMemorySize(size); + } + + /** See {@code JVM#setMethodSamplingInterval}. */ + @Substitute + @TargetElement(onlyWith = JDK17OrEarlier.class) + public void setMethodSamplingInterval(long type, long intervalMillis) { + SubstrateJVM.get().setMethodSamplingInterval(type, intervalMillis); + } + + /** See {@code JVM#setMethodSamplingPeriod}. */ + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + public void setMethodSamplingPeriod(long type, long intervalMillis) { + SubstrateJVM.get().setMethodSamplingInterval(type, intervalMillis); + } + + /** See {@link JVM#setOutput}. */ + @Substitute + public void setOutput(String file) { + SubstrateJVM.get().setOutput(file); + } + + /** See {@link JVM#setForceInstrumentation}. */ + @Substitute + public void setForceInstrumentation(boolean force) { + } + + @Substitute + @TargetElement(onlyWith = JDK17OrEarlier.class) + public void setSampleThreads(boolean sampleThreads) throws IllegalStateException { + SubstrateJVM.get().setSampleThreads(sampleThreads); + } + + /** See {@link JVM#setCompressedIntegers}. */ + @Substitute + public void setCompressedIntegers(boolean compressed) throws IllegalStateException { + SubstrateJVM.get().setCompressedIntegers(compressed); + } + + /** See {@link JVM#setStackDepth}. */ + @Substitute + public void setStackDepth(int depth) throws IllegalArgumentException, IllegalStateException { + SubstrateJVM.get().setStackDepth(depth); + } + + /** See {@link JVM#setStackTraceEnabled}. */ + @Substitute + public void setStackTraceEnabled(long eventTypeId, boolean enabled) { + SubstrateJVM.get().setStackTraceEnabled(eventTypeId, enabled); + } + + /** See {@link JVM#setThreadBufferSize}. */ + @Substitute + public void setThreadBufferSize(long size) throws IllegalArgumentException, IllegalStateException { + SubstrateJVM.get().setThreadBufferSize(size); + } + + /** See {@link JVM#setThreshold}. */ + @Substitute + public boolean setThreshold(long eventTypeId, long ticks) { + return SubstrateJVM.get().setThreshold(eventTypeId, ticks); + } + + /** See {@link JVM#storeMetadataDescriptor}. */ + @Substitute + public void storeMetadataDescriptor(byte[] bytes) { + SubstrateJVM.get().storeMetadataDescriptor(bytes); + } + + /** See {@link JVM#getAllowedToDoEventRetransforms}. */ + @Substitute + public boolean getAllowedToDoEventRetransforms() { + return false; + } + + /** See {@link JVM#createJFR}. */ + @Substitute + private boolean createJFR(boolean simulateFailure) throws IllegalStateException { + return SubstrateJVM.get().createJFR(simulateFailure); + } + + /** See {@link JVM#destroyJFR}. */ + @Substitute + private boolean destroyJFR() { + return SubstrateJVM.get().destroyJFR(); + } + + /** See {@link JVM#isAvailable}. */ + @Substitute + public boolean isAvailable() { + return true; + } + + /** See {@link JVM#getTimeConversionFactor}. */ + @Substitute + public double getTimeConversionFactor() { + return 1; + } + + @Substitute + @TargetElement(onlyWith = JDK17OrEarlier.class) + 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); + } + + /** See {@link SubstrateJVM#getHandler}. */ + @Substitute + @TargetElement(onlyWith = JDK17OrEarlier.class) + public Object getHandler(Class eventClass) { + return SubstrateJVM.getHandler(eventClass); + } + + /** See {@link JVM#getTypeId(Class)}. */ + @Substitute + public long getTypeId(Class clazz) { + return JfrTraceId.getTraceId(clazz); + } + + @Substitute + public void flush() { + SubstrateJVM.get().flush(); + } + + /** See {@link JVM#setRepositoryLocation}. */ + @Substitute + public void setRepositoryLocation(String dirText) { + SubstrateJVM.get().setRepositoryLocation(dirText); + } + + /** See {@code JVM#setDumpPath(String)}. */ + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + public void setDumpPath(String dumpPathText) { + SubstrateJVM.get().setDumpPath(dumpPathText); + } + + /** See {@code JVM#getDumpPath()}. */ + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) + public String getDumpPath() { + return SubstrateJVM.get().getDumpPath(); + } + + /** See {@link JVM#abort}. */ + @Substitute + public void abort(String errorMsg) { + SubstrateJVM.get().abort(errorMsg); + } + + /** See {@link JVM#uncaughtException}. */ + @Substitute + public void uncaughtException(Thread thread, Throwable t) { + // Would be used to determine the emergency dump filename if an exception happens during + // shutdown. + } + + /** See {@link JVM#setCutoff}. */ + @Substitute + public boolean setCutoff(long eventTypeId, long cutoffTicks) { + return SubstrateJVM.get().setCutoff(eventTypeId, cutoffTicks); + } + + @Substitute + public boolean setThrottle(long eventTypeId, long eventSampleSize, long periodMs) { + // Not supported but this method is called during JFR startup, so we can't throw an error. + return true; + } + + /** See {@link JVM#emitOldObjectSamples}. */ + @Substitute + public void emitOldObjectSamples(long cutoff, boolean emitAll, boolean skipBFS) { + // Not supported but this method is called during JFR shutdown, so we can't throw an error. + } + + /** See {@link JVM#shouldRotateDisk}. */ + @Substitute + public boolean shouldRotateDisk() { + return SubstrateJVM.get().shouldRotateDisk(); + } + + @Substitute + public void include(Thread thread) { + SubstrateJVM.get().setExcluded(thread, false); + } + + @Substitute + public void exclude(Thread thread) { + SubstrateJVM.get().setExcluded(thread, true); + } + + @Substitute + public boolean isExcluded(Thread thread) { + return SubstrateJVM.get().isExcluded(thread); + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) // + public boolean isExcluded(Class eventClass) { + // Temporarily always include. + return false; + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) // + public boolean isInstrumented(Class eventClass) { + // This should check for blessed commit methods in the event class [GR-41200] + return true; + } + + /** See {@link SubstrateJVM#getChunkStartNanos}. */ + @Substitute + public long getChunkStartNanos() { + return SubstrateJVM.get().getChunkStartNanos(); + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) // + public boolean setConfiguration(Class eventClass, Target_jdk_jfr_internal_event_EventConfiguration configuration) { + return SubstrateJVM.get().setConfiguration(eventClass, configuration); + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) // + public Object getConfiguration(Class eventClass) { + return SubstrateJVM.get().getConfiguration(eventClass); + } + + /** See {@link JVM#getTypeId(String)}. */ + @Substitute + public long getTypeId(String name) { + /* Not implemented at the moment. */ + return -1; + } + + @Substitute + @TargetElement(onlyWith = JDK19OrLater.class) // + public boolean isContainerized() { + return Containers.isContainerized(); + } + + @Substitute + @TargetElement(onlyWith = JDK20OrLater.class) // + public long hostTotalMemory() { + /* Not implemented at the moment. */ + return 0; + } +} diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java index fbccdebb2bdd..f0feb5b11836 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java @@ -43,6 +43,7 @@ import com.oracle.svm.core.hub.DynamicHubSupport; import com.oracle.svm.core.jfr.JfrFeature; import com.oracle.svm.core.jfr.JfrJavaEvents; +import com.oracle.svm.core.jfr.JfrJdkCompatibility; import com.oracle.svm.core.jfr.traceid.JfrTraceId; import com.oracle.svm.core.jfr.traceid.JfrTraceIdMap; import com.oracle.svm.core.meta.SharedType; @@ -122,7 +123,7 @@ public void beforeCompilation(BeforeCompilationAccess a) { FeatureImpl.CompilationAccessImpl accessImpl = ((FeatureImpl.CompilationAccessImpl) a); Method getConfiguration = JVM.class.getDeclaredMethod("getConfiguration", Class.class); for (var newEventClass : JfrJavaEvents.getAllEventClasses()) { - Object ec = getConfiguration.invoke(JVM.getJVM(), newEventClass); + Object ec = getConfiguration.invoke(JfrJdkCompatibility.getJVMOrNull(), newEventClass); DynamicHub dynamicHub = accessImpl.getMetaAccess().lookupJavaType(newEventClass).getHub(); dynamicHub.setJrfEventConfiguration(ec); } 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 2fe95c27c7a4..bc277421b7e6 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 @@ -39,6 +39,7 @@ import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor; import com.oracle.svm.core.jfr.JfrEventWriterAccess; import com.oracle.svm.core.jfr.JfrJavaEvents; +import com.oracle.svm.core.jfr.JfrJdkCompatibility; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; @@ -159,7 +160,7 @@ private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeExcepti JfrJavaEvents.registerEventClass(newEventClass); // the reflection registration for the event handler field is delayed to the JfrFeature // duringAnalysis callback so it does not race/interfere with other retransforms - JVM.getJVM().retransformClasses(new Class[]{newEventClass}); + JfrJdkCompatibility.retransformClasses(new Class[]{newEventClass}); return Boolean.TRUE; } catch (Throwable ex) { throw VMError.shouldNotReachHere(ex); From 2a8428e334e6afff1ff4bdef48b251db3b34e3cf Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 11 Aug 2023 10:19:52 +0200 Subject: [PATCH 06/10] Update to JDK 22+5 --- common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.json b/common.json index f55f6ed63539..0be0d45cbff5 100644 --- a/common.json +++ b/common.json @@ -42,7 +42,7 @@ "labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-debug", "platformspecific": true }, "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-sulong", "platformspecific": true }, - "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "4", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} + "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "5", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} }, "eclipse": { From 1a73447adb1175dad99381a6557a2ac6f4adb27b Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 11 Aug 2023 10:20:59 +0200 Subject: [PATCH 07/10] Update to JDK 22+6 --- common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.json b/common.json index 0be0d45cbff5..e9d508bed1d6 100644 --- a/common.json +++ b/common.json @@ -42,7 +42,7 @@ "labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-debug", "platformspecific": true }, "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-sulong", "platformspecific": true }, - "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "5", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} + "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "6", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} }, "eclipse": { From b738f0d3aba145b67b26d3a16ac7285280e93939 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 11 Aug 2023 10:27:37 +0200 Subject: [PATCH 08/10] svm: adapt "(reflect) provide method for mapping strings to class object for primitive types" [JDK-6361826] --- .../src/com/oracle/svm/core/hub/DynamicHub.java | 5 +++++ 1 file changed, 5 insertions(+) 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 11c64d298ec5..5aa74b4e3e24 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 @@ -102,6 +102,7 @@ import com.oracle.svm.core.heap.UnknownPrimitiveField; import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.JDK21OrLater; +import com.oracle.svm.core.jdk.JDK22OrLater; import com.oracle.svm.core.jdk.Resources; import com.oracle.svm.core.meta.SharedType; import com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils; @@ -1349,6 +1350,10 @@ private static Class forName(String name, boolean initialize, ClassLoader loa return result; } + @KeepOriginal + @TargetElement(onlyWith = JDK22OrLater.class) + public static native Class forPrimitiveName(String primitiveName); + @KeepOriginal private native Package getPackage(); From f209c56fbc913ed0b87b4b2d7fac3eb474f4e5a5 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 11 Aug 2023 10:40:03 +0200 Subject: [PATCH 09/10] Update to JDK 22+7 --- common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.json b/common.json index e9d508bed1d6..6247ff85e564 100644 --- a/common.json +++ b/common.json @@ -42,7 +42,7 @@ "labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-debug", "platformspecific": true }, "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-sulong", "platformspecific": true }, - "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "6", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} + "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "7", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} }, "eclipse": { From f98bcfd7c734f7d6c54f6fe787b2748a7c938803 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 11 Aug 2023 10:43:58 +0200 Subject: [PATCH 10/10] Update to JDK 22+8 --- common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.json b/common.json index 6247ff85e564..416e164e2c2c 100644 --- a/common.json +++ b/common.json @@ -42,7 +42,7 @@ "labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-debug", "platformspecific": true }, "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+33-jvmci-23.1-b11-sulong", "platformspecific": true }, - "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "7", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} + "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "8", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} }, "eclipse": {