149 int CompileBroker::_sum_nmethod_size = 0;
150 int CompileBroker::_sum_nmethod_code_size = 0;
151
152 long CompileBroker::_peak_compilation_time = 0;
153
154 CompileQueue* CompileBroker::_c2_compile_queue = NULL;
155 CompileQueue* CompileBroker::_c1_compile_queue = NULL;
156
157 GrowableArray<CompilerThread*>* CompileBroker::_compiler_threads = NULL;
158
159
160 class CompilationLog : public StringEventLog {
161 public:
162 CompilationLog() : StringEventLog("Compilation events") {
163 }
164
165 void log_compile(JavaThread* thread, CompileTask* task) {
166 StringLogMessage lm;
167 stringStream sstr = lm.stream();
168 // msg.time_stamp().update_to(tty->time_stamp().ticks());
169 task->print_compilation(&sstr, NULL, true);
170 log(thread, "%s", (const char*)lm);
171 }
172
173 void log_nmethod(JavaThread* thread, nmethod* nm) {
174 log(thread, "nmethod %d%s " INTPTR_FORMAT " code ["INTPTR_FORMAT ", " INTPTR_FORMAT "]",
175 nm->compile_id(), nm->is_osr_method() ? "%" : "",
176 p2i(nm), p2i(nm->code_begin()), p2i(nm->code_end()));
177 }
178
179 void log_failure(JavaThread* thread, CompileTask* task, const char* reason, const char* retry_message) {
180 StringLogMessage lm;
181 lm.print("%4d COMPILE SKIPPED: %s", task->compile_id(), reason);
182 if (retry_message != NULL) {
183 lm.append(" (%s)", retry_message);
184 }
185 lm.print("\n");
186 log(thread, "%s", (const char*)lm);
187 }
188 };
189
311 }
312 }
313 }
314
315 _next = NULL;
316 }
317
318 // ------------------------------------------------------------------
319 // CompileTask::code/set_code
320 nmethod* CompileTask::code() const {
321 if (_code_handle == NULL) return NULL;
322 return _code_handle->code();
323 }
324 void CompileTask::set_code(nmethod* nm) {
325 if (_code_handle == NULL && nm == NULL) return;
326 guarantee(_code_handle != NULL, "");
327 _code_handle->set_code(nm);
328 if (nm == NULL) _code_handle = NULL; // drop the handle also
329 }
330
331
332 void CompileTask::mark_on_stack() {
333 // Mark these methods as something redefine classes cannot remove.
334 _method->set_on_stack(true);
335 if (_hot_method != NULL) {
336 _hot_method->set_on_stack(true);
337 }
338 }
339
340 // ------------------------------------------------------------------
341 // CompileTask::print
342 void CompileTask::print() {
343 tty->print("<CompileTask compile_id=%d ", _compile_id);
344 tty->print("method=");
345 _method->print_name(tty);
346 tty->print_cr(" osr_bci=%d is_blocking=%s is_complete=%s is_success=%s>",
347 _osr_bci, bool_to_str(_is_blocking),
348 bool_to_str(_is_complete), bool_to_str(_is_success));
349 }
350
351
352 // ------------------------------------------------------------------
353 // CompileTask::print_line_on_error
354 //
355 // This function is called by fatal error handler when the thread
356 // causing troubles is a compiler thread.
357 //
358 // Do not grab any lock, do not allocate memory.
359 //
360 // Otherwise it's the same as CompileTask::print_line()
361 //
362 void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) {
363 // print compiler name
364 st->print("%s:", CompileBroker::compiler_name(comp_level()));
365 print_compilation(st);
366 }
367
368 // ------------------------------------------------------------------
369 // CompileTask::print_line
370 void CompileTask::print_line() {
371 ttyLocker ttyl; // keep the following output all in one block
372 // print compiler name if requested
373 if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler_name(comp_level()));
374 print_compilation();
375 }
376
377
378 // ------------------------------------------------------------------
379 // CompileTask::print_compilation_impl
380 void CompileTask::print_compilation_impl(outputStream* st, Method* method, int compile_id, int comp_level,
381 bool is_osr_method, int osr_bci, bool is_blocking,
382 const char* msg, bool short_form) {
383 if (!short_form) {
384 st->print("%7d ", (int) st->time_stamp().milliseconds()); // print timestamp
385 }
386 st->print("%4d ", compile_id); // print compilation number
387
388 // For unloaded methods the transition to zombie occurs after the
389 // method is cleared so it's impossible to report accurate
390 // information for that case.
391 bool is_synchronized = false;
392 bool has_exception_handler = false;
393 bool is_native = false;
394 if (method != NULL) {
395 is_synchronized = method->is_synchronized();
396 has_exception_handler = method->has_exception_handler();
397 is_native = method->is_native();
398 }
399 // method attributes
400 const char compile_type = is_osr_method ? '%' : ' ';
401 const char sync_char = is_synchronized ? 's' : ' ';
402 const char exception_char = has_exception_handler ? '!' : ' ';
411 else st->print("- ");
412 }
413 st->print(" "); // more indent
414
415 if (method == NULL) {
416 st->print("(method)");
417 } else {
418 method->print_short_name(st);
419 if (is_osr_method) {
420 st->print(" @ %d", osr_bci);
421 }
422 if (method->is_native())
423 st->print(" (native)");
424 else
425 st->print(" (%d bytes)", method->code_size());
426 }
427
428 if (msg != NULL) {
429 st->print(" %s", msg);
430 }
431 if (!short_form) {
432 st->cr();
433 }
434 }
435
436 // ------------------------------------------------------------------
437 // CompileTask::print_inlining
438 void CompileTask::print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg) {
439 // 1234567
440 st->print(" "); // print timestamp
441 // 1234
442 st->print(" "); // print compilation number
443
444 // method attributes
445 if (method->is_loaded()) {
446 const char sync_char = method->is_synchronized() ? 's' : ' ';
447 const char exception_char = method->has_exception_handlers() ? '!' : ' ';
448 const char monitors_char = method->has_monitor_bytecodes() ? 'm' : ' ';
449
450 // print method attributes
451 st->print(" %c%c%c ", sync_char, exception_char, monitors_char);
477
478 // ------------------------------------------------------------------
479 // CompileTask::print_inline_indent
480 void CompileTask::print_inline_indent(int inline_level, outputStream* st) {
481 // 1234567
482 st->print(" "); // print timestamp
483 // 1234
484 st->print(" "); // print compilation number
485 // %s!bn
486 st->print(" "); // print method attributes
487 if (TieredCompilation) {
488 st->print(" ");
489 }
490 st->print(" "); // more indent
491 st->print(" "); // initial inlining indent
492 for (int i = 0; i < inline_level; i++) st->print(" ");
493 }
494
495 // ------------------------------------------------------------------
496 // CompileTask::print_compilation
497 void CompileTask::print_compilation(outputStream* st, const char* msg, bool short_form) {
498 bool is_osr_method = osr_bci() != InvocationEntryBci;
499 print_compilation_impl(st, method(), compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking(), msg, short_form);
500 }
501
502 // ------------------------------------------------------------------
503 // CompileTask::log_task
504 void CompileTask::log_task(xmlStream* log) {
505 Thread* thread = Thread::current();
506 methodHandle method(thread, this->method());
507 ResourceMark rm(thread);
508
509 // <task id='9' method='M' osr_bci='X' level='1' blocking='1' stamp='1.234'>
510 log->print(" compile_id='%d'", _compile_id);
511 if (_osr_bci != CompileBroker::standard_entry_bci) {
512 log->print(" compile_kind='osr'"); // same as nmethod::compile_kind
513 } // else compile_kind='c2c'
514 if (!method.is_null()) log->method(method);
515 if (_osr_bci != CompileBroker::standard_entry_bci) {
516 log->print(" osr_bci='%d'", _osr_bci);
517 }
518 if (_comp_level != CompLevel_highest_tier) {
519 log->print(" level='%d'", _comp_level);
604 task->set_next(NULL);
605 task->set_prev(NULL);
606
607 if (_last == NULL) {
608 // The compile queue is empty.
609 assert(_first == NULL, "queue is empty");
610 _first = task;
611 _last = task;
612 } else {
613 // Append the task to the queue.
614 assert(_last->next() == NULL, "not last");
615 _last->set_next(task);
616 task->set_prev(_last);
617 _last = task;
618 }
619 ++_size;
620
621 // Mark the method as being in the compile queue.
622 task->method()->set_queued_for_compilation();
623
624 NOT_PRODUCT(print();)
625
626 if (LogCompilation && xtty != NULL) {
627 task->log_task_queued();
628 }
629
630 // Notify CompilerThreads that a task is available.
631 lock()->notify_all();
632 }
633
634 /**
635 * Empties compilation queue by putting all compilation tasks onto
636 * a freelist. Furthermore, the method wakes up all threads that are
637 * waiting on a compilation task to finish. This can happen if background
638 * compilation is disabled.
639 */
640 void CompileQueue::free_all() {
641 MutexLocker mu(lock());
642 CompileTask* next = _first;
643
644 // Iterate over all tasks in the compile queue
769 void CompileQueue::remove_and_mark_stale(CompileTask* task) {
770 assert(lock()->owned_by_self(), "must own lock");
771 remove(task);
772
773 // Enqueue the task for reclamation (should be done outside MCQ lock)
774 task->set_next(_first_stale);
775 task->set_prev(NULL);
776 _first_stale = task;
777 }
778
779 // methods in the compile queue need to be marked as used on the stack
780 // so that they don't get reclaimed by Redefine Classes
781 void CompileQueue::mark_on_stack() {
782 CompileTask* task = _first;
783 while (task != NULL) {
784 task->mark_on_stack();
785 task = task->next();
786 }
787 }
788
789 #ifndef PRODUCT
790 /**
791 * Print entire compilation queue.
792 */
793 void CompileQueue::print() {
794 if (CIPrintCompileQueue) {
795 ttyLocker ttyl;
796 tty->print_cr("Contents of %s", name());
797 tty->print_cr("----------------------");
798 CompileTask* task = _first;
799 while (task != NULL) {
800 task->print_line();
801 task = task->next();
802 }
803 tty->print_cr("----------------------");
804 }
805 }
806 #endif // PRODUCT
807
808 CompilerCounters::CompilerCounters(const char* thread_name, int instance, TRAPS) {
809
810 _current_method[0] = '\0';
811 _compile_type = CompileBroker::no_compile;
812
813 if (UsePerfData) {
814 ResourceMark rm;
815
816 // create the thread instance name space string - don't create an
817 // instance subspace if instance is -1 - keeps the adapterThread
818 // counters from having a ".0" namespace.
819 const char* thread_i = (instance == -1) ? thread_name :
820 PerfDataManager::name_space(thread_name, instance);
821
822
823 char* name = PerfDataManager::counter_name(thread_i, "method");
824 _perf_current_method =
825 PerfDataManager::create_string_variable(SUN_CI, name,
826 cmname_buffer_length,
1051 compiler_thread->set_threadObj(thread_oop());
1052 compiler_thread->set_compiler(comp);
1053 Threads::add(compiler_thread);
1054 Thread::start(compiler_thread);
1055 }
1056
1057 // Let go of Threads_lock before yielding
1058 os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
1059
1060 return compiler_thread;
1061 }
1062
1063
1064 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) {
1065 EXCEPTION_MARK;
1066 #if !defined(ZERO) && !defined(SHARK)
1067 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
1068 #endif // !ZERO && !SHARK
1069 // Initialize the compilation queue
1070 if (c2_compiler_count > 0) {
1071 _c2_compile_queue = new CompileQueue("C2 CompileQueue", MethodCompileQueue_lock);
1072 _compilers[1]->set_num_compiler_threads(c2_compiler_count);
1073 }
1074 if (c1_compiler_count > 0) {
1075 _c1_compile_queue = new CompileQueue("C1 CompileQueue", MethodCompileQueue_lock);
1076 _compilers[0]->set_num_compiler_threads(c1_compiler_count);
1077 }
1078
1079 int compiler_count = c1_compiler_count + c2_compiler_count;
1080
1081 _compiler_threads =
1082 new (ResourceObj::C_HEAP, mtCompiler) GrowableArray<CompilerThread*>(compiler_count, true);
1083
1084 char name_buffer[256];
1085 for (int i = 0; i < c2_compiler_count; i++) {
1086 // Create a name for our thread.
1087 sprintf(name_buffer, "C2 CompilerThread%d", i);
1088 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
1089 // Shark and C2
1090 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_compile_queue, counters, _compilers[1], CHECK);
1091 _compiler_threads->append(new_thread);
1092 }
1093
1094 for (int i = c2_compiler_count; i < compiler_count; i++) {
1095 // Create a name for our thread.
1875 {
1876 ResourceMark rm;
1877 stringStream s;
1878 // Dump code cache into a buffer before locking the tty,
1879 {
1880 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1881 CodeCache::print_summary(&s, detailed);
1882 }
1883 ttyLocker ttyl;
1884 tty->print("%s", s.as_string());
1885 }
1886
1887 // ------------------------------------------------------------------
1888 // CompileBroker::invoke_compiler_on_method
1889 //
1890 // Compile a method.
1891 //
1892 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1893 if (PrintCompilation) {
1894 ResourceMark rm;
1895 task->print_line();
1896 }
1897 elapsedTimer time;
1898
1899 CompilerThread* thread = CompilerThread::current();
1900 ResourceMark rm(thread);
1901
1902 if (LogEvents) {
1903 _compilation_log->log_compile(thread, task);
1904 }
1905
1906 // Common flags.
1907 uint compile_id = task->compile_id();
1908 int osr_bci = task->osr_bci();
1909 bool is_osr = (osr_bci != standard_entry_bci);
1910 bool should_log = (thread->log() != NULL);
1911 bool should_break = false;
1912 int task_level = task->comp_level();
1913 {
1914 // create the handle inside it's own block so it can't
1915 // accidentally be referenced once the thread transitions to
|
149 int CompileBroker::_sum_nmethod_size = 0;
150 int CompileBroker::_sum_nmethod_code_size = 0;
151
152 long CompileBroker::_peak_compilation_time = 0;
153
154 CompileQueue* CompileBroker::_c2_compile_queue = NULL;
155 CompileQueue* CompileBroker::_c1_compile_queue = NULL;
156
157 GrowableArray<CompilerThread*>* CompileBroker::_compiler_threads = NULL;
158
159
160 class CompilationLog : public StringEventLog {
161 public:
162 CompilationLog() : StringEventLog("Compilation events") {
163 }
164
165 void log_compile(JavaThread* thread, CompileTask* task) {
166 StringLogMessage lm;
167 stringStream sstr = lm.stream();
168 // msg.time_stamp().update_to(tty->time_stamp().ticks());
169 task->print_compilation(&sstr, NULL, true, false);
170 log(thread, "%s", (const char*)lm);
171 }
172
173 void log_nmethod(JavaThread* thread, nmethod* nm) {
174 log(thread, "nmethod %d%s " INTPTR_FORMAT " code ["INTPTR_FORMAT ", " INTPTR_FORMAT "]",
175 nm->compile_id(), nm->is_osr_method() ? "%" : "",
176 p2i(nm), p2i(nm->code_begin()), p2i(nm->code_end()));
177 }
178
179 void log_failure(JavaThread* thread, CompileTask* task, const char* reason, const char* retry_message) {
180 StringLogMessage lm;
181 lm.print("%4d COMPILE SKIPPED: %s", task->compile_id(), reason);
182 if (retry_message != NULL) {
183 lm.append(" (%s)", retry_message);
184 }
185 lm.print("\n");
186 log(thread, "%s", (const char*)lm);
187 }
188 };
189
311 }
312 }
313 }
314
315 _next = NULL;
316 }
317
318 // ------------------------------------------------------------------
319 // CompileTask::code/set_code
320 nmethod* CompileTask::code() const {
321 if (_code_handle == NULL) return NULL;
322 return _code_handle->code();
323 }
324 void CompileTask::set_code(nmethod* nm) {
325 if (_code_handle == NULL && nm == NULL) return;
326 guarantee(_code_handle != NULL, "");
327 _code_handle->set_code(nm);
328 if (nm == NULL) _code_handle = NULL; // drop the handle also
329 }
330
331 void CompileTask::mark_on_stack() {
332 // Mark these methods as something redefine classes cannot remove.
333 _method->set_on_stack(true);
334 if (_hot_method != NULL) {
335 _hot_method->set_on_stack(true);
336 }
337 }
338
339 // ------------------------------------------------------------------
340 // CompileTask::print_line_on_error
341 //
342 // This function is called by fatal error handler when the thread
343 // causing troubles is a compiler thread.
344 //
345 // Do not grab any lock, do not allocate memory.
346 //
347 // Otherwise it's the same as CompileTask::print_line()
348 //
349 void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) {
350 // print compiler name
351 st->print("%s:", CompileBroker::compiler_name(comp_level()));
352 print_compilation(st);
353 }
354
355 // ------------------------------------------------------------------
356 // CompileTask::print_line
357 void CompileTask::print_tty() {
358 ttyLocker ttyl; // keep the following output all in one block
359 // print compiler name if requested
360 if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler_name(comp_level()));
361 print_compilation(tty);
362 }
363
364 // ------------------------------------------------------------------
365 // CompileTask::print_compilation_impl
366 void CompileTask::print_compilation_impl(outputStream* st, Method* method, int compile_id, int comp_level,
367 bool is_osr_method, int osr_bci, bool is_blocking,
368 const char* msg, bool short_form, bool cr) {
369 if (!short_form) {
370 st->print("%7d ", (int) st->time_stamp().milliseconds()); // print timestamp
371 }
372 st->print("%4d ", compile_id); // print compilation number
373
374 // For unloaded methods the transition to zombie occurs after the
375 // method is cleared so it's impossible to report accurate
376 // information for that case.
377 bool is_synchronized = false;
378 bool has_exception_handler = false;
379 bool is_native = false;
380 if (method != NULL) {
381 is_synchronized = method->is_synchronized();
382 has_exception_handler = method->has_exception_handler();
383 is_native = method->is_native();
384 }
385 // method attributes
386 const char compile_type = is_osr_method ? '%' : ' ';
387 const char sync_char = is_synchronized ? 's' : ' ';
388 const char exception_char = has_exception_handler ? '!' : ' ';
397 else st->print("- ");
398 }
399 st->print(" "); // more indent
400
401 if (method == NULL) {
402 st->print("(method)");
403 } else {
404 method->print_short_name(st);
405 if (is_osr_method) {
406 st->print(" @ %d", osr_bci);
407 }
408 if (method->is_native())
409 st->print(" (native)");
410 else
411 st->print(" (%d bytes)", method->code_size());
412 }
413
414 if (msg != NULL) {
415 st->print(" %s", msg);
416 }
417 if (cr) {
418 st->cr();
419 }
420 }
421
422 // ------------------------------------------------------------------
423 // CompileTask::print_inlining
424 void CompileTask::print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg) {
425 // 1234567
426 st->print(" "); // print timestamp
427 // 1234
428 st->print(" "); // print compilation number
429
430 // method attributes
431 if (method->is_loaded()) {
432 const char sync_char = method->is_synchronized() ? 's' : ' ';
433 const char exception_char = method->has_exception_handlers() ? '!' : ' ';
434 const char monitors_char = method->has_monitor_bytecodes() ? 'm' : ' ';
435
436 // print method attributes
437 st->print(" %c%c%c ", sync_char, exception_char, monitors_char);
463
464 // ------------------------------------------------------------------
465 // CompileTask::print_inline_indent
466 void CompileTask::print_inline_indent(int inline_level, outputStream* st) {
467 // 1234567
468 st->print(" "); // print timestamp
469 // 1234
470 st->print(" "); // print compilation number
471 // %s!bn
472 st->print(" "); // print method attributes
473 if (TieredCompilation) {
474 st->print(" ");
475 }
476 st->print(" "); // more indent
477 st->print(" "); // initial inlining indent
478 for (int i = 0; i < inline_level; i++) st->print(" ");
479 }
480
481 // ------------------------------------------------------------------
482 // CompileTask::print_compilation
483 void CompileTask::print_compilation(outputStream* st, const char* msg, bool short_form, bool cr) {
484 bool is_osr_method = osr_bci() != InvocationEntryBci;
485 print_compilation_impl(st, method(), compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking(), msg, short_form, cr);
486 }
487
488 // ------------------------------------------------------------------
489 // CompileTask::log_task
490 void CompileTask::log_task(xmlStream* log) {
491 Thread* thread = Thread::current();
492 methodHandle method(thread, this->method());
493 ResourceMark rm(thread);
494
495 // <task id='9' method='M' osr_bci='X' level='1' blocking='1' stamp='1.234'>
496 log->print(" compile_id='%d'", _compile_id);
497 if (_osr_bci != CompileBroker::standard_entry_bci) {
498 log->print(" compile_kind='osr'"); // same as nmethod::compile_kind
499 } // else compile_kind='c2c'
500 if (!method.is_null()) log->method(method);
501 if (_osr_bci != CompileBroker::standard_entry_bci) {
502 log->print(" osr_bci='%d'", _osr_bci);
503 }
504 if (_comp_level != CompLevel_highest_tier) {
505 log->print(" level='%d'", _comp_level);
590 task->set_next(NULL);
591 task->set_prev(NULL);
592
593 if (_last == NULL) {
594 // The compile queue is empty.
595 assert(_first == NULL, "queue is empty");
596 _first = task;
597 _last = task;
598 } else {
599 // Append the task to the queue.
600 assert(_last->next() == NULL, "not last");
601 _last->set_next(task);
602 task->set_prev(_last);
603 _last = task;
604 }
605 ++_size;
606
607 // Mark the method as being in the compile queue.
608 task->method()->set_queued_for_compilation();
609
610 if (CIPrintCompileQueue) {
611 print_tty();
612 }
613
614 if (LogCompilation && xtty != NULL) {
615 task->log_task_queued();
616 }
617
618 // Notify CompilerThreads that a task is available.
619 lock()->notify_all();
620 }
621
622 /**
623 * Empties compilation queue by putting all compilation tasks onto
624 * a freelist. Furthermore, the method wakes up all threads that are
625 * waiting on a compilation task to finish. This can happen if background
626 * compilation is disabled.
627 */
628 void CompileQueue::free_all() {
629 MutexLocker mu(lock());
630 CompileTask* next = _first;
631
632 // Iterate over all tasks in the compile queue
757 void CompileQueue::remove_and_mark_stale(CompileTask* task) {
758 assert(lock()->owned_by_self(), "must own lock");
759 remove(task);
760
761 // Enqueue the task for reclamation (should be done outside MCQ lock)
762 task->set_next(_first_stale);
763 task->set_prev(NULL);
764 _first_stale = task;
765 }
766
767 // methods in the compile queue need to be marked as used on the stack
768 // so that they don't get reclaimed by Redefine Classes
769 void CompileQueue::mark_on_stack() {
770 CompileTask* task = _first;
771 while (task != NULL) {
772 task->mark_on_stack();
773 task = task->next();
774 }
775 }
776
777
778 CompileQueue* CompileBroker::compile_queue(int comp_level) {
779 if (is_c2_compile(comp_level)) return _c2_compile_queue;
780 if (is_c1_compile(comp_level)) return _c1_compile_queue;
781 return NULL;
782 }
783
784
785 void CompileBroker::print_compile_queues(outputStream* st) {
786 _c1_compile_queue->print(st);
787 _c2_compile_queue->print(st);
788 }
789
790
791 void CompileQueue::print(outputStream* st) {
792 assert_locked_or_safepoint(lock());
793 st->print_cr("Contents of %s", name());
794 st->print_cr("----------------------------");
795 CompileTask* task = _first;
796 if (task == NULL) {
797 st->print_cr("Empty");;
798 } else {
799 while (task != NULL) {
800 task->print_compilation(st, NULL, true, true);
801 task = task->next();
802 }
803 }
804 st->print_cr("----------------------------");
805 }
806
807 void CompileQueue::print_tty() {
808 ttyLocker ttyl;
809 print(tty);
810 }
811
812 CompilerCounters::CompilerCounters(const char* thread_name, int instance, TRAPS) {
813
814 _current_method[0] = '\0';
815 _compile_type = CompileBroker::no_compile;
816
817 if (UsePerfData) {
818 ResourceMark rm;
819
820 // create the thread instance name space string - don't create an
821 // instance subspace if instance is -1 - keeps the adapterThread
822 // counters from having a ".0" namespace.
823 const char* thread_i = (instance == -1) ? thread_name :
824 PerfDataManager::name_space(thread_name, instance);
825
826
827 char* name = PerfDataManager::counter_name(thread_i, "method");
828 _perf_current_method =
829 PerfDataManager::create_string_variable(SUN_CI, name,
830 cmname_buffer_length,
1055 compiler_thread->set_threadObj(thread_oop());
1056 compiler_thread->set_compiler(comp);
1057 Threads::add(compiler_thread);
1058 Thread::start(compiler_thread);
1059 }
1060
1061 // Let go of Threads_lock before yielding
1062 os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
1063
1064 return compiler_thread;
1065 }
1066
1067
1068 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) {
1069 EXCEPTION_MARK;
1070 #if !defined(ZERO) && !defined(SHARK)
1071 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
1072 #endif // !ZERO && !SHARK
1073 // Initialize the compilation queue
1074 if (c2_compiler_count > 0) {
1075 _c2_compile_queue = new CompileQueue("C2 compile queue", MethodCompileQueue_lock);
1076 _compilers[1]->set_num_compiler_threads(c2_compiler_count);
1077 }
1078 if (c1_compiler_count > 0) {
1079 _c1_compile_queue = new CompileQueue("C1 compile queue", MethodCompileQueue_lock);
1080 _compilers[0]->set_num_compiler_threads(c1_compiler_count);
1081 }
1082
1083 int compiler_count = c1_compiler_count + c2_compiler_count;
1084
1085 _compiler_threads =
1086 new (ResourceObj::C_HEAP, mtCompiler) GrowableArray<CompilerThread*>(compiler_count, true);
1087
1088 char name_buffer[256];
1089 for (int i = 0; i < c2_compiler_count; i++) {
1090 // Create a name for our thread.
1091 sprintf(name_buffer, "C2 CompilerThread%d", i);
1092 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
1093 // Shark and C2
1094 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_compile_queue, counters, _compilers[1], CHECK);
1095 _compiler_threads->append(new_thread);
1096 }
1097
1098 for (int i = c2_compiler_count; i < compiler_count; i++) {
1099 // Create a name for our thread.
1879 {
1880 ResourceMark rm;
1881 stringStream s;
1882 // Dump code cache into a buffer before locking the tty,
1883 {
1884 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1885 CodeCache::print_summary(&s, detailed);
1886 }
1887 ttyLocker ttyl;
1888 tty->print("%s", s.as_string());
1889 }
1890
1891 // ------------------------------------------------------------------
1892 // CompileBroker::invoke_compiler_on_method
1893 //
1894 // Compile a method.
1895 //
1896 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1897 if (PrintCompilation) {
1898 ResourceMark rm;
1899 task->print_tty();
1900 }
1901 elapsedTimer time;
1902
1903 CompilerThread* thread = CompilerThread::current();
1904 ResourceMark rm(thread);
1905
1906 if (LogEvents) {
1907 _compilation_log->log_compile(thread, task);
1908 }
1909
1910 // Common flags.
1911 uint compile_id = task->compile_id();
1912 int osr_bci = task->osr_bci();
1913 bool is_osr = (osr_bci != standard_entry_bci);
1914 bool should_log = (thread->log() != NULL);
1915 bool should_break = false;
1916 int task_level = task->comp_level();
1917 {
1918 // create the handle inside it's own block so it can't
1919 // accidentally be referenced once the thread transitions to
|