< prev index next >

src/hotspot/share/compiler/compileBroker.cpp

Print this page




 118 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
 119 
 120 // The installed compiler(s)
 121 AbstractCompiler* CompileBroker::_compilers[2];
 122 
 123 // The maximum numbers of compiler threads to be determined during startup.
 124 int CompileBroker::_c1_count = 0;
 125 int CompileBroker::_c2_count = 0;
 126 
 127 // An array of compiler names as Java String objects
 128 jobject* CompileBroker::_compiler1_objects = NULL;
 129 jobject* CompileBroker::_compiler2_objects = NULL;
 130 
 131 CompileLog** CompileBroker::_compiler1_logs = NULL;
 132 CompileLog** CompileBroker::_compiler2_logs = NULL;
 133 
 134 // These counters are used to assign an unique ID to each compilation.
 135 volatile jint CompileBroker::_compilation_id     = 0;
 136 volatile jint CompileBroker::_osr_compilation_id = 0;
 137 





 138 // Performance counters
 139 PerfCounter* CompileBroker::_perf_total_compilation = NULL;
 140 PerfCounter* CompileBroker::_perf_osr_compilation = NULL;
 141 PerfCounter* CompileBroker::_perf_standard_compilation = NULL;
 142 
 143 PerfCounter* CompileBroker::_perf_total_bailout_count = NULL;
 144 PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL;
 145 PerfCounter* CompileBroker::_perf_total_compile_count = NULL;
 146 PerfCounter* CompileBroker::_perf_total_osr_compile_count = NULL;
 147 PerfCounter* CompileBroker::_perf_total_standard_compile_count = NULL;
 148 
 149 PerfCounter* CompileBroker::_perf_sum_osr_bytes_compiled = NULL;
 150 PerfCounter* CompileBroker::_perf_sum_standard_bytes_compiled = NULL;
 151 PerfCounter* CompileBroker::_perf_sum_nmethod_size = NULL;
 152 PerfCounter* CompileBroker::_perf_sum_nmethod_code_size = NULL;
 153 
 154 PerfStringVariable* CompileBroker::_perf_last_method = NULL;
 155 PerfStringVariable* CompileBroker::_perf_last_failed_method = NULL;
 156 PerfStringVariable* CompileBroker::_perf_last_invalidated_method = NULL;
 157 PerfVariable*       CompileBroker::_perf_last_compile_type = NULL;


 555     }
 556   }
 557   st->cr();
 558 }
 559 
 560 void CompileQueue::print_tty() {
 561   ttyLocker ttyl;
 562   print(tty);
 563 }
 564 
 565 CompilerCounters::CompilerCounters() {
 566   _current_method[0] = '\0';
 567   _compile_type = CompileBroker::no_compile;
 568 }
 569 
 570 // ------------------------------------------------------------------
 571 // CompileBroker::compilation_init
 572 //
 573 // Initialize the Compilation object
 574 void CompileBroker::compilation_init_phase1(TRAPS) {


 575   // No need to initialize compilation system if we do not use it.
 576   if (!UseCompiler) {
 577     return;
 578   }
 579   // Set the interface to the current compiler(s).
 580   _c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
 581   _c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
 582 
 583 #if INCLUDE_JVMCI
 584   if (EnableJVMCI) {
 585     // This is creating a JVMCICompiler singleton.
 586     JVMCICompiler* jvmci = new JVMCICompiler();
 587 
 588     if (UseJVMCICompiler) {
 589       _compilers[1] = jvmci;
 590       if (FLAG_IS_DEFAULT(JVMCIThreads)) {
 591         if (BootstrapJVMCI) {
 592           // JVMCI will bootstrap so give it more threads
 593           _c2_count = MIN2(32, os::active_processor_count());
 594         }


2008   uint compile_id = task->compile_id();
2009   int osr_bci = task->osr_bci();
2010   bool is_osr = (osr_bci != standard_entry_bci);
2011   bool should_log = (thread->log() != NULL);
2012   bool should_break = false;
2013   const int task_level = task->comp_level();
2014   AbstractCompiler* comp = task->compiler();
2015 
2016   DirectiveSet* directive;
2017   {
2018     // create the handle inside it's own block so it can't
2019     // accidentally be referenced once the thread transitions to
2020     // native.  The NoHandleMark before the transition should catch
2021     // any cases where this occurs in the future.
2022     methodHandle method(thread, task->method());
2023     assert(!method->is_native(), "no longer compile natives");
2024 
2025     // Look up matching directives
2026     directive = DirectivesStack::getMatchingDirective(method, comp);
2027 
2028     // Update compile information when using perfdata.
2029     if (UsePerfData) {
2030       update_compile_perf_data(thread, method, is_osr);
2031     }
2032 
2033     DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, compiler_name(task_level));
2034   }
2035 
2036   should_break = directive->BreakAtExecuteOption || task->check_break_at_flags();
2037   if (should_log && !directive->LogOption) {
2038     should_log = false;
2039   }
2040 
2041   // Allocate a new set of JNI handles.
2042   push_jni_handle_block();
2043   Method* target_handle = task->method();
2044   int compilable = ciEnv::MethodCompilable;
2045   const char* failure_reason = NULL;
2046   bool failure_reason_on_C_heap = false;
2047   const char* retry_message = NULL;
2048 
2049   int system_dictionary_modification_counter;
2050   {
2051     MutexLocker locker(Compile_lock, thread);


2242       codecache_print(/* detailed= */ true);
2243       before_exit(JavaThread::current());
2244       exit_globals(); // will delete tty
2245       vm_direct_exit(1);
2246     }
2247 #endif
2248     if (UseCodeCacheFlushing) {
2249       // Since code cache is full, immediately stop new compiles
2250       if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) {
2251         NMethodSweeper::log_sweep("disable_compiler");
2252       }
2253     } else {
2254       disable_compilation_forever();
2255     }
2256 
2257     CodeCache::report_codemem_full(code_blob_type, should_print_compiler_warning());
2258   }
2259 }
2260 
2261 // ------------------------------------------------------------------
2262 // CompileBroker::update_compile_perf_data
2263 //
2264 // Record this compilation for debugging purposes.
2265 void CompileBroker::update_compile_perf_data(CompilerThread* thread, const methodHandle& method, bool is_osr) {
2266   ResourceMark rm;
2267   char* method_name = method->name()->as_C_string();


2268   char current_method[CompilerCounters::cmname_buffer_length];
2269   size_t maxLen = CompilerCounters::cmname_buffer_length;
2270 
2271   const char* class_name = method->method_holder()->name()->as_C_string();

2272 
2273   size_t s1len = strlen(class_name);
2274   size_t s2len = strlen(method_name);
2275 
2276   // check if we need to truncate the string
2277   if (s1len + s2len + 2 > maxLen) {
2278 
2279     // the strategy is to lop off the leading characters of the
2280     // class name and the trailing characters of the method name.
2281 
2282     if (s2len + 2 > maxLen) {
2283       // lop of the entire class name string, let snprintf handle
2284       // truncation of the method name.
2285       class_name += s1len; // null string
2286     }
2287     else {
2288       // lop off the extra characters from the front of the class name
2289       class_name += ((s1len + s2len + 2) - maxLen);

2290     }
2291   }
2292 
2293   jio_snprintf(current_method, maxLen, "%s %s", class_name, method_name);

2294 
2295   int last_compile_type = normal_compile;
2296   if (CICountOSR && is_osr) {
2297     last_compile_type = osr_compile;


2298   }

2299 
2300   CompilerCounters* counters = thread->counters();
2301   counters->set_current_method(current_method);
2302   counters->set_compile_type((jlong) last_compile_type);


2303 }
2304 

