Mercurial > hg > graal-compiler
comparison src/share/vm/compiler/compileBroker.cpp @ 1783:d5d065957597
6953144: Tiered compilation
Summary: Infrastructure for tiered compilation support (interpreter + c1 + c2) for 32 and 64 bit. Simple tiered policy implementation.
Reviewed-by: kvn, never, phh, twisti
author | iveresov |
---|---|
date | Fri, 03 Sep 2010 17:51:07 -0700 |
parents | 3e8fbc61cee8 |
children | 2d26b0046e0d 22ef3370343b |
comparison
equal
deleted
inserted
replaced
1782:f353275af40e | 1783:d5d065957597 |
---|---|
121 int CompileBroker::_sum_osr_bytes_compiled = 0; | 121 int CompileBroker::_sum_osr_bytes_compiled = 0; |
122 int CompileBroker::_sum_standard_bytes_compiled = 0; | 122 int CompileBroker::_sum_standard_bytes_compiled = 0; |
123 int CompileBroker::_sum_nmethod_size = 0; | 123 int CompileBroker::_sum_nmethod_size = 0; |
124 int CompileBroker::_sum_nmethod_code_size = 0; | 124 int CompileBroker::_sum_nmethod_code_size = 0; |
125 | 125 |
126 CompileQueue* CompileBroker::_method_queue = NULL; | 126 CompileQueue* CompileBroker::_c2_method_queue = NULL; |
127 CompileQueue* CompileBroker::_c1_method_queue = NULL; | |
127 CompileTask* CompileBroker::_task_free_list = NULL; | 128 CompileTask* CompileBroker::_task_free_list = NULL; |
128 | 129 |
129 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; | 130 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; |
130 | 131 |
131 // CompileTaskWrapper | |
132 // | |
133 // Assign this task to the current thread. Deallocate the task | |
134 // when the compilation is complete. | |
135 class CompileTaskWrapper : StackObj { | |
136 public: | |
137 CompileTaskWrapper(CompileTask* task); | |
138 ~CompileTaskWrapper(); | |
139 }; | |
140 | 132 |
141 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { | 133 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { |
142 CompilerThread* thread = CompilerThread::current(); | 134 CompilerThread* thread = CompilerThread::current(); |
143 thread->set_task(task); | 135 thread->set_task(task); |
144 CompileLog* log = thread->log(); | 136 CompileLog* log = thread->log(); |
244 tty->print_cr(" osr_bci=%d is_blocking=%s is_complete=%s is_success=%s>", | 236 tty->print_cr(" osr_bci=%d is_blocking=%s is_complete=%s is_success=%s>", |
245 _osr_bci, bool_to_str(_is_blocking), | 237 _osr_bci, bool_to_str(_is_blocking), |
246 bool_to_str(_is_complete), bool_to_str(_is_success)); | 238 bool_to_str(_is_complete), bool_to_str(_is_success)); |
247 } | 239 } |
248 | 240 |
241 | |
242 void CompileTask::print_compilation(outputStream *st, methodOop method, char* method_name) { | |
243 nmethod::print_compilation(st, method_name,/*title*/ NULL, method, | |
244 is_blocking(), compile_id(), osr_bci(), comp_level()); | |
245 } | |
246 | |
249 // ------------------------------------------------------------------ | 247 // ------------------------------------------------------------------ |
250 // CompileTask::print_line_on_error | 248 // CompileTask::print_line_on_error |
251 // | 249 // |
252 // This function is called by fatal error handler when the thread | 250 // This function is called by fatal error handler when the thread |
253 // causing troubles is a compiler thread. | 251 // causing troubles is a compiler thread. |
256 // | 254 // |
257 // Otherwise it's the same as CompileTask::print_line() | 255 // Otherwise it's the same as CompileTask::print_line() |
258 // | 256 // |
259 void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) { | 257 void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) { |
260 methodOop method = (methodOop)JNIHandles::resolve(_method); | 258 methodOop method = (methodOop)JNIHandles::resolve(_method); |
261 | |
262 // print compiler name | 259 // print compiler name |
263 st->print("%s:", CompileBroker::compiler(comp_level())->name()); | 260 st->print("%s:", CompileBroker::compiler(comp_level())->name()); |
264 | 261 char* method_name = NULL; |
265 // print compilation number | 262 if (method != NULL) { |
266 st->print("%3d", compile_id()); | 263 method_name = method->name_and_sig_as_C_string(buf, buflen); |
267 | 264 } |
268 // print method attributes | 265 print_compilation(st, method, method_name); |
269 const bool is_osr = osr_bci() != CompileBroker::standard_entry_bci; | |
270 { const char blocking_char = is_blocking() ? 'b' : ' '; | |
271 const char compile_type = is_osr ? '%' : ' '; | |
272 const char sync_char = method->is_synchronized() ? 's' : ' '; | |
273 const char exception_char = method->has_exception_handler() ? '!' : ' '; | |
274 const char tier_char = | |
275 is_highest_tier_compile(comp_level()) ? ' ' : ('0' + comp_level()); | |
276 st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, tier_char); | |
277 } | |
278 | |
279 // Use buf to get method name and signature | |
280 if (method != NULL) st->print("%s", method->name_and_sig_as_C_string(buf, buflen)); | |
281 | |
282 // print osr_bci if any | |
283 if (is_osr) st->print(" @ %d", osr_bci()); | |
284 | |
285 // print method size | |
286 st->print_cr(" (%d bytes)", method->code_size()); | |
287 } | 266 } |
288 | 267 |
289 // ------------------------------------------------------------------ | 268 // ------------------------------------------------------------------ |
290 // CompileTask::print_line | 269 // CompileTask::print_line |
291 void CompileTask::print_line() { | 270 void CompileTask::print_line() { |
296 | 275 |
297 ttyLocker ttyl; // keep the following output all in one block | 276 ttyLocker ttyl; // keep the following output all in one block |
298 | 277 |
299 // print compiler name if requested | 278 // print compiler name if requested |
300 if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler(comp_level())->name()); | 279 if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler(comp_level())->name()); |
301 | 280 print_compilation(tty, method(), NULL); |
302 // print compilation number | |
303 tty->print("%3d", compile_id()); | |
304 | |
305 // print method attributes | |
306 const bool is_osr = osr_bci() != CompileBroker::standard_entry_bci; | |
307 { const char blocking_char = is_blocking() ? 'b' : ' '; | |
308 const char compile_type = is_osr ? '%' : ' '; | |
309 const char sync_char = method->is_synchronized() ? 's' : ' '; | |
310 const char exception_char = method->has_exception_handler() ? '!' : ' '; | |
311 const char tier_char = | |
312 is_highest_tier_compile(comp_level()) ? ' ' : ('0' + comp_level()); | |
313 tty->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, tier_char); | |
314 } | |
315 | |
316 // print method name | |
317 method->print_short_name(tty); | |
318 | |
319 // print osr_bci if any | |
320 if (is_osr) tty->print(" @ %d", osr_bci()); | |
321 | |
322 // print method size | |
323 tty->print_cr(" (%d bytes)", method->code_size()); | |
324 } | 281 } |
325 | 282 |
326 | 283 |
327 // ------------------------------------------------------------------ | 284 // ------------------------------------------------------------------ |
328 // CompileTask::log_task | 285 // CompileTask::log_task |
425 // Add a CompileTask to a CompileQueue | 382 // Add a CompileTask to a CompileQueue |
426 void CompileQueue::add(CompileTask* task) { | 383 void CompileQueue::add(CompileTask* task) { |
427 assert(lock()->owned_by_self(), "must own lock"); | 384 assert(lock()->owned_by_self(), "must own lock"); |
428 | 385 |
429 task->set_next(NULL); | 386 task->set_next(NULL); |
387 task->set_prev(NULL); | |
430 | 388 |
431 if (_last == NULL) { | 389 if (_last == NULL) { |
432 // The compile queue is empty. | 390 // The compile queue is empty. |
433 assert(_first == NULL, "queue is empty"); | 391 assert(_first == NULL, "queue is empty"); |
434 _first = task; | 392 _first = task; |
435 _last = task; | 393 _last = task; |
436 } else { | 394 } else { |
437 // Append the task to the queue. | 395 // Append the task to the queue. |
438 assert(_last->next() == NULL, "not last"); | 396 assert(_last->next() == NULL, "not last"); |
439 _last->set_next(task); | 397 _last->set_next(task); |
398 task->set_prev(_last); | |
440 _last = task; | 399 _last = task; |
441 } | 400 } |
401 ++_size; | |
442 | 402 |
443 // Mark the method as being in the compile queue. | 403 // Mark the method as being in the compile queue. |
444 ((methodOop)JNIHandles::resolve(task->method_handle()))->set_queued_for_compilation(); | 404 ((methodOop)JNIHandles::resolve(task->method_handle()))->set_queued_for_compilation(); |
445 | 405 |
446 if (CIPrintCompileQueue) { | 406 if (CIPrintCompileQueue) { |
450 if (LogCompilation && xtty != NULL) { | 410 if (LogCompilation && xtty != NULL) { |
451 task->log_task_queued(); | 411 task->log_task_queued(); |
452 } | 412 } |
453 | 413 |
454 // Notify CompilerThreads that a task is available. | 414 // Notify CompilerThreads that a task is available. |
455 lock()->notify(); | 415 lock()->notify_all(); |
456 } | 416 } |
457 | |
458 | 417 |
459 // ------------------------------------------------------------------ | 418 // ------------------------------------------------------------------ |
460 // CompileQueue::get | 419 // CompileQueue::get |
461 // | 420 // |
462 // Get the next CompileTask from a CompileQueue | 421 // Get the next CompileTask from a CompileQueue |
463 CompileTask* CompileQueue::get() { | 422 CompileTask* CompileQueue::get() { |
464 NMethodSweeper::possibly_sweep(); | 423 NMethodSweeper::possibly_sweep(); |
465 | 424 |
466 MutexLocker locker(lock()); | 425 MutexLocker locker(lock()); |
467 | |
468 // Wait for an available CompileTask. | 426 // Wait for an available CompileTask. |
469 while (_first == NULL) { | 427 while (_first == NULL) { |
470 // There is no work to be done right now. Wait. | 428 // There is no work to be done right now. Wait. |
471 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) { | 429 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) { |
472 // During the emergency sweeping periods, wake up and sweep occasionally | 430 // During the emergency sweeping periods, wake up and sweep occasionally |
479 } else { | 437 } else { |
480 // During normal operation no need to wake up on timer | 438 // During normal operation no need to wake up on timer |
481 lock()->wait(); | 439 lock()->wait(); |
482 } | 440 } |
483 } | 441 } |
484 | 442 CompileTask* task = CompilationPolicy::policy()->select_task(this); |
485 CompileTask* task = _first; | 443 remove(task); |
486 | |
487 // Update queue first and last | |
488 _first =_first->next(); | |
489 if (_first == NULL) { | |
490 _last = NULL; | |
491 } | |
492 | |
493 return task; | 444 return task; |
494 | 445 } |
495 } | 446 |
496 | 447 void CompileQueue::remove(CompileTask* task) |
448 { | |
449 assert(lock()->owned_by_self(), "must own lock"); | |
450 if (task->prev() != NULL) { | |
451 task->prev()->set_next(task->next()); | |
452 } else { | |
453 // max is the first element | |
454 assert(task == _first, "Sanity"); | |
455 _first = task->next(); | |
456 } | |
457 | |
458 if (task->next() != NULL) { | |
459 task->next()->set_prev(task->prev()); | |
460 } else { | |
461 // max is the last element | |
462 assert(task == _last, "Sanity"); | |
463 _last = task->prev(); | |
464 } | |
465 --_size; | |
466 } | |
497 | 467 |
498 // ------------------------------------------------------------------ | 468 // ------------------------------------------------------------------ |
499 // CompileQueue::print | 469 // CompileQueue::print |
500 void CompileQueue::print() { | 470 void CompileQueue::print() { |
501 tty->print_cr("Contents of %s", name()); | 471 tty->print_cr("Contents of %s", name()); |
543 _perf_compiles = PerfDataManager::create_counter(SUN_CI, name, | 513 _perf_compiles = PerfDataManager::create_counter(SUN_CI, name, |
544 PerfData::U_Events, CHECK); | 514 PerfData::U_Events, CHECK); |
545 } | 515 } |
546 } | 516 } |
547 | 517 |
548 | |
549 // ------------------------------------------------------------------ | 518 // ------------------------------------------------------------------ |
550 // CompileBroker::compilation_init | 519 // CompileBroker::compilation_init |
551 // | 520 // |
552 // Initialize the Compilation object | 521 // Initialize the Compilation object |
553 void CompileBroker::compilation_init() { | 522 void CompileBroker::compilation_init() { |
554 _last_method_compiled[0] = '\0'; | 523 _last_method_compiled[0] = '\0'; |
555 | 524 |
556 // Set the interface to the current compiler(s). | 525 // Set the interface to the current compiler(s). |
526 int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple); | |
527 int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization); | |
557 #ifdef COMPILER1 | 528 #ifdef COMPILER1 |
558 _compilers[0] = new Compiler(); | 529 if (c1_count > 0) { |
559 #ifndef COMPILER2 | 530 _compilers[0] = new Compiler(); |
560 _compilers[1] = _compilers[0]; | 531 } |
561 #endif | |
562 #endif // COMPILER1 | 532 #endif // COMPILER1 |
563 | 533 |
564 #ifdef COMPILER2 | 534 #ifdef COMPILER2 |
565 _compilers[1] = new C2Compiler(); | 535 if (c2_count > 0) { |
566 #ifndef COMPILER1 | 536 _compilers[1] = new C2Compiler(); |
567 _compilers[0] = _compilers[1]; | 537 } |
568 #endif | |
569 #endif // COMPILER2 | 538 #endif // COMPILER2 |
570 | 539 |
571 #ifdef SHARK | 540 #ifdef SHARK |
572 #if defined(COMPILER1) || defined(COMPILER2) | 541 #if defined(COMPILER1) || defined(COMPILER2) |
573 #error "Can't use COMPILER1 or COMPILER2 with shark" | 542 #error "Can't use COMPILER1 or COMPILER2 with shark" |
578 | 547 |
579 // Initialize the CompileTask free list | 548 // Initialize the CompileTask free list |
580 _task_free_list = NULL; | 549 _task_free_list = NULL; |
581 | 550 |
582 // Start the CompilerThreads | 551 // Start the CompilerThreads |
583 init_compiler_threads(compiler_count()); | 552 init_compiler_threads(c1_count, c2_count); |
584 | |
585 | |
586 // totalTime performance counter is always created as it is required | 553 // totalTime performance counter is always created as it is required |
587 // by the implementation of java.lang.management.CompilationMBean. | 554 // by the implementation of java.lang.management.CompilationMBean. |
588 { | 555 { |
589 EXCEPTION_MARK; | 556 EXCEPTION_MARK; |
590 _perf_total_compilation = | 557 _perf_total_compilation = |
768 | 735 |
769 // ------------------------------------------------------------------ | 736 // ------------------------------------------------------------------ |
770 // CompileBroker::init_compiler_threads | 737 // CompileBroker::init_compiler_threads |
771 // | 738 // |
772 // Initialize the compilation queue | 739 // Initialize the compilation queue |
773 void CompileBroker::init_compiler_threads(int compiler_count) { | 740 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) { |
774 EXCEPTION_MARK; | 741 EXCEPTION_MARK; |
775 | 742 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?"); |
776 _method_queue = new CompileQueue("MethodQueue", MethodCompileQueue_lock); | 743 if (c2_compiler_count > 0) { |
744 _c2_method_queue = new CompileQueue("C2MethodQueue", MethodCompileQueue_lock); | |
745 } | |
746 if (c1_compiler_count > 0) { | |
747 _c1_method_queue = new CompileQueue("C1MethodQueue", MethodCompileQueue_lock); | |
748 } | |
749 | |
750 int compiler_count = c1_compiler_count + c2_compiler_count; | |
751 | |
777 _method_threads = | 752 _method_threads = |
778 new (ResourceObj::C_HEAP) GrowableArray<CompilerThread*>(compiler_count, true); | 753 new (ResourceObj::C_HEAP) GrowableArray<CompilerThread*>(compiler_count, true); |
779 | 754 |
780 char name_buffer[256]; | 755 char name_buffer[256]; |
781 int i; | 756 for (int i = 0; i < c2_compiler_count; i++) { |
782 for (i = 0; i < compiler_count; i++) { | |
783 // Create a name for our thread. | 757 // Create a name for our thread. |
784 sprintf(name_buffer, "CompilerThread%d", i); | 758 sprintf(name_buffer, "C2 CompilerThread%d", i); |
785 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); | 759 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); |
786 | 760 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, CHECK); |
787 CompilerThread* new_thread = make_compiler_thread(name_buffer, _method_queue, counters, CHECK); | |
788 _method_threads->append(new_thread); | 761 _method_threads->append(new_thread); |
789 } | 762 } |
763 | |
764 for (int i = c2_compiler_count; i < compiler_count; i++) { | |
765 // Create a name for our thread. | |
766 sprintf(name_buffer, "C1 CompilerThread%d", i); | |
767 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); | |
768 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c1_method_queue, counters, CHECK); | |
769 _method_threads->append(new_thread); | |
770 } | |
771 | |
790 if (UsePerfData) { | 772 if (UsePerfData) { |
791 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, | 773 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, |
792 compiler_count, CHECK); | 774 compiler_count, CHECK); |
793 } | 775 } |
794 } | 776 } |
795 | 777 |
796 // ------------------------------------------------------------------ | 778 // ------------------------------------------------------------------ |
797 // CompileBroker::is_idle | 779 // CompileBroker::is_idle |
798 bool CompileBroker::is_idle() { | 780 bool CompileBroker::is_idle() { |
799 if (!_method_queue->is_empty()) { | 781 if (_c2_method_queue != NULL && !_c2_method_queue->is_empty()) { |
782 return false; | |
783 } else if (_c1_method_queue != NULL && !_c1_method_queue->is_empty()) { | |
800 return false; | 784 return false; |
801 } else { | 785 } else { |
802 int num_threads = _method_threads->length(); | 786 int num_threads = _method_threads->length(); |
803 for (int i=0; i<num_threads; i++) { | 787 for (int i=0; i<num_threads; i++) { |
804 if (_method_threads->at(i)->task() != NULL) { | 788 if (_method_threads->at(i)->task() != NULL) { |
856 // real work, check to see if the method has been compiled | 840 // real work, check to see if the method has been compiled |
857 // in the meantime with a definitive result. | 841 // in the meantime with a definitive result. |
858 if (compilation_is_complete(method, osr_bci, comp_level)) { | 842 if (compilation_is_complete(method, osr_bci, comp_level)) { |
859 return; | 843 return; |
860 } | 844 } |
845 | |
861 | 846 |
862 // If this method is already in the compile queue, then | 847 // If this method is already in the compile queue, then |
863 // we do not block the current thread. | 848 // we do not block the current thread. |
864 if (compilation_is_in_queue(method, osr_bci)) { | 849 if (compilation_is_in_queue(method, osr_bci)) { |
865 // We may want to decay our counter a bit here to prevent | 850 // We may want to decay our counter a bit here to prevent |
874 } | 859 } |
875 | 860 |
876 // Outputs from the following MutexLocker block: | 861 // Outputs from the following MutexLocker block: |
877 CompileTask* task = NULL; | 862 CompileTask* task = NULL; |
878 bool blocking = false; | 863 bool blocking = false; |
864 CompileQueue* queue = compile_queue(comp_level); | |
879 | 865 |
880 // Acquire our lock. | 866 // Acquire our lock. |
881 { | 867 { |
882 MutexLocker locker(_method_queue->lock(), THREAD); | 868 MutexLocker locker(queue->lock(), THREAD); |
883 | 869 |
884 // Make sure the method has not slipped into the queues since | 870 // Make sure the method has not slipped into the queues since |
885 // last we checked; note that those checks were "fast bail-outs". | 871 // last we checked; note that those checks were "fast bail-outs". |
886 // Here we need to be more careful, see 14012000 below. | 872 // Here we need to be more careful, see 14012000 below. |
887 if (compilation_is_in_queue(method, osr_bci)) { | 873 if (compilation_is_in_queue(method, osr_bci)) { |
943 // NOTE: in the event that there are multiple compiler threads and | 929 // NOTE: in the event that there are multiple compiler threads and |
944 // there is de-optimization/recompilation, things will get hairy, | 930 // there is de-optimization/recompilation, things will get hairy, |
945 // and in that case it's best to protect both the testing (here) of | 931 // and in that case it's best to protect both the testing (here) of |
946 // these bits, and their updating (here and elsewhere) under a | 932 // these bits, and their updating (here and elsewhere) under a |
947 // common lock. | 933 // common lock. |
948 task = create_compile_task(_method_queue, | 934 task = create_compile_task(queue, |
949 compile_id, method, | 935 compile_id, method, |
950 osr_bci, comp_level, | 936 osr_bci, comp_level, |
951 hot_method, hot_count, comment, | 937 hot_method, hot_count, comment, |
952 blocking); | 938 blocking); |
953 } | 939 } |
957 } | 943 } |
958 } | 944 } |
959 | 945 |
960 | 946 |
961 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, | 947 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, |
948 int comp_level, | |
962 methodHandle hot_method, int hot_count, | 949 methodHandle hot_method, int hot_count, |
963 const char* comment, TRAPS) { | 950 const char* comment, TRAPS) { |
964 // make sure arguments make sense | 951 // make sure arguments make sense |
965 assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method"); | 952 assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method"); |
966 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); | 953 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); |
967 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); | 954 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); |
968 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized"); | 955 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized"); |
969 | 956 |
970 int comp_level = CompilationPolicy::policy()->compilation_level(method, osr_bci); | 957 if (!TieredCompilation) { |
971 | 958 comp_level = CompLevel_highest_tier; |
972 #ifdef TIERED | 959 } |
973 if (TieredCompilation && StressTieredRuntime) { | |
974 static int flipper = 0; | |
975 if (is_even(flipper++)) { | |
976 comp_level = CompLevel_fast_compile; | |
977 } else { | |
978 comp_level = CompLevel_full_optimization; | |
979 } | |
980 } | |
981 #ifdef SPARC | |
982 // QQQ FIX ME | |
983 // C2 only returns long results in G1 and c1 doesn't understand so disallow c2 | |
984 // compiles of long results | |
985 if (TieredCompilation && method()->result_type() == T_LONG) { | |
986 comp_level = CompLevel_fast_compile; | |
987 } | |
988 #endif // SPARC | |
989 #endif // TIERED | |
990 | 960 |
991 // return quickly if possible | 961 // return quickly if possible |
992 | 962 |
993 // lock, make sure that the compilation | 963 // lock, make sure that the compilation |
994 // isn't prohibited in a straightforward way. | 964 // isn't prohibited in a straightforward way. |
998 } | 968 } |
999 | 969 |
1000 if (osr_bci == InvocationEntryBci) { | 970 if (osr_bci == InvocationEntryBci) { |
1001 // standard compilation | 971 // standard compilation |
1002 nmethod* method_code = method->code(); | 972 nmethod* method_code = method->code(); |
1003 if (method_code != NULL | 973 if (method_code != NULL) { |
1004 #ifdef TIERED | 974 if (compilation_is_complete(method, osr_bci, comp_level)) { |
1005 && ( method_code->is_compiled_by_c2() || comp_level == CompLevel_fast_compile ) | 975 return method_code; |
1006 #endif // TIERED | 976 } |
1007 ) { | |
1008 return method_code; | |
1009 } | 977 } |
1010 if (method->is_not_compilable(comp_level)) return NULL; | 978 if (method->is_not_compilable(comp_level)) return NULL; |
1011 | 979 |
1012 if (UseCodeCacheFlushing) { | 980 if (UseCodeCacheFlushing) { |
1013 nmethod* saved = CodeCache::find_and_remove_saved_code(method()); | 981 nmethod* saved = CodeCache::find_and_remove_saved_code(method()); |
1019 | 987 |
1020 } else { | 988 } else { |
1021 // osr compilation | 989 // osr compilation |
1022 #ifndef TIERED | 990 #ifndef TIERED |
1023 // seems like an assert of dubious value | 991 // seems like an assert of dubious value |
1024 assert(comp_level == CompLevel_full_optimization, | 992 assert(comp_level == CompLevel_highest_tier, |
1025 "all OSR compiles are assumed to be at a single compilation lavel"); | 993 "all OSR compiles are assumed to be at a single compilation lavel"); |
1026 #endif // TIERED | 994 #endif // TIERED |
1027 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci); | 995 // We accept a higher level osr method |
996 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false); | |
1028 if (nm != NULL) return nm; | 997 if (nm != NULL) return nm; |
1029 if (method->is_not_osr_compilable()) return NULL; | 998 if (method->is_not_osr_compilable()) return NULL; |
1030 } | 999 } |
1031 | 1000 |
1032 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); | 1001 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); |
1069 } | 1038 } |
1070 | 1039 |
1071 // If the compiler is shut off due to code cache flushing or otherwise, | 1040 // If the compiler is shut off due to code cache flushing or otherwise, |
1072 // fail out now so blocking compiles dont hang the java thread | 1041 // fail out now so blocking compiles dont hang the java thread |
1073 if (!should_compile_new_jobs() || (UseCodeCacheFlushing && CodeCache::needs_flushing())) { | 1042 if (!should_compile_new_jobs() || (UseCodeCacheFlushing && CodeCache::needs_flushing())) { |
1074 method->invocation_counter()->decay(); | 1043 CompilationPolicy::policy()->delay_compilation(method()); |
1075 method->backedge_counter()->decay(); | |
1076 return NULL; | 1044 return NULL; |
1077 } | 1045 } |
1078 | 1046 |
1079 // do the compilation | 1047 // do the compilation |
1080 if (method->is_native()) { | 1048 if (method->is_native()) { |
1086 } else { | 1054 } else { |
1087 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, CHECK_0); | 1055 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, CHECK_0); |
1088 } | 1056 } |
1089 | 1057 |
1090 // return requested nmethod | 1058 // return requested nmethod |
1091 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci); | 1059 // We accept a higher level osr method |
1060 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false); | |
1092 } | 1061 } |
1093 | 1062 |
1094 | 1063 |
1095 // ------------------------------------------------------------------ | 1064 // ------------------------------------------------------------------ |
1096 // CompileBroker::compilation_is_complete | 1065 // CompileBroker::compilation_is_complete |
1102 bool is_osr = (osr_bci != standard_entry_bci); | 1071 bool is_osr = (osr_bci != standard_entry_bci); |
1103 if (is_osr) { | 1072 if (is_osr) { |
1104 if (method->is_not_osr_compilable()) { | 1073 if (method->is_not_osr_compilable()) { |
1105 return true; | 1074 return true; |
1106 } else { | 1075 } else { |
1107 nmethod* result = method->lookup_osr_nmethod_for(osr_bci); | 1076 nmethod* result = method->lookup_osr_nmethod_for(osr_bci, comp_level, true); |
1108 return (result != NULL); | 1077 return (result != NULL); |
1109 } | 1078 } |
1110 } else { | 1079 } else { |
1111 if (method->is_not_compilable(comp_level)) { | 1080 if (method->is_not_compilable(comp_level)) { |
1112 return true; | 1081 return true; |
1113 } else { | 1082 } else { |
1114 nmethod* result = method->code(); | 1083 nmethod* result = method->code(); |
1115 if (result == NULL) return false; | 1084 if (result == NULL) return false; |
1116 #ifdef TIERED | 1085 return comp_level == result->comp_level(); |
1117 if (comp_level == CompLevel_fast_compile) { | |
1118 // At worst the code is from c1 | |
1119 return true; | |
1120 } | |
1121 // comp level must be full opt | |
1122 return result->is_compiled_by_c2(); | |
1123 #endif // TIERED | |
1124 return true; | |
1125 } | 1086 } |
1126 } | 1087 } |
1127 } | 1088 } |
1128 | 1089 |
1129 | 1090 |
1137 // conservative in the sense that an osr compilation in the queue | 1098 // conservative in the sense that an osr compilation in the queue |
1138 // will block a normal compilation from entering the queue (and vice | 1099 // will block a normal compilation from entering the queue (and vice |
1139 // versa). This can be remedied by a full queue search to disambiguate | 1100 // versa). This can be remedied by a full queue search to disambiguate |
1140 // cases. If it is deemed profitible, this may be done. | 1101 // cases. If it is deemed profitible, this may be done. |
1141 bool CompileBroker::compilation_is_in_queue(methodHandle method, | 1102 bool CompileBroker::compilation_is_in_queue(methodHandle method, |
1142 int osr_bci) { | 1103 int osr_bci) { |
1143 return method->queued_for_compilation(); | 1104 return method->queued_for_compilation(); |
1144 } | 1105 } |
1145 | |
1146 | 1106 |
1147 // ------------------------------------------------------------------ | 1107 // ------------------------------------------------------------------ |
1148 // CompileBroker::compilation_is_prohibited | 1108 // CompileBroker::compilation_is_prohibited |
1149 // | 1109 // |
1150 // See if this compilation is not allowed. | 1110 // See if this compilation is not allowed. |
1151 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) { | 1111 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) { |
1152 bool is_native = method->is_native(); | 1112 bool is_native = method->is_native(); |
1153 // Some compilers may not support the compilation of natives. | 1113 // Some compilers may not support the compilation of natives. |
1154 // QQQ this needs some work ought to only record not compilable at | |
1155 // the specified level | |
1156 if (is_native && | 1114 if (is_native && |
1157 (!CICompileNatives || !compiler(comp_level)->supports_native())) { | 1115 (!CICompileNatives || !compiler(comp_level)->supports_native())) { |
1158 method->set_not_compilable_quietly(); | 1116 method->set_not_compilable_quietly(comp_level); |
1159 return true; | 1117 return true; |
1160 } | 1118 } |
1161 | 1119 |
1162 bool is_osr = (osr_bci != standard_entry_bci); | 1120 bool is_osr = (osr_bci != standard_entry_bci); |
1163 // Some compilers may not support on stack replacement. | 1121 // Some compilers may not support on stack replacement. |
1192 // Assign a serialized id number to this compilation request. If the | 1150 // Assign a serialized id number to this compilation request. If the |
1193 // number falls out of the allowed range, return a 0. OSR | 1151 // number falls out of the allowed range, return a 0. OSR |
1194 // compilations may be numbered separately from regular compilations | 1152 // compilations may be numbered separately from regular compilations |
1195 // if certain debugging flags are used. | 1153 // if certain debugging flags are used. |
1196 uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) { | 1154 uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) { |
1197 assert(_method_queue->lock()->owner() == JavaThread::current(), | 1155 assert(MethodCompileQueue_lock->owner() == Thread::current(), |
1198 "must hold the compilation queue lock"); | 1156 "must hold the compilation queue lock"); |
1199 bool is_osr = (osr_bci != standard_entry_bci); | 1157 bool is_osr = (osr_bci != standard_entry_bci); |
1200 assert(!method->is_native(), "no longer compile natives"); | 1158 assert(!method->is_native(), "no longer compile natives"); |
1201 uint id; | 1159 uint id; |
1202 if (CICountOSR && is_osr) { | 1160 if (CICountOSR && is_osr) { |
1641 vm_exit(0); | 1599 vm_exit(0); |
1642 } | 1600 } |
1643 #endif | 1601 #endif |
1644 } | 1602 } |
1645 | 1603 |
1646 | |
1647 // ------------------------------------------------------------------ | 1604 // ------------------------------------------------------------------ |
1648 // CompileBroker::handle_full_code_cache | 1605 // CompileBroker::handle_full_code_cache |
1649 // | 1606 // |
1650 // The CodeCache is full. Print out warning and disable compilation or | 1607 // The CodeCache is full. Print out warning and disable compilation or |
1651 // try code cache cleaning so compilation can continue later. | 1608 // try code cache cleaning so compilation can continue later. |
1881 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f", | 1838 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f", |
1882 CompileBroker::_t_standard_compilation.seconds(), | 1839 CompileBroker::_t_standard_compilation.seconds(), |
1883 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count); | 1840 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count); |
1884 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); | 1841 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); |
1885 | 1842 |
1886 if (compiler(CompLevel_fast_compile)) { | 1843 if (compiler(CompLevel_simple) != NULL) { |
1887 compiler(CompLevel_fast_compile)->print_timers(); | 1844 compiler(CompLevel_simple)->print_timers(); |
1888 if (compiler(CompLevel_fast_compile) != compiler(CompLevel_highest_tier)) | 1845 } |
1889 compiler(CompLevel_highest_tier)->print_timers(); | 1846 if (compiler(CompLevel_full_optimization) != NULL) { |
1890 } | 1847 compiler(CompLevel_full_optimization)->print_timers(); |
1891 | 1848 } |
1892 tty->cr(); | 1849 tty->cr(); |
1893 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled; | 1850 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled; |
1894 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb); | 1851 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb); |
1895 tty->print_cr(" Standard compilation : %6d bytes", CompileBroker::_sum_standard_bytes_compiled); | 1852 tty->print_cr(" Standard compilation : %6d bytes", CompileBroker::_sum_standard_bytes_compiled); |
1896 tty->print_cr(" On stack replacement : %6d bytes", CompileBroker::_sum_osr_bytes_compiled); | 1853 tty->print_cr(" On stack replacement : %6d bytes", CompileBroker::_sum_osr_bytes_compiled); |