Skip to content

Commit 45990d3

Browse files
[GR-72086] Espresso: Open JVMCI to jdk.graal.compiler earlier.
PullRequest: graal/22928
2 parents 38a32f6 + ac6912a commit 45990d3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/jvmci/Target_com_oracle_truffle_espresso_jvmci_EspressoJVMCIRuntime.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ private Target_com_oracle_truffle_espresso_jvmci_EspressoJVMCIRuntime() {
7070
if (meta.jvmci.DummyEspressoGraalJVMCICompiler == null) {
7171
throw meta.throwNoClassDefFoundErrorBoundary("com.oracle.truffle.espresso.graal.DummyEspressoGraalJVMCICompiler is missing");
7272
}
73-
openJVMCITo(meta.jvmci.GraalJVMCICompiler.module(), meta);
73+
/*
74+
* JVMCI.initializeRuntime has already opened JVMCI to jdk.graal.compiler. Let's further
75+
* open it to jdk.graal.compiler.espresso.
76+
*/
7477
openJVMCITo(meta.jvmci.DummyEspressoGraalJVMCICompiler.module(), meta);
7578
LOGGER.fine("Creating DummyEspressoGraalJVMCICompiler");
7679
return (StaticObject) meta.jvmci.DummyEspressoGraalJVMCICompiler_create.invokeDirectStatic(self);
7780
}
7881

79-
private static void openJVMCITo(ModuleTable.ModuleEntry compilerModuleEntry, Meta meta) {
82+
static void openJVMCITo(ModuleTable.ModuleEntry compilerModuleEntry, Meta meta) {
8083
LOGGER.finer(() -> "Opening JVMCI to " + compilerModuleEntry.getNameAsString());
8184
StaticObject compilerModule = compilerModuleEntry.module();
8285
meta.jvmci.Services_openJVMCITo.invokeDirectStatic(compilerModule);

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/jvmci/Target_jdk_vm_ci_runtime_JVMCI.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package com.oracle.truffle.espresso.substitutions.jvmci;
2424

25+
import static com.oracle.truffle.espresso.substitutions.jvmci.Target_com_oracle_truffle_espresso_jvmci_EspressoJVMCIRuntime.openJVMCITo;
26+
2527
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2628
import com.oracle.truffle.espresso.EspressoLanguage;
2729
import com.oracle.truffle.espresso.meta.Meta;
@@ -42,6 +44,23 @@ private Target_jdk_vm_ci_runtime_JVMCI() {
4244
@Substitution
4345
public static @JavaType(internalName = "Ljdk/vm/ci/runtime/JVMCIRuntime;") StaticObject initializeRuntime(@Inject EspressoContext context) {
4446
checkJVMCIAvailable(context.getLanguage());
47+
Meta meta = context.getMeta();
48+
if (meta.jvmci.GraalJVMCICompiler != null) {
49+
/*
50+
* On HotSpot, HotSpotJVMCIRuntime.runtime uses JVMCIServiceLocator.getProviders which
51+
* triggers Services.openJVMCITo for the module of HotSpotGraalJVMCIServiceLocator
52+
* (jdk.graal.compiler). Achieve the same here by directly calling Services.openJVMCITo
53+
* for the module of GraalJVMCICompiler (jdk.graal.compiler).
54+
*
55+
* Note that it is not enough to do this in
56+
* EspressoJVMCIRuntime.createEspressoGraalJVMCICompiler since GraalServices could be
57+
* used before the compiler is initialized.
58+
*
59+
* This is done only if GraalJVMCICompiler exists (i.e., jdk.graal.compiler is not an
60+
* empty module).
61+
*/
62+
openJVMCITo(meta.jvmci.GraalJVMCICompiler.module(), meta);
63+
}
4564
return (StaticObject) context.getMeta().jvmci.EspressoJVMCIRuntime_runtime.invokeDirectStatic();
4665
}
4766

0 commit comments

Comments
 (0)