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