2305 // ------------------------------------------------------------------
2306 // CompileBroker::push_jni_handle_block
2307 //
2308 // Push on a new block of JNI handles.
2309 void CompileBroker::push_jni_handle_block() {
2310   JavaThread* thread = JavaThread::current();
2311 
2312   // Allocate a new block for JNI handles.
2313   // Inlined code from jni_PushLocalFrame()
2314   JNIHandleBlock* java_handles = thread->active_handles();
2315   JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread);
2316   assert(compile_handles != NULL && java_handles != NULL, "should not be NULL");
2317   compile_handles->set_pop_frame_link(java_handles);  // make sure java handles get gc'd.
2318   thread->set_active_handles(compile_handles);
2319 }
2320 
2321 
2322 // ------------------------------------------------------------------
2323 // CompileBroker::pop_jni_handle_block
2324 //


2585   }
2586   comp = compiler(CompLevel_full_optimization);
2587   if (comp != NULL) {
2588     tty->cr();
2589     comp->print_timers();
2590   }
2591   tty->cr();
2592   tty->print_cr("  Total compiled methods    : %8d methods", total_compile_count);
2593   tty->print_cr("    Standard compilation    : %8d methods", standard_compile_count);
2594   tty->print_cr("    On stack replacement    : %8d methods", osr_compile_count);
2595   int tcb = osr_bytes_compiled + standard_bytes_compiled;
2596   tty->print_cr("  Total compiled bytecodes  : %8d bytes", tcb);
2597   tty->print_cr("    Standard compilation    : %8d bytes", standard_bytes_compiled);
2598   tty->print_cr("    On stack replacement    : %8d bytes", osr_bytes_compiled);
2599   double tcs = total_compilation.seconds();
2600   int bps = tcs == 0.0 ? 0 : (int)(tcb / tcs);
2601   tty->print_cr("  Average compilation speed : %8d bytes/s", bps);
2602   tty->cr();
2603   tty->print_cr("  nmethod code size         : %8d bytes", nmethods_code_size);
2604   tty->print_cr("  nmethod total size        : %8d bytes", nmethods_size);















