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..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; @@ -149,8 +148,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..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 @@ -45,7 +45,9 @@ 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; @SuppressWarnings({"static-method", "unused"}) @TargetClass(value = jdk.jfr.internal.JVM.class, onlyWith = HasJfrSupport.class) @@ -168,10 +170,15 @@ 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."); + Logger.log(LogTag.JFR_SETTING, LogLevel.WARN, "@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}. */ 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..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; @@ -67,14 +66,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..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; @@ -44,7 +42,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 +69,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 +182,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