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