src/share/vm/compiler/compileBroker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File JDK-8022494 Sdiff src/share/vm/compiler

src/share/vm/compiler/compileBroker.cpp

Print this page




 114       (char *) klass_name->bytes(), klass_name->utf8_length(),           \
 115       (char *) name->bytes(), name->utf8_length(),                       \
 116       (char *) signature->bytes(), signature->utf8_length(), (success)); \
 117   }
 118 #endif /* USDT2 */
 119 
 120 #else //  ndef DTRACE_ENABLED
 121 
 122 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name)
 123 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success)
 124 
 125 #endif // ndef DTRACE_ENABLED
 126 
 127 bool CompileBroker::_initialized = false;
 128 volatile bool CompileBroker::_should_block = false;
 129 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
 130 
 131 // The installed compiler(s)
 132 AbstractCompiler* CompileBroker::_compilers[2];
 133 
 134 // These counters are used for assigning id's to each compilation
 135 uint CompileBroker::_compilation_id        = 0;
 136 uint 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;


1136   {
1137     MutexLocker locker(queue->lock(), thread);
1138 
1139     // Make sure the method has not slipped into the queues since
1140     // last we checked; note that those checks were "fast bail-outs".
1141     // Here we need to be more careful, see 14012000 below.
1142     if (compilation_is_in_queue(method, osr_bci)) {
1143       return;
1144     }
1145 
1146     // We need to check again to see if the compilation has
1147     // completed.  A previous compilation may have registered
1148     // some result.
1149     if (compilation_is_complete(method, osr_bci, comp_level)) {
1150       return;
1151     }
1152 
1153     // We now know that this compilation is not pending, complete,
1154     // or prohibited.  Assign a compile_id to this compilation
1155     // and check to see if it is in our [Start..Stop) range.
1156     uint compile_id = assign_compile_id(method, osr_bci);
1157     if (compile_id == 0) {
1158       // The compilation falls outside the allowed range.
1159       return;
1160     }
1161 
1162     // Should this thread wait for completion of the compile?
1163     blocking = is_compile_blocking(method, osr_bci);
1164 
1165     // We will enter the compilation in the queue.
1166     // 14012000: Note that this sets the queued_for_compile bits in
1167     // the target method. We can now reason that a method cannot be
1168     // queued for compilation more than once, as follows:
1169     // Before a thread queues a task for compilation, it first acquires
1170     // the compile queue lock, then checks if the method's queued bits
1171     // are set or it has already been compiled. Thus there can not be two
1172     // instances of a compilation task for the same method on the
1173     // compilation queue. Consider now the case where the compilation
1174     // thread has already removed a task for that method from the queue
1175     // and is in the midst of compiling it. In this case, the
1176     // queued_for_compile bits must be set in the method (and these


1283       CLEAR_PENDING_EXCEPTION;
1284       return NULL;
1285     }
1286     assert(method->has_native_function(), "must have native code by now");
1287   }
1288 
1289   // RedefineClasses() has replaced this method; just return
1290   if (method->is_old()) {
1291     return NULL;
1292   }
1293 
1294   // JVMTI -- post_compile_event requires jmethod_id() that may require
1295   // a lock the compiling thread can not acquire. Prefetch it here.
1296   if (JvmtiExport::should_post_compiled_method_load()) {
1297     method->jmethod_id();
1298   }
1299 
1300   // do the compilation
1301   if (method->is_native()) {
1302     if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {
1303       // Acquire our lock.
1304       int compile_id;
1305       {
1306         MutexLocker locker(MethodCompileQueue_lock, THREAD);
1307         compile_id = assign_compile_id(method, standard_entry_bci);
1308       }
1309       // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
1310       // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1311       //
1312       // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1313       // in this case.  If we can't generate one and use it we can not execute the out-of-line method handle calls.
1314       (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id);
1315     } else {
1316       return NULL;
1317     }
1318   } else {
1319     // If the compiler is shut off due to code cache getting full
1320     // fail out now so blocking compiles dont hang the java thread
1321     if (!should_compile_new_jobs()) {
1322       CompilationPolicy::policy()->delay_compilation(method());
1323       return NULL;
1324     }
1325     compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD);
1326   }
1327 
1328   // return requested nmethod
1329   // We accept a higher level osr method
1330   return osr_bci  == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1331 }
1332 
1333 
1334 // ------------------------------------------------------------------


