33
33
import org .graalvm .nativeimage .Platform ;
34
34
import org .graalvm .nativeimage .Platforms ;
35
35
36
+ import com .oracle .graal .pointsto .heap .ImageHeapScanner ;
36
37
import com .oracle .graal .pointsto .infrastructure .OriginalClassProvider ;
37
38
import com .oracle .graal .pointsto .infrastructure .SubstitutionProcessor ;
39
+ import com .oracle .svm .core .BuildPhaseProvider ;
38
40
import com .oracle .svm .core .jfr .JfrJavaEvents ;
39
41
import com .oracle .svm .core .jfr .JfrJdkCompatibility ;
40
42
import com .oracle .svm .core .util .ObservableImageHeapMapProvider ;
57
59
@ Platforms (Platform .HOSTED_ONLY .class )
58
60
public class JfrEventSubstitution extends SubstitutionProcessor {
59
61
62
+ private final ImageHeapScanner heapScanner ;
63
+
60
64
private final ResolvedJavaType baseEventType ;
61
65
private final ConcurrentHashMap <ResolvedJavaType , Boolean > typeSubstitution ;
62
66
private final ConcurrentHashMap <ResolvedJavaMethod , ResolvedJavaMethod > methodSubstitutions ;
63
67
private final ConcurrentHashMap <ResolvedJavaField , ResolvedJavaField > fieldSubstitutions ;
64
68
private final Map <String , Class <? extends jdk .jfr .Event >> mirrorEventMapping ;
65
69
66
70
private static final Method registerMirror = JavaVersionUtil .JAVA_SPEC < 22 ? ReflectionUtil .lookupMethod (SecuritySupport .class , "registerMirror" , Class .class ) : null ;
71
+ private static final Method getConfiguration = ReflectionUtil .lookupMethod (JVM .class , "getConfiguration" , Class .class );
67
72
68
- JfrEventSubstitution (MetaAccessProvider metaAccess ) {
73
+ JfrEventSubstitution (MetaAccessProvider metaAccess , ImageHeapScanner heapScanner ) {
74
+ this .heapScanner = heapScanner ;
69
75
baseEventType = metaAccess .lookupJavaType (jdk .internal .event .Event .class );
70
76
typeSubstitution = new ConcurrentHashMap <>();
71
77
methodSubstitutions = new ConcurrentHashMap <>();
@@ -147,6 +153,7 @@ private static ResolvedJavaMethod initEventMethod(ResolvedJavaMethod oldMethod)
147
153
}
148
154
149
155
private Boolean initEventClass (ResolvedJavaType eventType ) throws RuntimeException {
156
+ VMError .guarantee (!BuildPhaseProvider .isAnalysisFinished ());
150
157
try {
151
158
Class <? extends jdk .internal .event .Event > newEventClass = OriginalClassProvider .getJavaClass (eventType ).asSubclass (jdk .internal .event .Event .class );
152
159
eventType .initialize ();
@@ -170,6 +177,10 @@ private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeExcepti
170
177
// the reflection registration for the event handler field is delayed to the JfrFeature
171
178
// duringAnalysis callback so it does not race/interfere with other retransforms
172
179
JfrJdkCompatibility .retransformClasses (new Class <?>[]{newEventClass });
180
+
181
+ // make sure the EventConfiguration object is fully scanned
182
+ heapScanner .rescanObject (getConfiguration .invoke (JfrJdkCompatibility .getJVMOrNull (), newEventClass ));
183
+
173
184
return Boolean .TRUE ;
174
185
} catch (Throwable ex ) {
175
186
throw VMError .shouldNotReachHere (ex );
0 commit comments