From 484a90cda0a3a691d62a9c33cd5c859ccc1f8df8 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Wed, 26 Jun 2024 13:25:07 -0400 Subject: [PATCH] fix substitutions --- .../oracle/svm/core/jdk/JDK23OrEarlier.java | 36 +++++++++++++++++++ .../com/oracle/svm/core/jdk/JDK24OrLater.java | 36 +++++++++++++++++++ .../Target_jdk_jfr_internal_HiddenWait.java | 34 ++++++++++++++++++ .../core/jfr/Target_jdk_jfr_internal_JVM.java | 7 ++++ ...jfr_internal_JVM_ChunkRotationMonitor.java | 3 +- .../core/jfr/events/JavaMonitorWaitEvent.java | 16 +++++++-- 6 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK23OrEarlier.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK24OrLater.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_HiddenWait.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK23OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK23OrEarlier.java new file mode 100644 index 000000000000..246dd5dda33d --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK23OrEarlier.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk; + +import jdk.graal.compiler.serviceprovider.JavaVersionUtil; + +import java.util.function.BooleanSupplier; + +public class JDK23OrEarlier implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return JavaVersionUtil.JAVA_SPEC <= 23; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK24OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK24OrLater.java new file mode 100644 index 000000000000..3f71ebaee5a7 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK24OrLater.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk; + +import jdk.graal.compiler.serviceprovider.JavaVersionUtil; + +import java.util.function.BooleanSupplier; + +public class JDK24OrLater implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return JavaVersionUtil.JAVA_SPEC >= 24; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_HiddenWait.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_HiddenWait.java new file mode 100644 index 000000000000..de253c62e95e --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_HiddenWait.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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; + +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.JDK24OrLater; + +@TargetClass(className = "jdk.jfr.internal.HiddenWait", onlyWith = {HasJfrSupport.class, JDK24OrLater.class}) +public final class Target_jdk_jfr_internal_HiddenWait { +} 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 bc05e841eb65..288075487254 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 @@ -42,6 +42,7 @@ import com.oracle.svm.core.heap.PhysicalMemory.PhysicalMemorySupport; import com.oracle.svm.core.jdk.JDK22OrLater; import com.oracle.svm.core.jdk.JDK23OrLater; +import com.oracle.svm.core.jdk.JDK24OrLater; import com.oracle.svm.core.jfr.traceid.JfrTraceId; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; @@ -198,6 +199,12 @@ public static long getTicksFrequency() { return JfrTicks.getTicksFrequency(); } + @Substitute + @TargetElement(onlyWith = JDK24OrLater.class) + public static long nanosNow() { + return JfrTicks.currentTimeNanos(); + } + /** See {@link JVM#log}. */ @Substitute public static void log(int tagSetId, int level, String message) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.java index b899031a14c4..b9e33f8e5cb6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.java @@ -27,7 +27,8 @@ package com.oracle.svm.core.jfr; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.JDK23OrEarlier; -@TargetClass(className = "jdk.jfr.internal.JVM$ChunkRotationMonitor", onlyWith = HasJfrSupport.class) +@TargetClass(className = "jdk.jfr.internal.JVM$ChunkRotationMonitor", onlyWith = {HasJfrSupport.class, JDK23OrEarlier.class}) public final class Target_jdk_jfr_internal_JVM_ChunkRotationMonitor { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/events/JavaMonitorWaitEvent.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/events/JavaMonitorWaitEvent.java index 2e6c2ac0957b..e61aedd87740 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/events/JavaMonitorWaitEvent.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/events/JavaMonitorWaitEvent.java @@ -27,7 +27,7 @@ package com.oracle.svm.core.jfr.events; import jdk.graal.compiler.word.Word; - +import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.jfr.HasJfrSupport; import com.oracle.svm.core.jfr.JfrEvent; @@ -37,11 +37,21 @@ import com.oracle.svm.core.jfr.JfrTicks; import com.oracle.svm.core.jfr.SubstrateJVM; import com.oracle.svm.core.jfr.Target_jdk_jfr_internal_JVM_ChunkRotationMonitor; +import com.oracle.svm.core.jfr.Target_jdk_jfr_internal_HiddenWait; public class JavaMonitorWaitEvent { public static void emit(long startTicks, Object obj, long notifier, long timeout, boolean timedOut) { - if (HasJfrSupport.get() && obj != null && !Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.class.equals(obj.getClass())) { - emit0(startTicks, obj, notifier, timeout, timedOut); + if (!HasJfrSupport.get() || obj == null) { + return; + } + if (JavaVersionUtil.JAVA_SPEC >= 24) { + if (!Target_jdk_jfr_internal_HiddenWait.class.equals(obj.getClass())) { + emit0(startTicks, obj, notifier, timeout, timedOut); + } + } else { + if (!Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.class.equals(obj.getClass())) { + emit0(startTicks, obj, notifier, timeout, timedOut); + } } }