diff --git a/src/hotspot/share/compiler/compileBroker.cpp b/src/hotspot/share/compiler/compileBroker.cpp index bdc023d0dbe..a3934129344 100644 --- a/src/hotspot/share/compiler/compileBroker.cpp +++ b/src/hotspot/share/compiler/compileBroker.cpp @@ -1320,6 +1320,13 @@ nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci, AbstractCompiler *comp = CompileBroker::compiler(comp_level); assert(comp != nullptr, "Ensure we have a compiler"); +#if INCLUDE_JVMCI + if (comp->is_jvmci() && !JVMCI::can_initialize_JVMCI()) { + // JVMCI compilation is not yet initializable. + return nullptr; + } +#endif + DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp); // CompileBroker::compile_method can trap and can have pending async exception. nmethod* nm = CompileBroker::compile_method(method, osr_bci, comp_level, hot_method, hot_count, compile_reason, directive, THREAD); @@ -1348,12 +1355,6 @@ nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci, return nullptr; } -#if INCLUDE_JVMCI - if (comp->is_jvmci() && !JVMCI::can_initialize_JVMCI()) { - return nullptr; - } -#endif - if (osr_bci == InvocationEntryBci) { // standard compilation CompiledMethod* method_code = method->code(); diff --git a/src/hotspot/share/compiler/compileBroker.hpp b/src/hotspot/share/compiler/compileBroker.hpp index e89ac326c4e..26029307a5e 100644 --- a/src/hotspot/share/compiler/compileBroker.hpp +++ b/src/hotspot/share/compiler/compileBroker.hpp @@ -301,7 +301,7 @@ public: int hot_count, CompileTask::CompileReason compile_reason, TRAPS); - +private: static nmethod* compile_method(const methodHandle& method, int osr_bci, int comp_level, @@ -311,6 +311,7 @@ public: DirectiveSet* directive, TRAPS); +public: // Acquire any needed locks and assign a compile id static int assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci); diff --git a/src/hotspot/share/jvmci/jvmci.cpp b/src/hotspot/share/jvmci/jvmci.cpp index 78b3e3004df..12b400478ca 100644 --- a/src/hotspot/share/jvmci/jvmci.cpp +++ b/src/hotspot/share/jvmci/jvmci.cpp @@ -56,6 +56,11 @@ const char* JVMCI::_fatal_log_filename = nullptr; void jvmci_vmStructs_init() NOT_DEBUG_RETURN; bool JVMCI::can_initialize_JVMCI() { + if (UseJVMCINativeLibrary) { + // Initializing libjvmci does not execute Java code so + // can be done any time. + return true; + } // Initializing JVMCI requires the module system to be initialized past phase 3. // The JVMCI API itself isn't available until phase 2 and ServiceLoader (which // JVMCI initialization requires) isn't usable until after phase 3. Testing diff --git a/src/hotspot/share/runtime/threads.cpp b/src/hotspot/share/runtime/threads.cpp index 23c1562255a..70f61ab6f55 100644 --- a/src/hotspot/share/runtime/threads.cpp +++ b/src/hotspot/share/runtime/threads.cpp @@ -693,25 +693,15 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { // initialize compiler(s) #if defined(COMPILER1) || COMPILER2_OR_JVMCI #if INCLUDE_JVMCI - bool force_JVMCI_intialization = false; + bool force_JVMCI_initialization = false; if (EnableJVMCI) { // Initialize JVMCI eagerly when it is explicitly requested. // Or when JVMCILibDumpJNIConfig or JVMCIPrintProperties is enabled. - force_JVMCI_intialization = EagerJVMCI || JVMCIPrintProperties || JVMCILibDumpJNIConfig; - - if (!force_JVMCI_intialization) { - // 8145270: Force initialization of JVMCI runtime otherwise requests for blocking - // compilations via JVMCI will not actually block until JVMCI is initialized. - force_JVMCI_intialization = UseJVMCICompiler && (!UseInterpreter || !BackgroundCompilation); - } + force_JVMCI_initialization = EagerJVMCI || JVMCIPrintProperties || JVMCILibDumpJNIConfig; } #endif CompileBroker::compilation_init_phase1(CHECK_JNI_ERR); - // Postpone completion of compiler initialization to after JVMCI - // is initialized to avoid timeouts of blocking compilations. - if (JVMCI_ONLY(!force_JVMCI_intialization) NOT_JVMCI(true)) { - CompileBroker::compilation_init_phase2(); - } + CompileBroker::compilation_init_phase2(); #endif // Start string deduplication thread if requested. @@ -754,9 +744,8 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { #endif #if INCLUDE_JVMCI - if (force_JVMCI_intialization) { + if (force_JVMCI_initialization) { JVMCI::initialize_compiler(CHECK_JNI_ERR); - CompileBroker::compilation_init_phase2(); } #endif