Skip to content

Commit 6ffde64

Browse files
committed
[GR-60534] Make sure JFR EventConfiguration is scanned.
PullRequest: graal/19617
2 parents 4ce826c + fb90620 commit 6ffde64

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void duringSetup(DuringSetupAccess c) {
9393
for (Class<?> eventSubClass : config.findSubclasses(Event.class)) {
9494
RuntimeClassInitialization.initializeAtBuildTime(eventSubClass.getName());
9595
}
96-
config.registerSubstitutionProcessor(new JfrEventSubstitution(metaAccess));
96+
config.registerSubstitutionProcessor(new JfrEventSubstitution(metaAccess, config.getUniverse().getHeapScanner()));
9797

9898
/*
9999
* The value of this field is set later in the beforeCompilation method after analysis

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import org.graalvm.nativeimage.Platform;
3434
import org.graalvm.nativeimage.Platforms;
3535

36+
import com.oracle.graal.pointsto.heap.ImageHeapScanner;
3637
import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
3738
import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor;
39+
import com.oracle.svm.core.BuildPhaseProvider;
3840
import com.oracle.svm.core.jfr.JfrJavaEvents;
3941
import com.oracle.svm.core.jfr.JfrJdkCompatibility;
4042
import com.oracle.svm.core.util.ObservableImageHeapMapProvider;
@@ -57,15 +59,19 @@
5759
@Platforms(Platform.HOSTED_ONLY.class)
5860
public class JfrEventSubstitution extends SubstitutionProcessor {
5961

62+
private final ImageHeapScanner heapScanner;
63+
6064
private final ResolvedJavaType baseEventType;
6165
private final ConcurrentHashMap<ResolvedJavaType, Boolean> typeSubstitution;
6266
private final ConcurrentHashMap<ResolvedJavaMethod, ResolvedJavaMethod> methodSubstitutions;
6367
private final ConcurrentHashMap<ResolvedJavaField, ResolvedJavaField> fieldSubstitutions;
6468
private final Map<String, Class<? extends jdk.jfr.Event>> mirrorEventMapping;
6569

6670
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);
6772

68-
JfrEventSubstitution(MetaAccessProvider metaAccess) {
73+
JfrEventSubstitution(MetaAccessProvider metaAccess, ImageHeapScanner heapScanner) {
74+
this.heapScanner = heapScanner;
6975
baseEventType = metaAccess.lookupJavaType(jdk.internal.event.Event.class);
7076
typeSubstitution = new ConcurrentHashMap<>();
7177
methodSubstitutions = new ConcurrentHashMap<>();
@@ -147,6 +153,7 @@ private static ResolvedJavaMethod initEventMethod(ResolvedJavaMethod oldMethod)
147153
}
148154

149155
private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeException {
156+
VMError.guarantee(!BuildPhaseProvider.isAnalysisFinished());
150157
try {
151158
Class<? extends jdk.internal.event.Event> newEventClass = OriginalClassProvider.getJavaClass(eventType).asSubclass(jdk.internal.event.Event.class);
152159
eventType.initialize();
@@ -170,6 +177,10 @@ private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeExcepti
170177
// the reflection registration for the event handler field is delayed to the JfrFeature
171178
// duringAnalysis callback so it does not race/interfere with other retransforms
172179
JfrJdkCompatibility.retransformClasses(new Class<?>[]{newEventClass});
180+
181+
// make sure the EventConfiguration object is fully scanned
182+
heapScanner.rescanObject(getConfiguration.invoke(JfrJdkCompatibility.getJVMOrNull(), newEventClass));
183+
173184
return Boolean.TRUE;
174185
} catch (Throwable ex) {
175186
throw VMError.shouldNotReachHere(ex);

0 commit comments

Comments
 (0)