From 19c9388c2001b7b3d21624e2dd4ab4fdd8821e2f Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Tue, 16 Jan 2024 19:31:04 +0000 Subject: [PATCH] 8323616: [JVMCI] TestInvalidJVMCIOption.java fails intermittently with NPE Reviewed-by: thartmann, never --- src/hotspot/share/jvmci/jvmciCompilerToVM.cpp | 7 +++++++ .../jtreg/compiler/jvmci/TestInvalidJVMCIOption.java | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp index 6f26c5cdff81c..1a1e0ba7fd64b 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 1fec1eeb278c5..77d5e7e91fa2c 100644 --- a/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java +++ b/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java @@ -48,9 +48,13 @@ public static void main(String[] args) throws Exception { "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); } }