src/hotspot/share/compiler/compileBroker.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54973 0927d8c7296f
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    28 #include "classfile/systemDictionary.hpp"
    28 #include "classfile/systemDictionary.hpp"
    29 #include "classfile/vmSymbols.hpp"
    29 #include "classfile/vmSymbols.hpp"
    30 #include "code/codeCache.hpp"
    30 #include "code/codeCache.hpp"
    31 #include "code/codeHeapState.hpp"
    31 #include "code/codeHeapState.hpp"
    32 #include "code/dependencyContext.hpp"
    32 #include "code/dependencyContext.hpp"
       
    33 #include "compiler/compilationPolicy.hpp"
    33 #include "compiler/compileBroker.hpp"
    34 #include "compiler/compileBroker.hpp"
    34 #include "compiler/compileLog.hpp"
    35 #include "compiler/compileLog.hpp"
    35 #include "compiler/compilerOracle.hpp"
    36 #include "compiler/compilerOracle.hpp"
    36 #include "compiler/directivesParser.hpp"
    37 #include "compiler/directivesParser.hpp"
    37 #include "interpreter/linkResolver.hpp"
    38 #include "interpreter/linkResolver.hpp"
    46 #include "oops/oop.inline.hpp"
    47 #include "oops/oop.inline.hpp"
    47 #include "prims/nativeLookup.hpp"
    48 #include "prims/nativeLookup.hpp"
    48 #include "prims/whitebox.hpp"
    49 #include "prims/whitebox.hpp"
    49 #include "runtime/arguments.hpp"
    50 #include "runtime/arguments.hpp"
    50 #include "runtime/atomic.hpp"
    51 #include "runtime/atomic.hpp"
    51 #include "runtime/compilationPolicy.hpp"
       
    52 #include "runtime/handles.inline.hpp"
    52 #include "runtime/handles.inline.hpp"
    53 #include "runtime/init.hpp"
    53 #include "runtime/init.hpp"
    54 #include "runtime/interfaceSupport.inline.hpp"
    54 #include "runtime/interfaceSupport.inline.hpp"
    55 #include "runtime/javaCalls.hpp"
    55 #include "runtime/javaCalls.hpp"
    56 #include "runtime/jniHandles.inline.hpp"
    56 #include "runtime/jniHandles.inline.hpp"
   185 
   185 
   186 
   186 
   187 
   187 
   188 class CompilationLog : public StringEventLog {
   188 class CompilationLog : public StringEventLog {
   189  public:
   189  public:
   190   CompilationLog() : StringEventLog("Compilation events") {
   190   CompilationLog() : StringEventLog("Compilation events", "jit") {
   191   }
   191   }
   192 
   192 
   193   void log_compile(JavaThread* thread, CompileTask* task) {
   193   void log_compile(JavaThread* thread, CompileTask* task) {
   194     StringLogMessage lm;
   194     StringLogMessage lm;
   195     stringStream sstr(lm.buffer(), lm.size());
   195     stringStream sstr(lm.buffer(), lm.size());
   314   if (ct->idle_time_millis() < (c1 ? 500 : 100)) return false;
   314   if (ct->idle_time_millis() < (c1 ? 500 : 100)) return false;
   315 
   315 
   316   // We only allow the last compiler thread of each type to get removed.
   316   // We only allow the last compiler thread of each type to get removed.
   317   jobject last_compiler = c1 ? CompileBroker::compiler1_object(compiler_count - 1)
   317   jobject last_compiler = c1 ? CompileBroker::compiler1_object(compiler_count - 1)
   318                              : CompileBroker::compiler2_object(compiler_count - 1);
   318                              : CompileBroker::compiler2_object(compiler_count - 1);
   319   if (oopDesc::equals(ct->threadObj(), JNIHandles::resolve_non_null(last_compiler))) {
   319   if (ct->threadObj() == JNIHandles::resolve_non_null(last_compiler)) {
   320     if (do_it) {
   320     if (do_it) {
   321       assert_locked_or_safepoint(CompileThread_lock); // Update must be consistent.
   321       assert_locked_or_safepoint(CompileThread_lock); // Update must be consistent.
   322       compiler->set_num_compiler_threads(compiler_count - 1);
   322       compiler->set_num_compiler_threads(compiler_count - 1);
   323     }
   323     }
   324     return true;
   324     return true;
   555   }
   555   }
   556   st->cr();
   556   st->cr();
   557 }
   557 }
   558 
   558 
   559 void CompileQueue::print_tty() {
   559 void CompileQueue::print_tty() {
   560   ttyLocker ttyl;
   560   ResourceMark rm;
   561   print(tty);
   561   stringStream ss;
       
   562   // Dump the compile queue into a buffer before locking the tty
       
   563   print(&ss);
       
   564   {
       
   565     ttyLocker ttyl;
       
   566     tty->print("%s", ss.as_string());
       
   567   }
   562 }
   568 }
   563 
   569 
   564 CompilerCounters::CompilerCounters() {
   570 CompilerCounters::CompilerCounters() {
   565   _current_method[0] = '\0';
   571   _current_method[0] = '\0';
   566   _compile_type = CompileBroker::no_compile;
   572   _compile_type = CompileBroker::no_compile;
  1240     bool in_base_library;
  1246     bool in_base_library;
  1241     address adr = NativeLookup::lookup(method, in_base_library, THREAD);
  1247     address adr = NativeLookup::lookup(method, in_base_library, THREAD);
  1242     if (HAS_PENDING_EXCEPTION) {
  1248     if (HAS_PENDING_EXCEPTION) {
  1243       // In case of an exception looking up the method, we just forget
  1249       // In case of an exception looking up the method, we just forget
  1244       // about it. The interpreter will kick-in and throw the exception.
  1250       // about it. The interpreter will kick-in and throw the exception.
  1245       method->set_not_compilable(); // implies is_not_osr_compilable()
  1251       method->set_not_compilable("NativeLookup::lookup failed"); // implies is_not_osr_compilable()
  1246       CLEAR_PENDING_EXCEPTION;
  1252       CLEAR_PENDING_EXCEPTION;
  1247       return NULL;
  1253       return NULL;
  1248     }
  1254     }
  1249     assert(method->has_native_function(), "must have native code by now");
  1255     assert(method->has_native_function(), "must have native code by now");
  1250   }
  1256   }
  1368   bool is_native = method->is_native();
  1374   bool is_native = method->is_native();
  1369   // Some compilers may not support the compilation of natives.
  1375   // Some compilers may not support the compilation of natives.
  1370   AbstractCompiler *comp = compiler(comp_level);
  1376   AbstractCompiler *comp = compiler(comp_level);
  1371   if (is_native &&
  1377   if (is_native &&
  1372       (!CICompileNatives || comp == NULL || !comp->supports_native())) {
  1378       (!CICompileNatives || comp == NULL || !comp->supports_native())) {
  1373     method->set_not_compilable_quietly(comp_level);
  1379     method->set_not_compilable_quietly("native methods not supported", comp_level);
  1374     return true;
  1380     return true;
  1375   }
  1381   }
  1376 
  1382 
  1377   bool is_osr = (osr_bci != standard_entry_bci);
  1383   bool is_osr = (osr_bci != standard_entry_bci);
  1378   // Some compilers may not support on stack replacement.
  1384   // Some compilers may not support on stack replacement.
  1379   if (is_osr &&
  1385   if (is_osr &&
  1380       (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
  1386       (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
  1381     method->set_not_osr_compilable(comp_level);
  1387     method->set_not_osr_compilable("OSR not supported", comp_level);
  1382     return true;
  1388     return true;
  1383   }
  1389   }
  1384 
  1390 
  1385   // The method may be explicitly excluded by the user.
  1391   // The method may be explicitly excluded by the user.
  1386   double scale;
  1392   double scale;
  1393                  method->is_native() ? "generation of native wrapper" : "compile",
  1399                  method->is_native() ? "generation of native wrapper" : "compile",
  1394                  (method->is_static() ? " static" : ""));
  1400                  (method->is_static() ? " static" : ""));
  1395       method->print_short_name(tty);
  1401       method->print_short_name(tty);
  1396       tty->cr();
  1402       tty->cr();
  1397     }
  1403     }
  1398     method->set_not_compilable(comp_level, !quietly, "excluded by CompileCommand");
  1404     method->set_not_compilable("excluded by CompileCommand", comp_level, !quietly);
  1399   }
  1405   }
  1400 
  1406 
  1401   return false;
  1407   return false;
  1402 }
  1408 }
  1403 
  1409 
  1426       return id;
  1432       return id;
  1427     }
  1433     }
  1428   }
  1434   }
  1429 
  1435 
  1430   // Method was not in the appropriate compilation range.
  1436   // Method was not in the appropriate compilation range.
  1431   method->set_not_compilable_quietly();
  1437   method->set_not_compilable_quietly("Not in requested compile id range");
  1432   return 0;
  1438   return 0;
  1433 #else
  1439 #else
  1434   // CICountOSR is a develop flag and set to 'false' by default. In a product built,
  1440   // CICountOSR is a develop flag and set to 'false' by default. In a product built,
  1435   // only _compilation_id is incremented.
  1441   // only _compilation_id is incremented.
  1436   return Atomic::add(1, &_compilation_id);
  1442   return Atomic::add(1, &_compilation_id);
  1544   }
  1550   }
  1545 
  1551 
  1546   assert(task->is_blocking(), "can only wait on blocking task");
  1552   assert(task->is_blocking(), "can only wait on blocking task");
  1547 
  1553 
  1548   JavaThread* thread = JavaThread::current();
  1554   JavaThread* thread = JavaThread::current();
  1549   thread->set_blocked_on_compilation(true);
       
  1550 
  1555 
  1551   methodHandle method(thread, task->method());
  1556   methodHandle method(thread, task->method());
  1552   bool free_task;
  1557   bool free_task;
  1553 #if INCLUDE_JVMCI
  1558 #if INCLUDE_JVMCI
  1554   AbstractCompiler* comp = compiler(task->comp_level());
  1559   AbstractCompiler* comp = compiler(task->comp_level());
  1562     while (!task->is_complete() && !is_compilation_disabled_forever()) {
  1567     while (!task->is_complete() && !is_compilation_disabled_forever()) {
  1563       ml.wait();
  1568       ml.wait();
  1564     }
  1569     }
  1565   }
  1570   }
  1566 
  1571 
  1567   thread->set_blocked_on_compilation(false);
       
  1568   if (free_task) {
  1572   if (free_task) {
  1569     if (is_compilation_disabled_forever()) {
  1573     if (is_compilation_disabled_forever()) {
  1570       CompileTask::free(task);
  1574       CompileTask::free(task);
  1571       return;
  1575       return;
  1572     }
  1576     }
  1593   CompilerThread* thread = CompilerThread::current();
  1597   CompilerThread* thread = CompilerThread::current();
  1594   AbstractCompiler* comp = thread->compiler();
  1598   AbstractCompiler* comp = thread->compiler();
  1595   // Final sanity check - the compiler object must exist
  1599   // Final sanity check - the compiler object must exist
  1596   guarantee(comp != NULL, "Compiler object must exist");
  1600   guarantee(comp != NULL, "Compiler object must exist");
  1597 
  1601 
  1598   int system_dictionary_modification_counter;
       
  1599   {
       
  1600     MutexLocker locker(Compile_lock, thread);
       
  1601     system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
       
  1602   }
       
  1603 
       
  1604   {
  1602   {
  1605     // Must switch to native to allocate ci_env
  1603     // Must switch to native to allocate ci_env
  1606     ThreadToNativeFromVM ttn(thread);
  1604     ThreadToNativeFromVM ttn(thread);
  1607     ciEnv ci_env(NULL, system_dictionary_modification_counter);
  1605     ciEnv ci_env((CompileTask*)NULL);
  1608     // Cache Jvmti state
  1606     // Cache Jvmti state
  1609     ci_env.cache_jvmti_state();
  1607     ci_env.cache_jvmti_state();
  1610     // Cache DTrace flags
  1608     // Cache DTrace flags
  1611     ci_env.cache_dtrace_flags();
  1609     ci_env.cache_dtrace_flags();
  1612 
  1610 
  1693   // Find Compiler number by its threadObj.
  1691   // Find Compiler number by its threadObj.
  1694   oop compiler_obj = ct->threadObj();
  1692   oop compiler_obj = ct->threadObj();
  1695   int compiler_number = 0;
  1693   int compiler_number = 0;
  1696   bool found = false;
  1694   bool found = false;
  1697   for (; compiler_number < count; compiler_number++) {
  1695   for (; compiler_number < count; compiler_number++) {
  1698     if (oopDesc::equals(JNIHandles::resolve_non_null(compiler_objects[compiler_number]), compiler_obj)) {
  1696     if (JNIHandles::resolve_non_null(compiler_objects[compiler_number]) == compiler_obj) {
  1699       found = true;
  1697       found = true;
  1700       break;
  1698       break;
  1701     }
  1699     }
  1702   }
  1700   }
  1703   assert(found, "Compiler must exist at this point");
  1701   assert(found, "Compiler must exist at this point");
  2043   int compilable = ciEnv::MethodCompilable;
  2041   int compilable = ciEnv::MethodCompilable;
  2044   const char* failure_reason = NULL;
  2042   const char* failure_reason = NULL;
  2045   bool failure_reason_on_C_heap = false;
  2043   bool failure_reason_on_C_heap = false;
  2046   const char* retry_message = NULL;
  2044   const char* retry_message = NULL;
  2047 
  2045 
  2048   int system_dictionary_modification_counter;
       
  2049   {
       
  2050     MutexLocker locker(Compile_lock, thread);
       
  2051     system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
       
  2052   }
       
  2053 
       
  2054 #if INCLUDE_JVMCI
  2046 #if INCLUDE_JVMCI
  2055   if (UseJVMCICompiler && comp != NULL && comp->is_jvmci()) {
  2047   if (UseJVMCICompiler && comp != NULL && comp->is_jvmci()) {
  2056     JVMCICompiler* jvmci = (JVMCICompiler*) comp;
  2048     JVMCICompiler* jvmci = (JVMCICompiler*) comp;
  2057 
  2049 
  2058     TraceTime t1("compilation", &time);
  2050     TraceTime t1("compilation", &time);
  2062     if (target_handle->is_old()) {
  2054     if (target_handle->is_old()) {
  2063       failure_reason = "redefined method";
  2055       failure_reason = "redefined method";
  2064       retry_message = "not retryable";
  2056       retry_message = "not retryable";
  2065       compilable = ciEnv::MethodCompilable_never;
  2057       compilable = ciEnv::MethodCompilable_never;
  2066     } else {
  2058     } else {
  2067       JVMCICompileState compile_state(task, system_dictionary_modification_counter);
  2059       JVMCICompileState compile_state(task);
  2068       JVMCIEnv env(thread, &compile_state, __FILE__, __LINE__);
  2060       JVMCIEnv env(thread, &compile_state, __FILE__, __LINE__);
  2069       methodHandle method(thread, target_handle);
  2061       methodHandle method(thread, target_handle);
  2070       env.runtime()->compile_method(&env, jvmci, method, osr_bci);
  2062       env.runtime()->compile_method(&env, jvmci, method, osr_bci);
  2071 
  2063 
  2072       failure_reason = compile_state.failure_reason();
  2064       failure_reason = compile_state.failure_reason();
  2088 #endif // INCLUDE_JVMCI
  2080 #endif // INCLUDE_JVMCI
  2089   {
  2081   {
  2090     NoHandleMark  nhm;
  2082     NoHandleMark  nhm;
  2091     ThreadToNativeFromVM ttn(thread);
  2083     ThreadToNativeFromVM ttn(thread);
  2092 
  2084 
  2093     ciEnv ci_env(task, system_dictionary_modification_counter);
  2085     ciEnv ci_env(task);
  2094     if (should_break) {
  2086     if (should_break) {
  2095       ci_env.set_break_at_compile(true);
  2087       ci_env.set_break_at_compile(true);
  2096     }
  2088     }
  2097     if (should_log) {
  2089     if (should_log) {
  2098       ci_env.set_log(thread->log());
  2090       ci_env.set_log(thread->log());
  2193   }
  2185   }
  2194   // Disable compilation, if required.
  2186   // Disable compilation, if required.
  2195   switch (compilable) {
  2187   switch (compilable) {
  2196   case ciEnv::MethodCompilable_never:
  2188   case ciEnv::MethodCompilable_never:
  2197     if (is_osr)
  2189     if (is_osr)
  2198       method->set_not_osr_compilable_quietly();
  2190       method->set_not_osr_compilable_quietly("MethodCompilable_never");
  2199     else
  2191     else
  2200       method->set_not_compilable_quietly();
  2192       method->set_not_compilable_quietly("MethodCompilable_never");
  2201     break;
  2193     break;
  2202   case ciEnv::MethodCompilable_not_at_tier:
  2194   case ciEnv::MethodCompilable_not_at_tier:
  2203     if (is_osr)
  2195     if (is_osr)
  2204       method->set_not_osr_compilable_quietly(task_level);
  2196       method->set_not_osr_compilable_quietly("MethodCompilable_not_at_tier", task_level);
  2205     else
  2197     else
  2206       method->set_not_compilable_quietly(task_level);
  2198       method->set_not_compilable_quietly("MethodCompilable_not_at_tier", task_level);
  2207     break;
  2199     break;
  2208   }
  2200   }
  2209 
  2201 
  2210   // Note that the queued_for_compilation bits are cleared without
  2202   // Note that the queued_for_compilation bits are cleared without
  2211   // protection of a mutex. [They were set by the requester thread,
  2203   // protection of a mutex. [They were set by the requester thread,
  2638 // Note: tty_lock must not be held upon entry to this function.
  2630 // Note: tty_lock must not be held upon entry to this function.
  2639 //       Print functions called from herein do "micro-locking" on tty_lock.
  2631 //       Print functions called from herein do "micro-locking" on tty_lock.
  2640 //       That's a tradeoff which keeps together important blocks of output.
  2632 //       That's a tradeoff which keeps together important blocks of output.
  2641 //       At the same time, continuous tty_lock hold time is kept in check,
  2633 //       At the same time, continuous tty_lock hold time is kept in check,
  2642 //       preventing concurrently printing threads from stalling a long time.
  2634 //       preventing concurrently printing threads from stalling a long time.
  2643 void CompileBroker::print_heapinfo(outputStream* out, const char* function, const char* granularity) {
  2635 void CompileBroker::print_heapinfo(outputStream* out, const char* function, size_t granularity) {
  2644   TimeStamp ts_total;
  2636   TimeStamp ts_total;
  2645   TimeStamp ts_global;
  2637   TimeStamp ts_global;
  2646   TimeStamp ts;
  2638   TimeStamp ts;
  2647 
  2639 
  2648   bool allFun = !strcmp(function, "all");
  2640   bool allFun = !strcmp(function, "all");
  2686 
  2678 
  2687   // If we serve an "allFun" call, it is beneficial to hold the CodeCache_lock
  2679   // If we serve an "allFun" call, it is beneficial to hold the CodeCache_lock
  2688   // for the entire duration of aggregation and printing. That makes sure
  2680   // for the entire duration of aggregation and printing. That makes sure
  2689   // we see a consistent picture and do not run into issues caused by
  2681   // we see a consistent picture and do not run into issues caused by
  2690   // the CodeHeap being altered concurrently.
  2682   // the CodeHeap being altered concurrently.
  2691   Monitor* global_lock   = allFun ? CodeCache_lock : NULL;
  2683   Mutex* global_lock   = allFun ? CodeCache_lock : NULL;
  2692   Monitor* function_lock = allFun ? NULL : CodeCache_lock;
  2684   Mutex* function_lock = allFun ? NULL : CodeCache_lock;
  2693   ts_global.update(); // record starting point
  2685   ts_global.update(); // record starting point
  2694   MutexLocker mu2(global_lock, Mutex::_no_safepoint_check_flag);
  2686   MutexLocker mu2(global_lock, Mutex::_no_safepoint_check_flag);
  2695   if (global_lock != NULL) {
  2687   if (global_lock != NULL) {
  2696     out->print_cr("\n__ CodeCache (global) lock wait took %10.3f seconds _________\n", ts_global.seconds());
  2688     out->print_cr("\n__ CodeCache (global) lock wait took %10.3f seconds _________\n", ts_global.seconds());
  2697     ts_global.update(); // record starting point
  2689     ts_global.update(); // record starting point