2605 }
2606 
2607 // Print general/accumulated JIT information.
2608 void CompileBroker::print_info(outputStream *out) {
2609   if (out == NULL) out = tty;
2610   out->cr();
2611   out->print_cr("======================");
2612   out->print_cr("   General JIT info   ");
2613   out->print_cr("======================");
2614   out->cr();
2615   out->print_cr("            JIT is : %7s",     should_compile_new_jobs() ? "on" : "off");
2616   out->print_cr("  Compiler threads : %7d",     (int)CICompilerCount);
2617   out->cr();
2618   out->print_cr("CodeCache overview");
2619   out->print_cr("--------------------------------------------------------");
2620   out->cr();
2621   out->print_cr("         Reserved size : " SIZE_FORMAT_W(7) " KB", CodeCache::max_capacity() / K);
2622   out->print_cr("        Committed size : " SIZE_FORMAT_W(7) " KB", CodeCache::capacity() / K);
2623   out->print_cr("  Unallocated capacity : " SIZE_FORMAT_W(7) " KB", CodeCache::unallocated_capacity() / K);
2624   out->cr();




 118 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
 119 
 120 // The installed compiler(s)
 121 AbstractCompiler* CompileBroker::_compilers[2];
 122 
 123 // The maximum numbers of compiler threads to be determined during startup.
 124 int CompileBroker::_c1_count = 0;
 125 int CompileBroker::_c2_count = 0;
 126 
 127 // An array of compiler names as Java String objects
 128 jobject* CompileBroker::_compiler1_objects = NULL;
 129 jobject* CompileBroker::_compiler2_objects = NULL;
 130 
 131 CompileLog** CompileBroker::_compiler1_logs = NULL;
 132 CompileLog** CompileBroker::_compiler2_logs = NULL;
 133 
 134 // These counters are used to assign an unique ID to each compilation.
 135 volatile jint CompileBroker::_compilation_id     = 0;
 136 volatile jint CompileBroker::_osr_compilation_id = 0;
 137 
 138 // Debugging information
 139 int  CompileBroker::_last_compile_type     = no_compile;
 140 int  CompileBroker::_last_compile_level    = CompLevel_none;
 141 char CompileBroker::_last_method_compiled[CompileBroker::name_buffer_length];
 142 
 143 // Performance counters
 144 PerfCounter* CompileBroker::_perf_total_compilation = NULL;
 145 PerfCounter* CompileBroker::_perf_osr_compilation = NULL;
 146 PerfCounter* CompileBroker::_perf_standard_compilation = NULL;
 147 
 148 PerfCounter* CompileBroker::_perf_total_bailout_count = NULL;
 149 PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL;
 150 PerfCounter* CompileBroker::_perf_total_compile_count = NULL;
 151 PerfCounter* CompileBroker::_perf_total_osr_compile_count = NULL;
 152 PerfCounter* CompileBroker::_perf_total_standard_compile_count = NULL;
 153 
 154 PerfCounter* CompileBroker::_perf_sum_osr_bytes_compiled = NULL;
 155 PerfCounter* CompileBroker::_perf_sum_standard_bytes_compiled = NULL;
 156 PerfCounter* CompileBroker::_perf_sum_nmethod_size = NULL;
 157 PerfCounter* CompileBroker::_perf_sum_nmethod_code_size = NULL;
 158 
 159 PerfStringVariable* CompileBroker::_perf_last_method = NULL;
 160 PerfStringVariable* CompileBroker::_perf_last_failed_method = NULL;
 161 PerfStringVariable* CompileBroker::_perf_last_invalidated_method = NULL;
 162 PerfVariable*       CompileBroker::_perf_last_compile_type = NULL;


 560     }
 561   }
 562   st->cr();
 563 }
 564 
 565 void CompileQueue::print_tty() {
 566   ttyLocker ttyl;
 567   print(tty);
 568 }
 569 
 570 CompilerCounters::CompilerCounters() {
 571   _current_method[0] = '\0';
 572   _compile_type = CompileBroker::no_compile;
 573 }
 574 
 575 // ------------------------------------------------------------------
 576 // CompileBroker::compilation_init
 577 //
 578 // Initialize the Compilation object
 579 void CompileBroker::compilation_init_phase1(TRAPS) {
 580   _last_method_compiled[0] = '\0';
 581 
 582   // No need to initialize compilation system if we do not use it.
 583   if (!UseCompiler) {
 584     return;
 585   }
 586   // Set the interface to the current compiler(s).
 587   _c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
 588   _c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
 589 
 590 #if INCLUDE_JVMCI
 591   if (EnableJVMCI) {
 592     // This is creating a JVMCICompiler singleton.
 593     JVMCICompiler* jvmci = new JVMCICompiler();
 594 
 595     if (UseJVMCICompiler) {
 596       _compilers[1] = jvmci;
 597       if (FLAG_IS_DEFAULT(JVMCIThreads)) {
 598         if (BootstrapJVMCI) {
 599           // JVMCI will bootstrap so give it more threads
 600           _c2_count = MIN2(32, os::active_processor_count());
 601         }


2015   uint compile_id = task->compile_id();
2016   int osr_bci = task->osr_bci();
2017   bool is_osr = (osr_bci != standard_entry_bci);
2018   bool should_log = (thread->log() != NULL);
2019   bool should_break = false;
2020   const int task_level = task->comp_level();
2021   AbstractCompiler* comp = task->compiler();
2022 
2023   DirectiveSet* directive;
2024   {
2025     // create the handle inside it's own block so it can't
2026     // accidentally be referenced once the thread transitions to
2027     // native.  The NoHandleMark before the transition should catch
2028     // any cases where this occurs in the future.
2029     methodHandle method(thread, task->method());
2030     assert(!method->is_native(), "no longer compile natives");
2031 
2032     // Look up matching directives
2033     directive = DirectivesStack::getMatchingDirective(method, comp);
2034 
2035     // Save information about this method in case of failure.
2036     set_last_compile(thread, method, is_osr, task_level);


2037 
2038     DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, compiler_name(task_level));
2039   }
2040 
2041   should_break = directive->BreakAtExecuteOption || task->check_break_at_flags();
2042   if (should_log && !directive->LogOption) {
2043     should_log = false;
2044   }
2045 
2046   // Allocate a new set of JNI handles.
2047   push_jni_handle_block();
2048   Method* target_handle = task->method();
2049   int compilable = ciEnv::MethodCompilable;
2050   const char* failure_reason = NULL;
2051   bool failure_reason_on_C_heap = false;
2052   const char* retry_message = NULL;
2053 
2054   int system_dictionary_modification_counter;
2055   {
2056     MutexLocker locker(Compile_lock, thread);


2247       codecache_print(/* detailed= */ true);
2248       before_exit(JavaThread::current());
2249       exit_globals(); // will delete tty
2250       vm_direct_exit(1);
2251     }
2252 #endif
2253     if (UseCodeCacheFlushing) {
2254       // Since code cache is full, immediately stop new compiles
2255       if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) {
2256         NMethodSweeper::log_sweep("disable_compiler");
2257       }
2258     } else {
2259       disable_compilation_forever();
2260     }
2261 
2262     CodeCache::report_codemem_full(code_blob_type, should_print_compiler_warning());
2263   }
2264 }
2265 
2266 // ------------------------------------------------------------------
2267 // CompileBroker::set_last_compile
2268 //
2269 // Record this compilation for debugging purposes.
2270 void CompileBroker::set_last_compile(CompilerThread* thread, const methodHandle& method, bool is_osr, int comp_level) {
2271   ResourceMark rm;
2272   char* method_name = method->name()->as_C_string();
2273   strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length);
2274   _last_method_compiled[CompileBroker::name_buffer_length - 1] = '\0'; // ensure null terminated
2275   char current_method[CompilerCounters::cmname_buffer_length];
2276   size_t maxLen = CompilerCounters::cmname_buffer_length;
2277 
2278   if (UsePerfData) {
2279     const char* class_name = method->method_holder()->name()->as_C_string();
2280 
2281     size_t s1len = strlen(class_name);
2282     size_t s2len = strlen(method_name);
2283 
2284     // check if we need to truncate the string
2285     if (s1len + s2len + 2 > maxLen) {
2286 
2287       // the strategy is to lop off the leading characters of the
2288       // class name and the trailing characters of the method name.
2289 
2290       if (s2len + 2 > maxLen) {
2291         // lop of the entire class name string, let snprintf handle
2292         // truncation of the method name.
2293         class_name += s1len; // null string
2294       }
2295       else {
2296         // lop off the extra characters from the front of the class name
2297         class_name += ((s1len + s2len + 2) - maxLen);
2298       }
2299     }

2300 
2301     jio_snprintf(current_method, maxLen, "%s %s", class_name, method_name);
2302   }
2303 

