src/share/vm/compiler/compileBroker.cpp

Print this page
rev 1083 : code cache unloading for webrev 091214
rev 1084 : This rev fixes all the print format stuff and resets less counters as recommended by Vladimir.
rev 1085 : checkpoint unloading changes on 100107
rev 1087 : use enum for passing compiler on/off state


  52     char* comp_name = (char*)(compiler)->name();                         \
  53     symbolOop klass_name = (method)->klass_name();                       \
  54     symbolOop name = (method)->name();                                   \
  55     symbolOop signature = (method)->signature();                         \
  56     HS_DTRACE_PROBE9(hotspot, method__compile__end,                      \
  57       comp_name, strlen(comp_name),                                      \
  58       klass_name->bytes(), klass_name->utf8_length(),                    \
  59       name->bytes(), name->utf8_length(),                                \
  60       signature->bytes(), signature->utf8_length(), (success));          \
  61   }
  62 
  63 #else //  ndef DTRACE_ENABLED
  64 
  65 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method)
  66 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success)
  67 
  68 #endif // ndef DTRACE_ENABLED
  69 
  70 bool CompileBroker::_initialized = false;
  71 volatile bool CompileBroker::_should_block = false;

  72 
  73 // The installed compiler(s)
  74 AbstractCompiler* CompileBroker::_compilers[2];
  75 
  76 // These counters are used for assigning id's to each compilation
  77 uint CompileBroker::_compilation_id        = 0;
  78 uint CompileBroker::_osr_compilation_id    = 0;
  79 
  80 // Debugging information
  81 int  CompileBroker::_last_compile_type     = no_compile;
  82 int  CompileBroker::_last_compile_level    = CompLevel_none;
  83 char CompileBroker::_last_method_compiled[CompileBroker::name_buffer_length];
  84 
  85 // Performance counters
  86 PerfCounter* CompileBroker::_perf_total_compilation = NULL;
  87 PerfCounter* CompileBroker::_perf_osr_compilation = NULL;
  88 PerfCounter* CompileBroker::_perf_standard_compilation = NULL;
  89 
  90 PerfCounter* CompileBroker::_perf_total_bailout_count = NULL;
  91 PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL;


 446     print();
 447   }
 448 
 449   if (LogCompilation && xtty != NULL) {
 450     task->log_task_queued();
 451   }
 452 
 453   // Notify CompilerThreads that a task is available.
 454   lock()->notify();
 455 }
 456 
 457 
 458 // ------------------------------------------------------------------
 459 // CompileQueue::get
 460 //
 461 // Get the next CompileTask from a CompileQueue
 462 CompileTask* CompileQueue::get() {
 463   MutexLocker locker(lock());
 464 
 465   // Wait for an available CompileTask.
 466   while (_first == NULL) {
 467     // There is no work to be done right now.  Wait.
 468     lock()->wait();
 469   }
 470 
 471   CompileTask* task = _first;
 472 
 473   // Update queue first and last
 474   _first =_first->next();
 475   if (_first == NULL) {
 476     _last = NULL;
 477   }
 478 
 479   return task;
 480 
 481 }
 482 
 483 
 484 // ------------------------------------------------------------------
 485 // CompileQueue::print
 486 void CompileQueue::print() {


1308     }
1309   }
1310 
1311   // Open a log.
1312   if (LogCompilation) {
1313     init_compiler_thread_log();
1314   }
1315   CompileLog* log = thread->log();
1316   if (log != NULL) {
1317     log->begin_elem("start_compile_thread thread='" UINTX_FORMAT "' process='%d'",
1318                     os::current_thread_id(),
1319                     os::current_process_id());
1320     log->stamp();
1321     log->end_elem();
1322   }
1323 
1324   while (true) {
1325     {
1326       // We need this HandleMark to avoid leaking VM handles.
1327       HandleMark hm(thread);

1328       if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
1329         // The CodeCache is full.  Print out warning and disable compilation.
1330         UseInterpreter = true;
1331         if (UseCompiler || AlwaysCompileLoopMethods ) {
1332           if (log != NULL) {
1333             log->begin_elem("code_cache_full");
1334             log->stamp();
1335             log->end_elem();
1336           }
1337 #ifndef PRODUCT
1338           warning("CodeCache is full. Compiler has been disabled");
1339           if (CompileTheWorld || ExitOnFullCodeCache) {
1340             before_exit(thread);
1341             exit_globals(); // will delete tty
1342             vm_direct_exit(CompileTheWorld ? 0 : 1);
1343           }
1344 #endif
1345           UseCompiler               = false;
1346           AlwaysCompileLoopMethods  = false;
1347         }
1348       }
1349 
1350       CompileTask* task = queue->get();
1351 
1352       // Give compiler threads an extra quanta.  They tend to be bursty and
1353       // this helps the compiler to finish up the job.
1354       if( CompilerThreadHintNoPreempt )
1355         os::hint_no_preempt();
1356 
1357       // trace per thread time and compile statistics
1358       CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1359       PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1360 
1361       // Assign the task to the current thread.  Mark this compilation
1362       // thread as active for the profiler.
1363       CompileTaskWrapper ctw(task);
1364       nmethodLocker result_handle;  // (handle for the nmethod produced by this task)
1365       task->set_code_handle(&result_handle);
1366       methodHandle method(thread,
1367                      (methodOop)JNIHandles::resolve(task->method_handle()));
1368 
1369       // Never compile a method if breakpoints are present in it
1370       if (method()->number_of_breakpoints() == 0) {
1371         // Compile the method.
1372         if (UseCompiler || AlwaysCompileLoopMethods) {
1373 #ifdef COMPILER1
1374           // Allow repeating compilations for the purpose of benchmarking
1375           // compile speed. This is not useful for customers.
1376           if (CompilationRepeat != 0) {
1377             int compile_count = CompilationRepeat;
1378             while (compile_count > 0) {
1379               invoke_compiler_on_method(task);
1380               nmethod* nm = method->code();
1381               if (nm != NULL) {
1382                 nm->make_zombie();
1383                 method->clear_code();
1384               }
1385               compile_count--;
1386             }
1387           }
1388 #endif /* COMPILER1 */
1389           invoke_compiler_on_method(task);
1390         } else {
1391           // After compilation is disabled, remove remaining methods from queue
1392           method->clear_queued_for_compilation();


1597   // protection of a mutex. [They were set by the requester thread,
1598   // when adding the task to the complie queue -- at which time the
1599   // compile queue lock was held. Subsequently, we acquired the compile
1600   // queue lock to get this task off the compile queue; thus (to belabour
1601   // the point somewhat) our clearing of the bits must be occurring
1602   // only after the setting of the bits. See also 14012000 above.
1603   method->clear_queued_for_compilation();
1604 
1605 #ifdef ASSERT
1606   if (CollectedHeap::fired_fake_oom()) {
1607     // The current compile received a fake OOM during compilation so
1608     // go ahead and exit the VM since the test apparently succeeded
1609     tty->print_cr("*** Shutting down VM after successful fake OOM");
1610     vm_exit(0);
1611   }
1612 #endif
1613 }
1614 
1615 
1616 // ------------------------------------------------------------------

























1617 // CompileBroker::set_last_compile
1618 //
1619 // Record this compilation for debugging purposes.
1620 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) {
1621   ResourceMark rm;
1622   char* method_name = method->name()->as_C_string();
1623   strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length);
1624   char current_method[CompilerCounters::cmname_buffer_length];
1625   size_t maxLen = CompilerCounters::cmname_buffer_length;
1626 
1627   if (UsePerfData) {
1628     const char* class_name = method->method_holder()->klass_part()->name()->as_C_string();
1629 
1630     size_t s1len = strlen(class_name);
1631     size_t s2len = strlen(method_name);
1632 
1633     // check if we need to truncate the string
1634     if (s1len + s2len + 2 > maxLen) {
1635 
1636       // the strategy is to lop off the leading characters of the




  52     char* comp_name = (char*)(compiler)->name();                         \
  53     symbolOop klass_name = (method)->klass_name();                       \
  54     symbolOop name = (method)->name();                                   \
  55     symbolOop signature = (method)->signature();                         \
  56     HS_DTRACE_PROBE9(hotspot, method__compile__end,                      \
  57       comp_name, strlen(comp_name),                                      \
  58       klass_name->bytes(), klass_name->utf8_length(),                    \
  59       name->bytes(), name->utf8_length(),                                \
  60       signature->bytes(), signature->utf8_length(), (success));          \
  61   }
  62 
  63 #else //  ndef DTRACE_ENABLED
  64 
  65 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method)
  66 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success)
  67 
  68 #endif // ndef DTRACE_ENABLED
  69 
  70 bool CompileBroker::_initialized = false;
  71 volatile bool CompileBroker::_should_block = false;
  72 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
  73 
  74 // The installed compiler(s)
  75 AbstractCompiler* CompileBroker::_compilers[2];
  76 
  77 // These counters are used for assigning id's to each compilation
  78 uint CompileBroker::_compilation_id        = 0;
  79 uint CompileBroker::_osr_compilation_id    = 0;
  80 
  81 // Debugging information
  82 int  CompileBroker::_last_compile_type     = no_compile;
  83 int  CompileBroker::_last_compile_level    = CompLevel_none;
  84 char CompileBroker::_last_method_compiled[CompileBroker::name_buffer_length];
  85 
  86 // Performance counters
  87 PerfCounter* CompileBroker::_perf_total_compilation = NULL;
  88 PerfCounter* CompileBroker::_perf_osr_compilation = NULL;
  89 PerfCounter* CompileBroker::_perf_standard_compilation = NULL;
  90 
  91 PerfCounter* CompileBroker::_perf_total_bailout_count = NULL;
  92 PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL;


 447     print();
 448   }
 449 
 450   if (LogCompilation && xtty != NULL) {
 451     task->log_task_queued();
 452   }
 453 
 454   // Notify CompilerThreads that a task is available.
 455   lock()->notify();
 456 }
 457 
 458 
 459 // ------------------------------------------------------------------
 460 // CompileQueue::get
 461 //
 462 // Get the next CompileTask from a CompileQueue
 463 CompileTask* CompileQueue::get() {
 464   MutexLocker locker(lock());
 465   
 466   // Wait for an available CompileTask.
 467   while ((_first == NULL) || (!CompileBroker::should_compile_new_jobs())) {
 468     // There is no work to be done right now.  Wait.
 469     lock()->wait();
 470   }
 471 
 472   CompileTask* task = _first;
 473 
 474   // Update queue first and last
 475   _first =_first->next();
 476   if (_first == NULL) {
 477     _last = NULL;
 478   }
 479 
 480   return task;
 481 
 482 }
 483 
 484 
 485 // ------------------------------------------------------------------
 486 // CompileQueue::print
 487 void CompileQueue::print() {


1309     }
1310   }
1311 
1312   // Open a log.
1313   if (LogCompilation) {
1314     init_compiler_thread_log();
1315   }
1316   CompileLog* log = thread->log();
1317   if (log != NULL) {
1318     log->begin_elem("start_compile_thread thread='" UINTX_FORMAT "' process='%d'",
1319                     os::current_thread_id(),
1320                     os::current_process_id());
1321     log->stamp();
1322     log->end_elem();
1323   }
1324 
1325   while (true) {
1326     {
1327       // We need this HandleMark to avoid leaking VM handles.
1328       HandleMark hm(thread);
1329      
1330       if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
1331         // the code cache is really full
1332         handle_full_code_cache();      
1333       } else if (UseCodeCacheFlushing && (CodeCache::unallocated_capacity() < CodeCacheFlushingMinimumFreeSpace)) {
1334         // Attempt to start cleaning the code cache while there is still a little headroom
1335         NMethodSweeper::handle_full_code_cache(false);      














1336       } 
1337 
1338       CompileTask* task = queue->get();
1339 
1340       // Give compiler threads an extra quanta.  They tend to be bursty and
1341       // this helps the compiler to finish up the job.
1342       if( CompilerThreadHintNoPreempt )
1343         os::hint_no_preempt();
1344 
1345       // trace per thread time and compile statistics
1346       CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1347       PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1348 
1349       // Assign the task to the current thread.  Mark this compilation
1350       // thread as active for the profiler.
1351       CompileTaskWrapper ctw(task);
1352       nmethodLocker result_handle;  // (handle for the nmethod produced by this task)
1353       task->set_code_handle(&result_handle);
1354       methodHandle method(thread,
1355                      (methodOop)JNIHandles::resolve(task->method_handle()));
1356 
1357       // Never compile a method if breakpoints are present in it
1358       if (method()->number_of_breakpoints() == 0) {
1359         // Compile the method.
1360         if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
1361 #ifdef COMPILER1
1362           // Allow repeating compilations for the purpose of benchmarking
1363           // compile speed. This is not useful for customers.
1364           if (CompilationRepeat != 0) {
1365             int compile_count = CompilationRepeat;
1366             while (compile_count > 0) {
1367               invoke_compiler_on_method(task);
1368               nmethod* nm = method->code();
1369               if (nm != NULL) {
1370                 nm->make_zombie();
1371                 method->clear_code();
1372               }
1373               compile_count--;
1374             }
1375           }
1376 #endif /* COMPILER1 */
1377           invoke_compiler_on_method(task);
1378         } else {
1379           // After compilation is disabled, remove remaining methods from queue
1380           method->clear_queued_for_compilation();


1585   // protection of a mutex. [They were set by the requester thread,
1586   // when adding the task to the complie queue -- at which time the
1587   // compile queue lock was held. Subsequently, we acquired the compile
1588   // queue lock to get this task off the compile queue; thus (to belabour
1589   // the point somewhat) our clearing of the bits must be occurring
1590   // only after the setting of the bits. See also 14012000 above.
1591   method->clear_queued_for_compilation();
1592 
1593 #ifdef ASSERT
1594   if (CollectedHeap::fired_fake_oom()) {
1595     // The current compile received a fake OOM during compilation so
1596     // go ahead and exit the VM since the test apparently succeeded
1597     tty->print_cr("*** Shutting down VM after successful fake OOM");
1598     vm_exit(0);
1599   }
1600 #endif
1601 }
1602 
1603 
1604 // ------------------------------------------------------------------
1605 // CompileBroker::handle_full_code_cache
1606 //
1607 // The CodeCache is full.  Print out warning and disable compilation or
1608 // try code cache cleaning so compilation can continue later.
1609 void CompileBroker::handle_full_code_cache() {
1610   UseInterpreter = true;
1611   if (UseCompiler || AlwaysCompileLoopMethods ) {
1612   #ifndef PRODUCT
1613     warning("CodeCache is full. Compiler has been disabled");    
1614     if (CompileTheWorld || ExitOnFullCodeCache) {
1615       before_exit(JavaThread::current());
1616       exit_globals(); // will delete tty
1617       vm_direct_exit(CompileTheWorld ? 0 : 1);
1618     }
1619   #endif
1620     if (UseCodeCacheFlushing) {
1621       NMethodSweeper::handle_full_code_cache(true);
1622     } else {
1623       UseCompiler               = false;
1624       AlwaysCompileLoopMethods  = false;
1625     }
1626   }
1627 }
1628 
1629 // ------------------------------------------------------------------
1630 // CompileBroker::set_last_compile
1631 //
1632 // Record this compilation for debugging purposes.
1633 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) {
1634   ResourceMark rm;
1635   char* method_name = method->name()->as_C_string();
1636   strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length);
1637   char current_method[CompilerCounters::cmname_buffer_length];
1638   size_t maxLen = CompilerCounters::cmname_buffer_length;
1639 
1640   if (UsePerfData) {
1641     const char* class_name = method->method_holder()->klass_part()->name()->as_C_string();
1642 
1643     size_t s1len = strlen(class_name);
1644     size_t s2len = strlen(method_name);
1645 
1646     // check if we need to truncate the string
1647     if (s1len + s2len + 2 > maxLen) {
1648 
1649       // the strategy is to lop off the leading characters of the