1 /* 2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include "precompiled.hpp" 25 #include "compiler/compileBroker.hpp" 26 #include "classfile/moduleEntry.hpp" 27 #include "jvmci/jvmciEnv.hpp" 28 #include "jvmci/jvmciRuntime.hpp" 29 #include "oops/objArrayOop.inline.hpp" 30 #include "runtime/compilationPolicy.hpp" 31 #include "runtime/handles.inline.hpp" 32 33 JVMCICompiler* JVMCICompiler::_instance = NULL; 34 elapsedTimer JVMCICompiler::_codeInstallTimer; 35 36 JVMCICompiler::JVMCICompiler() : AbstractCompiler(compiler_jvmci) { 37 _bootstrapping = false; 38 _bootstrap_compilation_request_handled = false; 39 _methods_compiled = 0; 40 assert(_instance == NULL, "only one instance allowed"); 41 _instance = this; 42 } 43 44 // Initialization 45 void JVMCICompiler::initialize() { 46 if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) { 47 return; 48 } 49 50 set_state(initialized); 51 52 // JVMCI is considered as application code so we need to 53 // stop the VM deferring compilation now. 54 CompilationPolicy::completed_vm_startup(); 55 } 56 57 void JVMCICompiler::bootstrap(TRAPS) { 58 if (Arguments::mode() == Arguments::_int) { 59 // Nothing to do in -Xint mode 60 return; 61 } 62 #ifndef PRODUCT 63 // We turn off CompileTheWorld so that compilation requests are not 64 // ignored during bootstrap or that JVMCI can be compiled by C1/C2. 65 FlagSetting ctwOff(CompileTheWorld, false); 66 #endif 67 68 _bootstrapping = true; 69 ResourceMark rm; 70 HandleMark hm; 71 if (PrintBootstrap) { 72 tty->print("Bootstrapping JVMCI"); 73 } 74 jlong start = os::javaTimeMillis(); 75 76 Array<Method*>* objectMethods = SystemDictionary::Object_klass()->methods(); 77 // Initialize compile queue with a selected set of methods. 78 int len = objectMethods->length(); 79 for (int i = 0; i < len; i++) { 80 methodHandle mh = objectMethods->at(i); 81 if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) { 82 ResourceMark rm; 83 int hot_count = 10; // TODO: what's the appropriate value? 84 CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, CompileTask::Reason_Bootstrap, THREAD); 85 } 86 } 87 88 int qsize; 89 bool first_round = true; 90 int z = 0; 91 do { 92 // Loop until there is something in the queue. 93 do { 94 os::sleep(THREAD, 100, true); 95 qsize = CompileBroker::queue_size(CompLevel_full_optimization); 96 } while (!_bootstrap_compilation_request_handled && first_round && qsize == 0); 97 first_round = false; 98 if (PrintBootstrap) { 99 while (z < (_methods_compiled / 100)) { 100 ++z; 101 tty->print_raw("."); 102 } 103 } 104 } while (qsize != 0); 105 106 if (PrintBootstrap) { 107 tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled); 108 } 109 _bootstrapping = false; 110 JVMCI::java_runtime()->bootstrap_finished(CHECK); 111 } 112 113 bool JVMCICompiler::force_comp_at_level_simple(Method *method) { 114 if (_bootstrapping) { 115 // When bootstrapping, the JVMCI compiler can compile its own methods. 116 return false; 117 } 118 if (UseJVMCINativeLibrary) { 119 // This mechanism exists to force compilation of a JVMCI compiler by C1 120 // to reduce the compilation time spent on the JVMCI compiler itself. In 121 // +UseJVMCINativeLibrary mode, the JVMCI compiler is AOT compiled. 122 return false; 123 } else { 124 JVMCIRuntime* runtime = JVMCI::java_runtime(); 125 if (runtime != NULL) { 126 JVMCIObject receiver = runtime->probe_HotSpotJVMCIRuntime(); 127 if (receiver.is_null()) { 128 return false; 129 } 130 JVMCIEnv* ignored_env = NULL; 131 objArrayHandle excludeModules(JavaThread::current(), HotSpotJVMCI::HotSpotJVMCIRuntime::excludeFromJVMCICompilation(ignored_env, HotSpotJVMCI::resolve(receiver))); 132 if (excludeModules.not_null()) { 133 ModuleEntry* moduleEntry = method->method_holder()->module(); 134 for (int i = 0; i < excludeModules->length(); i++) { 135 if (oopDesc::equals(excludeModules->obj_at(i), moduleEntry->module())) { 136 return true; 137 } 138 } 139 } 140 } 141 return false; 142 } 143 } 144 145 // Compilation entry point for methods 146 void JVMCICompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, DirectiveSet* directive) { 147 ShouldNotReachHere(); 148 } 149 150 // Print compilation timers and statistics 151 void JVMCICompiler::print_timers() { 152 print_compilation_timers(); 153 } 154 155 // Print compilation timers and statistics 156 void JVMCICompiler::print_compilation_timers() { 157 TRACE_jvmci_1("JVMCICompiler::print_timers"); 158 tty->print_cr(" JVMCI code install time: %6.3f s", _codeInstallTimer.seconds()); 159 }