2304   if (CICountOSR && is_osr) {
2305     _last_compile_type = osr_compile;
2306   } else {
2307     _last_compile_type = normal_compile;
2308   }
2309   _last_compile_level = comp_level;
2310 
2311   if (UsePerfData) {
2312     CompilerCounters* counters = thread->counters();
2313     counters->set_current_method(current_method);
2314     counters->set_compile_type((jlong)_last_compile_type);
2315   }
2316 }
2317 
2318 
2319 // ------------------------------------------------------------------
2320 // CompileBroker::push_jni_handle_block
2321 //
2322 // Push on a new block of JNI handles.
2323 void CompileBroker::push_jni_handle_block() {
2324   JavaThread* thread = JavaThread::current();
2325 
2326   // Allocate a new block for JNI handles.
2327   // Inlined code from jni_PushLocalFrame()
2328   JNIHandleBlock* java_handles = thread->active_handles();
2329   JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread);
2330   assert(compile_handles != NULL && java_handles != NULL, "should not be NULL");
2331   compile_handles->set_pop_frame_link(java_handles);  // make sure java handles get gc'd.
2332   thread->set_active_handles(compile_handles);
2333 }
2334 
2335 
2336 // ------------------------------------------------------------------
2337 // CompileBroker::pop_jni_handle_block
2338 //


