Skip to content

Commit aafed07

Browse files
committed
[GR-48726] Support HotSpotGraalVMEventListener being created before HotSpotGraalRuntime.
PullRequest: graal/15615
2 parents 9118437 + af56018 commit aafed07

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LazyClassLoadingTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.graalvm.compiler.hotspot.CommunityCompilerConfigurationFactory;
4545
import org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
4646
import org.graalvm.compiler.hotspot.EconomyCompilerConfigurationFactory;
47+
import org.graalvm.compiler.hotspot.HotSpotGraalVMEventListener;
4748
import org.graalvm.compiler.nodes.Cancellable;
4849
import org.graalvm.compiler.options.OptionDescriptor;
4950
import org.graalvm.compiler.options.OptionDescriptors;
@@ -259,7 +260,7 @@ private boolean isGraalClassAllowed(Class<?> cls) {
259260
return true;
260261
}
261262

262-
if (JVMCIServiceLocator.class.isAssignableFrom(cls) || cls == hotSpotGraalJVMCIServiceLocatorShared) {
263+
if (JVMCIServiceLocator.class.isAssignableFrom(cls) || cls == hotSpotGraalJVMCIServiceLocatorShared || HotSpotGraalVMEventListener.class.isAssignableFrom(cls)) {
263264
return true;
264265
}
265266

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/HotSpotGraalJVMCIServiceLocator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,29 @@ <T> T getProvider(Class<T> service, HotSpotGraalJVMCIServiceLocator locator) {
4848
if (graalRuntime != null) {
4949
return service.cast(new HotSpotGraalVMEventListener(graalRuntime));
5050
}
51+
// Need to hold onto the listener to connect it with a Graal runtime
52+
// once we have one. This supports a JVMCI runtime that eagerly
53+
// creates its VM event listeners (JDK-8315566).
54+
if (vmEventListener == null) {
55+
vmEventListener = new HotSpotGraalVMEventListener(null);
56+
}
57+
return service.cast(vmEventListener);
5158
}
5259
return null;
5360
}
5461

5562
@NativeImageReinitialize private HotSpotGraalRuntime graalRuntime;
63+
@NativeImageReinitialize private HotSpotGraalVMEventListener vmEventListener;
5664

5765
/**
5866
* Notifies this object of the compiler created via {@link HotSpotGraalJVMCIServiceLocator}.
5967
*/
6068
void onCompilerCreation(HotSpotGraalCompiler compiler) {
6169
assert this.graalRuntime == null : "only expect a single JVMCICompiler to be created";
6270
this.graalRuntime = (HotSpotGraalRuntime) compiler.getGraalRuntime();
71+
if (this.vmEventListener != null) {
72+
this.vmEventListener.setRuntime(graalRuntime);
73+
}
6374
}
6475
}
6576

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/HotSpotGraalVMEventListener.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,27 @@
3939

4040
public class HotSpotGraalVMEventListener implements HotSpotVMEventListener {
4141

42-
private final HotSpotGraalRuntime runtime;
42+
private HotSpotGraalRuntime runtime;
4343
private List<HotSpotCodeCacheListener> listeners;
4444

4545
HotSpotGraalVMEventListener(HotSpotGraalRuntime runtime) {
46-
this.runtime = runtime;
46+
setRuntime(runtime);
4747
listeners = new ArrayList<>();
4848
for (HotSpotCodeCacheListener listener : GraalServices.load(HotSpotCodeCacheListener.class)) {
4949
listeners.add(listener);
5050
}
5151
}
5252

53+
void setRuntime(HotSpotGraalRuntime runtime) {
54+
assert this.runtime == null || this.runtime == runtime;
55+
this.runtime = runtime;
56+
}
57+
5358
@Override
5459
public void notifyShutdown() {
55-
runtime.shutdown();
60+
if (runtime != null) {
61+
runtime.shutdown();
62+
}
5663
}
5764

5865
@Override

0 commit comments

Comments
 (0)