1397   }
1398 
1399   // The method may be explicitly excluded by the user.
1400   bool quietly;
1401   if (CompilerOracle::should_exclude(method, quietly)) {
1402     if (!quietly) {
1403       // This does not happen quietly...
1404       ResourceMark rm;
1405       tty->print("### Excluding %s:%s",
1406                  method->is_native() ? "generation of native wrapper" : "compile",
1407                  (method->is_static() ? " static" : ""));
1408       method->print_short_name(tty);
1409       tty->cr();
1410     }
1411     method->set_not_compilable(CompLevel_all, !quietly, "excluded by CompilerOracle");
1412   }
1413 
1414   return false;
1415 }
1416 
1417 
1418 // ------------------------------------------------------------------
1419 // CompileBroker::assign_compile_id
1420 //
1421 // Assign a serialized id number to this compilation request.  If the
1422 // number falls out of the allowed range, return a 0.  OSR
1423 // compilations may be numbered separately from regular compilations
1424 // if certain debugging flags are used.
1425 uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
1426   assert(MethodCompileQueue_lock->owner() == Thread::current(),
1427          "must hold the compilation queue lock");
1428   bool is_osr = (osr_bci != standard_entry_bci);
1429   uint id;
1430   if (CICountOSR && is_osr) {
1431     id = ++_osr_compilation_id;
1432     if ((uint)CIStartOSR <= id && id < (uint)CIStopOSR) {
1433       return id;
1434     }
1435   } else {
1436     id = ++_compilation_id;
1437     if ((uint)CIStart <= id && id < (uint)CIStop) {
1438       return id;
1439     }
1440   }
1441 
1442   // Method was not in the appropriate compilation range.
1443   method->set_not_compilable_quietly();
1444   return 0;



1445 }
1446 
1447 
1448 // ------------------------------------------------------------------
1449 // CompileBroker::is_compile_blocking
1450 //
1451 // Should the current thread be blocked until this compilation request
1452 // has been fulfilled?
1453 bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) {
1454   assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock");
1455   return !BackgroundCompilation;
1456 }
1457 
1458 
1459 // ------------------------------------------------------------------
1460 // CompileBroker::preload_classes
1461 void CompileBroker::preload_classes(methodHandle method, TRAPS) {
1462   // Move this code over from c1_Compiler.cpp
1463   ShouldNotReachHere();
1464 }




 114       (char *) klass_name->bytes(), klass_name->utf8_length(),           \
 115       (char *) name->bytes(), name->utf8_length(),                       \
 116       (char *) signature->bytes(), signature->utf8_length(), (success)); \
 117   }
 118 #endif /* USDT2 */
 119 
 120 #else //  ndef DTRACE_ENABLED
 121 
 122 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name)
 123 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success)
 124 
 125 #endif // ndef DTRACE_ENABLED
 126 
 127 bool CompileBroker::_initialized = false;
 128 volatile bool CompileBroker::_should_block = false;
 129 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
 130 
 131 // The installed compiler(s)
 132 AbstractCompiler* CompileBroker::_compilers[2];
 133 
 134 // These counters are used to assign each compilation an unique ID
 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;