2599   }
2600   comp = compiler(CompLevel_full_optimization);
2601   if (comp != NULL) {
2602     tty->cr();
2603     comp->print_timers();
2604   }
2605   tty->cr();
2606   tty->print_cr("  Total compiled methods    : %8d methods", total_compile_count);
2607   tty->print_cr("    Standard compilation    : %8d methods", standard_compile_count);
2608   tty->print_cr("    On stack replacement    : %8d methods", osr_compile_count);
2609   int tcb = osr_bytes_compiled + standard_bytes_compiled;
2610   tty->print_cr("  Total compiled bytecodes  : %8d bytes", tcb);
2611   tty->print_cr("    Standard compilation    : %8d bytes", standard_bytes_compiled);
2612   tty->print_cr("    On stack replacement    : %8d bytes", osr_bytes_compiled);
2613   double tcs = total_compilation.seconds();
2614   int bps = tcs == 0.0 ? 0 : (int)(tcb / tcs);
2615   tty->print_cr("  Average compilation speed : %8d bytes/s", bps);
2616   tty->cr();
2617   tty->print_cr("  nmethod code size         : %8d bytes", nmethods_code_size);
2618   tty->print_cr("  nmethod total size        : %8d bytes", nmethods_size);
2619 }
2620 
2621 // Debugging output for failure
2622 void CompileBroker::print_last_compile() {
2623   if (_last_compile_level != CompLevel_none &&
2624       compiler(_last_compile_level) != NULL &&
2625       _last_compile_type != no_compile) {
2626     if (_last_compile_type == osr_compile) {
2627       tty->print_cr("Last parse:  [osr]%d+++(%d) %s",
2628                     _osr_compilation_id, _last_compile_level, _last_method_compiled);
2629     } else {
2630       tty->print_cr("Last parse:  %d+++(%d) %s",
2631                     _compilation_id, _last_compile_level, _last_method_compiled);
2632     }
2633   }
2634 }
2635 
2636 // Print general/accumulated JIT information.
2637 void CompileBroker::print_info(outputStream *out) {
2638   if (out == NULL) out = tty;
2639   out->cr();
2640   out->print_cr("======================");
2641   out->print_cr("   General JIT info   ");
2642   out->print_cr("======================");
2643   out->cr();
2644   out->print_cr("            JIT is : %7s",     should_compile_new_jobs() ? "on" : "off");
2645   out->print_cr("  Compiler threads : %7d",     (int)CICompilerCount);
2646   out->cr();
2647   out->print_cr("CodeCache overview");
2648   out->print_cr("--------------------------------------------------------");
2649   out->cr();
2650   out->print_cr("         Reserved size : " SIZE_FORMAT_W(7) " KB", CodeCache::max_capacity() / K);
2651   out->print_cr("        Committed size : " SIZE_FORMAT_W(7) " KB", CodeCache::capacity() / K);
2652   out->print_cr("  Unallocated capacity : " SIZE_FORMAT_W(7) " KB", CodeCache::unallocated_capacity() / K);
2653   out->cr();


< prev index next >