src/share/vm/compiler/compileBroker.cpp

Thu, 29 May 2014 09:56:06 -0700

author
asaha
date
Thu, 29 May 2014 09:56:06 -0700
changeset 6782
f73af4455d7d
parent 6779
364b73402247
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
child 7179
7301840ea20e
permissions
-rw-r--r--

Merge

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

mercurial