rev 55090 : secret-sfac
1 /* 2 * Copyright (c) 2011, 2019, 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 "jvm.h" 26 #include "memory/oopFactory.hpp" 27 #include "memory/resourceArea.hpp" 28 #include "oops/oop.inline.hpp" 29 #include "runtime/javaCalls.hpp" 30 #include "runtime/handles.hpp" 31 #include "jvmci/jvmciJavaClasses.hpp" 32 #include "jvmci/jvmciCompiler.hpp" 33 #include "jvmci/jvmciEnv.hpp" 34 #include "jvmci/jvmciRuntime.hpp" 35 #include "runtime/compilationPolicy.hpp" 36 #include "runtime/globals_extension.hpp" 37 #include "runtime/handles.inline.hpp" 38 39 JVMCICompiler* JVMCICompiler::_instance = NULL; 40 elapsedTimer JVMCICompiler::_codeInstallTimer; 41 42 JVMCICompiler::JVMCICompiler() : AbstractCompiler(compiler_jvmci) { 43 _bootstrapping = false; 44 _bootstrap_compilation_request_handled = false; 45 _methods_compiled = 0; 46 assert(_instance == NULL, "only one instance allowed"); 47 _instance = this; 48 } 49 50 // Initialization 51 void JVMCICompiler::initialize() { 52 if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) { 53 return; 54 } 55 56 set_state(initialized); 57 } 58 59 void JVMCICompiler::bootstrap(TRAPS) { 60 if (Arguments::mode() == Arguments::_int) { 61 // Nothing to do in -Xint mode 62 return; 63 } 64 _bootstrapping = true; 65 ResourceMark rm; 66 HandleMark hm; 67 if (PrintBootstrap) { 68 tty->print("Bootstrapping JVMCI"); 69 } 70 jlong start = os::javaTimeMillis(); 71 72 Array<Method*>* objectMethods = SystemDictionary::Object_klass()->methods(); 73 // Initialize compile queue with a selected set of methods. 74 int len = objectMethods->length(); 75 for (int i = 0; i < len; i++) { 76 methodHandle mh = objectMethods->at(i); 77 if (!mh->is_native() && 78 !mh->is_static() && 79 !mh->is_object_constructor() && 80 !mh->is_class_initializer()) { 81 ResourceMark rm; 82 int hot_count = 10; // TODO: what's the appropriate value? 83 CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, CompileTask::Reason_Bootstrap, THREAD); 84 } 85 } 86 87 int qsize; 88 bool first_round = true; 89 int z = 0; 90 do { 91 // Loop until there is something in the queue. 92 do { 93 os::sleep(THREAD, 100, true); 94 qsize = CompileBroker::queue_size(CompLevel_full_optimization); 95 } while (!_bootstrap_compilation_request_handled && first_round && qsize == 0); 96 first_round = false; 97 if (PrintBootstrap) { 98 while (z < (_methods_compiled / 100)) { 99 ++z; 100 tty->print_raw("."); 101 } 102 } 103 } while (qsize != 0); 104 105 if (PrintBootstrap) { 106 tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled); 107 } 108 _bootstrapping = false; 109 JVMCIRuntime::bootstrap_finished(CHECK); 110 } 111 112 #define CHECK_EXIT THREAD); \ 113 if (HAS_PENDING_EXCEPTION) { \ 114 char buf[256]; \ 115 jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ 116 JVMCICompiler::exit_on_pending_exception(PENDING_EXCEPTION, buf); \ 117 return; \ 118 } \ 119 (void)(0 120 121 void JVMCICompiler::compile_method(const methodHandle& method, int entry_bci, JVMCIEnv* env) { 122 JVMCI_EXCEPTION_CONTEXT 123 124 bool is_osr = entry_bci != InvocationEntryBci; 125 if (_bootstrapping && is_osr) { 126 // no OSR compilations during bootstrap - the compiler is just too slow at this point, 127 // and we know that there are no endless loops 128 env->set_failure(true, "No OSR during boostrap"); 129 return; 130 } 131 132 JVMCIRuntime::initialize_well_known_classes(CHECK_EXIT); 133 134 HandleMark hm; 135 Handle receiver = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK_EXIT); 136 137 JavaValue method_result(T_OBJECT); 138 JavaCallArguments args; 139 args.push_long((jlong) (address) method()); 140 JavaCalls::call_static(&method_result, SystemDictionary::HotSpotResolvedJavaMethodImpl_klass(), 141 vmSymbols::fromMetaspace_name(), vmSymbols::method_fromMetaspace_signature(), &args, THREAD); 142 143 JavaValue result(T_OBJECT); 144 if (!HAS_PENDING_EXCEPTION) { 145 JavaCallArguments args; 146 args.push_oop(receiver); 147 args.push_oop(Handle(THREAD, (oop)method_result.get_jobject())); 148 args.push_int(entry_bci); 149 args.push_long((jlong) (address) env); 150 args.push_int(env->task()->compile_id()); 151 JavaCalls::call_special(&result, receiver->klass(), 152 vmSymbols::compileMethod_name(), vmSymbols::compileMethod_signature(), &args, THREAD); 153 } 154 155 // An uncaught exception was thrown during compilation. Generally these 156 // should be handled by the Java code in some useful way but if they leak 157 // through to here report them instead of dying or silently ignoring them. 158 if (HAS_PENDING_EXCEPTION) { 159 Handle exception(THREAD, PENDING_EXCEPTION); 160 CLEAR_PENDING_EXCEPTION; 161 162 java_lang_Throwable::java_printStackTrace(exception, THREAD); 163 if (HAS_PENDING_EXCEPTION) { 164 CLEAR_PENDING_EXCEPTION; 165 } 166 167 env->set_failure(false, "unexpected exception thrown"); 168 } else { 169 oop result_object = (oop) result.get_jobject(); 170 if (result_object != NULL) { 171 oop failure_message = HotSpotCompilationRequestResult::failureMessage(result_object); 172 if (failure_message != NULL) { 173 // Copy failure reason into resource memory first ... 174 const char* failure_reason = java_lang_String::as_utf8_string(failure_message); 175 // ... and then into the C heap. 176 failure_reason = os::strdup(failure_reason, mtCompiler); 177 bool retryable = HotSpotCompilationRequestResult::retry(result_object) != 0; 178 env->set_failure(retryable, failure_reason, true); 179 } else { 180 if (env->task()->code() == NULL) { 181 env->set_failure(true, "no nmethod produced"); 182 } else { 183 env->task()->set_num_inlined_bytecodes(HotSpotCompilationRequestResult::inlinedBytecodes(result_object)); 184 Atomic::inc(&_methods_compiled); 185 } 186 } 187 } else { 188 assert(false, "JVMCICompiler.compileMethod should always return non-null"); 189 } 190 } 191 if (_bootstrapping) { 192 _bootstrap_compilation_request_handled = true; 193 } 194 } 195 196 CompLevel JVMCIRuntime::adjust_comp_level(const methodHandle& method, bool is_osr, CompLevel level, JavaThread* thread) { 197 if (!thread->adjusting_comp_level()) { 198 thread->set_adjusting_comp_level(true); 199 level = adjust_comp_level_inner(method, is_osr, level, thread); 200 thread->set_adjusting_comp_level(false); 201 } 202 return level; 203 } 204 205 void JVMCICompiler::exit_on_pending_exception(oop exception, const char* message) { 206 JavaThread* THREAD = JavaThread::current(); 207 CLEAR_PENDING_EXCEPTION; 208 209 static volatile int report_error = 0; 210 if (!report_error && Atomic::cmpxchg(1, &report_error, 0) == 0) { 211 // Only report an error once 212 tty->print_raw_cr(message); 213 Handle ex(THREAD, exception); 214 java_lang_Throwable::java_printStackTrace(ex, THREAD); 215 } else { 216 // Allow error reporting thread to print the stack trace. Windows 217 // doesn't allow uninterruptible wait for JavaThreads 218 const bool interruptible = true; 219 os::sleep(THREAD, 200, interruptible); 220 } 221 222 before_exit(THREAD); 223 vm_exit(-1); 224 } 225 226 // Compilation entry point for methods 227 void JVMCICompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, DirectiveSet* directive) { 228 ShouldNotReachHere(); 229 } 230 231 // Print compilation timers and statistics 232 void JVMCICompiler::print_timers() { 233 print_compilation_timers(); 234 } 235 236 // Print compilation timers and statistics 237 void JVMCICompiler::print_compilation_timers() { 238 TRACE_jvmci_1("JVMCICompiler::print_timers"); 239 tty->print_cr(" JVMCI code install time: %6.3f s", _codeInstallTimer.seconds()); 240 } --- EOF ---