43
43
import com .oracle .svm .core .util .VMError ;
44
44
import com .oracle .svm .util .ReflectionUtil ;
45
45
46
+ import jdk .graal .compiler .serviceprovider .JavaVersionUtil ;
46
47
import jdk .internal .misc .Unsafe ;
47
48
import jdk .jfr .internal .JVM ;
48
49
import jdk .jfr .internal .SecuritySupport ;
@@ -66,14 +67,20 @@ public class JfrEventSubstitution extends SubstitutionProcessor {
66
67
private final ConcurrentHashMap <ResolvedJavaField , ResolvedJavaField > fieldSubstitutions ;
67
68
private final Map <String , Class <? extends jdk .jfr .Event >> mirrorEventMapping ;
68
69
70
+ private static final Method registerMirror = JavaVersionUtil .JAVA_SPEC < 22 ? ReflectionUtil .lookupMethod (SecuritySupport .class , "registerMirror" , jdk .internal .event .Event .class ) : null ;
71
+
69
72
JfrEventSubstitution (MetaAccessProvider metaAccess ) {
70
73
baseEventType = metaAccess .lookupJavaType (jdk .internal .event .Event .class );
71
74
ResolvedJavaType jdkJfrEventWriter = metaAccess .lookupJavaType (EventWriter .class );
72
75
changeWriterResetMethod (jdkJfrEventWriter );
73
76
typeSubstitution = new ConcurrentHashMap <>();
74
77
methodSubstitutions = new ConcurrentHashMap <>();
75
78
fieldSubstitutions = new ConcurrentHashMap <>();
76
- mirrorEventMapping = createMirrorEventsMapping ();
79
+ if (JavaVersionUtil .JAVA_SPEC < 22 ) {
80
+ mirrorEventMapping = createMirrorEventsMapping ();
81
+ } else {
82
+ mirrorEventMapping = null ;
83
+ }
77
84
}
78
85
79
86
@ Override
@@ -150,10 +157,12 @@ private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeExcepti
150
157
Class <? extends jdk .internal .event .Event > newEventClass = OriginalClassProvider .getJavaClass (eventType ).asSubclass (jdk .internal .event .Event .class );
151
158
eventType .initialize ();
152
159
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
+ }
157
166
}
158
167
159
168
SecuritySupport .registerEvent (newEventClass );
0 commit comments