From 708e42489b0a88b1dd6889f45b78105777dac4a0 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Fri, 15 Dec 2023 13:09:33 -0500 Subject: [PATCH 1/3] clean up --- .../com/oracle/svm/core/jfr/JfrFeature.java | 2 - .../core/jfr/Target_jdk_jfr_internal_JVM.java | 10 +++- .../svm/hosted/jfr/JfrEventFeature.java | 8 --- .../svm/hosted/jfr/JfrEventSubstitution.java | 50 ------------------- 4 files changed, 9 insertions(+), 61 deletions(-) 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 67e977e6aca8..182b3ed513f5 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 @@ -149,8 +149,6 @@ public List> getRequiredFeatures() { @Override public void afterRegistration(AfterRegistrationAccess access) { - ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "jdk.jfr"); - ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "java.base"); // Initialize some parts of JFR/JFC at image build time. List knownConfigurations = JFC.getConfigurations(); 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 103ff7276ce0..4f4330b8a4af 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,6 +27,7 @@ import java.util.List; import java.util.function.BooleanSupplier; +import jdk.jfr.internal.LogLevel; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.ProcessProperties; @@ -46,6 +47,7 @@ import jdk.graal.compiler.api.replacements.Fold; import jdk.jfr.internal.JVM; import jdk.jfr.internal.LogTag; +import jdk.jfr.internal.Logger; @SuppressWarnings({"static-method", "unused"}) @TargetClass(value = jdk.jfr.internal.JVM.class, onlyWith = HasJfrSupport.class) @@ -168,10 +170,16 @@ public static void unregisterStackFilter(long stackFilterId) { throw VMError.unimplemented("JFR StackFilters are not yet supported."); } + /** + * As of 22+27, This method is both used to set cutoff tick values for leak profiling and + * for @Deprecated events. + */ @Substitute @TargetElement(onlyWith = JDK22OrLater.class) public static void setMiscellaneous(long eventTypeId, long value) { - throw VMError.unimplemented("@Deprecated JFR events are not yet supported."); + // Add logging here since JDK code obfuscates root exception message. + Logger.log(LogTag.JFR_SETTING, LogLevel.WARN, "@Deprecated JFR events, and leak profiling are not yet supported."); + throw VMError.unimplemented("@Deprecated JFR events, and leak profiling are not yet supported."); } /** See {@link JVM#getThreadId}. */ 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 d3c5453b4f34..e3a3dfbe3600 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 @@ -67,14 +67,6 @@ public List> getRequiredFeatures() { return Collections.singletonList(JfrFeature.class); } - @Override - public void afterRegistration(AfterRegistrationAccess access) { - ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrEventFeature.class, false, "jdk.jfr", "jdk.jfr.events"); - ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrFeature.class, false, "jdk.jfr", "jdk.jfr.events"); - ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrEventSubstitution.class, false, "jdk.internal.vm.ci", "jdk.vm.ci.hotspot"); - ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrEventFeature.class, false, "java.base", "jdk.internal.event"); - } - @Override public void duringSetup(DuringSetupAccess c) { FeatureImpl.DuringSetupAccessImpl config = (FeatureImpl.DuringSetupAccessImpl) c; 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 9d6e27c95553..73c61c26ba97 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 @@ -44,7 +44,6 @@ import com.oracle.svm.util.ReflectionUtil; import jdk.graal.compiler.serviceprovider.JavaVersionUtil; -import jdk.internal.misc.Unsafe; import jdk.jfr.internal.JVM; import jdk.jfr.internal.SecuritySupport; import jdk.jfr.internal.event.EventWriter; @@ -72,7 +71,6 @@ public class JfrEventSubstitution extends SubstitutionProcessor { JfrEventSubstitution(MetaAccessProvider metaAccess) { baseEventType = metaAccess.lookupJavaType(jdk.internal.event.Event.class); ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(EventWriter.class); - changeWriterResetMethod(jdkJfrEventWriter); typeSubstitution = new ConcurrentHashMap<>(); methodSubstitutions = new ConcurrentHashMap<>(); fieldSubstitutions = new ConcurrentHashMap<>(); @@ -186,54 +184,6 @@ private boolean needsClassRedefinition(ResolvedJavaType type) { return !type.isAbstract() && baseEventType.isAssignableFrom(type) && !baseEventType.equals(type); } - /** - * The method EventWriter.reset() is private but it is called by the EventHandler classes, which - * are generated automatically. To prevent bytecode parsing issues, we patch the visibility of - * that method using the hacky way below. - */ - private static void changeWriterResetMethod(ResolvedJavaType eventWriterType) { - for (ResolvedJavaMethod m : eventWriterType.getDeclaredMethods(false)) { - if (m.getName().equals("reset")) { - setPublicModifier(m); - } - } - } - - private static void setPublicModifier(ResolvedJavaMethod m) { - try { - Class hotspotMethodClass = m.getClass(); - Method metaspaceMethodM = getMethodToFetchMetaspaceMethod(hotspotMethodClass); - metaspaceMethodM.setAccessible(true); - long metaspaceMethod = (Long) metaspaceMethodM.invoke(m); - VMError.guarantee(metaspaceMethod != 0); - Class hotSpotVMConfigC = Class.forName("jdk.vm.ci.hotspot.HotSpotVMConfig"); - Method configM = hotSpotVMConfigC.getDeclaredMethod("config"); - configM.setAccessible(true); - Field methodAccessFlagsOffsetF = hotSpotVMConfigC.getDeclaredField("methodAccessFlagsOffset"); - methodAccessFlagsOffsetF.setAccessible(true); - Object hotSpotVMConfig = configM.invoke(null); - int methodAccessFlagsOffset = methodAccessFlagsOffsetF.getInt(hotSpotVMConfig); - int modifiers = Unsafe.getUnsafe().getInt(metaspaceMethod + methodAccessFlagsOffset); - int newModifiers = modifiers & ~Modifier.PRIVATE | Modifier.PUBLIC; - Unsafe.getUnsafe().putInt(metaspaceMethod + methodAccessFlagsOffset, newModifiers); - } catch (Exception ex) { - throw VMError.shouldNotReachHere(ex); - } - } - - private static Method getMethodToFetchMetaspaceMethod(Class method) throws NoSuchMethodException { - // The exact method depends on the JVMCI version. - try { - return method.getDeclaredMethod("getMethodPointer"); - } catch (NoSuchMethodException e) { - try { - return method.getDeclaredMethod("getMetaspaceMethod"); - } catch (NoSuchMethodException e2) { - return method.getDeclaredMethod("getMetaspacePointer"); - } - } - } - /* * Mirror events contain the JFR-specific annotations. The mirrored event does not have any * dependency on JFR-specific classes. If the mirrored event is used, we must ensure that the From d77207f8aac693f7d9f13d644e5c343c56ec944d Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Fri, 15 Dec 2023 13:24:34 -0500 Subject: [PATCH 2/3] style fixes style 2 --- .../src/com/oracle/svm/core/jfr/JfrFeature.java | 1 - .../src/com/oracle/svm/hosted/jfr/JfrEventFeature.java | 1 - .../src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java | 2 -- 3 files changed, 4 deletions(-) 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 182b3ed513f5..055b4bf3ddc5 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 @@ -47,7 +47,6 @@ import com.oracle.svm.core.util.UserError; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.LogUtils; -import com.oracle.svm.util.ModuleSupport; import com.oracle.svm.util.ReflectionUtil; import com.sun.management.HotSpotDiagnosticMXBean; import com.sun.management.internal.PlatformMBeanProviderImpl; 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 e3a3dfbe3600..0d3c2273a6fc 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 @@ -45,7 +45,6 @@ import com.oracle.svm.core.meta.SharedType; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FeatureImpl; -import com.oracle.svm.util.ModuleSupport; import jdk.internal.event.Event; import jdk.jfr.internal.JVM; 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 73c61c26ba97..02ee0fcb91ef 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 @@ -25,9 +25,7 @@ package com.oracle.svm.hosted.jfr; import java.lang.annotation.Annotation; -import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; From fce46ca723ee08be11f0dd1752e98f25a7bc827a Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Tue, 19 Dec 2023 11:35:44 +0100 Subject: [PATCH 3/3] Remove exception throw. --- .../com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 4f4330b8a4af..f24d53912021 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,7 +27,6 @@ import java.util.List; import java.util.function.BooleanSupplier; -import jdk.jfr.internal.LogLevel; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.ProcessProperties; @@ -46,6 +45,7 @@ import jdk.graal.compiler.api.replacements.Fold; import jdk.jfr.internal.JVM; +import jdk.jfr.internal.LogLevel; import jdk.jfr.internal.LogTag; import jdk.jfr.internal.Logger; @@ -177,9 +177,8 @@ public static void unregisterStackFilter(long stackFilterId) { @Substitute @TargetElement(onlyWith = JDK22OrLater.class) public static void setMiscellaneous(long eventTypeId, long value) { - // Add logging here since JDK code obfuscates root exception message. Logger.log(LogTag.JFR_SETTING, LogLevel.WARN, "@Deprecated JFR events, and leak profiling are not yet supported."); - throw VMError.unimplemented("@Deprecated JFR events, and leak profiling are not yet supported."); + /* Explicitly don't throw an exception (would result in an unspecific warning). */ } /** See {@link JVM#getThreadId}. */