comparison src/share/vm/compiler/compileBroker.cpp @ 1930:2d26b0046e0d

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 30 Nov 2010 14:53:30 +0100
parents 5571b97fc1ec d5d065957597
children 48bbaead8b6c
comparison
equal deleted inserted replaced
1484:6b7001391c97 1930:2d26b0046e0d
1 /* 1 /*
2 * Copyright 1999-2010 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
14 * 14 *
15 * You should have received a copy of the GNU General Public License version 15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation, 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * CA 95054 USA or visit www.sun.com if you need additional information or 20 * or visit www.oracle.com if you need additional information or have any
21 * have any questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 #include "incls/_precompiled.incl" 25 #include "incls/_precompiled.incl"
26 #include "incls/_compileBroker.cpp.incl" 26 #include "incls/_compileBroker.cpp.incl"
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(" (%d bytes)", method->code_size());
324
325 // invocation count
326 tty->print_cr(" %d invocations", _hot_count);
327 } 281 }
328 282
329 283
330 // ------------------------------------------------------------------ 284 // ------------------------------------------------------------------
331 // CompileTask::log_task 285 // CompileTask::log_task
400 ResourceMark rm(thread); 354 ResourceMark rm(thread);
401 355
402 // <task_done ... stamp='1.234'> </task> 356 // <task_done ... stamp='1.234'> </task>
403 nmethod* nm = code(); 357 nmethod* nm = code();
404 log->begin_elem("task_done success='%d' nmsize='%d' count='%d'", 358 log->begin_elem("task_done success='%d' nmsize='%d' count='%d'",
405 _is_success, nm == NULL ? 0 : nm->instructions_size(), 359 _is_success, nm == NULL ? 0 : nm->content_size(),
406 method->invocation_count()); 360 method->invocation_count());
407 int bec = method->backedge_count(); 361 int bec = method->backedge_count();
408 if (bec != 0) log->print(" backedge_count='%d'", bec); 362 if (bec != 0) log->print(" backedge_count='%d'", bec);
409 // Note: "_is_complete" is about to be set, but is not. 363 // Note: "_is_complete" is about to be set, but is not.
410 if (_num_inlined_bytecodes != 0) { 364 if (_num_inlined_bytecodes != 0) {
428 // Add a CompileTask to a CompileQueue 382 // Add a CompileTask to a CompileQueue
429 void CompileQueue::add(CompileTask* task) { 383 void CompileQueue::add(CompileTask* task) {
430 assert(lock()->owned_by_self(), "must own lock"); 384 assert(lock()->owned_by_self(), "must own lock");
431 385
432 task->set_next(NULL); 386 task->set_next(NULL);
387 task->set_prev(NULL);
433 388
434 if (_last == NULL) { 389 if (_last == NULL) {
435 // The compile queue is empty. 390 // The compile queue is empty.
436 assert(_first == NULL, "queue is empty"); 391 assert(_first == NULL, "queue is empty");
437 _first = task; 392 _first = task;
438 _last = task; 393 _last = task;
439 } else { 394 } else {
440 // Append the task to the queue. 395 // Append the task to the queue.
441 assert(_last->next() == NULL, "not last"); 396 assert(_last->next() == NULL, "not last");
442 _last->set_next(task); 397 _last->set_next(task);
398 task->set_prev(_last);
443 _last = task; 399 _last = task;
444 } 400 }
401 ++_size;
445 402
446 // Mark the method as being in the compile queue. 403 // Mark the method as being in the compile queue.
447 ((methodOop)JNIHandles::resolve(task->method_handle()))->set_queued_for_compilation(); 404 ((methodOop)JNIHandles::resolve(task->method_handle()))->set_queued_for_compilation();
448 405
449 if (CIPrintCompileQueue) { 406 if (CIPrintCompileQueue) {
453 if (LogCompilation && xtty != NULL) { 410 if (LogCompilation && xtty != NULL) {
454 task->log_task_queued(); 411 task->log_task_queued();
455 } 412 }
456 413
457 // Notify CompilerThreads that a task is available. 414 // Notify CompilerThreads that a task is available.
458 lock()->notify(); 415 lock()->notify_all();
459 } 416 }
460
461 417
462 // ------------------------------------------------------------------ 418 // ------------------------------------------------------------------
463 // CompileQueue::get 419 // CompileQueue::get
464 // 420 //
465 // Get the next CompileTask from a CompileQueue 421 // Get the next CompileTask from a CompileQueue
466 CompileTask* CompileQueue::get() { 422 CompileTask* CompileQueue::get() {
423 NMethodSweeper::possibly_sweep();
424
467 MutexLocker locker(lock()); 425 MutexLocker locker(lock());
468
469 // Wait for an available CompileTask. 426 // Wait for an available CompileTask.
470 while (_first == NULL) { 427 while (_first == NULL) {
471 // There is no work to be done right now. Wait. 428 // There is no work to be done right now. Wait.
472 lock()->wait(); 429 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) {
473 } 430 // During the emergency sweeping periods, wake up and sweep occasionally
474 431 bool timedout = lock()->wait(!Mutex::_no_safepoint_check_flag, NmethodSweepCheckInterval*1000);
475 CompileTask* task = _first; 432 if (timedout) {
476 433 MutexUnlocker ul(lock());
477 // Update queue first and last 434 // When otherwise not busy, run nmethod sweeping
478 _first =_first->next(); 435 NMethodSweeper::possibly_sweep();
479 if (_first == NULL) { 436 }
480 _last = NULL; 437 } else {
438 // During normal operation no need to wake up on timer
439 lock()->wait();
440 }
441 }
442 CompileTask* task = CompilationPolicy::policy()->select_task(this);
443 remove(task);
444 return task;
445 }
446
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();
481 } 464 }
482 465
483 // (tw) Immediately set compiling flag. 466 // (tw) Immediately set compiling flag.
484 JavaThread::current()->as_CompilerThread()->set_compiling(true); 467 JavaThread::current()->as_CompilerThread()->set_compiling(true);
485 468 --_size;
486 return task; 469 }
487
488 }
489
490 470
491 // ------------------------------------------------------------------ 471 // ------------------------------------------------------------------
492 // CompileQueue::print 472 // CompileQueue::print
493 void CompileQueue::print() { 473 void CompileQueue::print() {
494 tty->print_cr("Contents of %s", name()); 474 tty->print_cr("Contents of %s", name());
612 // Initialize the Compilation object 592 // Initialize the Compilation object
613 void CompileBroker::compilation_init() { 593 void CompileBroker::compilation_init() {
614 _last_method_compiled[0] = '\0'; 594 _last_method_compiled[0] = '\0';
615 595
616 // Set the interface to the current compiler(s). 596 // Set the interface to the current compiler(s).
597 int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
598 int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
617 #ifdef COMPILER1 599 #ifdef COMPILER1
618 if (UseC1X) { 600 if (UseC1X) {
619 _compilers[0] = new C1XCompiler(); 601 _compilers[0] = new C1XCompiler();
620 } else { 602 } else if (c1_count > 0) {
621 _compilers[0] = new Compiler(); 603 _compilers[0] = new Compiler();
622 } 604 }
623 #ifndef COMPILER2 605 #ifndef COMPILER2
624 _compilers[1] = _compilers[0]; 606 _compilers[1] = _compilers[0];
625 #endif 607 #endif
626 #endif // COMPILER1 608 #endif // COMPILER1
627 609
628 #ifdef COMPILER2 610 #ifdef COMPILER2
629 _compilers[1] = new C2Compiler(); 611 if (c2_count > 0) {
630 #ifndef COMPILER1 612 _compilers[1] = new C2Compiler();
631 _compilers[0] = _compilers[1]; 613 }
614 #endif // COMPILER2
615
616 #ifdef SHARK
617 #if defined(COMPILER1) || defined(COMPILER2)
618 #error "Can't use COMPILER1 or COMPILER2 with shark"
632 #endif 619 #endif
633 #endif // COMPILER2 620 _compilers[0] = new SharkCompiler();
621 _compilers[1] = _compilers[0];
622 #endif
634 623
635 // Initialize the CompileTask free list 624 // Initialize the CompileTask free list
636 _task_free_list = NULL; 625 _task_free_list = NULL;
637 626
638 // Start the CompilerThreads 627 // Start the CompilerThreads
639 init_compiler_threads(compiler_count()); 628 init_compiler_threads(c1_count, c2_count);
640
641
642 // totalTime performance counter is always created as it is required 629 // totalTime performance counter is always created as it is required
643 // by the implementation of java.lang.management.CompilationMBean. 630 // by the implementation of java.lang.management.CompilationMBean.
644 { 631 {
645 EXCEPTION_MARK; 632 EXCEPTION_MARK;
646 _perf_total_compilation = 633 _perf_total_compilation =
824 811
825 // ------------------------------------------------------------------ 812 // ------------------------------------------------------------------
826 // CompileBroker::init_compiler_threads 813 // CompileBroker::init_compiler_threads
827 // 814 //
828 // Initialize the compilation queue 815 // Initialize the compilation queue
829 void CompileBroker::init_compiler_threads(int compiler_count) { 816 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) {
830 EXCEPTION_MARK; 817 EXCEPTION_MARK;
831 818 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
832 _method_queue = new CompileQueue("MethodQueue", MethodCompileQueue_lock); 819 if (c2_compiler_count > 0) {
820 _c2_method_queue = new CompileQueue("C2MethodQueue", MethodCompileQueue_lock);
821 }
822 if (c1_compiler_count > 0) {
823 _c1_method_queue = new CompileQueue("C1MethodQueue", MethodCompileQueue_lock);
824 }
825
826 int compiler_count = c1_compiler_count + c2_compiler_count;
827
833 _method_threads = 828 _method_threads =
834 new (ResourceObj::C_HEAP) GrowableArray<CompilerThread*>(compiler_count, true); 829 new (ResourceObj::C_HEAP) GrowableArray<CompilerThread*>(compiler_count, true);
835 830
836 char name_buffer[256]; 831 char name_buffer[256];
837 int i; 832 for (int i = 0; i < c2_compiler_count; i++) {
838 for (i = 0; i < compiler_count; i++) {
839 // Create a name for our thread. 833 // Create a name for our thread.
840 sprintf(name_buffer, "CompilerThread%d", i); 834 sprintf(name_buffer, "C2 CompilerThread%d", i);
841 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); 835 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
842 836 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, CHECK);
843 CompilerThread* new_thread = make_compiler_thread(name_buffer, _method_queue, counters, CHECK);
844 _method_threads->append(new_thread); 837 _method_threads->append(new_thread);
845 } 838 }
839
840 for (int i = c2_compiler_count; i < compiler_count; i++) {
841 // Create a name for our thread.
842 sprintf(name_buffer, "C1 CompilerThread%d", i);
843 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
844 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c1_method_queue, counters, CHECK);
845 _method_threads->append(new_thread);
846 }
847
846 if (UsePerfData) { 848 if (UsePerfData) {
847 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, 849 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes,
848 compiler_count, CHECK); 850 compiler_count, CHECK);
849 } 851 }
850 } 852 }
851 853
852 // ------------------------------------------------------------------ 854 // ------------------------------------------------------------------
853 // CompileBroker::is_idle 855 // CompileBroker::is_idle
854 bool CompileBroker::is_idle() { 856 bool CompileBroker::is_idle() {
855 if (!_method_queue->is_empty()) { 857 if (_c2_method_queue != NULL && !_c2_method_queue->is_empty()) {
858 return false;
859 } else if (_c1_method_queue != NULL && !_c1_method_queue->is_empty()) {
856 return false; 860 return false;
857 } else { 861 } else {
858 int num_threads = _method_threads->length(); 862 int num_threads = _method_threads->length();
859 for (int i=0; i<num_threads; i++) { 863 for (int i=0; i<num_threads; i++) {
860 if (_method_threads->at(i)->task() != NULL) { 864 if (_method_threads->at(i)->task() != NULL) {
912 // real work, check to see if the method has been compiled 916 // real work, check to see if the method has been compiled
913 // in the meantime with a definitive result. 917 // in the meantime with a definitive result.
914 if (compilation_is_complete(method, osr_bci, comp_level)) { 918 if (compilation_is_complete(method, osr_bci, comp_level)) {
915 return; 919 return;
916 } 920 }
921
917 922
918 // If this method is already in the compile queue, then 923 // If this method is already in the compile queue, then
919 // we do not block the current thread. 924 // we do not block the current thread.
920 if (compilation_is_in_queue(method, osr_bci)) { 925 if (compilation_is_in_queue(method, osr_bci)) {
921 // We may want to decay our counter a bit here to prevent 926 // We may want to decay our counter a bit here to prevent
930 } 935 }
931 936
932 // Outputs from the following MutexLocker block: 937 // Outputs from the following MutexLocker block:
933 CompileTask* task = NULL; 938 CompileTask* task = NULL;
934 bool blocking = false; 939 bool blocking = false;
940 CompileQueue* queue = compile_queue(comp_level);
935 941
936 // Acquire our lock. 942 // Acquire our lock.
937 { 943 {
938 MutexLocker locker(_method_queue->lock(), THREAD); 944 MutexLocker locker(queue->lock(), THREAD);
939 945
940 if (Thread::current()->is_Compiler_thread() && CompilerThread::current()->is_compiling() && !BackgroundCompilation) { 946 if (Thread::current()->is_Compiler_thread() && CompilerThread::current()->is_compiling() && !BackgroundCompilation) {
941 947
942 TRACE_C1X_1("Recursive compile %s!", method->name_and_sig_as_C_string()); 948 TRACE_C1X_1("Recursive compile %s!", method->name_and_sig_as_C_string());
943 method->set_not_compilable(); 949 method->set_not_compilable();
1006 // NOTE: in the event that there are multiple compiler threads and 1012 // NOTE: in the event that there are multiple compiler threads and
1007 // there is de-optimization/recompilation, things will get hairy, 1013 // there is de-optimization/recompilation, things will get hairy,
1008 // and in that case it's best to protect both the testing (here) of 1014 // and in that case it's best to protect both the testing (here) of
1009 // these bits, and their updating (here and elsewhere) under a 1015 // these bits, and their updating (here and elsewhere) under a
1010 // common lock. 1016 // common lock.
1011 task = create_compile_task(_method_queue, 1017 task = create_compile_task(queue,
1012 compile_id, method, 1018 compile_id, method,
1013 osr_bci, comp_level, 1019 osr_bci, comp_level,
1014 hot_method, hot_count, comment, 1020 hot_method, hot_count, comment,
1015 blocking); 1021 blocking);
1016 } 1022 }
1020 } 1026 }
1021 } 1027 }
1022 1028
1023 1029
1024 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, 1030 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci,
1031 int comp_level,
1025 methodHandle hot_method, int hot_count, 1032 methodHandle hot_method, int hot_count,
1026 const char* comment, TRAPS) { 1033 const char* comment, TRAPS) {
1027 // make sure arguments make sense 1034 // make sure arguments make sense
1028 assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method"); 1035 assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
1029 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); 1036 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
1030 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); 1037 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods");
1031 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized"); 1038 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized");
1032 1039
1033 int comp_level = CompilationPolicy::policy()->compilation_level(method, osr_bci); 1040 if (!TieredCompilation) {
1034 1041 comp_level = CompLevel_highest_tier;
1035 #ifdef TIERED 1042 }
1036 if (TieredCompilation && StressTieredRuntime) {
1037 static int flipper = 0;
1038 if (is_even(flipper++)) {
1039 comp_level = CompLevel_fast_compile;
1040 } else {
1041 comp_level = CompLevel_full_optimization;
1042 }
1043 }
1044 #ifdef SPARC
1045 // QQQ FIX ME
1046 // C2 only returns long results in G1 and c1 doesn't understand so disallow c2
1047 // compiles of long results
1048 if (TieredCompilation && method()->result_type() == T_LONG) {
1049 comp_level = CompLevel_fast_compile;
1050 }
1051 #endif // SPARC
1052 #endif // TIERED
1053 1043
1054 // return quickly if possible 1044 // return quickly if possible
1055 1045
1056 // lock, make sure that the compilation 1046 // lock, make sure that the compilation
1057 // isn't prohibited in a straightforward way. 1047 // isn't prohibited in a straightforward way.
1061 } 1051 }
1062 1052
1063 if (osr_bci == InvocationEntryBci) { 1053 if (osr_bci == InvocationEntryBci) {
1064 // standard compilation 1054 // standard compilation
1065 nmethod* method_code = method->code(); 1055 nmethod* method_code = method->code();
1066 if (method_code != NULL 1056 if (method_code != NULL) {
1067 #ifdef TIERED 1057 if (compilation_is_complete(method, osr_bci, comp_level)) {
1068 && ( method_code->is_compiled_by_c2() || comp_level == CompLevel_fast_compile ) 1058 return method_code;
1069 #endif // TIERED 1059 }
1070 ) {
1071 return method_code;
1072 } 1060 }
1073 if (method->is_not_compilable(comp_level)) return NULL; 1061 if (method->is_not_compilable(comp_level)) return NULL;
1074 1062
1075 if (UseCodeCacheFlushing) { 1063 if (UseCodeCacheFlushing) {
1076 nmethod* saved = CodeCache::find_and_remove_saved_code(method()); 1064 nmethod* saved = CodeCache::find_and_remove_saved_code(method());
1082 1070
1083 } else { 1071 } else {
1084 // osr compilation 1072 // osr compilation
1085 #ifndef TIERED 1073 #ifndef TIERED
1086 // seems like an assert of dubious value 1074 // seems like an assert of dubious value
1087 assert(comp_level == CompLevel_full_optimization, 1075 assert(comp_level == CompLevel_highest_tier,
1088 "all OSR compiles are assumed to be at a single compilation lavel"); 1076 "all OSR compiles are assumed to be at a single compilation lavel");
1089 #endif // TIERED 1077 #endif // TIERED
1090 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci); 1078 // We accept a higher level osr method
1079 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1091 if (nm != NULL) return nm; 1080 if (nm != NULL) return nm;
1092 if (method->is_not_osr_compilable()) return NULL; 1081 if (method->is_not_osr_compilable()) return NULL;
1093 } 1082 }
1094 1083
1095 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); 1084 assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1132 } 1121 }
1133 1122
1134 // If the compiler is shut off due to code cache flushing or otherwise, 1123 // If the compiler is shut off due to code cache flushing or otherwise,
1135 // fail out now so blocking compiles dont hang the java thread 1124 // fail out now so blocking compiles dont hang the java thread
1136 if (!should_compile_new_jobs() || (UseCodeCacheFlushing && CodeCache::needs_flushing())) { 1125 if (!should_compile_new_jobs() || (UseCodeCacheFlushing && CodeCache::needs_flushing())) {
1137 method->invocation_counter()->decay(); 1126 CompilationPolicy::policy()->delay_compilation(method());
1138 method->backedge_counter()->decay();
1139 return NULL; 1127 return NULL;
1140 } 1128 }
1141 1129
1142 // do the compilation 1130 // do the compilation
1143 if (method->is_native()) { 1131 if (method->is_native()) {
1149 } else { 1137 } else {
1150 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, CHECK_0); 1138 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, CHECK_0);
1151 } 1139 }
1152 1140
1153 // return requested nmethod 1141 // return requested nmethod
1154 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci); 1142 // We accept a higher level osr method
1143 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1155 } 1144 }
1156 1145
1157 1146
1158 // ------------------------------------------------------------------ 1147 // ------------------------------------------------------------------
1159 // CompileBroker::compilation_is_complete 1148 // CompileBroker::compilation_is_complete
1165 bool is_osr = (osr_bci != standard_entry_bci); 1154 bool is_osr = (osr_bci != standard_entry_bci);
1166 if (is_osr) { 1155 if (is_osr) {
1167 if (method->is_not_osr_compilable()) { 1156 if (method->is_not_osr_compilable()) {
1168 return true; 1157 return true;
1169 } else { 1158 } else {
1170 nmethod* result = method->lookup_osr_nmethod_for(osr_bci); 1159 nmethod* result = method->lookup_osr_nmethod_for(osr_bci, comp_level, true);
1171 return (result != NULL); 1160 return (result != NULL);
1172 } 1161 }
1173 } else { 1162 } else {
1174 if (method->is_not_compilable(comp_level)) { 1163 if (method->is_not_compilable(comp_level)) {
1175 return true; 1164 return true;
1176 } else { 1165 } else {
1177 nmethod* result = method->code(); 1166 nmethod* result = method->code();
1178 if (result == NULL) return false; 1167 if (result == NULL) return false;
1179 #ifdef TIERED 1168 return comp_level == result->comp_level();
1180 if (comp_level == CompLevel_fast_compile) {
1181 // At worst the code is from c1
1182 return true;
1183 }
1184 // comp level must be full opt
1185 return result->is_compiled_by_c2();
1186 #endif // TIERED
1187 return true;
1188 } 1169 }
1189 } 1170 }
1190 } 1171 }
1191 1172
1192 1173
1200 // conservative in the sense that an osr compilation in the queue 1181 // conservative in the sense that an osr compilation in the queue
1201 // will block a normal compilation from entering the queue (and vice 1182 // will block a normal compilation from entering the queue (and vice
1202 // versa). This can be remedied by a full queue search to disambiguate 1183 // versa). This can be remedied by a full queue search to disambiguate
1203 // cases. If it is deemed profitible, this may be done. 1184 // cases. If it is deemed profitible, this may be done.
1204 bool CompileBroker::compilation_is_in_queue(methodHandle method, 1185 bool CompileBroker::compilation_is_in_queue(methodHandle method,
1205 int osr_bci) { 1186 int osr_bci) {
1206 return method->queued_for_compilation(); 1187 return method->queued_for_compilation();
1207 } 1188 }
1208
1209 1189
1210 // ------------------------------------------------------------------ 1190 // ------------------------------------------------------------------
1211 // CompileBroker::compilation_is_prohibited 1191 // CompileBroker::compilation_is_prohibited
1212 // 1192 //
1213 // See if this compilation is not allowed. 1193 // See if this compilation is not allowed.
1214 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) { 1194 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) {
1215 bool is_native = method->is_native(); 1195 bool is_native = method->is_native();
1216 // Some compilers may not support the compilation of natives. 1196 // Some compilers may not support the compilation of natives.
1217 // QQQ this needs some work ought to only record not compilable at
1218 // the specified level
1219 if (is_native && 1197 if (is_native &&
1220 (!CICompileNatives || !compiler(comp_level)->supports_native())) { 1198 (!CICompileNatives || !compiler(comp_level)->supports_native())) {
1221 method->set_not_compilable_quietly(); 1199 method->set_not_compilable_quietly(comp_level);
1222 return true; 1200 return true;
1223 } 1201 }
1224 1202
1225 bool is_osr = (osr_bci != standard_entry_bci); 1203 bool is_osr = (osr_bci != standard_entry_bci);
1226 // Some compilers may not support on stack replacement. 1204 // Some compilers may not support on stack replacement.
1255 // Assign a serialized id number to this compilation request. If the 1233 // Assign a serialized id number to this compilation request. If the
1256 // number falls out of the allowed range, return a 0. OSR 1234 // number falls out of the allowed range, return a 0. OSR
1257 // compilations may be numbered separately from regular compilations 1235 // compilations may be numbered separately from regular compilations
1258 // if certain debugging flags are used. 1236 // if certain debugging flags are used.
1259 uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) { 1237 uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
1260 assert(_method_queue->lock()->owner() == JavaThread::current(), 1238 assert(MethodCompileQueue_lock->owner() == Thread::current(),
1261 "must hold the compilation queue lock"); 1239 "must hold the compilation queue lock");
1262 bool is_osr = (osr_bci != standard_entry_bci); 1240 bool is_osr = (osr_bci != standard_entry_bci);
1263 assert(!method->is_native(), "no longer compile natives"); 1241 assert(!method->is_native(), "no longer compile natives");
1264 uint id; 1242 uint id;
1265 if (CICountOSR && is_osr) { 1243 if (CICountOSR && is_osr) {
1709 vm_exit(0); 1687 vm_exit(0);
1710 } 1688 }
1711 #endif 1689 #endif
1712 } 1690 }
1713 1691
1714
1715 // ------------------------------------------------------------------ 1692 // ------------------------------------------------------------------
1716 // CompileBroker::handle_full_code_cache 1693 // CompileBroker::handle_full_code_cache
1717 // 1694 //
1718 // The CodeCache is full. Print out warning and disable compilation or 1695 // The CodeCache is full. Print out warning and disable compilation or
1719 // try code cache cleaning so compilation can continue later. 1696 // try code cache cleaning so compilation can continue later.
1720 void CompileBroker::handle_full_code_cache() { 1697 void CompileBroker::handle_full_code_cache() {
1721 UseInterpreter = true; 1698 UseInterpreter = true;
1722 if (UseCompiler || AlwaysCompileLoopMethods ) { 1699 if (UseCompiler || AlwaysCompileLoopMethods ) {
1723 CompilerThread* thread = CompilerThread::current(); 1700 if (xtty != NULL) {
1724 CompileLog* log = thread->log(); 1701 xtty->begin_elem("code_cache_full");
1725 if (log != NULL) { 1702 xtty->stamp();
1726 log->begin_elem("code_cache_full"); 1703 xtty->end_elem();
1727 log->stamp(); 1704 }
1728 log->end_elem(); 1705 warning("CodeCache is full. Compiler has been disabled.");
1729 } 1706 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
1730 #ifndef PRODUCT 1707 #ifndef PRODUCT
1731 warning("CodeCache is full. Compiler has been disabled");
1732 if (CompileTheWorld || ExitOnFullCodeCache) { 1708 if (CompileTheWorld || ExitOnFullCodeCache) {
1733 before_exit(JavaThread::current()); 1709 before_exit(JavaThread::current());
1734 exit_globals(); // will delete tty 1710 exit_globals(); // will delete tty
1735 vm_direct_exit(CompileTheWorld ? 0 : 1); 1711 vm_direct_exit(CompileTheWorld ? 0 : 1);
1736 } 1712 }
1737 #endif 1713 #endif
1738 if (UseCodeCacheFlushing) { 1714 if (UseCodeCacheFlushing) {
1739 NMethodSweeper::handle_full_code_cache(true); 1715 NMethodSweeper::handle_full_code_cache(true);
1740 } else { 1716 } else {
1741 UseCompiler = false; 1717 UseCompiler = false;
1742 AlwaysCompileLoopMethods = false; 1718 AlwaysCompileLoopMethods = false;
1914 tty->print_cr("%3d seconds: %f bytes/sec : %f (bytes %d + %d inlined)", 1890 tty->print_cr("%3d seconds: %f bytes/sec : %f (bytes %d + %d inlined)",
1915 compile_id, time.seconds(), bytes_per_sec, method->code_size(), task->num_inlined_bytecodes()); 1891 compile_id, time.seconds(), bytes_per_sec, method->code_size(), task->num_inlined_bytecodes());
1916 } 1892 }
1917 1893
1918 // Collect counts of successful compilations 1894 // Collect counts of successful compilations
1919 _sum_nmethod_size += code->total_size(); 1895 _sum_nmethod_size += code->total_size();
1920 _sum_nmethod_code_size += code->code_size(); 1896 _sum_nmethod_code_size += code->insts_size();
1921 _total_compile_count++; 1897 _total_compile_count++;
1922 1898
1923 if (UsePerfData) { 1899 if (UsePerfData) {
1924 _perf_sum_nmethod_size->inc(code->total_size()); 1900 _perf_sum_nmethod_size->inc( code->total_size());
1925 _perf_sum_nmethod_code_size->inc(code->code_size()); 1901 _perf_sum_nmethod_code_size->inc(code->insts_size());
1926 _perf_total_compile_count->inc(); 1902 _perf_total_compile_count->inc();
1927 } 1903 }
1928 1904
1929 if (is_osr) { 1905 if (is_osr) {
1930 if (UsePerfData) _perf_total_osr_compile_count->inc(); 1906 if (UsePerfData) _perf_total_osr_compile_count->inc();
1950 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f", 1926 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f",
1951 CompileBroker::_t_standard_compilation.seconds(), 1927 CompileBroker::_t_standard_compilation.seconds(),
1952 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count); 1928 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count);
1953 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); 1929 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);
1954 1930
1955 if (compiler(CompLevel_fast_compile)) { 1931 if (compiler(CompLevel_simple) != NULL) {
1956 compiler(CompLevel_fast_compile)->print_timers(); 1932 compiler(CompLevel_simple)->print_timers();
1957 if (compiler(CompLevel_fast_compile) != compiler(CompLevel_highest_tier)) 1933 }
1958 compiler(CompLevel_highest_tier)->print_timers(); 1934 if (compiler(CompLevel_full_optimization) != NULL) {
1959 } 1935 compiler(CompLevel_full_optimization)->print_timers();
1960 1936 }
1961 tty->cr(); 1937 tty->cr();
1962 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled; 1938 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled;
1963 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb); 1939 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb);
1964 tty->print_cr(" Standard compilation : %6d bytes", CompileBroker::_sum_standard_bytes_compiled); 1940 tty->print_cr(" Standard compilation : %6d bytes", CompileBroker::_sum_standard_bytes_compiled);
1965 tty->print_cr(" On stack replacement : %6d bytes", CompileBroker::_sum_osr_bytes_compiled); 1941 tty->print_cr(" On stack replacement : %6d bytes", CompileBroker::_sum_osr_bytes_compiled);