Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,8 +148,6 @@ public List<Class<? extends Feature>> 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<Configuration> knownConfigurations = JFC.getConfigurations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -67,14 +66,6 @@ public List<Class<? extends Feature>> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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<>();
Expand Down Expand Up @@ -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
Expand Down