--- old/src/share/vm/compiler/compileBroker.cpp 2016-06-27 19:50:34.000000000 -0700 +++ new/src/share/vm/compiler/compileBroker.cpp 2016-06-27 19:50:34.000000000 -0700 @@ -551,17 +551,6 @@ } else { c1_count = JVMCIHostThreads; } - - if (!UseInterpreter || !BackgroundCompilation) { - // Force initialization of JVMCI compiler otherwise JVMCI - // compilations will not block until JVMCI is initialized - ResourceMark rm; - TempNewSymbol getCompiler = SymbolTable::new_symbol("getCompiler", CHECK); - TempNewSymbol sig = SymbolTable::new_symbol("()Ljdk/vm/ci/runtime/JVMCICompiler;", CHECK); - Handle jvmciRuntime = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK); - JavaValue result(T_OBJECT); - JavaCalls::call_virtual(&result, jvmciRuntime, HotSpotJVMCIRuntime::klass(), getCompiler, sig, CHECK); - } } } #endif // INCLUDE_JVMCI --- old/src/share/vm/jvmci/jvmciRuntime.cpp 2016-06-27 19:50:35.000000000 -0700 +++ new/src/share/vm/jvmci/jvmciRuntime.cpp 2016-06-27 19:50:34.000000000 -0700 @@ -612,6 +612,17 @@ return value; JRT_END +void JVMCIRuntime::force_initialization(TRAPS) { + JVMCIRuntime::initialize_well_known_classes(CHECK); + + ResourceMark rm; + TempNewSymbol getCompiler = SymbolTable::new_symbol("getCompiler", CHECK); + TempNewSymbol sig = SymbolTable::new_symbol("()Ljdk/vm/ci/runtime/JVMCICompiler;", CHECK); + Handle jvmciRuntime = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK); + JavaValue result(T_OBJECT); + JavaCalls::call_virtual(&result, jvmciRuntime, HotSpotJVMCIRuntime::klass(), getCompiler, sig, CHECK); +} + // private static JVMCIRuntime JVMCI.initializeRuntime() JVM_ENTRY(jobject, JVM_GetJVMCIRuntime(JNIEnv *env, jclass c)) if (!EnableJVMCI) { --- old/src/share/vm/jvmci/jvmciRuntime.hpp 2016-06-27 19:50:35.000000000 -0700 +++ new/src/share/vm/jvmci/jvmciRuntime.hpp 2016-06-27 19:50:35.000000000 -0700 @@ -157,6 +157,9 @@ static void throw_klass_external_name_exception(JavaThread* thread, const char* exception, Klass* klass); static void throw_class_cast_exception(JavaThread* thread, const char* exception, Klass* caster_klass, Klass* target_klass); + // Forces initialization of the JVMCI runtime. + static void force_initialization(TRAPS); + // Test only function static int test_deoptimize_call_int(JavaThread* thread, int value); }; --- old/src/share/vm/runtime/simpleThresholdPolicy.cpp 2016-06-27 19:50:35.000000000 -0700 +++ new/src/share/vm/runtime/simpleThresholdPolicy.cpp 2016-06-27 19:50:35.000000000 -0700 @@ -238,8 +238,11 @@ } #if INCLUDE_JVMCI - // We can't compile with a JVMCI compiler until the module system is initialized. - if (level == CompLevel_full_optimization && UseJVMCICompiler && !Universe::is_module_initialized()) { + // We can't compile with a JVMCI compiler until the module system is initialized past + // phase 3. The JVMCI API itself isn't available until phase 2 and ServiceLoader isn't + // usable until after phase 3. + if (level == CompLevel_full_optimization && UseJVMCICompiler && SystemDictionary::java_system_loader() == NULL) { + assert(Universe::is_module_initialized(), "must be"); return; } #endif --- old/src/share/vm/runtime/thread.cpp 2016-06-27 19:50:36.000000000 -0700 +++ new/src/share/vm/runtime/thread.cpp 2016-06-27 19:50:36.000000000 -0700 @@ -3770,6 +3770,13 @@ // Final system initialization including security manager and system class loader call_initPhase3(CHECK_JNI_ERR); +#ifdef INCLUDE_JVMCI + if (EnableJVMCI && UseJVMCICompiler && (!UseInterpreter || !BackgroundCompilation)) { + // 8145270: Force initialization of JVMCI runtime otherwise requests for blocking + // compilations via JVMCI will not actually block until JVMCI is initialized. + JVMCIRuntime::force_initialization(CHECK_JNI_ERR); + } +#endif // cache the system class loader SystemDictionary::compute_java_system_loader(CHECK_(JNI_ERR)); --- old/test/compiler/jvmci/events/JvmciNotifyBootstrapFinishedEventTest.java 2016-06-27 19:50:36.000000000 -0700 +++ new/test/compiler/jvmci/events/JvmciNotifyBootstrapFinishedEventTest.java 2016-06-27 19:50:36.000000000 -0700 @@ -43,6 +43,8 @@ * @run main ClassFileInstaller * compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler * compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory + * compiler.jvmci.common.JVMCIHelpers$EmptyCompilationRequestResult + * compiler.jvmci.common.JVMCIHelpers$EmptyVMEventListener * compiler.jvmci.events.JvmciNotifyBootstrapFinishedEventTest * jdk.test.lib.Asserts * jdk.test.lib.Utils --- old/test/compiler/jvmci/events/JvmciNotifyInstallEventTest.java 2016-06-27 19:50:37.000000000 -0700 +++ new/test/compiler/jvmci/events/JvmciNotifyInstallEventTest.java 2016-06-27 19:50:36.000000000 -0700 @@ -44,6 +44,8 @@ * @run main ClassFileInstaller * compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler * compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory + * compiler.jvmci.common.JVMCIHelpers$EmptyCompilationRequestResult + * compiler.jvmci.common.JVMCIHelpers$EmptyVMEventListener * compiler.jvmci.events.JvmciNotifyInstallEventTest * compiler.jvmci.common.CTVMUtilities * compiler.jvmci.common.testcases.SimpleClass --- old/test/compiler/jvmci/events/JvmciShutdownEventTest.java 2016-06-27 19:50:37.000000000 -0700 +++ new/test/compiler/jvmci/events/JvmciShutdownEventTest.java 2016-06-27 19:50:37.000000000 -0700 @@ -40,6 +40,8 @@ * @run main ClassFileInstaller * compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler * compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory + * compiler.jvmci.common.JVMCIHelpers$EmptyCompilationRequestResult + * compiler.jvmci.common.JVMCIHelpers$EmptyVMEventListener * compiler.jvmci.events.JvmciShutdownEventListener * @run main/othervm compiler.jvmci.events.JvmciShutdownEventTest */