diff --git a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp index 6f26c5cdff8..1a1e0ba7fd6 100644 --- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp +++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp @@ -3037,6 +3037,13 @@ C2V_VMENTRY_0(jboolean, addFailedSpeculation, (JNIEnv* env, jobject, jlong faile C2V_END C2V_VMENTRY(void, callSystemExit, (JNIEnv* env, jobject, jint status)) + if (!JVMCIENV->is_hotspot()) { + // It's generally not safe to call Java code before the module system is initialized + if (!Universe::is_module_initialized()) { + JVMCI_event_1("callSystemExit(%d) before Universe::is_module_initialized() -> direct VM exit", status); + vm_exit_during_initialization(); + } + } CompilerThreadCanCallJava canCallJava(thread, true); JavaValue result(T_VOID); JavaCallArguments jargs(1); diff --git a/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java b/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java index 1fec1eeb278..77d5e7e91fa 100644 --- a/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java +++ b/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java @@ -48,9 +48,13 @@ public class TestInvalidJVMCIOption { "Error parsing JVMCI options: Could not find option jvmci.XXXXXXXXX%n" + "Error: A fatal exception has occurred. Program will exit.%n"); - Asserts.assertEQ(expectStdout, output.getStdout()); - output.stderrShouldBeEmpty(); + // Test for containment instead of equality as -XX:+EagerJVMCI means + // the main thread and one or more libjvmci compiler threads + // may initialize libjvmci at the same time and thus the error + // message can appear multiple times. + output.stdoutShouldContain(expectStdout); + output.stderrShouldBeEmpty(); output.shouldHaveExitValue(1); } }