Thu, 10 Apr 2008 15:49:16 -0400
6686407: Fix for 6666698 broke -XX:BiasedLockingStartupDelay=0
Summary: Stack allocated VM_EnableBiasedLocking op must be marked as such
Reviewed-by: xlu, acorn, never, dholmes
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_compileBroker.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | #ifdef DTRACE_ENABLED |
duke@435 | 29 | |
duke@435 | 30 | // Only bother with this argument setup if dtrace is available |
duke@435 | 31 | |
duke@435 | 32 | HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin, |
duke@435 | 33 | char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t); |
duke@435 | 34 | HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end, |
duke@435 | 35 | char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t, bool); |
duke@435 | 36 | |
duke@435 | 37 | #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method) \ |
duke@435 | 38 | { \ |
duke@435 | 39 | char* comp_name = (char*)(compiler)->name(); \ |
duke@435 | 40 | symbolOop klass_name = (method)->klass_name(); \ |
duke@435 | 41 | symbolOop name = (method)->name(); \ |
duke@435 | 42 | symbolOop signature = (method)->signature(); \ |
duke@435 | 43 | HS_DTRACE_PROBE8(hotspot, method__compile__begin, \ |
duke@435 | 44 | comp_name, strlen(comp_name), \ |
duke@435 | 45 | klass_name->bytes(), klass_name->utf8_length(), \ |
duke@435 | 46 | name->bytes(), name->utf8_length(), \ |
duke@435 | 47 | signature->bytes(), signature->utf8_length()); \ |
duke@435 | 48 | } |
duke@435 | 49 | |
duke@435 | 50 | #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success) \ |
duke@435 | 51 | { \ |
duke@435 | 52 | char* comp_name = (char*)(compiler)->name(); \ |
duke@435 | 53 | symbolOop klass_name = (method)->klass_name(); \ |
duke@435 | 54 | symbolOop name = (method)->name(); \ |
duke@435 | 55 | symbolOop signature = (method)->signature(); \ |
duke@435 | 56 | HS_DTRACE_PROBE9(hotspot, method__compile__end, \ |
duke@435 | 57 | comp_name, strlen(comp_name), \ |
duke@435 | 58 | klass_name->bytes(), klass_name->utf8_length(), \ |
duke@435 | 59 | name->bytes(), name->utf8_length(), \ |
duke@435 | 60 | signature->bytes(), signature->utf8_length(), (success)); \ |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | #else // ndef DTRACE_ENABLED |
duke@435 | 64 | |
duke@435 | 65 | #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method) |
duke@435 | 66 | #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success) |
duke@435 | 67 | |
duke@435 | 68 | #endif // ndef DTRACE_ENABLED |
duke@435 | 69 | |
duke@435 | 70 | bool CompileBroker::_initialized = false; |
duke@435 | 71 | volatile bool CompileBroker::_should_block = false; |
duke@435 | 72 | |
duke@435 | 73 | // The installed compiler(s) |
duke@435 | 74 | AbstractCompiler* CompileBroker::_compilers[2]; |
duke@435 | 75 | |
duke@435 | 76 | // These counters are used for assigning id's to each compilation |
duke@435 | 77 | uint CompileBroker::_compilation_id = 0; |
duke@435 | 78 | uint CompileBroker::_osr_compilation_id = 0; |
duke@435 | 79 | |
duke@435 | 80 | // Debugging information |
duke@435 | 81 | int CompileBroker::_last_compile_type = no_compile; |
duke@435 | 82 | int CompileBroker::_last_compile_level = CompLevel_none; |
duke@435 | 83 | char CompileBroker::_last_method_compiled[CompileBroker::name_buffer_length]; |
duke@435 | 84 | |
duke@435 | 85 | // Performance counters |
duke@435 | 86 | PerfCounter* CompileBroker::_perf_total_compilation = NULL; |
duke@435 | 87 | PerfCounter* CompileBroker::_perf_osr_compilation = NULL; |
duke@435 | 88 | PerfCounter* CompileBroker::_perf_standard_compilation = NULL; |
duke@435 | 89 | |
duke@435 | 90 | PerfCounter* CompileBroker::_perf_total_bailout_count = NULL; |
duke@435 | 91 | PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL; |
duke@435 | 92 | PerfCounter* CompileBroker::_perf_total_compile_count = NULL; |
duke@435 | 93 | PerfCounter* CompileBroker::_perf_total_osr_compile_count = NULL; |
duke@435 | 94 | PerfCounter* CompileBroker::_perf_total_standard_compile_count = NULL; |
duke@435 | 95 | |
duke@435 | 96 | PerfCounter* CompileBroker::_perf_sum_osr_bytes_compiled = NULL; |
duke@435 | 97 | PerfCounter* CompileBroker::_perf_sum_standard_bytes_compiled = NULL; |
duke@435 | 98 | PerfCounter* CompileBroker::_perf_sum_nmethod_size = NULL; |
duke@435 | 99 | PerfCounter* CompileBroker::_perf_sum_nmethod_code_size = NULL; |
duke@435 | 100 | |
duke@435 | 101 | PerfStringVariable* CompileBroker::_perf_last_method = NULL; |
duke@435 | 102 | PerfStringVariable* CompileBroker::_perf_last_failed_method = NULL; |
duke@435 | 103 | PerfStringVariable* CompileBroker::_perf_last_invalidated_method = NULL; |
duke@435 | 104 | PerfVariable* CompileBroker::_perf_last_compile_type = NULL; |
duke@435 | 105 | PerfVariable* CompileBroker::_perf_last_compile_size = NULL; |
duke@435 | 106 | PerfVariable* CompileBroker::_perf_last_failed_type = NULL; |
duke@435 | 107 | PerfVariable* CompileBroker::_perf_last_invalidated_type = NULL; |
duke@435 | 108 | |
duke@435 | 109 | // Timers and counters for generating statistics |
duke@435 | 110 | elapsedTimer CompileBroker::_t_total_compilation; |
duke@435 | 111 | elapsedTimer CompileBroker::_t_osr_compilation; |
duke@435 | 112 | elapsedTimer CompileBroker::_t_standard_compilation; |
duke@435 | 113 | |
duke@435 | 114 | int CompileBroker::_total_bailout_count = 0; |
duke@435 | 115 | int CompileBroker::_total_invalidated_count = 0; |
duke@435 | 116 | int CompileBroker::_total_compile_count = 0; |
duke@435 | 117 | int CompileBroker::_total_osr_compile_count = 0; |
duke@435 | 118 | int CompileBroker::_total_standard_compile_count = 0; |
duke@435 | 119 | |
duke@435 | 120 | int CompileBroker::_sum_osr_bytes_compiled = 0; |
duke@435 | 121 | int CompileBroker::_sum_standard_bytes_compiled = 0; |
duke@435 | 122 | int CompileBroker::_sum_nmethod_size = 0; |
duke@435 | 123 | int CompileBroker::_sum_nmethod_code_size = 0; |
duke@435 | 124 | |
duke@435 | 125 | CompileQueue* CompileBroker::_method_queue = NULL; |
duke@435 | 126 | CompileTask* CompileBroker::_task_free_list = NULL; |
duke@435 | 127 | |
duke@435 | 128 | GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; |
duke@435 | 129 | |
duke@435 | 130 | // CompileTaskWrapper |
duke@435 | 131 | // |
duke@435 | 132 | // Assign this task to the current thread. Deallocate the task |
duke@435 | 133 | // when the compilation is complete. |
duke@435 | 134 | class CompileTaskWrapper : StackObj { |
duke@435 | 135 | public: |
duke@435 | 136 | CompileTaskWrapper(CompileTask* task); |
duke@435 | 137 | ~CompileTaskWrapper(); |
duke@435 | 138 | }; |
duke@435 | 139 | |
duke@435 | 140 | CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { |
duke@435 | 141 | CompilerThread* thread = CompilerThread::current(); |
duke@435 | 142 | thread->set_task(task); |
duke@435 | 143 | CompileLog* log = thread->log(); |
duke@435 | 144 | if (log != NULL) task->log_task_start(log); |
duke@435 | 145 | } |
duke@435 | 146 | |
duke@435 | 147 | CompileTaskWrapper::~CompileTaskWrapper() { |
duke@435 | 148 | CompilerThread* thread = CompilerThread::current(); |
duke@435 | 149 | CompileTask* task = thread->task(); |
duke@435 | 150 | CompileLog* log = thread->log(); |
duke@435 | 151 | if (log != NULL) task->log_task_done(log); |
duke@435 | 152 | thread->set_task(NULL); |
duke@435 | 153 | task->set_code_handle(NULL); |
duke@435 | 154 | DEBUG_ONLY(thread->set_env((ciEnv*)badAddress)); |
duke@435 | 155 | if (task->is_blocking()) { |
duke@435 | 156 | MutexLocker notifier(task->lock(), thread); |
duke@435 | 157 | task->mark_complete(); |
duke@435 | 158 | // Notify the waiting thread that the compilation has completed. |
duke@435 | 159 | task->lock()->notify_all(); |
duke@435 | 160 | } else { |
duke@435 | 161 | task->mark_complete(); |
duke@435 | 162 | |
duke@435 | 163 | // By convention, the compiling thread is responsible for |
duke@435 | 164 | // recycling a non-blocking CompileTask. |
duke@435 | 165 | CompileBroker::free_task(task); |
duke@435 | 166 | } |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | |
duke@435 | 170 | // ------------------------------------------------------------------ |
duke@435 | 171 | // CompileTask::initialize |
duke@435 | 172 | void CompileTask::initialize(int compile_id, |
duke@435 | 173 | methodHandle method, |
duke@435 | 174 | int osr_bci, |
duke@435 | 175 | int comp_level, |
duke@435 | 176 | methodHandle hot_method, |
duke@435 | 177 | int hot_count, |
duke@435 | 178 | const char* comment, |
duke@435 | 179 | bool is_blocking) { |
duke@435 | 180 | assert(!_lock->is_locked(), "bad locking"); |
duke@435 | 181 | |
duke@435 | 182 | _compile_id = compile_id; |
duke@435 | 183 | _method = JNIHandles::make_global(method); |
duke@435 | 184 | _osr_bci = osr_bci; |
duke@435 | 185 | _is_blocking = is_blocking; |
duke@435 | 186 | _comp_level = comp_level; |
duke@435 | 187 | _num_inlined_bytecodes = 0; |
duke@435 | 188 | |
duke@435 | 189 | _is_complete = false; |
duke@435 | 190 | _is_success = false; |
duke@435 | 191 | _code_handle = NULL; |
duke@435 | 192 | |
duke@435 | 193 | _hot_method = NULL; |
duke@435 | 194 | _hot_count = hot_count; |
duke@435 | 195 | _time_queued = 0; // tidy |
duke@435 | 196 | _comment = comment; |
duke@435 | 197 | |
duke@435 | 198 | if (LogCompilation) { |
duke@435 | 199 | _time_queued = os::elapsed_counter(); |
duke@435 | 200 | if (hot_method.not_null()) { |
duke@435 | 201 | if (hot_method == method) { |
duke@435 | 202 | _hot_method = _method; |
duke@435 | 203 | } else { |
duke@435 | 204 | _hot_method = JNIHandles::make_global(hot_method); |
duke@435 | 205 | } |
duke@435 | 206 | } |
duke@435 | 207 | } |
duke@435 | 208 | |
duke@435 | 209 | _next = NULL; |
duke@435 | 210 | } |
duke@435 | 211 | |
duke@435 | 212 | // ------------------------------------------------------------------ |
duke@435 | 213 | // CompileTask::code/set_code |
duke@435 | 214 | nmethod* CompileTask::code() const { |
duke@435 | 215 | if (_code_handle == NULL) return NULL; |
duke@435 | 216 | return _code_handle->code(); |
duke@435 | 217 | } |
duke@435 | 218 | void CompileTask::set_code(nmethod* nm) { |
duke@435 | 219 | if (_code_handle == NULL && nm == NULL) return; |
duke@435 | 220 | guarantee(_code_handle != NULL, ""); |
duke@435 | 221 | _code_handle->set_code(nm); |
duke@435 | 222 | if (nm == NULL) _code_handle = NULL; // drop the handle also |
duke@435 | 223 | } |
duke@435 | 224 | |
duke@435 | 225 | // ------------------------------------------------------------------ |
duke@435 | 226 | // CompileTask::free |
duke@435 | 227 | void CompileTask::free() { |
duke@435 | 228 | set_code(NULL); |
duke@435 | 229 | assert(!_lock->is_locked(), "Should not be locked when freed"); |
duke@435 | 230 | if (_hot_method != NULL && _hot_method != _method) { |
duke@435 | 231 | JNIHandles::destroy_global(_hot_method); |
duke@435 | 232 | } |
duke@435 | 233 | JNIHandles::destroy_global(_method); |
duke@435 | 234 | } |
duke@435 | 235 | |
duke@435 | 236 | |
duke@435 | 237 | // ------------------------------------------------------------------ |
duke@435 | 238 | // CompileTask::print |
duke@435 | 239 | void CompileTask::print() { |
duke@435 | 240 | tty->print("<CompileTask compile_id=%d ", _compile_id); |
duke@435 | 241 | tty->print("method="); |
duke@435 | 242 | ((methodOop)JNIHandles::resolve(_method))->print_name(tty); |
duke@435 | 243 | tty->print_cr(" osr_bci=%d is_blocking=%s is_complete=%s is_success=%s>", |
duke@435 | 244 | _osr_bci, bool_to_str(_is_blocking), |
duke@435 | 245 | bool_to_str(_is_complete), bool_to_str(_is_success)); |
duke@435 | 246 | } |
duke@435 | 247 | |
duke@435 | 248 | // ------------------------------------------------------------------ |
duke@435 | 249 | // CompileTask::print_line_on_error |
duke@435 | 250 | // |
duke@435 | 251 | // This function is called by fatal error handler when the thread |
duke@435 | 252 | // causing troubles is a compiler thread. |
duke@435 | 253 | // |
duke@435 | 254 | // Do not grab any lock, do not allocate memory. |
duke@435 | 255 | // |
duke@435 | 256 | // Otherwise it's the same as CompileTask::print_line() |
duke@435 | 257 | // |
duke@435 | 258 | void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) { |
duke@435 | 259 | methodOop method = (methodOop)JNIHandles::resolve(_method); |
duke@435 | 260 | |
duke@435 | 261 | // print compiler name |
duke@435 | 262 | st->print("%s:", CompileBroker::compiler(comp_level())->name()); |
duke@435 | 263 | |
duke@435 | 264 | // print compilation number |
duke@435 | 265 | st->print("%3d", compile_id()); |
duke@435 | 266 | |
duke@435 | 267 | // print method attributes |
duke@435 | 268 | const bool is_osr = osr_bci() != CompileBroker::standard_entry_bci; |
duke@435 | 269 | { const char blocking_char = is_blocking() ? 'b' : ' '; |
duke@435 | 270 | const char compile_type = is_osr ? '%' : ' '; |
duke@435 | 271 | const char sync_char = method->is_synchronized() ? 's' : ' '; |
duke@435 | 272 | const char exception_char = method->has_exception_handler() ? '!' : ' '; |
duke@435 | 273 | const char tier_char = |
duke@435 | 274 | is_highest_tier_compile(comp_level()) ? ' ' : ('0' + comp_level()); |
duke@435 | 275 | st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, tier_char); |
duke@435 | 276 | } |
duke@435 | 277 | |
duke@435 | 278 | // Use buf to get method name and signature |
duke@435 | 279 | if (method != NULL) st->print("%s", method->name_and_sig_as_C_string(buf, buflen)); |
duke@435 | 280 | |
duke@435 | 281 | // print osr_bci if any |
duke@435 | 282 | if (is_osr) st->print(" @ %d", osr_bci()); |
duke@435 | 283 | |
duke@435 | 284 | // print method size |
duke@435 | 285 | st->print_cr(" (%d bytes)", method->code_size()); |
duke@435 | 286 | } |
duke@435 | 287 | |
duke@435 | 288 | // ------------------------------------------------------------------ |
duke@435 | 289 | // CompileTask::print_line |
duke@435 | 290 | void CompileTask::print_line() { |
duke@435 | 291 | Thread *thread = Thread::current(); |
duke@435 | 292 | methodHandle method(thread, |
duke@435 | 293 | (methodOop)JNIHandles::resolve(method_handle())); |
duke@435 | 294 | ResourceMark rm(thread); |
duke@435 | 295 | |
duke@435 | 296 | ttyLocker ttyl; // keep the following output all in one block |
duke@435 | 297 | |
duke@435 | 298 | // print compiler name if requested |
duke@435 | 299 | if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler(comp_level())->name()); |
duke@435 | 300 | |
duke@435 | 301 | // print compilation number |
duke@435 | 302 | tty->print("%3d", compile_id()); |
duke@435 | 303 | |
duke@435 | 304 | // print method attributes |
duke@435 | 305 | const bool is_osr = osr_bci() != CompileBroker::standard_entry_bci; |
duke@435 | 306 | { const char blocking_char = is_blocking() ? 'b' : ' '; |
duke@435 | 307 | const char compile_type = is_osr ? '%' : ' '; |
duke@435 | 308 | const char sync_char = method->is_synchronized() ? 's' : ' '; |
duke@435 | 309 | const char exception_char = method->has_exception_handler() ? '!' : ' '; |
duke@435 | 310 | const char tier_char = |
duke@435 | 311 | is_highest_tier_compile(comp_level()) ? ' ' : ('0' + comp_level()); |
duke@435 | 312 | tty->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, tier_char); |
duke@435 | 313 | } |
duke@435 | 314 | |
duke@435 | 315 | // print method name |
duke@435 | 316 | method->print_short_name(tty); |
duke@435 | 317 | |
duke@435 | 318 | // print osr_bci if any |
duke@435 | 319 | if (is_osr) tty->print(" @ %d", osr_bci()); |
duke@435 | 320 | |
duke@435 | 321 | // print method size |
duke@435 | 322 | tty->print_cr(" (%d bytes)", method->code_size()); |
duke@435 | 323 | } |
duke@435 | 324 | |
duke@435 | 325 | |
duke@435 | 326 | // ------------------------------------------------------------------ |
duke@435 | 327 | // CompileTask::log_task |
duke@435 | 328 | void CompileTask::log_task(xmlStream* log) { |
duke@435 | 329 | Thread* thread = Thread::current(); |
duke@435 | 330 | methodHandle method(thread, |
duke@435 | 331 | (methodOop)JNIHandles::resolve(method_handle())); |
duke@435 | 332 | ResourceMark rm(thread); |
duke@435 | 333 | |
duke@435 | 334 | // <task id='9' method='M' osr_bci='X' level='1' blocking='1' stamp='1.234'> |
duke@435 | 335 | if (_compile_id != 0) log->print(" compile_id='%d'", _compile_id); |
duke@435 | 336 | if (_osr_bci != CompileBroker::standard_entry_bci) { |
duke@435 | 337 | log->print(" compile_kind='osr'"); // same as nmethod::compile_kind |
duke@435 | 338 | } // else compile_kind='c2c' |
duke@435 | 339 | if (!method.is_null()) log->method(method); |
duke@435 | 340 | if (_osr_bci != CompileBroker::standard_entry_bci) { |
duke@435 | 341 | log->print(" osr_bci='%d'", _osr_bci); |
duke@435 | 342 | } |
duke@435 | 343 | if (_comp_level != CompLevel_highest_tier) { |
duke@435 | 344 | log->print(" level='%d'", _comp_level); |
duke@435 | 345 | } |
duke@435 | 346 | if (_is_blocking) { |
duke@435 | 347 | log->print(" blocking='1'"); |
duke@435 | 348 | } |
duke@435 | 349 | log->stamp(); |
duke@435 | 350 | } |
duke@435 | 351 | |
duke@435 | 352 | |
duke@435 | 353 | // ------------------------------------------------------------------ |
duke@435 | 354 | // CompileTask::log_task_queued |
duke@435 | 355 | void CompileTask::log_task_queued() { |
duke@435 | 356 | Thread* thread = Thread::current(); |
duke@435 | 357 | ttyLocker ttyl; |
duke@435 | 358 | ResourceMark rm(thread); |
duke@435 | 359 | |
duke@435 | 360 | xtty->begin_elem("task_queued"); |
duke@435 | 361 | log_task(xtty); |
duke@435 | 362 | if (_comment != NULL) { |
duke@435 | 363 | xtty->print(" comment='%s'", _comment); |
duke@435 | 364 | } |
duke@435 | 365 | if (_hot_method != NULL) { |
duke@435 | 366 | methodHandle hot(thread, |
duke@435 | 367 | (methodOop)JNIHandles::resolve(_hot_method)); |
duke@435 | 368 | methodHandle method(thread, |
duke@435 | 369 | (methodOop)JNIHandles::resolve(_method)); |
duke@435 | 370 | if (hot() != method()) { |
duke@435 | 371 | xtty->method(hot); |
duke@435 | 372 | } |
duke@435 | 373 | } |
duke@435 | 374 | if (_hot_count != 0) { |
duke@435 | 375 | xtty->print(" hot_count='%d'", _hot_count); |
duke@435 | 376 | } |
duke@435 | 377 | xtty->end_elem(); |
duke@435 | 378 | } |
duke@435 | 379 | |
duke@435 | 380 | |
duke@435 | 381 | // ------------------------------------------------------------------ |
duke@435 | 382 | // CompileTask::log_task_start |
duke@435 | 383 | void CompileTask::log_task_start(CompileLog* log) { |
duke@435 | 384 | log->begin_head("task"); |
duke@435 | 385 | log_task(log); |
duke@435 | 386 | log->end_head(); |
duke@435 | 387 | } |
duke@435 | 388 | |
duke@435 | 389 | |
duke@435 | 390 | // ------------------------------------------------------------------ |
duke@435 | 391 | // CompileTask::log_task_done |
duke@435 | 392 | void CompileTask::log_task_done(CompileLog* log) { |
duke@435 | 393 | Thread* thread = Thread::current(); |
duke@435 | 394 | methodHandle method(thread, |
duke@435 | 395 | (methodOop)JNIHandles::resolve(method_handle())); |
duke@435 | 396 | ResourceMark rm(thread); |
duke@435 | 397 | |
duke@435 | 398 | // <task_done ... stamp='1.234'> </task> |
duke@435 | 399 | nmethod* nm = code(); |
duke@435 | 400 | log->begin_elem("task_done success='%d' nmsize='%d' count='%d'", |
duke@435 | 401 | _is_success, nm == NULL ? 0 : nm->instructions_size(), |
duke@435 | 402 | method->invocation_count()); |
duke@435 | 403 | int bec = method->backedge_count(); |
duke@435 | 404 | if (bec != 0) log->print(" backedge_count='%d'", bec); |
duke@435 | 405 | // Note: "_is_complete" is about to be set, but is not. |
duke@435 | 406 | if (_num_inlined_bytecodes != 0) { |
duke@435 | 407 | log->print(" inlined_bytes='%d'", _num_inlined_bytecodes); |
duke@435 | 408 | } |
duke@435 | 409 | log->stamp(); |
duke@435 | 410 | log->end_elem(); |
duke@435 | 411 | log->tail("task"); |
duke@435 | 412 | log->clear_identities(); // next task will have different CI |
duke@435 | 413 | if (log->unflushed_count() > 2000) { |
duke@435 | 414 | log->flush(); |
duke@435 | 415 | } |
duke@435 | 416 | log->mark_file_end(); |
duke@435 | 417 | } |
duke@435 | 418 | |
duke@435 | 419 | |
duke@435 | 420 | |
duke@435 | 421 | // ------------------------------------------------------------------ |
duke@435 | 422 | // CompileQueue::add |
duke@435 | 423 | // |
duke@435 | 424 | // Add a CompileTask to a CompileQueue |
duke@435 | 425 | void CompileQueue::add(CompileTask* task) { |
duke@435 | 426 | assert(lock()->owned_by_self(), "must own lock"); |
duke@435 | 427 | |
duke@435 | 428 | task->set_next(NULL); |
duke@435 | 429 | |
duke@435 | 430 | if (_last == NULL) { |
duke@435 | 431 | // The compile queue is empty. |
duke@435 | 432 | assert(_first == NULL, "queue is empty"); |
duke@435 | 433 | _first = task; |
duke@435 | 434 | _last = task; |
duke@435 | 435 | } else { |
duke@435 | 436 | // Append the task to the queue. |
duke@435 | 437 | assert(_last->next() == NULL, "not last"); |
duke@435 | 438 | _last->set_next(task); |
duke@435 | 439 | _last = task; |
duke@435 | 440 | } |
duke@435 | 441 | |
duke@435 | 442 | // Mark the method as being in the compile queue. |
duke@435 | 443 | ((methodOop)JNIHandles::resolve(task->method_handle()))->set_queued_for_compilation(); |
duke@435 | 444 | |
duke@435 | 445 | if (CIPrintCompileQueue) { |
duke@435 | 446 | print(); |
duke@435 | 447 | } |
duke@435 | 448 | |
duke@435 | 449 | if (LogCompilation && xtty != NULL) { |
duke@435 | 450 | task->log_task_queued(); |
duke@435 | 451 | } |
duke@435 | 452 | |
duke@435 | 453 | // Notify CompilerThreads that a task is available. |
duke@435 | 454 | lock()->notify(); |
duke@435 | 455 | } |
duke@435 | 456 | |
duke@435 | 457 | |
duke@435 | 458 | // ------------------------------------------------------------------ |
duke@435 | 459 | // CompileQueue::get |
duke@435 | 460 | // |
duke@435 | 461 | // Get the next CompileTask from a CompileQueue |
duke@435 | 462 | CompileTask* CompileQueue::get() { |
duke@435 | 463 | MutexLocker locker(lock()); |
duke@435 | 464 | |
duke@435 | 465 | // Wait for an available CompileTask. |
duke@435 | 466 | while (_first == NULL) { |
duke@435 | 467 | // There is no work to be done right now. Wait. |
duke@435 | 468 | lock()->wait(); |
duke@435 | 469 | } |
duke@435 | 470 | |
duke@435 | 471 | CompileTask* task = _first; |
duke@435 | 472 | |
duke@435 | 473 | // Update queue first and last |
duke@435 | 474 | _first =_first->next(); |
duke@435 | 475 | if (_first == NULL) { |
duke@435 | 476 | _last = NULL; |
duke@435 | 477 | } |
duke@435 | 478 | |
duke@435 | 479 | return task; |
duke@435 | 480 | |
duke@435 | 481 | } |
duke@435 | 482 | |
duke@435 | 483 | |
duke@435 | 484 | // ------------------------------------------------------------------ |
duke@435 | 485 | // CompileQueue::print |
duke@435 | 486 | void CompileQueue::print() { |
duke@435 | 487 | tty->print_cr("Contents of %s", name()); |
duke@435 | 488 | tty->print_cr("----------------------"); |
duke@435 | 489 | CompileTask* task = _first; |
duke@435 | 490 | while (task != NULL) { |
duke@435 | 491 | task->print_line(); |
duke@435 | 492 | task = task->next(); |
duke@435 | 493 | } |
duke@435 | 494 | tty->print_cr("----------------------"); |
duke@435 | 495 | } |
duke@435 | 496 | |
duke@435 | 497 | CompilerCounters::CompilerCounters(const char* thread_name, int instance, TRAPS) { |
duke@435 | 498 | |
duke@435 | 499 | _current_method[0] = '\0'; |
duke@435 | 500 | _compile_type = CompileBroker::no_compile; |
duke@435 | 501 | |
duke@435 | 502 | if (UsePerfData) { |
duke@435 | 503 | ResourceMark rm; |
duke@435 | 504 | |
duke@435 | 505 | // create the thread instance name space string - don't create an |
duke@435 | 506 | // instance subspace if instance is -1 - keeps the adapterThread |
duke@435 | 507 | // counters from having a ".0" namespace. |
duke@435 | 508 | const char* thread_i = (instance == -1) ? thread_name : |
duke@435 | 509 | PerfDataManager::name_space(thread_name, instance); |
duke@435 | 510 | |
duke@435 | 511 | |
duke@435 | 512 | char* name = PerfDataManager::counter_name(thread_i, "method"); |
duke@435 | 513 | _perf_current_method = |
duke@435 | 514 | PerfDataManager::create_string_variable(SUN_CI, name, |
duke@435 | 515 | cmname_buffer_length, |
duke@435 | 516 | _current_method, CHECK); |
duke@435 | 517 | |
duke@435 | 518 | name = PerfDataManager::counter_name(thread_i, "type"); |
duke@435 | 519 | _perf_compile_type = PerfDataManager::create_variable(SUN_CI, name, |
duke@435 | 520 | PerfData::U_None, |
duke@435 | 521 | (jlong)_compile_type, |
duke@435 | 522 | CHECK); |
duke@435 | 523 | |
duke@435 | 524 | name = PerfDataManager::counter_name(thread_i, "time"); |
duke@435 | 525 | _perf_time = PerfDataManager::create_counter(SUN_CI, name, |
duke@435 | 526 | PerfData::U_Ticks, CHECK); |
duke@435 | 527 | |
duke@435 | 528 | name = PerfDataManager::counter_name(thread_i, "compiles"); |
duke@435 | 529 | _perf_compiles = PerfDataManager::create_counter(SUN_CI, name, |
duke@435 | 530 | PerfData::U_Events, CHECK); |
duke@435 | 531 | } |
duke@435 | 532 | } |
duke@435 | 533 | |
duke@435 | 534 | |
duke@435 | 535 | // ------------------------------------------------------------------ |
duke@435 | 536 | // CompileBroker::compilation_init |
duke@435 | 537 | // |
duke@435 | 538 | // Initialize the Compilation object |
duke@435 | 539 | void CompileBroker::compilation_init() { |
duke@435 | 540 | _last_method_compiled[0] = '\0'; |
duke@435 | 541 | |
duke@435 | 542 | // Set the interface to the current compiler(s). |
duke@435 | 543 | #ifdef COMPILER1 |
duke@435 | 544 | _compilers[0] = new Compiler(); |
duke@435 | 545 | #ifndef COMPILER2 |
duke@435 | 546 | _compilers[1] = _compilers[0]; |
duke@435 | 547 | #endif |
duke@435 | 548 | #endif // COMPILER1 |
duke@435 | 549 | |
duke@435 | 550 | #ifdef COMPILER2 |
duke@435 | 551 | _compilers[1] = new C2Compiler(); |
duke@435 | 552 | #ifndef COMPILER1 |
duke@435 | 553 | _compilers[0] = _compilers[1]; |
duke@435 | 554 | #endif |
duke@435 | 555 | #endif // COMPILER2 |
duke@435 | 556 | |
duke@435 | 557 | // Initialize the CompileTask free list |
duke@435 | 558 | _task_free_list = NULL; |
duke@435 | 559 | |
duke@435 | 560 | // Start the CompilerThreads |
duke@435 | 561 | init_compiler_threads(compiler_count()); |
duke@435 | 562 | |
duke@435 | 563 | |
duke@435 | 564 | // totalTime performance counter is always created as it is required |
duke@435 | 565 | // by the implementation of java.lang.management.CompilationMBean. |
duke@435 | 566 | { |
duke@435 | 567 | EXCEPTION_MARK; |
duke@435 | 568 | _perf_total_compilation = |
duke@435 | 569 | PerfDataManager::create_counter(JAVA_CI, "totalTime", |
duke@435 | 570 | PerfData::U_Ticks, CHECK); |
duke@435 | 571 | } |
duke@435 | 572 | |
duke@435 | 573 | |
duke@435 | 574 | if (UsePerfData) { |
duke@435 | 575 | |
duke@435 | 576 | EXCEPTION_MARK; |
duke@435 | 577 | |
duke@435 | 578 | // create the jvmstat performance counters |
duke@435 | 579 | _perf_osr_compilation = |
duke@435 | 580 | PerfDataManager::create_counter(SUN_CI, "osrTime", |
duke@435 | 581 | PerfData::U_Ticks, CHECK); |
duke@435 | 582 | |
duke@435 | 583 | _perf_standard_compilation = |
duke@435 | 584 | PerfDataManager::create_counter(SUN_CI, "standardTime", |
duke@435 | 585 | PerfData::U_Ticks, CHECK); |
duke@435 | 586 | |
duke@435 | 587 | _perf_total_bailout_count = |
duke@435 | 588 | PerfDataManager::create_counter(SUN_CI, "totalBailouts", |
duke@435 | 589 | PerfData::U_Events, CHECK); |
duke@435 | 590 | |
duke@435 | 591 | _perf_total_invalidated_count = |
duke@435 | 592 | PerfDataManager::create_counter(SUN_CI, "totalInvalidates", |
duke@435 | 593 | PerfData::U_Events, CHECK); |
duke@435 | 594 | |
duke@435 | 595 | _perf_total_compile_count = |
duke@435 | 596 | PerfDataManager::create_counter(SUN_CI, "totalCompiles", |
duke@435 | 597 | PerfData::U_Events, CHECK); |
duke@435 | 598 | _perf_total_osr_compile_count = |
duke@435 | 599 | PerfDataManager::create_counter(SUN_CI, "osrCompiles", |
duke@435 | 600 | PerfData::U_Events, CHECK); |
duke@435 | 601 | |
duke@435 | 602 | _perf_total_standard_compile_count = |
duke@435 | 603 | PerfDataManager::create_counter(SUN_CI, "standardCompiles", |
duke@435 | 604 | PerfData::U_Events, CHECK); |
duke@435 | 605 | |
duke@435 | 606 | _perf_sum_osr_bytes_compiled = |
duke@435 | 607 | PerfDataManager::create_counter(SUN_CI, "osrBytes", |
duke@435 | 608 | PerfData::U_Bytes, CHECK); |
duke@435 | 609 | |
duke@435 | 610 | _perf_sum_standard_bytes_compiled = |
duke@435 | 611 | PerfDataManager::create_counter(SUN_CI, "standardBytes", |
duke@435 | 612 | PerfData::U_Bytes, CHECK); |
duke@435 | 613 | |
duke@435 | 614 | _perf_sum_nmethod_size = |
duke@435 | 615 | PerfDataManager::create_counter(SUN_CI, "nmethodSize", |
duke@435 | 616 | PerfData::U_Bytes, CHECK); |
duke@435 | 617 | |
duke@435 | 618 | _perf_sum_nmethod_code_size = |
duke@435 | 619 | PerfDataManager::create_counter(SUN_CI, "nmethodCodeSize", |
duke@435 | 620 | PerfData::U_Bytes, CHECK); |
duke@435 | 621 | |
duke@435 | 622 | _perf_last_method = |
duke@435 | 623 | PerfDataManager::create_string_variable(SUN_CI, "lastMethod", |
duke@435 | 624 | CompilerCounters::cmname_buffer_length, |
duke@435 | 625 | "", CHECK); |
duke@435 | 626 | |
duke@435 | 627 | _perf_last_failed_method = |
duke@435 | 628 | PerfDataManager::create_string_variable(SUN_CI, "lastFailedMethod", |
duke@435 | 629 | CompilerCounters::cmname_buffer_length, |
duke@435 | 630 | "", CHECK); |
duke@435 | 631 | |
duke@435 | 632 | _perf_last_invalidated_method = |
duke@435 | 633 | PerfDataManager::create_string_variable(SUN_CI, "lastInvalidatedMethod", |
duke@435 | 634 | CompilerCounters::cmname_buffer_length, |
duke@435 | 635 | "", CHECK); |
duke@435 | 636 | |
duke@435 | 637 | _perf_last_compile_type = |
duke@435 | 638 | PerfDataManager::create_variable(SUN_CI, "lastType", |
duke@435 | 639 | PerfData::U_None, |
duke@435 | 640 | (jlong)CompileBroker::no_compile, |
duke@435 | 641 | CHECK); |
duke@435 | 642 | |
duke@435 | 643 | _perf_last_compile_size = |
duke@435 | 644 | PerfDataManager::create_variable(SUN_CI, "lastSize", |
duke@435 | 645 | PerfData::U_Bytes, |
duke@435 | 646 | (jlong)CompileBroker::no_compile, |
duke@435 | 647 | CHECK); |
duke@435 | 648 | |
duke@435 | 649 | |
duke@435 | 650 | _perf_last_failed_type = |
duke@435 | 651 | PerfDataManager::create_variable(SUN_CI, "lastFailedType", |
duke@435 | 652 | PerfData::U_None, |
duke@435 | 653 | (jlong)CompileBroker::no_compile, |
duke@435 | 654 | CHECK); |
duke@435 | 655 | |
duke@435 | 656 | _perf_last_invalidated_type = |
duke@435 | 657 | PerfDataManager::create_variable(SUN_CI, "lastInvalidatedType", |
duke@435 | 658 | PerfData::U_None, |
duke@435 | 659 | (jlong)CompileBroker::no_compile, |
duke@435 | 660 | CHECK); |
duke@435 | 661 | } |
duke@435 | 662 | |
duke@435 | 663 | _initialized = true; |
duke@435 | 664 | } |
duke@435 | 665 | |
duke@435 | 666 | |
duke@435 | 667 | |
duke@435 | 668 | // ------------------------------------------------------------------ |
duke@435 | 669 | // CompileBroker::make_compiler_thread |
duke@435 | 670 | CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS) { |
duke@435 | 671 | CompilerThread* compiler_thread = NULL; |
duke@435 | 672 | |
duke@435 | 673 | klassOop k = |
duke@435 | 674 | SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_Thread(), |
duke@435 | 675 | true, CHECK_0); |
duke@435 | 676 | instanceKlassHandle klass (THREAD, k); |
duke@435 | 677 | instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_0); |
duke@435 | 678 | Handle string = java_lang_String::create_from_str(name, CHECK_0); |
duke@435 | 679 | |
duke@435 | 680 | // Initialize thread_oop to put it into the system threadGroup |
duke@435 | 681 | Handle thread_group (THREAD, Universe::system_thread_group()); |
duke@435 | 682 | JavaValue result(T_VOID); |
duke@435 | 683 | JavaCalls::call_special(&result, thread_oop, |
duke@435 | 684 | klass, |
duke@435 | 685 | vmSymbolHandles::object_initializer_name(), |
duke@435 | 686 | vmSymbolHandles::threadgroup_string_void_signature(), |
duke@435 | 687 | thread_group, |
duke@435 | 688 | string, |
duke@435 | 689 | CHECK_0); |
duke@435 | 690 | |
duke@435 | 691 | { |
duke@435 | 692 | MutexLocker mu(Threads_lock, THREAD); |
duke@435 | 693 | compiler_thread = new CompilerThread(queue, counters); |
duke@435 | 694 | // At this point the new CompilerThread data-races with this startup |
duke@435 | 695 | // thread (which I believe is the primoridal thread and NOT the VM |
duke@435 | 696 | // thread). This means Java bytecodes being executed at startup can |
duke@435 | 697 | // queue compile jobs which will run at whatever default priority the |
duke@435 | 698 | // newly created CompilerThread runs at. |
duke@435 | 699 | |
duke@435 | 700 | |
duke@435 | 701 | // At this point it may be possible that no osthread was created for the |
duke@435 | 702 | // JavaThread due to lack of memory. We would have to throw an exception |
duke@435 | 703 | // in that case. However, since this must work and we do not allow |
duke@435 | 704 | // exceptions anyway, check and abort if this fails. |
duke@435 | 705 | |
duke@435 | 706 | if (compiler_thread == NULL || compiler_thread->osthread() == NULL){ |
duke@435 | 707 | vm_exit_during_initialization("java.lang.OutOfMemoryError", |
duke@435 | 708 | "unable to create new native thread"); |
duke@435 | 709 | } |
duke@435 | 710 | |
duke@435 | 711 | java_lang_Thread::set_thread(thread_oop(), compiler_thread); |
duke@435 | 712 | |
duke@435 | 713 | // Note that this only sets the JavaThread _priority field, which by |
duke@435 | 714 | // definition is limited to Java priorities and not OS priorities. |
duke@435 | 715 | // The os-priority is set in the CompilerThread startup code itself |
duke@435 | 716 | java_lang_Thread::set_priority(thread_oop(), NearMaxPriority); |
duke@435 | 717 | // CLEANUP PRIORITIES: This -if- statement hids a bug whereby the compiler |
duke@435 | 718 | // threads never have their OS priority set. The assumption here is to |
duke@435 | 719 | // enable the Performance group to do flag tuning, figure out a suitable |
duke@435 | 720 | // CompilerThreadPriority, and then remove this 'if' statement (and |
duke@435 | 721 | // comment) and unconditionally set the priority. |
duke@435 | 722 | |
duke@435 | 723 | // Compiler Threads should be at the highest Priority |
duke@435 | 724 | if ( CompilerThreadPriority != -1 ) |
duke@435 | 725 | os::set_native_priority( compiler_thread, CompilerThreadPriority ); |
duke@435 | 726 | else |
duke@435 | 727 | os::set_native_priority( compiler_thread, os::java_to_os_priority[NearMaxPriority]); |
duke@435 | 728 | |
duke@435 | 729 | // Note that I cannot call os::set_priority because it expects Java |
duke@435 | 730 | // priorities and I am *explicitly* using OS priorities so that it's |
duke@435 | 731 | // possible to set the compiler thread priority higher than any Java |
duke@435 | 732 | // thread. |
duke@435 | 733 | |
duke@435 | 734 | java_lang_Thread::set_daemon(thread_oop()); |
duke@435 | 735 | |
duke@435 | 736 | compiler_thread->set_threadObj(thread_oop()); |
duke@435 | 737 | Threads::add(compiler_thread); |
duke@435 | 738 | Thread::start(compiler_thread); |
duke@435 | 739 | } |
duke@435 | 740 | // Let go of Threads_lock before yielding |
duke@435 | 741 | os::yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS) |
duke@435 | 742 | |
duke@435 | 743 | return compiler_thread; |
duke@435 | 744 | } |
duke@435 | 745 | |
duke@435 | 746 | |
duke@435 | 747 | // ------------------------------------------------------------------ |
duke@435 | 748 | // CompileBroker::init_compiler_threads |
duke@435 | 749 | // |
duke@435 | 750 | // Initialize the compilation queue |
duke@435 | 751 | void CompileBroker::init_compiler_threads(int compiler_count) { |
duke@435 | 752 | EXCEPTION_MARK; |
duke@435 | 753 | |
duke@435 | 754 | _method_queue = new CompileQueue("MethodQueue", MethodCompileQueue_lock); |
duke@435 | 755 | _method_threads = |
duke@435 | 756 | new (ResourceObj::C_HEAP) GrowableArray<CompilerThread*>(compiler_count, true); |
duke@435 | 757 | |
duke@435 | 758 | char name_buffer[256]; |
duke@435 | 759 | int i; |
duke@435 | 760 | for (i = 0; i < compiler_count; i++) { |
duke@435 | 761 | // Create a name for our thread. |
duke@435 | 762 | sprintf(name_buffer, "CompilerThread%d", i); |
duke@435 | 763 | CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); |
duke@435 | 764 | |
duke@435 | 765 | CompilerThread* new_thread = make_compiler_thread(name_buffer, _method_queue, counters, CHECK); |
duke@435 | 766 | _method_threads->append(new_thread); |
duke@435 | 767 | } |
duke@435 | 768 | if (UsePerfData) { |
duke@435 | 769 | PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, |
duke@435 | 770 | compiler_count, CHECK); |
duke@435 | 771 | } |
duke@435 | 772 | } |
duke@435 | 773 | |
duke@435 | 774 | // ------------------------------------------------------------------ |
duke@435 | 775 | // CompileBroker::is_idle |
duke@435 | 776 | bool CompileBroker::is_idle() { |
duke@435 | 777 | if (!_method_queue->is_empty()) { |
duke@435 | 778 | return false; |
duke@435 | 779 | } else { |
duke@435 | 780 | int num_threads = _method_threads->length(); |
duke@435 | 781 | for (int i=0; i<num_threads; i++) { |
duke@435 | 782 | if (_method_threads->at(i)->task() != NULL) { |
duke@435 | 783 | return false; |
duke@435 | 784 | } |
duke@435 | 785 | } |
duke@435 | 786 | |
duke@435 | 787 | // No pending or active compilations. |
duke@435 | 788 | return true; |
duke@435 | 789 | } |
duke@435 | 790 | } |
duke@435 | 791 | |
duke@435 | 792 | |
duke@435 | 793 | // ------------------------------------------------------------------ |
duke@435 | 794 | // CompileBroker::compile_method |
duke@435 | 795 | // |
duke@435 | 796 | // Request compilation of a method. |
duke@435 | 797 | void CompileBroker::compile_method_base(methodHandle method, |
duke@435 | 798 | int osr_bci, |
duke@435 | 799 | int comp_level, |
duke@435 | 800 | methodHandle hot_method, |
duke@435 | 801 | int hot_count, |
duke@435 | 802 | const char* comment, |
duke@435 | 803 | TRAPS) { |
duke@435 | 804 | // do nothing if compiler thread(s) is not available |
duke@435 | 805 | if (!_initialized ) { |
duke@435 | 806 | return; |
duke@435 | 807 | } |
duke@435 | 808 | |
duke@435 | 809 | guarantee(!method->is_abstract(), "cannot compile abstract methods"); |
duke@435 | 810 | assert(method->method_holder()->klass_part()->oop_is_instance(), |
duke@435 | 811 | "sanity check"); |
duke@435 | 812 | assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), |
duke@435 | 813 | "method holder must be initialized"); |
duke@435 | 814 | |
duke@435 | 815 | if (CIPrintRequests) { |
duke@435 | 816 | tty->print("request: "); |
duke@435 | 817 | method->print_short_name(tty); |
duke@435 | 818 | if (osr_bci != InvocationEntryBci) { |
duke@435 | 819 | tty->print(" osr_bci: %d", osr_bci); |
duke@435 | 820 | } |
duke@435 | 821 | tty->print(" comment: %s count: %d", comment, hot_count); |
duke@435 | 822 | if (!hot_method.is_null()) { |
duke@435 | 823 | tty->print(" hot: "); |
duke@435 | 824 | if (hot_method() != method()) { |
duke@435 | 825 | hot_method->print_short_name(tty); |
duke@435 | 826 | } else { |
duke@435 | 827 | tty->print("yes"); |
duke@435 | 828 | } |
duke@435 | 829 | } |
duke@435 | 830 | tty->cr(); |
duke@435 | 831 | } |
duke@435 | 832 | |
duke@435 | 833 | // A request has been made for compilation. Before we do any |
duke@435 | 834 | // real work, check to see if the method has been compiled |
duke@435 | 835 | // in the meantime with a definitive result. |
duke@435 | 836 | if (compilation_is_complete(method, osr_bci, comp_level)) { |
duke@435 | 837 | return; |
duke@435 | 838 | } |
duke@435 | 839 | |
duke@435 | 840 | // If this method is already in the compile queue, then |
duke@435 | 841 | // we do not block the current thread. |
duke@435 | 842 | if (compilation_is_in_queue(method, osr_bci)) { |
duke@435 | 843 | // We may want to decay our counter a bit here to prevent |
duke@435 | 844 | // multiple denied requests for compilation. This is an |
duke@435 | 845 | // open compilation policy issue. Note: The other possibility, |
duke@435 | 846 | // in the case that this is a blocking compile request, is to have |
duke@435 | 847 | // all subsequent blocking requesters wait for completion of |
duke@435 | 848 | // ongoing compiles. Note that in this case we'll need a protocol |
duke@435 | 849 | // for freeing the associated compile tasks. [Or we could have |
duke@435 | 850 | // a single static monitor on which all these waiters sleep.] |
duke@435 | 851 | return; |
duke@435 | 852 | } |
duke@435 | 853 | |
duke@435 | 854 | // Outputs from the following MutexLocker block: |
duke@435 | 855 | CompileTask* task = NULL; |
duke@435 | 856 | bool blocking = false; |
duke@435 | 857 | |
duke@435 | 858 | // Acquire our lock. |
duke@435 | 859 | { |
duke@435 | 860 | MutexLocker locker(_method_queue->lock(), THREAD); |
duke@435 | 861 | |
duke@435 | 862 | // Make sure the method has not slipped into the queues since |
duke@435 | 863 | // last we checked; note that those checks were "fast bail-outs". |
duke@435 | 864 | // Here we need to be more careful, see 14012000 below. |
duke@435 | 865 | if (compilation_is_in_queue(method, osr_bci)) { |
duke@435 | 866 | return; |
duke@435 | 867 | } |
duke@435 | 868 | |
duke@435 | 869 | // We need to check again to see if the compilation has |
duke@435 | 870 | // completed. A previous compilation may have registered |
duke@435 | 871 | // some result. |
duke@435 | 872 | if (compilation_is_complete(method, osr_bci, comp_level)) { |
duke@435 | 873 | return; |
duke@435 | 874 | } |
duke@435 | 875 | |
duke@435 | 876 | // We now know that this compilation is not pending, complete, |
duke@435 | 877 | // or prohibited. Assign a compile_id to this compilation |
duke@435 | 878 | // and check to see if it is in our [Start..Stop) range. |
duke@435 | 879 | uint compile_id = assign_compile_id(method, osr_bci); |
duke@435 | 880 | if (compile_id == 0) { |
duke@435 | 881 | // The compilation falls outside the allowed range. |
duke@435 | 882 | return; |
duke@435 | 883 | } |
duke@435 | 884 | |
duke@435 | 885 | // Should this thread wait for completion of the compile? |
duke@435 | 886 | blocking = is_compile_blocking(method, osr_bci); |
duke@435 | 887 | |
duke@435 | 888 | // We will enter the compilation in the queue. |
duke@435 | 889 | // 14012000: Note that this sets the queued_for_compile bits in |
duke@435 | 890 | // the target method. We can now reason that a method cannot be |
duke@435 | 891 | // queued for compilation more than once, as follows: |
duke@435 | 892 | // Before a thread queues a task for compilation, it first acquires |
duke@435 | 893 | // the compile queue lock, then checks if the method's queued bits |
duke@435 | 894 | // are set or it has already been compiled. Thus there can not be two |
duke@435 | 895 | // instances of a compilation task for the same method on the |
duke@435 | 896 | // compilation queue. Consider now the case where the compilation |
duke@435 | 897 | // thread has already removed a task for that method from the queue |
duke@435 | 898 | // and is in the midst of compiling it. In this case, the |
duke@435 | 899 | // queued_for_compile bits must be set in the method (and these |
duke@435 | 900 | // will be visible to the current thread, since the bits were set |
duke@435 | 901 | // under protection of the compile queue lock, which we hold now. |
duke@435 | 902 | // When the compilation completes, the compiler thread first sets |
duke@435 | 903 | // the compilation result and then clears the queued_for_compile |
duke@435 | 904 | // bits. Neither of these actions are protected by a barrier (or done |
duke@435 | 905 | // under the protection of a lock), so the only guarantee we have |
duke@435 | 906 | // (on machines with TSO (Total Store Order)) is that these values |
duke@435 | 907 | // will update in that order. As a result, the only combinations of |
duke@435 | 908 | // these bits that the current thread will see are, in temporal order: |
duke@435 | 909 | // <RESULT, QUEUE> : |
duke@435 | 910 | // <0, 1> : in compile queue, but not yet compiled |
duke@435 | 911 | // <1, 1> : compiled but queue bit not cleared |
duke@435 | 912 | // <1, 0> : compiled and queue bit cleared |
duke@435 | 913 | // Because we first check the queue bits then check the result bits, |
duke@435 | 914 | // we are assured that we cannot introduce a duplicate task. |
duke@435 | 915 | // Note that if we did the tests in the reverse order (i.e. check |
duke@435 | 916 | // result then check queued bit), we could get the result bit before |
duke@435 | 917 | // the compilation completed, and the queue bit after the compilation |
duke@435 | 918 | // completed, and end up introducing a "duplicate" (redundant) task. |
duke@435 | 919 | // In that case, the compiler thread should first check if a method |
duke@435 | 920 | // has already been compiled before trying to compile it. |
duke@435 | 921 | // NOTE: in the event that there are multiple compiler threads and |
duke@435 | 922 | // there is de-optimization/recompilation, things will get hairy, |
duke@435 | 923 | // and in that case it's best to protect both the testing (here) of |
duke@435 | 924 | // these bits, and their updating (here and elsewhere) under a |
duke@435 | 925 | // common lock. |
duke@435 | 926 | task = create_compile_task(_method_queue, |
duke@435 | 927 | compile_id, method, |
duke@435 | 928 | osr_bci, comp_level, |
duke@435 | 929 | hot_method, hot_count, comment, |
duke@435 | 930 | blocking); |
duke@435 | 931 | } |
duke@435 | 932 | |
duke@435 | 933 | if (blocking) { |
duke@435 | 934 | wait_for_completion(task); |
duke@435 | 935 | } |
duke@435 | 936 | } |
duke@435 | 937 | |
duke@435 | 938 | |
duke@435 | 939 | nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, |
duke@435 | 940 | methodHandle hot_method, int hot_count, |
duke@435 | 941 | const char* comment, TRAPS) { |
duke@435 | 942 | // make sure arguments make sense |
duke@435 | 943 | assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method"); |
duke@435 | 944 | assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); |
duke@435 | 945 | assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); |
duke@435 | 946 | assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized"); |
duke@435 | 947 | |
duke@435 | 948 | int comp_level = CompilationPolicy::policy()->compilation_level(method, osr_bci); |
duke@435 | 949 | |
duke@435 | 950 | #ifdef TIERED |
duke@435 | 951 | if (TieredCompilation && StressTieredRuntime) { |
duke@435 | 952 | static int flipper = 0; |
duke@435 | 953 | if (is_even(flipper++)) { |
duke@435 | 954 | comp_level = CompLevel_fast_compile; |
duke@435 | 955 | } else { |
duke@435 | 956 | comp_level = CompLevel_full_optimization; |
duke@435 | 957 | } |
duke@435 | 958 | } |
duke@435 | 959 | #ifdef SPARC |
duke@435 | 960 | // QQQ FIX ME |
duke@435 | 961 | // C2 only returns long results in G1 and c1 doesn't understand so disallow c2 |
duke@435 | 962 | // compiles of long results |
duke@435 | 963 | if (TieredCompilation && method()->result_type() == T_LONG) { |
duke@435 | 964 | comp_level = CompLevel_fast_compile; |
duke@435 | 965 | } |
duke@435 | 966 | #endif // SPARC |
duke@435 | 967 | #endif // TIERED |
duke@435 | 968 | |
duke@435 | 969 | // return quickly if possible |
duke@435 | 970 | |
duke@435 | 971 | // lock, make sure that the compilation |
duke@435 | 972 | // isn't prohibited in a straightforward way. |
duke@435 | 973 | |
duke@435 | 974 | if (compiler(comp_level) == NULL || compilation_is_prohibited(method, osr_bci, comp_level)) { |
duke@435 | 975 | return NULL; |
duke@435 | 976 | } |
duke@435 | 977 | |
duke@435 | 978 | if (osr_bci == InvocationEntryBci) { |
duke@435 | 979 | // standard compilation |
duke@435 | 980 | nmethod* method_code = method->code(); |
duke@435 | 981 | if (method_code != NULL |
duke@435 | 982 | #ifdef TIERED |
duke@435 | 983 | && ( method_code->is_compiled_by_c2() || comp_level == CompLevel_fast_compile ) |
duke@435 | 984 | #endif // TIERED |
duke@435 | 985 | ) { |
duke@435 | 986 | return method_code; |
duke@435 | 987 | } |
duke@435 | 988 | if (method->is_not_compilable(comp_level)) return NULL; |
duke@435 | 989 | } else { |
duke@435 | 990 | // osr compilation |
duke@435 | 991 | #ifndef TIERED |
duke@435 | 992 | // seems like an assert of dubious value |
duke@435 | 993 | assert(comp_level == CompLevel_full_optimization, |
duke@435 | 994 | "all OSR compiles are assumed to be at a single compilation lavel"); |
duke@435 | 995 | #endif // TIERED |
duke@435 | 996 | nmethod* nm = method->lookup_osr_nmethod_for(osr_bci); |
duke@435 | 997 | if (nm != NULL) return nm; |
duke@435 | 998 | if (method->is_not_osr_compilable()) return NULL; |
duke@435 | 999 | } |
duke@435 | 1000 | |
duke@435 | 1001 | assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); |
duke@435 | 1002 | // some prerequisites that are compiler specific |
duke@435 | 1003 | if (compiler(comp_level)->is_c2()) { |
duke@435 | 1004 | method->constants()->resolve_string_constants(CHECK_0); |
duke@435 | 1005 | // Resolve all classes seen in the signature of the method |
duke@435 | 1006 | // we are compiling. |
duke@435 | 1007 | methodOopDesc::load_signature_classes(method, CHECK_0); |
duke@435 | 1008 | } |
duke@435 | 1009 | |
duke@435 | 1010 | // If the method is native, do the lookup in the thread requesting |
duke@435 | 1011 | // the compilation. Native lookups can load code, which is not |
duke@435 | 1012 | // permitted during compilation. |
duke@435 | 1013 | // |
duke@435 | 1014 | // Note: A native method implies non-osr compilation which is |
duke@435 | 1015 | // checked with an assertion at the entry of this method. |
duke@435 | 1016 | if (method->is_native()) { |
duke@435 | 1017 | bool in_base_library; |
duke@435 | 1018 | address adr = NativeLookup::lookup(method, in_base_library, THREAD); |
duke@435 | 1019 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1020 | // In case of an exception looking up the method, we just forget |
duke@435 | 1021 | // about it. The interpreter will kick-in and throw the exception. |
duke@435 | 1022 | method->set_not_compilable(); // implies is_not_osr_compilable() |
duke@435 | 1023 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1024 | return NULL; |
duke@435 | 1025 | } |
duke@435 | 1026 | assert(method->has_native_function(), "must have native code by now"); |
duke@435 | 1027 | } |
duke@435 | 1028 | |
duke@435 | 1029 | // RedefineClasses() has replaced this method; just return |
duke@435 | 1030 | if (method->is_old()) { |
duke@435 | 1031 | return NULL; |
duke@435 | 1032 | } |
duke@435 | 1033 | |
duke@435 | 1034 | // JVMTI -- post_compile_event requires jmethod_id() that may require |
duke@435 | 1035 | // a lock the compiling thread can not acquire. Prefetch it here. |
duke@435 | 1036 | if (JvmtiExport::should_post_compiled_method_load()) { |
duke@435 | 1037 | method->jmethod_id(); |
duke@435 | 1038 | } |
duke@435 | 1039 | |
duke@435 | 1040 | // do the compilation |
duke@435 | 1041 | if (method->is_native()) { |
duke@435 | 1042 | if (!PreferInterpreterNativeStubs) { |
duke@435 | 1043 | (void) AdapterHandlerLibrary::create_native_wrapper(method); |
duke@435 | 1044 | } else { |
duke@435 | 1045 | return NULL; |
duke@435 | 1046 | } |
duke@435 | 1047 | } else { |
duke@435 | 1048 | compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, CHECK_0); |
duke@435 | 1049 | } |
duke@435 | 1050 | |
duke@435 | 1051 | // return requested nmethod |
duke@435 | 1052 | return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci); |
duke@435 | 1053 | } |
duke@435 | 1054 | |
duke@435 | 1055 | |
duke@435 | 1056 | // ------------------------------------------------------------------ |
duke@435 | 1057 | // CompileBroker::compilation_is_complete |
duke@435 | 1058 | // |
duke@435 | 1059 | // See if compilation of this method is already complete. |
duke@435 | 1060 | bool CompileBroker::compilation_is_complete(methodHandle method, |
duke@435 | 1061 | int osr_bci, |
duke@435 | 1062 | int comp_level) { |
duke@435 | 1063 | bool is_osr = (osr_bci != standard_entry_bci); |
duke@435 | 1064 | if (is_osr) { |
duke@435 | 1065 | if (method->is_not_osr_compilable()) { |
duke@435 | 1066 | return true; |
duke@435 | 1067 | } else { |
duke@435 | 1068 | nmethod* result = method->lookup_osr_nmethod_for(osr_bci); |
duke@435 | 1069 | return (result != NULL); |
duke@435 | 1070 | } |
duke@435 | 1071 | } else { |
duke@435 | 1072 | if (method->is_not_compilable(comp_level)) { |
duke@435 | 1073 | return true; |
duke@435 | 1074 | } else { |
duke@435 | 1075 | nmethod* result = method->code(); |
duke@435 | 1076 | if (result == NULL) return false; |
duke@435 | 1077 | #ifdef TIERED |
duke@435 | 1078 | if (comp_level == CompLevel_fast_compile) { |
duke@435 | 1079 | // At worst the code is from c1 |
duke@435 | 1080 | return true; |
duke@435 | 1081 | } |
duke@435 | 1082 | // comp level must be full opt |
duke@435 | 1083 | return result->is_compiled_by_c2(); |
duke@435 | 1084 | #endif // TIERED |
duke@435 | 1085 | return true; |
duke@435 | 1086 | } |
duke@435 | 1087 | } |
duke@435 | 1088 | } |
duke@435 | 1089 | |
duke@435 | 1090 | |
duke@435 | 1091 | // ------------------------------------------------------------------ |
duke@435 | 1092 | // CompileBroker::compilation_is_in_queue |
duke@435 | 1093 | // |
duke@435 | 1094 | // See if this compilation is already requested. |
duke@435 | 1095 | // |
duke@435 | 1096 | // Implementation note: there is only a single "is in queue" bit |
duke@435 | 1097 | // for each method. This means that the check below is overly |
duke@435 | 1098 | // conservative in the sense that an osr compilation in the queue |
duke@435 | 1099 | // will block a normal compilation from entering the queue (and vice |
duke@435 | 1100 | // versa). This can be remedied by a full queue search to disambiguate |
duke@435 | 1101 | // cases. If it is deemed profitible, this may be done. |
duke@435 | 1102 | bool CompileBroker::compilation_is_in_queue(methodHandle method, |
duke@435 | 1103 | int osr_bci) { |
duke@435 | 1104 | return method->queued_for_compilation(); |
duke@435 | 1105 | } |
duke@435 | 1106 | |
duke@435 | 1107 | |
duke@435 | 1108 | // ------------------------------------------------------------------ |
duke@435 | 1109 | // CompileBroker::compilation_is_prohibited |
duke@435 | 1110 | // |
duke@435 | 1111 | // See if this compilation is not allowed. |
duke@435 | 1112 | bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) { |
duke@435 | 1113 | bool is_native = method->is_native(); |
duke@435 | 1114 | // Some compilers may not support the compilation of natives. |
duke@435 | 1115 | // QQQ this needs some work ought to only record not compilable at |
duke@435 | 1116 | // the specified level |
duke@435 | 1117 | if (is_native && |
duke@435 | 1118 | (!CICompileNatives || !compiler(comp_level)->supports_native())) { |
duke@435 | 1119 | method->set_not_compilable(); |
duke@435 | 1120 | return true; |
duke@435 | 1121 | } |
duke@435 | 1122 | |
duke@435 | 1123 | bool is_osr = (osr_bci != standard_entry_bci); |
duke@435 | 1124 | // Some compilers may not support on stack replacement. |
duke@435 | 1125 | if (is_osr && |
duke@435 | 1126 | (!CICompileOSR || !compiler(comp_level)->supports_osr())) { |
duke@435 | 1127 | method->set_not_osr_compilable(); |
duke@435 | 1128 | return true; |
duke@435 | 1129 | } |
duke@435 | 1130 | |
duke@435 | 1131 | // The method may be explicitly excluded by the user. |
duke@435 | 1132 | bool quietly; |
duke@435 | 1133 | if (CompilerOracle::should_exclude(method, quietly)) { |
duke@435 | 1134 | if (!quietly) { |
duke@435 | 1135 | // This does not happen quietly... |
duke@435 | 1136 | ResourceMark rm; |
duke@435 | 1137 | tty->print("### Excluding %s:%s", |
duke@435 | 1138 | method->is_native() ? "generation of native wrapper" : "compile", |
duke@435 | 1139 | (method->is_static() ? " static" : "")); |
duke@435 | 1140 | method->print_short_name(tty); |
duke@435 | 1141 | tty->cr(); |
duke@435 | 1142 | } |
duke@435 | 1143 | method->set_not_compilable(); |
duke@435 | 1144 | } |
duke@435 | 1145 | |
duke@435 | 1146 | return false; |
duke@435 | 1147 | } |
duke@435 | 1148 | |
duke@435 | 1149 | |
duke@435 | 1150 | // ------------------------------------------------------------------ |
duke@435 | 1151 | // CompileBroker::assign_compile_id |
duke@435 | 1152 | // |
duke@435 | 1153 | // Assign a serialized id number to this compilation request. If the |
duke@435 | 1154 | // number falls out of the allowed range, return a 0. OSR |
duke@435 | 1155 | // compilations may be numbered separately from regular compilations |
duke@435 | 1156 | // if certain debugging flags are used. |
duke@435 | 1157 | uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) { |
duke@435 | 1158 | assert(_method_queue->lock()->owner() == JavaThread::current(), |
duke@435 | 1159 | "must hold the compilation queue lock"); |
duke@435 | 1160 | bool is_osr = (osr_bci != standard_entry_bci); |
duke@435 | 1161 | assert(!method->is_native(), "no longer compile natives"); |
duke@435 | 1162 | uint id; |
duke@435 | 1163 | if (CICountOSR && is_osr) { |
duke@435 | 1164 | id = ++_osr_compilation_id; |
duke@435 | 1165 | if ((uint)CIStartOSR <= id && id < (uint)CIStopOSR) { |
duke@435 | 1166 | return id; |
duke@435 | 1167 | } |
duke@435 | 1168 | } else { |
duke@435 | 1169 | id = ++_compilation_id; |
duke@435 | 1170 | if ((uint)CIStart <= id && id < (uint)CIStop) { |
duke@435 | 1171 | return id; |
duke@435 | 1172 | } |
duke@435 | 1173 | } |
duke@435 | 1174 | |
duke@435 | 1175 | // Method was not in the appropriate compilation range. |
duke@435 | 1176 | method->set_not_compilable(); |
duke@435 | 1177 | return 0; |
duke@435 | 1178 | } |
duke@435 | 1179 | |
duke@435 | 1180 | |
duke@435 | 1181 | // ------------------------------------------------------------------ |
duke@435 | 1182 | // CompileBroker::is_compile_blocking |
duke@435 | 1183 | // |
duke@435 | 1184 | // Should the current thread be blocked until this compilation request |
duke@435 | 1185 | // has been fulfilled? |
duke@435 | 1186 | bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) { |
duke@435 | 1187 | return !BackgroundCompilation; |
duke@435 | 1188 | } |
duke@435 | 1189 | |
duke@435 | 1190 | |
duke@435 | 1191 | // ------------------------------------------------------------------ |
duke@435 | 1192 | // CompileBroker::preload_classes |
duke@435 | 1193 | void CompileBroker::preload_classes(methodHandle method, TRAPS) { |
duke@435 | 1194 | // Move this code over from c1_Compiler.cpp |
duke@435 | 1195 | ShouldNotReachHere(); |
duke@435 | 1196 | } |
duke@435 | 1197 | |
duke@435 | 1198 | |
duke@435 | 1199 | // ------------------------------------------------------------------ |
duke@435 | 1200 | // CompileBroker::create_compile_task |
duke@435 | 1201 | // |
duke@435 | 1202 | // Create a CompileTask object representing the current request for |
duke@435 | 1203 | // compilation. Add this task to the queue. |
duke@435 | 1204 | CompileTask* CompileBroker::create_compile_task(CompileQueue* queue, |
duke@435 | 1205 | int compile_id, |
duke@435 | 1206 | methodHandle method, |
duke@435 | 1207 | int osr_bci, |
duke@435 | 1208 | int comp_level, |
duke@435 | 1209 | methodHandle hot_method, |
duke@435 | 1210 | int hot_count, |
duke@435 | 1211 | const char* comment, |
duke@435 | 1212 | bool blocking) { |
duke@435 | 1213 | CompileTask* new_task = allocate_task(); |
duke@435 | 1214 | new_task->initialize(compile_id, method, osr_bci, comp_level, |
duke@435 | 1215 | hot_method, hot_count, comment, |
duke@435 | 1216 | blocking); |
duke@435 | 1217 | queue->add(new_task); |
duke@435 | 1218 | return new_task; |
duke@435 | 1219 | } |
duke@435 | 1220 | |
duke@435 | 1221 | |
duke@435 | 1222 | // ------------------------------------------------------------------ |
duke@435 | 1223 | // CompileBroker::allocate_task |
duke@435 | 1224 | // |
duke@435 | 1225 | // Allocate a CompileTask, from the free list if possible. |
duke@435 | 1226 | CompileTask* CompileBroker::allocate_task() { |
duke@435 | 1227 | MutexLocker locker(CompileTaskAlloc_lock); |
duke@435 | 1228 | CompileTask* task = NULL; |
duke@435 | 1229 | if (_task_free_list != NULL) { |
duke@435 | 1230 | task = _task_free_list; |
duke@435 | 1231 | _task_free_list = task->next(); |
duke@435 | 1232 | task->set_next(NULL); |
duke@435 | 1233 | } else { |
duke@435 | 1234 | task = new CompileTask(); |
duke@435 | 1235 | task->set_next(NULL); |
duke@435 | 1236 | } |
duke@435 | 1237 | return task; |
duke@435 | 1238 | } |
duke@435 | 1239 | |
duke@435 | 1240 | |
duke@435 | 1241 | // ------------------------------------------------------------------ |
duke@435 | 1242 | // CompileBroker::free_task |
duke@435 | 1243 | // |
duke@435 | 1244 | // Add a task to the free list. |
duke@435 | 1245 | void CompileBroker::free_task(CompileTask* task) { |
duke@435 | 1246 | MutexLocker locker(CompileTaskAlloc_lock); |
duke@435 | 1247 | task->free(); |
duke@435 | 1248 | task->set_next(_task_free_list); |
duke@435 | 1249 | _task_free_list = task; |
duke@435 | 1250 | } |
duke@435 | 1251 | |
duke@435 | 1252 | |
duke@435 | 1253 | // ------------------------------------------------------------------ |
duke@435 | 1254 | // CompileBroker::wait_for_completion |
duke@435 | 1255 | // |
duke@435 | 1256 | // Wait for the given method CompileTask to complete. |
duke@435 | 1257 | void CompileBroker::wait_for_completion(CompileTask* task) { |
duke@435 | 1258 | if (CIPrintCompileQueue) { |
duke@435 | 1259 | tty->print_cr("BLOCKING FOR COMPILE"); |
duke@435 | 1260 | } |
duke@435 | 1261 | |
duke@435 | 1262 | assert(task->is_blocking(), "can only wait on blocking task"); |
duke@435 | 1263 | |
duke@435 | 1264 | JavaThread *thread = JavaThread::current(); |
duke@435 | 1265 | thread->set_blocked_on_compilation(true); |
duke@435 | 1266 | |
duke@435 | 1267 | methodHandle method(thread, |
duke@435 | 1268 | (methodOop)JNIHandles::resolve(task->method_handle())); |
duke@435 | 1269 | { |
duke@435 | 1270 | MutexLocker waiter(task->lock(), thread); |
duke@435 | 1271 | |
duke@435 | 1272 | while (!task->is_complete()) |
duke@435 | 1273 | task->lock()->wait(); |
duke@435 | 1274 | } |
duke@435 | 1275 | // It is harmless to check this status without the lock, because |
duke@435 | 1276 | // completion is a stable property (until the task object is recycled). |
duke@435 | 1277 | assert(task->is_complete(), "Compilation should have completed"); |
duke@435 | 1278 | assert(task->code_handle() == NULL, "must be reset"); |
duke@435 | 1279 | |
duke@435 | 1280 | thread->set_blocked_on_compilation(false); |
duke@435 | 1281 | |
duke@435 | 1282 | // By convention, the waiter is responsible for recycling a |
duke@435 | 1283 | // blocking CompileTask. Since there is only one waiter ever |
duke@435 | 1284 | // waiting on a CompileTask, we know that no one else will |
duke@435 | 1285 | // be using this CompileTask; we can free it. |
duke@435 | 1286 | free_task(task); |
duke@435 | 1287 | } |
duke@435 | 1288 | |
duke@435 | 1289 | // ------------------------------------------------------------------ |
duke@435 | 1290 | // CompileBroker::compiler_thread_loop |
duke@435 | 1291 | // |
duke@435 | 1292 | // The main loop run by a CompilerThread. |
duke@435 | 1293 | void CompileBroker::compiler_thread_loop() { |
duke@435 | 1294 | CompilerThread* thread = CompilerThread::current(); |
duke@435 | 1295 | CompileQueue* queue = thread->queue(); |
duke@435 | 1296 | |
duke@435 | 1297 | // For the thread that initializes the ciObjectFactory |
duke@435 | 1298 | // this resource mark holds all the shared objects |
duke@435 | 1299 | ResourceMark rm; |
duke@435 | 1300 | |
duke@435 | 1301 | // First thread to get here will initialize the compiler interface |
duke@435 | 1302 | |
duke@435 | 1303 | if (!ciObjectFactory::is_initialized()) { |
duke@435 | 1304 | ASSERT_IN_VM; |
duke@435 | 1305 | MutexLocker only_one (CompileThread_lock, thread); |
duke@435 | 1306 | if (!ciObjectFactory::is_initialized()) { |
duke@435 | 1307 | ciObjectFactory::initialize(); |
duke@435 | 1308 | } |
duke@435 | 1309 | } |
duke@435 | 1310 | |
duke@435 | 1311 | // Open a log. |
duke@435 | 1312 | if (LogCompilation) { |
duke@435 | 1313 | init_compiler_thread_log(); |
duke@435 | 1314 | } |
duke@435 | 1315 | CompileLog* log = thread->log(); |
duke@435 | 1316 | if (log != NULL) { |
duke@435 | 1317 | log->begin_elem("start_compile_thread thread='" UINTX_FORMAT "' process='%d'", |
duke@435 | 1318 | os::current_thread_id(), |
duke@435 | 1319 | os::current_process_id()); |
duke@435 | 1320 | log->stamp(); |
duke@435 | 1321 | log->end_elem(); |
duke@435 | 1322 | } |
duke@435 | 1323 | |
duke@435 | 1324 | while (true) { |
duke@435 | 1325 | { |
duke@435 | 1326 | // We need this HandleMark to avoid leaking VM handles. |
duke@435 | 1327 | HandleMark hm(thread); |
duke@435 | 1328 | if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { |
duke@435 | 1329 | // The CodeCache is full. Print out warning and disable compilation. |
duke@435 | 1330 | UseInterpreter = true; |
duke@435 | 1331 | if (UseCompiler || AlwaysCompileLoopMethods ) { |
duke@435 | 1332 | if (log != NULL) { |
duke@435 | 1333 | log->begin_elem("code_cache_full"); |
duke@435 | 1334 | log->stamp(); |
duke@435 | 1335 | log->end_elem(); |
duke@435 | 1336 | } |
duke@435 | 1337 | #ifndef PRODUCT |
duke@435 | 1338 | warning("CodeCache is full. Compiler has been disabled"); |
duke@435 | 1339 | if (CompileTheWorld || ExitOnFullCodeCache) { |
duke@435 | 1340 | before_exit(thread); |
duke@435 | 1341 | exit_globals(); // will delete tty |
duke@435 | 1342 | vm_direct_exit(CompileTheWorld ? 0 : 1); |
duke@435 | 1343 | } |
duke@435 | 1344 | #endif |
duke@435 | 1345 | UseCompiler = false; |
duke@435 | 1346 | AlwaysCompileLoopMethods = false; |
duke@435 | 1347 | } |
duke@435 | 1348 | } |
duke@435 | 1349 | |
duke@435 | 1350 | CompileTask* task = queue->get(); |
duke@435 | 1351 | |
duke@435 | 1352 | // Give compiler threads an extra quanta. They tend to be bursty and |
duke@435 | 1353 | // this helps the compiler to finish up the job. |
duke@435 | 1354 | if( CompilerThreadHintNoPreempt ) |
duke@435 | 1355 | os::hint_no_preempt(); |
duke@435 | 1356 | |
duke@435 | 1357 | // trace per thread time and compile statistics |
duke@435 | 1358 | CompilerCounters* counters = ((CompilerThread*)thread)->counters(); |
duke@435 | 1359 | PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); |
duke@435 | 1360 | |
duke@435 | 1361 | // Assign the task to the current thread. Mark this compilation |
duke@435 | 1362 | // thread as active for the profiler. |
duke@435 | 1363 | CompileTaskWrapper ctw(task); |
duke@435 | 1364 | nmethodLocker result_handle; // (handle for the nmethod produced by this task) |
duke@435 | 1365 | task->set_code_handle(&result_handle); |
duke@435 | 1366 | methodHandle method(thread, |
duke@435 | 1367 | (methodOop)JNIHandles::resolve(task->method_handle())); |
duke@435 | 1368 | |
duke@435 | 1369 | // Never compile a method if breakpoints are present in it |
duke@435 | 1370 | if (method()->number_of_breakpoints() == 0) { |
duke@435 | 1371 | // Compile the method. |
duke@435 | 1372 | if (UseCompiler || AlwaysCompileLoopMethods) { |
duke@435 | 1373 | #ifdef COMPILER1 |
duke@435 | 1374 | // Allow repeating compilations for the purpose of benchmarking |
duke@435 | 1375 | // compile speed. This is not useful for customers. |
duke@435 | 1376 | if (CompilationRepeat != 0) { |
duke@435 | 1377 | int compile_count = CompilationRepeat; |
duke@435 | 1378 | while (compile_count > 0) { |
duke@435 | 1379 | invoke_compiler_on_method(task); |
duke@435 | 1380 | nmethod* nm = method->code(); |
duke@435 | 1381 | if (nm != NULL) { |
duke@435 | 1382 | nm->make_zombie(); |
duke@435 | 1383 | method->clear_code(); |
duke@435 | 1384 | } |
duke@435 | 1385 | compile_count--; |
duke@435 | 1386 | } |
duke@435 | 1387 | } |
duke@435 | 1388 | #endif /* COMPILER1 */ |
duke@435 | 1389 | invoke_compiler_on_method(task); |
duke@435 | 1390 | } else { |
duke@435 | 1391 | // After compilation is disabled, remove remaining methods from queue |
duke@435 | 1392 | method->clear_queued_for_compilation(); |
duke@435 | 1393 | } |
duke@435 | 1394 | } |
duke@435 | 1395 | } |
duke@435 | 1396 | } |
duke@435 | 1397 | } |
duke@435 | 1398 | |
duke@435 | 1399 | |
duke@435 | 1400 | // ------------------------------------------------------------------ |
duke@435 | 1401 | // CompileBroker::init_compiler_thread_log |
duke@435 | 1402 | // |
duke@435 | 1403 | // Set up state required by +LogCompilation. |
duke@435 | 1404 | void CompileBroker::init_compiler_thread_log() { |
duke@435 | 1405 | CompilerThread* thread = CompilerThread::current(); |
duke@435 | 1406 | char fileBuf[4*K]; |
duke@435 | 1407 | FILE* fp = NULL; |
duke@435 | 1408 | char* file = NULL; |
duke@435 | 1409 | intx thread_id = os::current_thread_id(); |
duke@435 | 1410 | for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) { |
duke@435 | 1411 | const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL); |
duke@435 | 1412 | if (dir == NULL) dir = ""; |
duke@435 | 1413 | sprintf(fileBuf, "%shs_c" UINTX_FORMAT "_pid%u.log", |
duke@435 | 1414 | dir, thread_id, os::current_process_id()); |
duke@435 | 1415 | fp = fopen(fileBuf, "at"); |
duke@435 | 1416 | if (fp != NULL) { |
duke@435 | 1417 | file = NEW_C_HEAP_ARRAY(char, strlen(fileBuf)+1); |
duke@435 | 1418 | strcpy(file, fileBuf); |
duke@435 | 1419 | break; |
duke@435 | 1420 | } |
duke@435 | 1421 | } |
duke@435 | 1422 | if (fp == NULL) { |
duke@435 | 1423 | warning("Cannot open log file: %s", fileBuf); |
duke@435 | 1424 | } else { |
duke@435 | 1425 | if (LogCompilation && Verbose) |
duke@435 | 1426 | tty->print_cr("Opening compilation log %s", file); |
duke@435 | 1427 | CompileLog* log = new(ResourceObj::C_HEAP) CompileLog(file, fp, thread_id); |
duke@435 | 1428 | thread->init_log(log); |
duke@435 | 1429 | |
duke@435 | 1430 | if (xtty != NULL) { |
duke@435 | 1431 | ttyLocker ttyl; |
duke@435 | 1432 | |
duke@435 | 1433 | // Record any per thread log files |
duke@435 | 1434 | xtty->elem("thread_logfile thread='%d' filename='%s'", thread_id, file); |
duke@435 | 1435 | } |
duke@435 | 1436 | } |
duke@435 | 1437 | } |
duke@435 | 1438 | |
duke@435 | 1439 | // ------------------------------------------------------------------ |
duke@435 | 1440 | // CompileBroker::set_should_block |
duke@435 | 1441 | // |
duke@435 | 1442 | // Set _should_block. |
duke@435 | 1443 | // Call this from the VM, with Threads_lock held and a safepoint requested. |
duke@435 | 1444 | void CompileBroker::set_should_block() { |
duke@435 | 1445 | assert(Threads_lock->owner() == Thread::current(), "must have threads lock"); |
duke@435 | 1446 | assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint already"); |
duke@435 | 1447 | #ifndef PRODUCT |
duke@435 | 1448 | if (PrintCompilation && (Verbose || WizardMode)) |
duke@435 | 1449 | tty->print_cr("notifying compiler thread pool to block"); |
duke@435 | 1450 | #endif |
duke@435 | 1451 | _should_block = true; |
duke@435 | 1452 | } |
duke@435 | 1453 | |
duke@435 | 1454 | // ------------------------------------------------------------------ |
duke@435 | 1455 | // CompileBroker::maybe_block |
duke@435 | 1456 | // |
duke@435 | 1457 | // Call this from the compiler at convenient points, to poll for _should_block. |
duke@435 | 1458 | void CompileBroker::maybe_block() { |
duke@435 | 1459 | if (_should_block) { |
duke@435 | 1460 | #ifndef PRODUCT |
duke@435 | 1461 | if (PrintCompilation && (Verbose || WizardMode)) |
duke@435 | 1462 | tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", Thread::current()); |
duke@435 | 1463 | #endif |
duke@435 | 1464 | ThreadInVMfromNative tivfn(JavaThread::current()); |
duke@435 | 1465 | } |
duke@435 | 1466 | } |
duke@435 | 1467 | |
duke@435 | 1468 | |
duke@435 | 1469 | // ------------------------------------------------------------------ |
duke@435 | 1470 | // CompileBroker::invoke_compiler_on_method |
duke@435 | 1471 | // |
duke@435 | 1472 | // Compile a method. |
duke@435 | 1473 | // |
duke@435 | 1474 | void CompileBroker::invoke_compiler_on_method(CompileTask* task) { |
duke@435 | 1475 | if (PrintCompilation) { |
duke@435 | 1476 | ResourceMark rm; |
duke@435 | 1477 | task->print_line(); |
duke@435 | 1478 | } |
duke@435 | 1479 | elapsedTimer time; |
duke@435 | 1480 | |
duke@435 | 1481 | CompilerThread* thread = CompilerThread::current(); |
duke@435 | 1482 | ResourceMark rm(thread); |
duke@435 | 1483 | |
duke@435 | 1484 | // Common flags. |
duke@435 | 1485 | uint compile_id = task->compile_id(); |
duke@435 | 1486 | int osr_bci = task->osr_bci(); |
duke@435 | 1487 | bool is_osr = (osr_bci != standard_entry_bci); |
duke@435 | 1488 | bool should_log = (thread->log() != NULL); |
duke@435 | 1489 | bool should_break = false; |
duke@435 | 1490 | { |
duke@435 | 1491 | // create the handle inside it's own block so it can't |
duke@435 | 1492 | // accidentally be referenced once the thread transitions to |
duke@435 | 1493 | // native. The NoHandleMark before the transition should catch |
duke@435 | 1494 | // any cases where this occurs in the future. |
duke@435 | 1495 | methodHandle method(thread, |
duke@435 | 1496 | (methodOop)JNIHandles::resolve(task->method_handle())); |
duke@435 | 1497 | should_break = check_break_at(method, compile_id, is_osr); |
duke@435 | 1498 | if (should_log && !CompilerOracle::should_log(method)) { |
duke@435 | 1499 | should_log = false; |
duke@435 | 1500 | } |
duke@435 | 1501 | assert(!method->is_native(), "no longer compile natives"); |
duke@435 | 1502 | |
duke@435 | 1503 | // Save information about this method in case of failure. |
duke@435 | 1504 | set_last_compile(thread, method, is_osr, task->comp_level()); |
duke@435 | 1505 | |
duke@435 | 1506 | DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler(task->comp_level()), method); |
duke@435 | 1507 | } |
duke@435 | 1508 | |
duke@435 | 1509 | // Allocate a new set of JNI handles. |
duke@435 | 1510 | push_jni_handle_block(); |
duke@435 | 1511 | jobject target_handle = JNIHandles::make_local(thread, JNIHandles::resolve(task->method_handle())); |
duke@435 | 1512 | int compilable = ciEnv::MethodCompilable; |
duke@435 | 1513 | { |
duke@435 | 1514 | int system_dictionary_modification_counter; |
duke@435 | 1515 | { |
duke@435 | 1516 | MutexLocker locker(Compile_lock, thread); |
duke@435 | 1517 | system_dictionary_modification_counter = SystemDictionary::number_of_modifications(); |
duke@435 | 1518 | } |
duke@435 | 1519 | |
duke@435 | 1520 | NoHandleMark nhm; |
duke@435 | 1521 | ThreadToNativeFromVM ttn(thread); |
duke@435 | 1522 | |
duke@435 | 1523 | ciEnv ci_env(task, system_dictionary_modification_counter); |
duke@435 | 1524 | if (should_break) { |
duke@435 | 1525 | ci_env.set_break_at_compile(true); |
duke@435 | 1526 | } |
duke@435 | 1527 | if (should_log) { |
duke@435 | 1528 | ci_env.set_log(thread->log()); |
duke@435 | 1529 | } |
duke@435 | 1530 | assert(thread->env() == &ci_env, "set by ci_env"); |
duke@435 | 1531 | // The thread-env() field is cleared in ~CompileTaskWrapper. |
duke@435 | 1532 | |
duke@435 | 1533 | ciMethod* target = ci_env.get_method_from_handle(target_handle); |
duke@435 | 1534 | |
duke@435 | 1535 | TraceTime t1("compilation", &time); |
duke@435 | 1536 | |
duke@435 | 1537 | compiler(task->comp_level())->compile_method(&ci_env, target, osr_bci); |
duke@435 | 1538 | |
duke@435 | 1539 | if (!ci_env.failing() && task->code() == NULL) { |
duke@435 | 1540 | //assert(false, "compiler should always document failure"); |
duke@435 | 1541 | // The compiler elected, without comment, not to register a result. |
duke@435 | 1542 | // Do not attempt further compilations of this method. |
duke@435 | 1543 | ci_env.record_method_not_compilable("compile failed"); |
duke@435 | 1544 | } |
duke@435 | 1545 | |
duke@435 | 1546 | if (ci_env.failing()) { |
duke@435 | 1547 | // Copy this bit to the enclosing block: |
duke@435 | 1548 | compilable = ci_env.compilable(); |
duke@435 | 1549 | if (PrintCompilation) { |
duke@435 | 1550 | const char* reason = ci_env.failure_reason(); |
duke@435 | 1551 | if (compilable == ciEnv::MethodCompilable_not_at_tier) { |
duke@435 | 1552 | if (is_highest_tier_compile(ci_env.comp_level())) { |
duke@435 | 1553 | // Already at highest tier, promote to not compilable. |
duke@435 | 1554 | compilable = ciEnv::MethodCompilable_never; |
duke@435 | 1555 | } else { |
duke@435 | 1556 | tty->print_cr("%3d COMPILE SKIPPED: %s (retry at different tier)", compile_id, reason); |
duke@435 | 1557 | } |
duke@435 | 1558 | } |
duke@435 | 1559 | |
duke@435 | 1560 | if (compilable == ciEnv::MethodCompilable_never) { |
duke@435 | 1561 | tty->print_cr("%3d COMPILE SKIPPED: %s (not retryable)", compile_id, reason); |
duke@435 | 1562 | } else if (compilable == ciEnv::MethodCompilable) { |
duke@435 | 1563 | tty->print_cr("%3d COMPILE SKIPPED: %s", compile_id, reason); |
duke@435 | 1564 | } |
duke@435 | 1565 | } |
duke@435 | 1566 | } else { |
duke@435 | 1567 | task->mark_success(); |
duke@435 | 1568 | task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes()); |
duke@435 | 1569 | } |
duke@435 | 1570 | } |
duke@435 | 1571 | pop_jni_handle_block(); |
duke@435 | 1572 | |
duke@435 | 1573 | methodHandle method(thread, |
duke@435 | 1574 | (methodOop)JNIHandles::resolve(task->method_handle())); |
duke@435 | 1575 | |
duke@435 | 1576 | DTRACE_METHOD_COMPILE_END_PROBE(compiler(task->comp_level()), method, task->is_success()); |
duke@435 | 1577 | |
duke@435 | 1578 | collect_statistics(thread, time, task); |
duke@435 | 1579 | |
duke@435 | 1580 | if (compilable == ciEnv::MethodCompilable_never) { |
duke@435 | 1581 | if (is_osr) { |
duke@435 | 1582 | method->set_not_osr_compilable(); |
duke@435 | 1583 | } else { |
duke@435 | 1584 | method->set_not_compilable(); |
duke@435 | 1585 | } |
duke@435 | 1586 | } else if (compilable == ciEnv::MethodCompilable_not_at_tier) { |
duke@435 | 1587 | method->set_not_compilable(task->comp_level()); |
duke@435 | 1588 | } |
duke@435 | 1589 | |
duke@435 | 1590 | // Note that the queued_for_compilation bits are cleared without |
duke@435 | 1591 | // protection of a mutex. [They were set by the requester thread, |
duke@435 | 1592 | // when adding the task to the complie queue -- at which time the |
duke@435 | 1593 | // compile queue lock was held. Subsequently, we acquired the compile |
duke@435 | 1594 | // queue lock to get this task off the compile queue; thus (to belabour |
duke@435 | 1595 | // the point somewhat) our clearing of the bits must be occurring |
duke@435 | 1596 | // only after the setting of the bits. See also 14012000 above. |
duke@435 | 1597 | method->clear_queued_for_compilation(); |
duke@435 | 1598 | |
duke@435 | 1599 | #ifdef ASSERT |
duke@435 | 1600 | if (CollectedHeap::fired_fake_oom()) { |
duke@435 | 1601 | // The current compile received a fake OOM during compilation so |
duke@435 | 1602 | // go ahead and exit the VM since the test apparently succeeded |
duke@435 | 1603 | tty->print_cr("*** Shutting down VM after successful fake OOM"); |
duke@435 | 1604 | vm_exit(0); |
duke@435 | 1605 | } |
duke@435 | 1606 | #endif |
duke@435 | 1607 | } |
duke@435 | 1608 | |
duke@435 | 1609 | |
duke@435 | 1610 | // ------------------------------------------------------------------ |
duke@435 | 1611 | // CompileBroker::set_last_compile |
duke@435 | 1612 | // |
duke@435 | 1613 | // Record this compilation for debugging purposes. |
duke@435 | 1614 | void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) { |
duke@435 | 1615 | ResourceMark rm; |
duke@435 | 1616 | char* method_name = method->name()->as_C_string(); |
duke@435 | 1617 | strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length); |
duke@435 | 1618 | char current_method[CompilerCounters::cmname_buffer_length]; |
duke@435 | 1619 | size_t maxLen = CompilerCounters::cmname_buffer_length; |
duke@435 | 1620 | |
duke@435 | 1621 | if (UsePerfData) { |
duke@435 | 1622 | const char* class_name = method->method_holder()->klass_part()->name()->as_C_string(); |
duke@435 | 1623 | |
duke@435 | 1624 | size_t s1len = strlen(class_name); |
duke@435 | 1625 | size_t s2len = strlen(method_name); |
duke@435 | 1626 | |
duke@435 | 1627 | // check if we need to truncate the string |
duke@435 | 1628 | if (s1len + s2len + 2 > maxLen) { |
duke@435 | 1629 | |
duke@435 | 1630 | // the strategy is to lop off the leading characters of the |
duke@435 | 1631 | // class name and the trailing characters of the method name. |
duke@435 | 1632 | |
duke@435 | 1633 | if (s2len + 2 > maxLen) { |
duke@435 | 1634 | // lop of the entire class name string, let snprintf handle |
duke@435 | 1635 | // truncation of the method name. |
duke@435 | 1636 | class_name += s1len; // null string |
duke@435 | 1637 | } |
duke@435 | 1638 | else { |
duke@435 | 1639 | // lop off the extra characters from the front of the class name |
duke@435 | 1640 | class_name += ((s1len + s2len + 2) - maxLen); |
duke@435 | 1641 | } |
duke@435 | 1642 | } |
duke@435 | 1643 | |
duke@435 | 1644 | jio_snprintf(current_method, maxLen, "%s %s", class_name, method_name); |
duke@435 | 1645 | } |
duke@435 | 1646 | |
duke@435 | 1647 | if (CICountOSR && is_osr) { |
duke@435 | 1648 | _last_compile_type = osr_compile; |
duke@435 | 1649 | } else { |
duke@435 | 1650 | _last_compile_type = normal_compile; |
duke@435 | 1651 | } |
duke@435 | 1652 | _last_compile_level = comp_level; |
duke@435 | 1653 | |
duke@435 | 1654 | if (UsePerfData) { |
duke@435 | 1655 | CompilerCounters* counters = thread->counters(); |
duke@435 | 1656 | counters->set_current_method(current_method); |
duke@435 | 1657 | counters->set_compile_type((jlong)_last_compile_type); |
duke@435 | 1658 | } |
duke@435 | 1659 | } |
duke@435 | 1660 | |
duke@435 | 1661 | |
duke@435 | 1662 | // ------------------------------------------------------------------ |
duke@435 | 1663 | // CompileBroker::push_jni_handle_block |
duke@435 | 1664 | // |
duke@435 | 1665 | // Push on a new block of JNI handles. |
duke@435 | 1666 | void CompileBroker::push_jni_handle_block() { |
duke@435 | 1667 | JavaThread* thread = JavaThread::current(); |
duke@435 | 1668 | |
duke@435 | 1669 | // Allocate a new block for JNI handles. |
duke@435 | 1670 | // Inlined code from jni_PushLocalFrame() |
duke@435 | 1671 | JNIHandleBlock* java_handles = thread->active_handles(); |
duke@435 | 1672 | JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread); |
duke@435 | 1673 | assert(compile_handles != NULL && java_handles != NULL, "should not be NULL"); |
duke@435 | 1674 | compile_handles->set_pop_frame_link(java_handles); // make sure java handles get gc'd. |
duke@435 | 1675 | thread->set_active_handles(compile_handles); |
duke@435 | 1676 | } |
duke@435 | 1677 | |
duke@435 | 1678 | |
duke@435 | 1679 | // ------------------------------------------------------------------ |
duke@435 | 1680 | // CompileBroker::pop_jni_handle_block |
duke@435 | 1681 | // |
duke@435 | 1682 | // Pop off the current block of JNI handles. |
duke@435 | 1683 | void CompileBroker::pop_jni_handle_block() { |
duke@435 | 1684 | JavaThread* thread = JavaThread::current(); |
duke@435 | 1685 | |
duke@435 | 1686 | // Release our JNI handle block |
duke@435 | 1687 | JNIHandleBlock* compile_handles = thread->active_handles(); |
duke@435 | 1688 | JNIHandleBlock* java_handles = compile_handles->pop_frame_link(); |
duke@435 | 1689 | thread->set_active_handles(java_handles); |
duke@435 | 1690 | compile_handles->set_pop_frame_link(NULL); |
duke@435 | 1691 | JNIHandleBlock::release_block(compile_handles, thread); // may block |
duke@435 | 1692 | } |
duke@435 | 1693 | |
duke@435 | 1694 | |
duke@435 | 1695 | // ------------------------------------------------------------------ |
duke@435 | 1696 | // CompileBroker::check_break_at |
duke@435 | 1697 | // |
duke@435 | 1698 | // Should the compilation break at the current compilation. |
duke@435 | 1699 | bool CompileBroker::check_break_at(methodHandle method, int compile_id, bool is_osr) { |
duke@435 | 1700 | if (CICountOSR && is_osr && (compile_id == CIBreakAtOSR)) { |
duke@435 | 1701 | return true; |
duke@435 | 1702 | } else if( CompilerOracle::should_break_at(method) ) { // break when compiling |
duke@435 | 1703 | return true; |
duke@435 | 1704 | } else { |
duke@435 | 1705 | return (compile_id == CIBreakAt); |
duke@435 | 1706 | } |
duke@435 | 1707 | } |
duke@435 | 1708 | |
duke@435 | 1709 | // ------------------------------------------------------------------ |
duke@435 | 1710 | // CompileBroker::collect_statistics |
duke@435 | 1711 | // |
duke@435 | 1712 | // Collect statistics about the compilation. |
duke@435 | 1713 | |
duke@435 | 1714 | void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task) { |
duke@435 | 1715 | bool success = task->is_success(); |
duke@435 | 1716 | methodHandle method (thread, (methodOop)JNIHandles::resolve(task->method_handle())); |
duke@435 | 1717 | uint compile_id = task->compile_id(); |
duke@435 | 1718 | bool is_osr = (task->osr_bci() != standard_entry_bci); |
duke@435 | 1719 | nmethod* code = task->code(); |
duke@435 | 1720 | CompilerCounters* counters = thread->counters(); |
duke@435 | 1721 | |
duke@435 | 1722 | assert(code == NULL || code->is_locked_by_vm(), "will survive the MutexLocker"); |
duke@435 | 1723 | MutexLocker locker(CompileStatistics_lock); |
duke@435 | 1724 | |
duke@435 | 1725 | // _perf variables are production performance counters which are |
duke@435 | 1726 | // updated regardless of the setting of the CITime and CITimeEach flags |
duke@435 | 1727 | // |
duke@435 | 1728 | if (!success) { |
duke@435 | 1729 | _total_bailout_count++; |
duke@435 | 1730 | if (UsePerfData) { |
duke@435 | 1731 | _perf_last_failed_method->set_value(counters->current_method()); |
duke@435 | 1732 | _perf_last_failed_type->set_value(counters->compile_type()); |
duke@435 | 1733 | _perf_total_bailout_count->inc(); |
duke@435 | 1734 | } |
duke@435 | 1735 | } else if (code == NULL) { |
duke@435 | 1736 | if (UsePerfData) { |
duke@435 | 1737 | _perf_last_invalidated_method->set_value(counters->current_method()); |
duke@435 | 1738 | _perf_last_invalidated_type->set_value(counters->compile_type()); |
duke@435 | 1739 | _perf_total_invalidated_count->inc(); |
duke@435 | 1740 | } |
duke@435 | 1741 | _total_invalidated_count++; |
duke@435 | 1742 | } else { |
duke@435 | 1743 | // Compilation succeeded |
duke@435 | 1744 | |
duke@435 | 1745 | // update compilation ticks - used by the implementation of |
duke@435 | 1746 | // java.lang.management.CompilationMBean |
duke@435 | 1747 | _perf_total_compilation->inc(time.ticks()); |
duke@435 | 1748 | |
duke@435 | 1749 | if (CITime) { |
duke@435 | 1750 | _t_total_compilation.add(time); |
duke@435 | 1751 | if (is_osr) { |
duke@435 | 1752 | _t_osr_compilation.add(time); |
duke@435 | 1753 | _sum_osr_bytes_compiled += method->code_size() + task->num_inlined_bytecodes(); |
duke@435 | 1754 | } else { |
duke@435 | 1755 | _t_standard_compilation.add(time); |
duke@435 | 1756 | _sum_standard_bytes_compiled += method->code_size() + task->num_inlined_bytecodes(); |
duke@435 | 1757 | } |
duke@435 | 1758 | } |
duke@435 | 1759 | |
duke@435 | 1760 | if (UsePerfData) { |
duke@435 | 1761 | // save the name of the last method compiled |
duke@435 | 1762 | _perf_last_method->set_value(counters->current_method()); |
duke@435 | 1763 | _perf_last_compile_type->set_value(counters->compile_type()); |
duke@435 | 1764 | _perf_last_compile_size->set_value(method->code_size() + |
duke@435 | 1765 | task->num_inlined_bytecodes()); |
duke@435 | 1766 | if (is_osr) { |
duke@435 | 1767 | _perf_osr_compilation->inc(time.ticks()); |
duke@435 | 1768 | _perf_sum_osr_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes()); |
duke@435 | 1769 | } else { |
duke@435 | 1770 | _perf_standard_compilation->inc(time.ticks()); |
duke@435 | 1771 | _perf_sum_standard_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes()); |
duke@435 | 1772 | } |
duke@435 | 1773 | } |
duke@435 | 1774 | |
duke@435 | 1775 | if (CITimeEach) { |
duke@435 | 1776 | float bytes_per_sec = 1.0 * (method->code_size() + task->num_inlined_bytecodes()) / time.seconds(); |
duke@435 | 1777 | tty->print_cr("%3d seconds: %f bytes/sec : %f (bytes %d + %d inlined)", |
duke@435 | 1778 | compile_id, time.seconds(), bytes_per_sec, method->code_size(), task->num_inlined_bytecodes()); |
duke@435 | 1779 | } |
duke@435 | 1780 | |
duke@435 | 1781 | // Collect counts of successful compilations |
duke@435 | 1782 | _sum_nmethod_size += code->total_size(); |
duke@435 | 1783 | _sum_nmethod_code_size += code->code_size(); |
duke@435 | 1784 | _total_compile_count++; |
duke@435 | 1785 | |
duke@435 | 1786 | if (UsePerfData) { |
duke@435 | 1787 | _perf_sum_nmethod_size->inc(code->total_size()); |
duke@435 | 1788 | _perf_sum_nmethod_code_size->inc(code->code_size()); |
duke@435 | 1789 | _perf_total_compile_count->inc(); |
duke@435 | 1790 | } |
duke@435 | 1791 | |
duke@435 | 1792 | if (is_osr) { |
duke@435 | 1793 | if (UsePerfData) _perf_total_osr_compile_count->inc(); |
duke@435 | 1794 | _total_osr_compile_count++; |
duke@435 | 1795 | } else { |
duke@435 | 1796 | if (UsePerfData) _perf_total_standard_compile_count->inc(); |
duke@435 | 1797 | _total_standard_compile_count++; |
duke@435 | 1798 | } |
duke@435 | 1799 | } |
duke@435 | 1800 | // set the current method for the thread to null |
duke@435 | 1801 | if (UsePerfData) counters->set_current_method(""); |
duke@435 | 1802 | } |
duke@435 | 1803 | |
duke@435 | 1804 | |
duke@435 | 1805 | |
duke@435 | 1806 | void CompileBroker::print_times() { |
duke@435 | 1807 | tty->cr(); |
duke@435 | 1808 | tty->print_cr("Accumulated compiler times (for compiled methods only)"); |
duke@435 | 1809 | tty->print_cr("------------------------------------------------"); |
duke@435 | 1810 | //0000000000111111111122222222223333333333444444444455555555556666666666 |
duke@435 | 1811 | //0123456789012345678901234567890123456789012345678901234567890123456789 |
duke@435 | 1812 | tty->print_cr(" Total compilation time : %6.3f s", CompileBroker::_t_total_compilation.seconds()); |
duke@435 | 1813 | tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f", |
duke@435 | 1814 | CompileBroker::_t_standard_compilation.seconds(), |
duke@435 | 1815 | CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count); |
duke@435 | 1816 | tty->print_cr(" On stack replacement : %6.3f s, Average : %2.3f", CompileBroker::_t_osr_compilation.seconds(), CompileBroker::_t_osr_compilation.seconds() / CompileBroker::_total_osr_compile_count); |
duke@435 | 1817 | compiler(CompLevel_fast_compile)->print_timers(); |
duke@435 | 1818 | if (compiler(CompLevel_fast_compile) != compiler(CompLevel_highest_tier)) { |
duke@435 | 1819 | compiler(CompLevel_highest_tier)->print_timers(); |
duke@435 | 1820 | } |
duke@435 | 1821 | |
duke@435 | 1822 | tty->cr(); |
duke@435 | 1823 | int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled; |
duke@435 | 1824 | tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb); |
duke@435 | 1825 | tty->print_cr(" Standard compilation : %6d bytes", CompileBroker::_sum_standard_bytes_compiled); |
duke@435 | 1826 | tty->print_cr(" On stack replacement : %6d bytes", CompileBroker::_sum_osr_bytes_compiled); |
duke@435 | 1827 | int bps = (int)(tcb / CompileBroker::_t_total_compilation.seconds()); |
duke@435 | 1828 | tty->print_cr(" Average compilation speed: %6d bytes/s", bps); |
duke@435 | 1829 | tty->cr(); |
duke@435 | 1830 | tty->print_cr(" nmethod code size : %6d bytes", CompileBroker::_sum_nmethod_code_size); |
duke@435 | 1831 | tty->print_cr(" nmethod total size : %6d bytes", CompileBroker::_sum_nmethod_size); |
duke@435 | 1832 | } |
duke@435 | 1833 | |
duke@435 | 1834 | |
duke@435 | 1835 | // Debugging output for failure |
duke@435 | 1836 | void CompileBroker::print_last_compile() { |
duke@435 | 1837 | if ( _last_compile_level != CompLevel_none && |
duke@435 | 1838 | compiler(_last_compile_level) != NULL && |
duke@435 | 1839 | _last_method_compiled != NULL && |
duke@435 | 1840 | _last_compile_type != no_compile) { |
duke@435 | 1841 | if (_last_compile_type == osr_compile) { |
duke@435 | 1842 | tty->print_cr("Last parse: [osr]%d+++(%d) %s", |
duke@435 | 1843 | _osr_compilation_id, _last_compile_level, _last_method_compiled); |
duke@435 | 1844 | } else { |
duke@435 | 1845 | tty->print_cr("Last parse: %d+++(%d) %s", |
duke@435 | 1846 | _compilation_id, _last_compile_level, _last_method_compiled); |
duke@435 | 1847 | } |
duke@435 | 1848 | } |
duke@435 | 1849 | } |
duke@435 | 1850 | |
duke@435 | 1851 | |
duke@435 | 1852 | void CompileBroker::print_compiler_threads_on(outputStream* st) { |
duke@435 | 1853 | #ifndef PRODUCT |
duke@435 | 1854 | st->print_cr("Compiler thread printing unimplemented."); |
duke@435 | 1855 | st->cr(); |
duke@435 | 1856 | #endif |
duke@435 | 1857 | } |