1136   {
1137     MutexLocker locker(queue->lock(), thread);
1138 
1139     // Make sure the method has not slipped into the queues since
1140     // last we checked; note that those checks were "fast bail-outs".
1141     // Here we need to be more careful, see 14012000 below.
1142     if (compilation_is_in_queue(method, osr_bci)) {
1143       return;
1144     }
1145 
1146     // We need to check again to see if the compilation has
1147     // completed.  A previous compilation may have registered
1148     // some result.
1149     if (compilation_is_complete(method, osr_bci, comp_level)) {
1150       return;
1151     }
1152 
1153     // We now know that this compilation is not pending, complete,
1154     // or prohibited.  Assign a compile_id to this compilation
1155     // and check to see if it is in our [Start..Stop) range.
1156     int compile_id = assign_compile_id(method, osr_bci);
1157     if (compile_id == 0) {
1158       // The compilation falls outside the allowed range.
1159       return;
1160     }
1161 
1162     // Should this thread wait for completion of the compile?
1163     blocking = is_compile_blocking(method, osr_bci);
1164 
1165     // We will enter the compilation in the queue.
1166     // 14012000: Note that this sets the queued_for_compile bits in
1167     // the target method. We can now reason that a method cannot be
1168     // queued for compilation more than once, as follows:
1169     // Before a thread queues a task for compilation, it first acquires
1170     // the compile queue lock, then checks if the method's queued bits
1171     // are set or it has already been compiled. Thus there can not be two
1172     // instances of a compilation task for the same method on the
1173     // compilation queue. Consider now the case where the compilation
1174     // thread has already removed a task for that method from the queue
1175     // and is in the midst of compiling it. In this case, the
1176     // queued_for_compile bits must be set in the method (and these


1283       CLEAR_PENDING_EXCEPTION;
1284       return NULL;
1285     }
1286     assert(method->has_native_function(), "must have native code by now");
1287   }
1288 
1289   // RedefineClasses() has replaced this method; just return
1290   if (method->is_old()) {
1291     return NULL;
1292   }
1293 
1294   // JVMTI -- post_compile_event requires jmethod_id() that may require
1295   // a lock the compiling thread can not acquire. Prefetch it here.
1296   if (JvmtiExport::should_post_compiled_method_load()) {
1297     method->jmethod_id();
1298   }
1299 
1300   // do the compilation
1301   if (method->is_native()) {
1302     if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {






1303       // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
1304       // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1305       //
1306       // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1307       // in this case.  If we can't generate one and use it we can not execute the out-of-line method handle calls.
1308       AdapterHandlerLibrary::create_native_wrapper(method);
1309     } else {
1310       return NULL;
1311     }
1312   } else {
1313     // If the compiler is shut off due to code cache getting full
1314     // fail out now so blocking compiles dont hang the java thread
1315     if (!should_compile_new_jobs()) {
1316       CompilationPolicy::policy()->delay_compilation(method());
1317       return NULL;
1318     }
1319     compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD);
1320   }
1321 
1322   // return requested nmethod
1323   // We accept a higher level osr method
1324   return osr_bci  == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1325 }
1326 
1327 
1328 // ------------------------------------------------------------------


1391   }
1392 
1393   // The method may be explicitly excluded by the user.
1394   bool quietly;
1395   if (CompilerOracle::should_exclude(method, quietly)) {
1396     if (!quietly) {
1397       // This does not happen quietly...
1398       ResourceMark rm;
1399       tty->print("### Excluding %s:%s",
1400                  method->is_native() ? "generation of native wrapper" : "compile",
1401                  (method->is_static() ? " static" : ""));
1402       method->print_short_name(tty);
1403       tty->cr();
1404     }
1405     method->set_not_compilable(CompLevel_all, !quietly, "excluded by CompilerOracle");
1406   }
1407 
1408   return false;
1409 }
1410 
1411 /**
1412  * Generate serialized IDs for compilation requests. If certain debugging flags are used
1413  * and the ID is within the specified range, the method is not compiled and 0 is returned.
1414  * The functions also allows to generate separate compilation IDs for OSR compilations.
1415  */
1416 int CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
1417 #ifdef ASSERT




1418   bool is_osr = (osr_bci != standard_entry_bci);
1419   int id;
1420   if (CICountOSR && is_osr) {
1421     id = Atomic::add(1, &_osr_compilation_id);
1422     if (CIStartOSR <= id && id < CIStopOSR) {
1423       return id;
1424     }
1425   } else {
1426     id = Atomic::add(1, &_compilation_id);
1427     if (CIStart <= id && id < CIStop) {
1428       return id;
1429     }
1430   }
1431 
1432   // Method was not in the appropriate compilation range.
1433   method->set_not_compilable_quietly();
1434   return 0;
1435 #else
1436   return Atomic::add(1, &_compilation_id);
1437 #endif
1438 }
1439 
1440 
1441 // ------------------------------------------------------------------
1442 // CompileBroker::is_compile_blocking
1443 //
1444 // Should the current thread be blocked until this compilation request
1445 // has been fulfilled?
1446 bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) {
1447   assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock");
1448   return !BackgroundCompilation;
1449 }
1450 
1451 
1452 // ------------------------------------------------------------------
1453 // CompileBroker::preload_classes
1454 void CompileBroker::preload_classes(methodHandle method, TRAPS) {
1455   // Move this code over from c1_Compiler.cpp
1456   ShouldNotReachHere();
1457 }


src/share/vm/compiler/compileBroker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File