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::_print_compilation_warning = 0;
130 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
131
132 // The installed compiler(s)
133 AbstractCompiler* CompileBroker::_compilers[2];
134
135 // These counters are used for assigning id's to each compilation
136 uint CompileBroker::_compilation_id = 0;
137 uint CompileBroker::_osr_compilation_id = 0;
138
139 // Debugging information
140 int CompileBroker::_last_compile_type = no_compile;
141 int CompileBroker::_last_compile_level = CompLevel_none;
142 char CompileBroker::_last_method_compiled[CompileBroker::name_buffer_length];
143
144 // Performance counters
145 PerfCounter* CompileBroker::_perf_total_compilation = NULL;
146 PerfCounter* CompileBroker::_perf_osr_compilation = NULL;
147 PerfCounter* CompileBroker::_perf_standard_compilation = NULL;
148
149 PerfCounter* CompileBroker::_perf_total_bailout_count = NULL;
150 PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL;
151 PerfCounter* CompileBroker::_perf_total_compile_count = NULL;
152 PerfCounter* CompileBroker::_perf_total_osr_compile_count = NULL;
153 PerfCounter* CompileBroker::_perf_total_standard_compile_count = NULL;
154
155 PerfCounter* CompileBroker::_perf_sum_osr_bytes_compiled = NULL;
156 PerfCounter* CompileBroker::_perf_sum_standard_bytes_compiled = NULL;
157 PerfCounter* CompileBroker::_perf_sum_nmethod_size = NULL;
1141 {
1142 MutexLocker locker(queue->lock(), thread);
1143
1144 // Make sure the method has not slipped into the queues since
1145 // last we checked; note that those checks were "fast bail-outs".
1146 // Here we need to be more careful, see 14012000 below.
1147 if (compilation_is_in_queue(method, osr_bci)) {
1148 return;
1149 }
1150
1151 // We need to check again to see if the compilation has
1152 // completed. A previous compilation may have registered
1153 // some result.
1154 if (compilation_is_complete(method, osr_bci, comp_level)) {
1155 return;
1156 }
1157
1158 // We now know that this compilation is not pending, complete,
1159 // or prohibited. Assign a compile_id to this compilation
1160 // and check to see if it is in our [Start..Stop) range.
1161 uint compile_id = assign_compile_id(method, osr_bci);
1162 if (compile_id == 0) {
1163 // The compilation falls outside the allowed range.
1164 return;
1165 }
1166
1167 // Should this thread wait for completion of the compile?
1168 blocking = is_compile_blocking(method, osr_bci);
1169
1170 // We will enter the compilation in the queue.
1171 // 14012000: Note that this sets the queued_for_compile bits in
1172 // the target method. We can now reason that a method cannot be
1173 // queued for compilation more than once, as follows:
1174 // Before a thread queues a task for compilation, it first acquires
1175 // the compile queue lock, then checks if the method's queued bits
1176 // are set or it has already been compiled. Thus there can not be two
1177 // instances of a compilation task for the same method on the
1178 // compilation queue. Consider now the case where the compilation
1179 // thread has already removed a task for that method from the queue
1180 // and is in the midst of compiling it. In this case, the
1181 // queued_for_compile bits must be set in the method (and these
1288 CLEAR_PENDING_EXCEPTION;
1289 return NULL;
1290 }
1291 assert(method->has_native_function(), "must have native code by now");
1292 }
1293
1294 // RedefineClasses() has replaced this method; just return
1295 if (method->is_old()) {
1296 return NULL;
1297 }
1298
1299 // JVMTI -- post_compile_event requires jmethod_id() that may require
1300 // a lock the compiling thread can not acquire. Prefetch it here.
1301 if (JvmtiExport::should_post_compiled_method_load()) {
1302 method->jmethod_id();
1303 }
1304
1305 // do the compilation
1306 if (method->is_native()) {
1307 if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {
1308 // Acquire our lock.
1309 int compile_id;
1310 {
1311 MutexLocker locker(MethodCompileQueue_lock, THREAD);
1312 compile_id = assign_compile_id(method, standard_entry_bci);
1313 }
1314 // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
1315 // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1316 //
1317 // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1318 // in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls.
1319 (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id);
1320 } else {
1321 return NULL;
1322 }
1323 } else {
1324 // If the compiler is shut off due to code cache getting full
1325 // fail out now so blocking compiles dont hang the java thread
1326 if (!should_compile_new_jobs()) {
1327 CompilationPolicy::policy()->delay_compilation(method());
1328 return NULL;
1329 }
1330 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD);
1331 }
1332
1333 // return requested nmethod
1334 // We accept a higher level osr method
1335 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1336 }
1337
1338
1339 // ------------------------------------------------------------------
1402 }
1403
1404 // The method may be explicitly excluded by the user.
1405 bool quietly;
1406 if (CompilerOracle::should_exclude(method, quietly)) {
1407 if (!quietly) {
1408 // This does not happen quietly...
1409 ResourceMark rm;
1410 tty->print("### Excluding %s:%s",
1411 method->is_native() ? "generation of native wrapper" : "compile",
1412 (method->is_static() ? " static" : ""));
1413 method->print_short_name(tty);
1414 tty->cr();
1415 }
1416 method->set_not_compilable(CompLevel_all, !quietly, "excluded by CompilerOracle");
1417 }
1418
1419 return false;
1420 }
1421
1422
1423 // ------------------------------------------------------------------
1424 // CompileBroker::assign_compile_id
1425 //
1426 // Assign a serialized id number to this compilation request. If the
1427 // number falls out of the allowed range, return a 0. OSR
1428 // compilations may be numbered separately from regular compilations
1429 // if certain debugging flags are used.
1430 uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
1431 assert(MethodCompileQueue_lock->owner() == Thread::current(),
1432 "must hold the compilation queue lock");
1433 bool is_osr = (osr_bci != standard_entry_bci);
1434 uint id;
1435 if (CICountOSR && is_osr) {
1436 id = ++_osr_compilation_id;
1437 if ((uint)CIStartOSR <= id && id < (uint)CIStopOSR) {
1438 return id;
1439 }
1440 } else {
1441 id = ++_compilation_id;
1442 if ((uint)CIStart <= id && id < (uint)CIStop) {
1443 return id;
1444 }
1445 }
1446
1447 // Method was not in the appropriate compilation range.
1448 method->set_not_compilable_quietly();
1449 return 0;
1450 }
1451
1452
1453 // ------------------------------------------------------------------
1454 // CompileBroker::is_compile_blocking
1455 //
1456 // Should the current thread be blocked until this compilation request
1457 // has been fulfilled?
1458 bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) {
1459 assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock");
1460 return !BackgroundCompilation;
1461 }
1462
1463
1464 // ------------------------------------------------------------------
1465 // CompileBroker::preload_classes
1466 void CompileBroker::preload_classes(methodHandle method, TRAPS) {
1467 // Move this code over from c1_Compiler.cpp
1468 ShouldNotReachHere();
1469 }
|
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::_print_compilation_warning = 0;
130 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
131
132 // The installed compiler(s)
133 AbstractCompiler* CompileBroker::_compilers[2];
134
135 // These counters are used to assign an unique ID to each compilation.
136 volatile jint CompileBroker::_compilation_id = 0;
137 volatile jint CompileBroker::_osr_compilation_id = 0;
138
139 // Debugging information
140 int CompileBroker::_last_compile_type = no_compile;
141 int CompileBroker::_last_compile_level = CompLevel_none;
142 char CompileBroker::_last_method_compiled[CompileBroker::name_buffer_length];
143
144 // Performance counters
145 PerfCounter* CompileBroker::_perf_total_compilation = NULL;
146 PerfCounter* CompileBroker::_perf_osr_compilation = NULL;
147 PerfCounter* CompileBroker::_perf_standard_compilation = NULL;
148
149 PerfCounter* CompileBroker::_perf_total_bailout_count = NULL;
150 PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL;
151 PerfCounter* CompileBroker::_perf_total_compile_count = NULL;
152 PerfCounter* CompileBroker::_perf_total_osr_compile_count = NULL;
153 PerfCounter* CompileBroker::_perf_total_standard_compile_count = NULL;
154
155 PerfCounter* CompileBroker::_perf_sum_osr_bytes_compiled = NULL;
156 PerfCounter* CompileBroker::_perf_sum_standard_bytes_compiled = NULL;
157 PerfCounter* CompileBroker::_perf_sum_nmethod_size = NULL;
1141 {
1142 MutexLocker locker(queue->lock(), thread);
1143
1144 // Make sure the method has not slipped into the queues since
1145 // last we checked; note that those checks were "fast bail-outs".
1146 // Here we need to be more careful, see 14012000 below.
1147 if (compilation_is_in_queue(method, osr_bci)) {
1148 return;
1149 }
1150
1151 // We need to check again to see if the compilation has
1152 // completed. A previous compilation may have registered
1153 // some result.
1154 if (compilation_is_complete(method, osr_bci, comp_level)) {
1155 return;
1156 }
1157
1158 // We now know that this compilation is not pending, complete,
1159 // or prohibited. Assign a compile_id to this compilation
1160 // and check to see if it is in our [Start..Stop) range.
1161 int compile_id = assign_compile_id(method, osr_bci);
1162 if (compile_id == 0) {
1163 // The compilation falls outside the allowed range.
1164 return;
1165 }
1166
1167 // Should this thread wait for completion of the compile?
1168 blocking = is_compile_blocking(method, osr_bci);
1169
1170 // We will enter the compilation in the queue.
1171 // 14012000: Note that this sets the queued_for_compile bits in
1172 // the target method. We can now reason that a method cannot be
1173 // queued for compilation more than once, as follows:
1174 // Before a thread queues a task for compilation, it first acquires
1175 // the compile queue lock, then checks if the method's queued bits
1176 // are set or it has already been compiled. Thus there can not be two
1177 // instances of a compilation task for the same method on the
1178 // compilation queue. Consider now the case where the compilation
1179 // thread has already removed a task for that method from the queue
1180 // and is in the midst of compiling it. In this case, the
1181 // queued_for_compile bits must be set in the method (and these
1288 CLEAR_PENDING_EXCEPTION;
1289 return NULL;
1290 }
1291 assert(method->has_native_function(), "must have native code by now");
1292 }
1293
1294 // RedefineClasses() has replaced this method; just return
1295 if (method->is_old()) {
1296 return NULL;
1297 }
1298
1299 // JVMTI -- post_compile_event requires jmethod_id() that may require
1300 // a lock the compiling thread can not acquire. Prefetch it here.
1301 if (JvmtiExport::should_post_compiled_method_load()) {
1302 method->jmethod_id();
1303 }
1304
1305 // do the compilation
1306 if (method->is_native()) {
1307 if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {
1308 // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
1309 // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1310 //
1311 // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1312 // in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls.
1313 AdapterHandlerLibrary::create_native_wrapper(method);
1314 } else {
1315 return NULL;
1316 }
1317 } else {
1318 // If the compiler is shut off due to code cache getting full
1319 // fail out now so blocking compiles dont hang the java thread
1320 if (!should_compile_new_jobs()) {
1321 CompilationPolicy::policy()->delay_compilation(method());
1322 return NULL;
1323 }
1324 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD);
1325 }
1326
1327 // return requested nmethod
1328 // We accept a higher level osr method
1329 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1330 }
1331
1332
1333 // ------------------------------------------------------------------
1396 }
1397
1398 // The method may be explicitly excluded by the user.
1399 bool quietly;
1400 if (CompilerOracle::should_exclude(method, quietly)) {
1401 if (!quietly) {
1402 // This does not happen quietly...
1403 ResourceMark rm;
1404 tty->print("### Excluding %s:%s",
1405 method->is_native() ? "generation of native wrapper" : "compile",
1406 (method->is_static() ? " static" : ""));
1407 method->print_short_name(tty);
1408 tty->cr();
1409 }
1410 method->set_not_compilable(CompLevel_all, !quietly, "excluded by CompilerOracle");
1411 }
1412
1413 return false;
1414 }
1415
1416 /**
1417 * Generate serialized IDs for compilation requests. If certain debugging flags are used
1418 * and the ID is not within the specified range, the method is not compiled and 0 is returned.
1419 * The function also allows to generate separate compilation IDs for OSR compilations.
1420 */
1421 int CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
1422 #ifdef ASSERT
1423 bool is_osr = (osr_bci != standard_entry_bci);
1424 int id;
1425 if (method->is_native()) {
1426 assert(!is_osr, "can't be osr");
1427 // Adapters, native wrappers and method handle intrinsics
1428 // should be generated always.
1429 return Atomic::add(1, &_compilation_id);
1430 } else if (CICountOSR && is_osr) {
1431 // CICountOSR is a develop flag and set to 'false' by default. In a product built,
1432 // only _compilation_id is incremented.
1433 id = Atomic::add(1, &_osr_compilation_id);
1434 if (CIStartOSR <= id && id < CIStopOSR) {
1435 return id;
1436 }
1437 } else {
1438 id = Atomic::add(1, &_compilation_id);
1439 if (CIStart <= id && id < CIStop) {
1440 return id;
1441 }
1442 }
1443
1444 // Method was not in the appropriate compilation range.
1445 method->set_not_compilable_quietly();
1446 return 0;
1447 #else
1448 return Atomic::add(1, &_compilation_id);
1449 #endif
1450 }
1451
1452
1453 // ------------------------------------------------------------------
1454 // CompileBroker::is_compile_blocking
1455 //
1456 // Should the current thread be blocked until this compilation request
1457 // has been fulfilled?
1458 bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) {
1459 assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock");
1460 return !BackgroundCompilation;
1461 }
1462
1463
1464 // ------------------------------------------------------------------
1465 // CompileBroker::preload_classes
1466 void CompileBroker::preload_classes(methodHandle method, TRAPS) {
1467 // Move this code over from c1_Compiler.cpp
1468 ShouldNotReachHere();
1469 }
|