diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index c2b0a85683b1..7d02e944cae5 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -289,9 +289,6 @@ "jdk.jfr.internal", "jdk.jfr.internal.jfc", ], - "jdk.jfr@11..18": [ - "jdk.jfr.internal.handlers", - ], "jdk.internal.vm.ci": [ "jdk.vm.ci.meta", "jdk.vm.ci.code", 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 f0104f5901ef..b5491f6c926c 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,7 +26,6 @@ import java.lang.reflect.Field; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.word.Pointer; @@ -56,32 +55,21 @@ private JfrEventWriterAccess() { @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); + return ReflectionUtil.lookupClass(false, "jdk.jfr.internal.event.EventWriter"); } - public static Target_jdk_jfr_internal_EventWriter newEventWriter(JfrBuffer buffer, boolean isCurrentThreadExcluded) { + public static Target_jdk_jfr_internal_event_EventWriter newEventWriter(JfrBuffer buffer, boolean isCurrentThreadExcluded) { assert JfrBufferAccess.isEmpty(buffer) : "a fresh JFR buffer must be empty"; long committedPos = buffer.getCommittedPos().rawValue(); long maxPos = JfrBufferAccess.getDataEnd(buffer).rawValue(); long jfrThreadId = SubstrateJVM.getCurrentThreadId(); - if (JavaVersionUtil.JAVA_SPEC >= 19) { - return new Target_jdk_jfr_internal_EventWriter(committedPos, maxPos, jfrThreadId, true, isCurrentThreadExcluded); - } else { - long addressOfCommittedPos = JfrBufferAccess.getAddressOfCommittedPos(buffer).rawValue(); - return new Target_jdk_jfr_internal_EventWriter(committedPos, maxPos, addressOfCommittedPos, jfrThreadId, true); - } + return new Target_jdk_jfr_internal_event_EventWriter(committedPos, maxPos, jfrThreadId, true, isCurrentThreadExcluded); } /** Update the EventWriter so that it uses the correct buffer and positions. */ @Uninterruptible(reason = "Accesses a JFR buffer.") - public static void update(Target_jdk_jfr_internal_EventWriter writer, JfrBuffer buffer, int uncommittedSize, boolean valid) { + public static void update(Target_jdk_jfr_internal_event_EventWriter writer, JfrBuffer buffer, int uncommittedSize, boolean valid) { assert SubstrateJVM.getThreadLocal().getJavaBuffer() == buffer; assert JfrBufferAccess.verify(buffer); @@ -98,7 +86,7 @@ public static void update(Target_jdk_jfr_internal_EventWriter writer, JfrBuffer } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void markAsInvalid(Target_jdk_jfr_internal_EventWriter writer) { + public static void markAsInvalid(Target_jdk_jfr_internal_event_EventWriter writer) { /* The VM should never write true (only the JDK code may do that). */ U.putBooleanVolatile(writer, U.objectFieldOffset(VALID_FIELD), false); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrMetadataTypeLibrary.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrMetadataTypeLibrary.java index fed19329c2a7..0beb0e1c6b80 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrMetadataTypeLibrary.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrMetadataTypeLibrary.java @@ -30,7 +30,6 @@ import org.graalvm.compiler.core.common.NumUtil; import org.graalvm.compiler.options.OptionsParser; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -70,13 +69,7 @@ private static Collection getTypes0() { MetadataRepository.getInstance(); Method getTypes = ReflectionUtil.lookupMethod(TypeLibrary.class, "getTypes"); - if (JavaVersionUtil.JAVA_SPEC >= 21) { - return (Collection) getTypes.invoke(null); - } else { - Method getInstance = ReflectionUtil.lookupMethod(TypeLibrary.class, "getInstance"); - TypeLibrary instance = (TypeLibrary) getInstance.invoke(null); - return (Collection) getTypes.invoke(instance); - } + return (Collection) getTypes.invoke(null); } catch (Throwable e) { throw VMError.shouldNotReachHere("Error while calling TypeLibrary.getTypes().", e); } 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 356f998997d2..fe6158a3dd9f 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 @@ -24,7 +24,6 @@ */ package com.oracle.svm.core.jfr; -import com.oracle.svm.core.threadlocal.FastThreadLocalInt; import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.IsolateThread; @@ -49,6 +48,7 @@ import com.oracle.svm.core.thread.ThreadListener; import com.oracle.svm.core.thread.VMOperation; import com.oracle.svm.core.threadlocal.FastThreadLocalFactory; +import com.oracle.svm.core.threadlocal.FastThreadLocalInt; import com.oracle.svm.core.threadlocal.FastThreadLocalLong; import com.oracle.svm.core.threadlocal.FastThreadLocalObject; import com.oracle.svm.core.threadlocal.FastThreadLocalWord; @@ -79,7 +79,7 @@ */ public class JfrThreadLocal implements ThreadListener { /* Event-related thread-locals. */ - private static final FastThreadLocalObject javaEventWriter = FastThreadLocalFactory.createObject(Target_jdk_jfr_internal_EventWriter.class, + private static final FastThreadLocalObject javaEventWriter = FastThreadLocalFactory.createObject(Target_jdk_jfr_internal_event_EventWriter.class, "JfrThreadLocal.javaEventWriter"); private static final FastThreadLocalWord javaBuffer = FastThreadLocalFactory.createWord("JfrThreadLocal.javaBuffer"); private static final FastThreadLocalWord nativeBuffer = FastThreadLocalFactory.createWord("JfrThreadLocal.nativeBuffer"); @@ -258,8 +258,8 @@ public static boolean isCurrentThreadExcluded() { return tjlt.jfrExcluded; } - public static Target_jdk_jfr_internal_EventWriter getEventWriter() { - Target_jdk_jfr_internal_EventWriter eventWriter = javaEventWriter.get(); + public static Target_jdk_jfr_internal_event_EventWriter getEventWriter() { + Target_jdk_jfr_internal_event_EventWriter eventWriter = javaEventWriter.get(); /* * EventWriter objects cache various thread-specific values. Virtual threads use the * EventWriter object of their carrier thread, so we need to update all cached values so @@ -278,7 +278,7 @@ public static Target_jdk_jfr_internal_EventWriter getEventWriter() { * sufficiently consistent as the JFR buffer is still empty. So, this method does not need to be * uninterruptible. */ - public Target_jdk_jfr_internal_EventWriter newEventWriter() { + public Target_jdk_jfr_internal_event_EventWriter newEventWriter() { assert javaEventWriter.get() == null; JfrBuffer buffer = reinstateJavaBuffer(getJavaBuffer()); @@ -286,7 +286,7 @@ public Target_jdk_jfr_internal_EventWriter newEventWriter() { throw new OutOfMemoryError("OOME for thread local buffer"); } - Target_jdk_jfr_internal_EventWriter result = JfrEventWriterAccess.newEventWriter(buffer, isCurrentThreadExcluded()); + Target_jdk_jfr_internal_event_EventWriter result = JfrEventWriterAccess.newEventWriter(buffer, isCurrentThreadExcluded()); javaEventWriter.set(result); return result; } 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 2a09935b4f96..e1c0862a4472 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 @@ -24,7 +24,6 @@ */ package com.oracle.svm.core.jfr; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -135,9 +134,7 @@ public void registerThread(Thread thread) { JfrNativeEventWriter.putString(data, thread.getName()); // Java thread name JfrNativeEventWriter.putLong(data, threadId); // Java thread id JfrNativeEventWriter.putLong(data, threadGroupId); // Java thread group - if (JavaVersionUtil.JAVA_SPEC >= 19) { - JfrNativeEventWriter.putBoolean(data, isVirtual); - } + JfrNativeEventWriter.putBoolean(data, isVirtual); if (!JfrNativeEventWriter.commit(data)) { return; } 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 deleted file mode 100644 index b4e07bbc24fc..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Package_jdk_jfr_internal_event_helper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 72f601e18586..b8092d7a89c1 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 @@ -486,7 +486,7 @@ public void setThreadBufferSize(long size) { * See {@link JVM#flush}. */ @Uninterruptible(reason = "Accesses a JFR buffer.") - public boolean flush(Target_jdk_jfr_internal_EventWriter writer, int uncommittedSize, int requestedSize) { + public boolean flush(Target_jdk_jfr_internal_event_EventWriter writer, int uncommittedSize, int requestedSize) { assert writer != null; assert uncommittedSize >= 0; @@ -627,14 +627,14 @@ public void subscribeLogLevel(@SuppressWarnings("unused") LogTag lt, @SuppressWa /** * See {@link JVM#getEventWriter}. */ - public Target_jdk_jfr_internal_EventWriter getEventWriter() { + public Target_jdk_jfr_internal_event_EventWriter getEventWriter() { return JfrThreadLocal.getEventWriter(); } /** * See {@link JVM#newEventWriter}. */ - public Target_jdk_jfr_internal_EventWriter newEventWriter() { + public Target_jdk_jfr_internal_event_EventWriter newEventWriter() { return threadLocal.newEventWriter(); } 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 deleted file mode 100644 index 0a60fffa1325..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventHandlerCreator.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 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; - -@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() { - throw VMError.shouldNotReachHereSubstitution(); - } -} 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 deleted file mode 100644 index 583ee2f9fa3a..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_EventWriter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2020, 2021, 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.Alias; -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 = "EventWriter", classNameProvider = Package_jdk_jfr_internal_event_helper.class, onlyWith = HasJfrSupport.class) -public final class Target_jdk_jfr_internal_EventWriter { - - @Alias // - @TargetElement(onlyWith = JDK19OrLater.class) boolean excluded; - - @Alias // - long threadID; - - @Alias - @SuppressWarnings("unused") - @TargetElement(onlyWith = JDK17OrEarlier.class) - Target_jdk_jfr_internal_EventWriter(long committedPos, long maxPos, long committedPosAddress, long threadID, boolean valid) { - } - - @Alias - @SuppressWarnings("unused") - @TargetElement(onlyWith = JDK19OrLater.class) - Target_jdk_jfr_internal_EventWriter(long committedPos, long maxPos, long threadID, boolean valid, boolean excluded) { - } -} 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 a36047cee2ea..e0f307db21fa 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 @@ -39,12 +39,8 @@ 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.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; import jdk.jfr.internal.JVM; @@ -233,13 +229,6 @@ public static 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 = JDK22OrLater.class) @@ -260,12 +249,6 @@ public static void setOutput(String file) { public static 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 @TargetElement(onlyWith = JDK22OrLater.class) @@ -343,21 +326,6 @@ public static 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 @TargetElement(onlyWith = JDK22OrLater.class) @@ -373,23 +341,13 @@ public static Object getEventWriter() { /** See {@link JVM#newEventWriter}. */ @Substitute - public static Target_jdk_jfr_internal_EventWriter newEventWriter() { + public static Target_jdk_jfr_internal_event_EventWriter newEventWriter() { return SubstrateJVM.get().newEventWriter(); } - /** - * See {@link JVM#flush}. - */ - @Substitute - @TargetElement(name = "flush", onlyWith = JDK20OrEarlier.class) - public static boolean flushJDK20(Target_jdk_jfr_internal_EventWriter writer, int uncommittedSize, int requestedSize) { - return SubstrateJVM.get().flush(writer, uncommittedSize, requestedSize); - } - /** See {@link JVM#flush}. */ @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) - public static void flush(Target_jdk_jfr_internal_EventWriter writer, int uncommittedSize, int requestedSize) { + public static void flush(Target_jdk_jfr_internal_event_EventWriter writer, int uncommittedSize, int requestedSize) { SubstrateJVM.get().flush(writer, uncommittedSize, requestedSize); } @@ -400,7 +358,6 @@ public static void flush() { } @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) public static long commit(long nextPosition) { return SubstrateJVM.get().commit(nextPosition); } 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 index 4bbc17d9ef89..612c237f1cc8 100644 --- 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 @@ -34,13 +34,8 @@ 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; @@ -160,16 +155,8 @@ 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); } @@ -185,12 +172,6 @@ public void setOutput(String file) { 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 { @@ -257,21 +238,6 @@ 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) { @@ -291,14 +257,12 @@ public void setRepositoryLocation(String 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(); } @@ -356,14 +320,12 @@ public boolean isExcluded(Thread 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; @@ -376,13 +338,11 @@ public long 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); } @@ -395,13 +355,11 @@ public long getTypeId(String name) { } @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.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_SecuritySupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_SecuritySupport.java index 30f98b5a6f9c..edc735901472 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_SecuritySupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_SecuritySupport.java @@ -30,8 +30,6 @@ 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.util.VMError; import jdk.jfr.internal.SecuritySupport.SafePath; @@ -42,9 +40,6 @@ public final class Target_jdk_jfr_internal_SecuritySupport { @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // static SafePath JFC_DIRECTORY; @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // - @TargetElement(onlyWith = JDK17OrEarlier.class) // - static SafePath USER_HOME; - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // static SafePath JAVA_IO_TMPDIR; // Checkstyle: resume diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventConfiguration.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventConfiguration.java index 9555c76da87e..e558119e9d22 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventConfiguration.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventConfiguration.java @@ -25,8 +25,7 @@ package com.oracle.svm.core.jfr; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK19OrLater; -@TargetClass(className = "jdk.jfr.internal.event.EventConfiguration", onlyWith = {HasJfrSupport.class, JDK19OrLater.class}) +@TargetClass(className = "jdk.jfr.internal.event.EventConfiguration", onlyWith = HasJfrSupport.class) public final class Target_jdk_jfr_internal_event_EventConfiguration { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_Options.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventWriter.java similarity index 72% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_Options.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventWriter.java index dfab488c0c51..f299695f5eb4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_Options.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, 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 @@ -25,14 +25,18 @@ package com.oracle.svm.core.jfr; import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK17OrEarlier; -import jdk.jfr.internal.SecuritySupport.SafePath; +@TargetClass(className = "jdk.jfr.internal.event.EventWriter", onlyWith = HasJfrSupport.class) +public final class Target_jdk_jfr_internal_event_EventWriter { + @Alias // + boolean excluded; -@TargetClass(value = jdk.jfr.internal.Options.class, onlyWith = {HasJfrSupport.class, JDK17OrEarlier.class}) -public final class Target_jdk_jfr_internal_Options { - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // - private static SafePath dumpPath; + @Alias // + long threadID; + + @Alias + @SuppressWarnings("unused") + Target_jdk_jfr_internal_event_EventWriter(long committedPos, long maxPos, long threadID, boolean valid, boolean excluded) { + } } 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 deleted file mode 100644 index 9e93c8450018..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_handlers_EventHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.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.core/src/com/oracle/svm/core/jfr/events/ThreadSleepEventJDK17.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/events/ThreadSleepEventJDK17.java deleted file mode 100644 index 86c9005014f7..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/events/ThreadSleepEventJDK17.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2022, 2022, Red Hat Inc. 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.events; - -import org.graalvm.nativeimage.StackValue; - -import com.oracle.svm.core.Uninterruptible; -import com.oracle.svm.core.jfr.HasJfrSupport; -import com.oracle.svm.core.jfr.JfrEvent; -import com.oracle.svm.core.jfr.JfrNativeEventWriter; -import com.oracle.svm.core.jfr.JfrNativeEventWriterData; -import com.oracle.svm.core.jfr.JfrNativeEventWriterDataAccess; -import com.oracle.svm.core.jfr.JfrTicks; -import com.oracle.svm.core.jfr.SubstrateJVM; - -public class ThreadSleepEventJDK17 { - private static final JfrEvent ThreadSleep = JfrEvent.create("jdk.ThreadSleep", true); - - public static void emit(long time, long startTicks) { - if (HasJfrSupport.get()) { - emit0(time, startTicks); - } - } - - @Uninterruptible(reason = "Accesses a JFR buffer.") - private static void emit0(long time, long startTicks) { - long duration = JfrTicks.duration(startTicks); - if (ThreadSleep.shouldEmit(duration)) { - JfrNativeEventWriterData data = StackValue.get(JfrNativeEventWriterData.class); - JfrNativeEventWriterDataAccess.initializeThreadLocalNativeBuffer(data); - - JfrNativeEventWriter.beginSmallEvent(data, ThreadSleep); - JfrNativeEventWriter.putLong(data, startTicks); - JfrNativeEventWriter.putLong(data, duration); - JfrNativeEventWriter.putEventThread(data); - JfrNativeEventWriter.putLong(data, SubstrateJVM.get().getStackTraceId(ThreadSleep, 0)); - JfrNativeEventWriter.putLong(data, time); - JfrNativeEventWriter.endSmallEvent(data); - } - } -} 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 c30108b99dec..8783c586fe71 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 @@ -88,7 +88,6 @@ import com.oracle.svm.core.heap.VMOperationInfos; import com.oracle.svm.core.jdk.StackTraceUtils; import com.oracle.svm.core.jdk.UninterruptibleUtils; -import com.oracle.svm.core.jfr.events.ThreadSleepEventJDK17; import com.oracle.svm.core.locks.VMMutex; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.monitor.MonitorSupport; @@ -964,24 +963,17 @@ static void unpark(Thread thread) { */ static void sleep(long nanos) throws InterruptedException { assert !isCurrentThreadVirtual(); - /* Starting with JDK 19, the thread sleep event is implemented as a Java-level event. */ - if (JavaVersionUtil.JAVA_SPEC >= 19) { - if (com.oracle.svm.core.jfr.HasJfrSupport.get() && Target_jdk_internal_event_ThreadSleepEvent.isTurnedOn()) { - Target_jdk_internal_event_ThreadSleepEvent event = new Target_jdk_internal_event_ThreadSleepEvent(); - try { - event.time = nanos; - event.begin(); - sleep0(nanos); - } finally { - event.commit(); - } - } else { + if (com.oracle.svm.core.jfr.HasJfrSupport.get() && Target_jdk_internal_event_ThreadSleepEvent.isTurnedOn()) { + Target_jdk_internal_event_ThreadSleepEvent event = new Target_jdk_internal_event_ThreadSleepEvent(); + try { + event.time = nanos; + event.begin(); sleep0(nanos); + } finally { + event.commit(); } } else { - long startTicks = com.oracle.svm.core.jfr.JfrTicks.elapsedTicks(); sleep0(nanos); - ThreadSleepEventJDK17.emit(TimeUtils.roundNanosToMillis(nanos), startTicks); } } 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 f0feb5b11836..d3c5453b4f34 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 @@ -24,18 +24,14 @@ */ package com.oracle.svm.hosted.jfr; -import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.Collection; import java.util.Collections; import java.util.List; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.hosted.RuntimeClassInitialization; -import org.graalvm.nativeimage.hosted.RuntimeReflection; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; @@ -49,9 +45,7 @@ import com.oracle.svm.core.meta.SharedType; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FeatureImpl; -import com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl; import com.oracle.svm.util.ModuleSupport; -import com.oracle.svm.util.ReflectionUtil; import jdk.internal.event.Event; import jdk.jfr.internal.JVM; @@ -92,14 +86,6 @@ public void duringSetup(DuringSetupAccess c) { config.registerSubstitutionProcessor(new JfrEventSubstitution(metaAccess)); } - @Override - public void beforeAnalysis(Feature.BeforeAnalysisAccess access) { - if (JavaVersionUtil.JAVA_SPEC < 19) { - /* In JDK 19+, events don't have an eventHandler field anymore. */ - access.registerSubtypeReachabilityHandler(JfrEventFeature::eventSubtypeReachable, Event.class); - } - } - @Override public void beforeCompilation(BeforeCompilationAccess a) { // Reserve slot 0 for error-catcher. @@ -118,32 +104,16 @@ public void beforeCompilation(BeforeCompilationAccess a) { } /* Store the event configuration in the dynamic hub companion. */ - if (JavaVersionUtil.JAVA_SPEC >= 19) { - try { - FeatureImpl.CompilationAccessImpl accessImpl = ((FeatureImpl.CompilationAccessImpl) a); - Method getConfiguration = JVM.class.getDeclaredMethod("getConfiguration", Class.class); - for (var newEventClass : JfrJavaEvents.getAllEventClasses()) { - Object ec = getConfiguration.invoke(JfrJdkCompatibility.getJVMOrNull(), newEventClass); - DynamicHub dynamicHub = accessImpl.getMetaAccess().lookupJavaType(newEventClass).getHub(); - dynamicHub.setJrfEventConfiguration(ec); - } - } catch (ReflectiveOperationException ex) { - throw VMError.shouldNotReachHere(ex); + try { + FeatureImpl.CompilationAccessImpl accessImpl = ((FeatureImpl.CompilationAccessImpl) a); + Method getConfiguration = JVM.class.getDeclaredMethod("getConfiguration", Class.class); + for (var newEventClass : JfrJavaEvents.getAllEventClasses()) { + Object ec = getConfiguration.invoke(JfrJdkCompatibility.getJVMOrNull(), newEventClass); + DynamicHub dynamicHub = accessImpl.getMetaAccess().lookupJavaType(newEventClass).getHub(); + dynamicHub.setJrfEventConfiguration(ec); } - } - } - - private static void eventSubtypeReachable(DuringAnalysisAccess a, Class c) { - if (Modifier.isAbstract(c.getModifiers())) { - return; - } - - DuringAnalysisAccessImpl access = (DuringAnalysisAccessImpl) a; - Field f = ReflectionUtil.lookupField(c, "eventHandler"); - RuntimeReflection.register(f); - access.rescanRoot(f); - if (!access.concurrentReachabilityHandlers()) { - access.requireAnalysisIteration(); + } catch (ReflectiveOperationException ex) { + throw VMError.shouldNotReachHere(ex); } } }