Skip to content

Commit b314c0f

Browse files
committed
svm: adopt "JDK-8239508 JFR: @RemoveFields" [GR-49904]
1 parent 70080a3 commit b314c0f

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_instrument_JDKEvents.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.oracle.svm.core.annotate.Alias;
2828
import com.oracle.svm.core.annotate.RecomputeFieldValue;
2929
import com.oracle.svm.core.annotate.TargetClass;
30+
import com.oracle.svm.core.annotate.TargetElement;
31+
import com.oracle.svm.core.jdk.JDK21OrEarlier;
3032

3133
import jdk.jfr.events.ActiveRecordingEvent;
3234
import jdk.jfr.events.ActiveSettingEvent;
@@ -42,5 +44,8 @@ final class Target_jdk_jfr_internal_instrument_JDKEvents {
4244
// This is a list of the classes with instrumentation code that should be applied.
4345
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) private static Class<?>[] instrumentationClasses = new Class<?>[]{};
4446

45-
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) private static Class<?>[] mirrorEventClasses = new Class<?>[]{};
47+
@Alias //
48+
@TargetElement(onlyWith = JDK21OrEarlier.class) //
49+
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) //
50+
private static Class<?>[] mirrorEventClasses = new Class<?>[]{};
4651
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.oracle.svm.core.util.VMError;
4444
import com.oracle.svm.util.ReflectionUtil;
4545

46+
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
4647
import jdk.internal.misc.Unsafe;
4748
import jdk.jfr.internal.JVM;
4849
import jdk.jfr.internal.SecuritySupport;
@@ -66,14 +67,20 @@ public class JfrEventSubstitution extends SubstitutionProcessor {
6667
private final ConcurrentHashMap<ResolvedJavaField, ResolvedJavaField> fieldSubstitutions;
6768
private final Map<String, Class<? extends jdk.jfr.Event>> mirrorEventMapping;
6869

70+
private static final Method registerMirror = JavaVersionUtil.JAVA_SPEC < 22 ? ReflectionUtil.lookupMethod(SecuritySupport.class, "registerMirror", jdk.internal.event.Event.class) : null;
71+
6972
JfrEventSubstitution(MetaAccessProvider metaAccess) {
7073
baseEventType = metaAccess.lookupJavaType(jdk.internal.event.Event.class);
7174
ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(EventWriter.class);
7275
changeWriterResetMethod(jdkJfrEventWriter);
7376
typeSubstitution = new ConcurrentHashMap<>();
7477
methodSubstitutions = new ConcurrentHashMap<>();
7578
fieldSubstitutions = new ConcurrentHashMap<>();
76-
mirrorEventMapping = createMirrorEventsMapping();
79+
if (JavaVersionUtil.JAVA_SPEC < 22) {
80+
mirrorEventMapping = createMirrorEventsMapping();
81+
} else {
82+
mirrorEventMapping = null;
83+
}
7784
}
7885

7986
@Override
@@ -150,10 +157,12 @@ private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeExcepti
150157
Class<? extends jdk.internal.event.Event> newEventClass = OriginalClassProvider.getJavaClass(eventType).asSubclass(jdk.internal.event.Event.class);
151158
eventType.initialize();
152159

153-
// It is crucial that mirror events are registered before the actual events.
154-
Class<? extends jdk.jfr.Event> mirrorEventClass = mirrorEventMapping.get(newEventClass.getName());
155-
if (mirrorEventClass != null) {
156-
SecuritySupport.registerMirror(mirrorEventClass);
160+
if (JavaVersionUtil.JAVA_SPEC < 22) {
161+
// It is crucial that mirror events are registered before the actual events.
162+
Class<? extends jdk.jfr.Event> mirrorEventClass = mirrorEventMapping.get(newEventClass.getName());
163+
if (mirrorEventClass != null) {
164+
registerMirror.invoke(null, mirrorEventClass);
165+
}
157166
}
158167

159168
SecuritySupport.registerEvent(newEventClass);

0 commit comments

Comments
 (0)