hotspot/src/share/vm/compiler/compileBroker.cpp
changeset 26587 e8b28fa936af
parent 25647 949674dcd7c7
child 26796 666464578742
equal deleted inserted replaced
26585:2048b8d90c91 26587:e8b28fa936af
   164 
   164 
   165   void log_compile(JavaThread* thread, CompileTask* task) {
   165   void log_compile(JavaThread* thread, CompileTask* task) {
   166     StringLogMessage lm;
   166     StringLogMessage lm;
   167     stringStream sstr = lm.stream();
   167     stringStream sstr = lm.stream();
   168     // msg.time_stamp().update_to(tty->time_stamp().ticks());
   168     // msg.time_stamp().update_to(tty->time_stamp().ticks());
   169     task->print_compilation(&sstr, NULL, true);
   169     task->print_compilation(&sstr, NULL, true, false);
   170     log(thread, "%s", (const char*)lm);
   170     log(thread, "%s", (const char*)lm);
   171   }
   171   }
   172 
   172 
   173   void log_nmethod(JavaThread* thread, nmethod* nm) {
   173   void log_nmethod(JavaThread* thread, nmethod* nm) {
   174     log(thread, "nmethod %d%s " INTPTR_FORMAT " code ["INTPTR_FORMAT ", " INTPTR_FORMAT "]",
   174     log(thread, "nmethod %d%s " INTPTR_FORMAT " code ["INTPTR_FORMAT ", " INTPTR_FORMAT "]",
   326   guarantee(_code_handle != NULL, "");
   326   guarantee(_code_handle != NULL, "");
   327   _code_handle->set_code(nm);
   327   _code_handle->set_code(nm);
   328   if (nm == NULL)  _code_handle = NULL;  // drop the handle also
   328   if (nm == NULL)  _code_handle = NULL;  // drop the handle also
   329 }
   329 }
   330 
   330 
   331 
       
   332 void CompileTask::mark_on_stack() {
   331 void CompileTask::mark_on_stack() {
   333   // Mark these methods as something redefine classes cannot remove.
   332   // Mark these methods as something redefine classes cannot remove.
   334   _method->set_on_stack(true);
   333   _method->set_on_stack(true);
   335   if (_hot_method != NULL) {
   334   if (_hot_method != NULL) {
   336     _hot_method->set_on_stack(true);
   335     _hot_method->set_on_stack(true);
   337   }
   336   }
   338 }
   337 }
   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 
   338 
   352 // ------------------------------------------------------------------
   339 // ------------------------------------------------------------------
   353 // CompileTask::print_line_on_error
   340 // CompileTask::print_line_on_error
   354 //
   341 //
   355 // This function is called by fatal error handler when the thread
   342 // This function is called by fatal error handler when the thread
   365   print_compilation(st);
   352   print_compilation(st);
   366 }
   353 }
   367 
   354 
   368 // ------------------------------------------------------------------
   355 // ------------------------------------------------------------------
   369 // CompileTask::print_line
   356 // CompileTask::print_line
   370 void CompileTask::print_line() {
   357 void CompileTask::print_tty() {
   371   ttyLocker ttyl;  // keep the following output all in one block
   358   ttyLocker ttyl;  // keep the following output all in one block
   372   // print compiler name if requested
   359   // print compiler name if requested
   373   if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler_name(comp_level()));
   360   if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler_name(comp_level()));
   374   print_compilation();
   361     print_compilation(tty);
   375 }
   362 }
   376 
       
   377 
   363 
   378 // ------------------------------------------------------------------
   364 // ------------------------------------------------------------------
   379 // CompileTask::print_compilation_impl
   365 // CompileTask::print_compilation_impl
   380 void CompileTask::print_compilation_impl(outputStream* st, Method* method, int compile_id, int comp_level,
   366 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,
   367                                          bool is_osr_method, int osr_bci, bool is_blocking,
   382                                          const char* msg, bool short_form) {
   368                                          const char* msg, bool short_form, bool cr) {
   383   if (!short_form) {
   369   if (!short_form) {
   384     st->print("%7d ", (int) st->time_stamp().milliseconds());  // print timestamp
   370     st->print("%7d ", (int) st->time_stamp().milliseconds());  // print timestamp
   385   }
   371   }
   386   st->print("%4d ", compile_id);    // print compilation number
   372   st->print("%4d ", compile_id);    // print compilation number
   387 
   373 
   426   }
   412   }
   427 
   413 
   428   if (msg != NULL) {
   414   if (msg != NULL) {
   429     st->print("   %s", msg);
   415     st->print("   %s", msg);
   430   }
   416   }
   431   if (!short_form) {
   417   if (cr) {
   432     st->cr();
   418     st->cr();
   433   }
   419   }
   434 }
   420 }
   435 
   421 
   436 // ------------------------------------------------------------------
   422 // ------------------------------------------------------------------
   492   for (int i = 0; i < inline_level; i++)  st->print("  ");
   478   for (int i = 0; i < inline_level; i++)  st->print("  ");
   493 }
   479 }
   494 
   480 
   495 // ------------------------------------------------------------------
   481 // ------------------------------------------------------------------
   496 // CompileTask::print_compilation
   482 // CompileTask::print_compilation
   497 void CompileTask::print_compilation(outputStream* st, const char* msg, bool short_form) {
   483 void CompileTask::print_compilation(outputStream* st, const char* msg, bool short_form, bool cr) {
   498   bool is_osr_method = osr_bci() != InvocationEntryBci;
   484   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);
   485   print_compilation_impl(st, method(), compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking(), msg, short_form, cr);
   500 }
   486 }
   501 
   487 
   502 // ------------------------------------------------------------------
   488 // ------------------------------------------------------------------
   503 // CompileTask::log_task
   489 // CompileTask::log_task
   504 void CompileTask::log_task(xmlStream* log) {
   490 void CompileTask::log_task(xmlStream* log) {
   619   ++_size;
   605   ++_size;
   620 
   606 
   621   // Mark the method as being in the compile queue.
   607   // Mark the method as being in the compile queue.
   622   task->method()->set_queued_for_compilation();
   608   task->method()->set_queued_for_compilation();
   623 
   609 
   624   NOT_PRODUCT(print();)
   610   if (CIPrintCompileQueue) {
       
   611     print_tty();
       
   612   }
   625 
   613 
   626   if (LogCompilation && xtty != NULL) {
   614   if (LogCompilation && xtty != NULL) {
   627     task->log_task_queued();
   615     task->log_task_queued();
   628   }
   616   }
   629 
   617 
   784     task->mark_on_stack();
   772     task->mark_on_stack();
   785     task = task->next();
   773     task = task->next();
   786   }
   774   }
   787 }
   775 }
   788 
   776 
   789 #ifndef PRODUCT
   777 
   790 /**
   778 CompileQueue* CompileBroker::compile_queue(int comp_level) {
   791  * Print entire compilation queue.
   779   if (is_c2_compile(comp_level)) return _c2_compile_queue;
   792  */
   780   if (is_c1_compile(comp_level)) return _c1_compile_queue;
   793 void CompileQueue::print() {
   781   return NULL;
   794   if (CIPrintCompileQueue) {
   782 }
   795     ttyLocker ttyl;
   783 
   796     tty->print_cr("Contents of %s", name());
   784 
   797     tty->print_cr("----------------------");
   785 void CompileBroker::print_compile_queues(outputStream* st) {
   798     CompileTask* task = _first;
   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) {
   799     while (task != NULL) {
   800       task->print_line();
   800       task->print_compilation(st, NULL, true, true);
   801       task = task->next();
   801       task = task->next();
   802     }
   802     }
   803     tty->print_cr("----------------------");
   803   }
   804   }
   804   st->print_cr("----------------------------");
   805 }
   805 }
   806 #endif // PRODUCT
   806 
       
   807 void CompileQueue::print_tty() {
       
   808   ttyLocker ttyl;
       
   809   print(tty);
       
   810 }
   807 
   811 
   808 CompilerCounters::CompilerCounters(const char* thread_name, int instance, TRAPS) {
   812 CompilerCounters::CompilerCounters(const char* thread_name, int instance, TRAPS) {
   809 
   813 
   810   _current_method[0] = '\0';
   814   _current_method[0] = '\0';
   811   _compile_type = CompileBroker::no_compile;
   815   _compile_type = CompileBroker::no_compile;
  1066 #if !defined(ZERO) && !defined(SHARK)
  1070 #if !defined(ZERO) && !defined(SHARK)
  1067   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
  1071   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
  1068 #endif // !ZERO && !SHARK
  1072 #endif // !ZERO && !SHARK
  1069   // Initialize the compilation queue
  1073   // Initialize the compilation queue
  1070   if (c2_compiler_count > 0) {
  1074   if (c2_compiler_count > 0) {
  1071     _c2_compile_queue  = new CompileQueue("C2 CompileQueue",  MethodCompileQueue_lock);
  1075     _c2_compile_queue  = new CompileQueue("C2 compile queue",  MethodCompileQueue_lock);
  1072     _compilers[1]->set_num_compiler_threads(c2_compiler_count);
  1076     _compilers[1]->set_num_compiler_threads(c2_compiler_count);
  1073   }
  1077   }
  1074   if (c1_compiler_count > 0) {
  1078   if (c1_compiler_count > 0) {
  1075     _c1_compile_queue  = new CompileQueue("C1 CompileQueue",  MethodCompileQueue_lock);
  1079     _c1_compile_queue  = new CompileQueue("C1 compile queue",  MethodCompileQueue_lock);
  1076     _compilers[0]->set_num_compiler_threads(c1_compiler_count);
  1080     _compilers[0]->set_num_compiler_threads(c1_compiler_count);
  1077   }
  1081   }
  1078 
  1082 
  1079   int compiler_count = c1_compiler_count + c2_compiler_count;
  1083   int compiler_count = c1_compiler_count + c2_compiler_count;
  1080 
  1084 
  1890 // Compile a method.
  1894 // Compile a method.
  1891 //
  1895 //
  1892 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
  1896 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
  1893   if (PrintCompilation) {
  1897   if (PrintCompilation) {
  1894     ResourceMark rm;
  1898     ResourceMark rm;
  1895     task->print_line();
  1899     task->print_tty();
  1896   }
  1900   }
  1897   elapsedTimer time;
  1901   elapsedTimer time;
  1898 
  1902 
  1899   CompilerThread* thread = CompilerThread::current();
  1903   CompilerThread* thread = CompilerThread::current();
  1900   ResourceMark rm(thread);
  1904   ResourceMark rm(thread);