# HG changeset patch # User thartmann # Date 1522144299 -7200 # Node ID c5b066caefba6d3fce42b11d7e3d1ee03a6ae381 # Parent 82634a458dc8c3681dec5752142920c4900f769a 8200230: [Graal] Compilations should not be enqueued before Graal is initialized Summary: Split compiler initialization into two phases to avoid compilations being enqueued before Graal is initialized. Reviewed-by: kvn, dnsimon diff -r 82634a458dc8 -r c5b066caefba src/hotspot/share/compiler/compileBroker.cpp --- a/src/hotspot/share/compiler/compileBroker.cpp Tue Mar 27 11:13:11 2018 +0200 +++ b/src/hotspot/share/compiler/compileBroker.cpp Tue Mar 27 11:51:39 2018 +0200 @@ -524,7 +524,7 @@ // CompileBroker::compilation_init // // Initialize the Compilation object -void CompileBroker::compilation_init(TRAPS) { +void CompileBroker::compilation_init_phase1(TRAPS) { _last_method_compiled[0] = '\0'; // No need to initialize compilation system if we do not use it. @@ -671,11 +671,14 @@ (jlong)CompileBroker::no_compile, CHECK); } +} +// Completes compiler initialization. Compilation requests submitted +// prior to this will be silently ignored. +void CompileBroker::compilation_init_phase2() { _initialized = true; } - JavaThread* CompileBroker::make_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, AbstractCompiler* comp, bool compiler_thread, TRAPS) { JavaThread* thread = NULL; diff -r 82634a458dc8 -r c5b066caefba src/hotspot/share/compiler/compileBroker.hpp --- a/src/hotspot/share/compiler/compileBroker.hpp Tue Mar 27 11:13:11 2018 +0200 +++ b/src/hotspot/share/compiler/compileBroker.hpp Tue Mar 27 11:51:39 2018 +0200 @@ -282,7 +282,8 @@ CompileQueue *q = compile_queue(comp_level); return q != NULL ? q->size() : 0; } - static void compilation_init(TRAPS); + static void compilation_init_phase1(TRAPS); + static void compilation_init_phase2(); static void init_compiler_thread_log(); static nmethod* compile_method(const methodHandle& method, int osr_bci, diff -r 82634a458dc8 -r c5b066caefba src/hotspot/share/runtime/thread.cpp --- a/src/hotspot/share/runtime/thread.cpp Tue Mar 27 11:13:11 2018 +0200 +++ b/src/hotspot/share/runtime/thread.cpp Tue Mar 27 11:51:39 2018 +0200 @@ -3835,7 +3835,28 @@ // initialize compiler(s) #if defined(COMPILER1) || COMPILER2_OR_JVMCI - CompileBroker::compilation_init(CHECK_JNI_ERR); +#if INCLUDE_JVMCI + bool force_JVMCI_intialization = false; + if (EnableJVMCI) { + // Initialize JVMCI eagerly when it is explicitly requested. + // Or when JVMCIPrintProperties is enabled. + // The JVMCI Java initialization code will read this flag and + // do the printing if it's set. + force_JVMCI_intialization = EagerJVMCI || JVMCIPrintProperties; + + 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); + } + } +#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(); + } #endif // Pre-initialize some JSR292 core classes to avoid deadlock during class loading. @@ -3862,22 +3883,9 @@ SystemDictionary::compute_java_loaders(CHECK_JNI_ERR); #if INCLUDE_JVMCI - if (EnableJVMCI) { - // Initialize JVMCI eagerly when it is explicitly requested. - // Or when JVMCIPrintProperties is enabled. - // The JVMCI Java initialization code will read this flag and - // do the printing if it's set. - bool init = EagerJVMCI || JVMCIPrintProperties; - - if (!init) { - // 8145270: Force initialization of JVMCI runtime otherwise requests for blocking - // compilations via JVMCI will not actually block until JVMCI is initialized. - init = UseJVMCICompiler && (!UseInterpreter || !BackgroundCompilation); - } - - if (init) { - JVMCIRuntime::force_initialization(CHECK_JNI_ERR); - } + if (force_JVMCI_intialization) { + JVMCIRuntime::force_initialization(CHECK_JNI_ERR); + CompileBroker::compilation_init_phase2(); } #endif