Mercurial > hg > truffle
comparison src/share/vm/compiler/compileBroker.cpp @ 6948:e522a00b91aa
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 12 Nov 2012 23:14:12 +0100 |
parents | 957c266d8bc5 18fb7da42534 |
children | 1baf7f1e3f23 |
comparison
equal
deleted
inserted
replaced
6711:ae13cc658b80 | 6948:e522a00b91aa |
---|---|
29 #include "compiler/compileBroker.hpp" | 29 #include "compiler/compileBroker.hpp" |
30 #include "compiler/compileLog.hpp" | 30 #include "compiler/compileLog.hpp" |
31 #include "compiler/compilerOracle.hpp" | 31 #include "compiler/compilerOracle.hpp" |
32 #include "interpreter/linkResolver.hpp" | 32 #include "interpreter/linkResolver.hpp" |
33 #include "memory/allocation.inline.hpp" | 33 #include "memory/allocation.inline.hpp" |
34 #include "oops/methodDataOop.hpp" | 34 #include "oops/methodData.hpp" |
35 #include "oops/methodOop.hpp" | 35 #include "oops/method.hpp" |
36 #include "oops/oop.inline.hpp" | 36 #include "oops/oop.inline.hpp" |
37 #include "prims/nativeLookup.hpp" | 37 #include "prims/nativeLookup.hpp" |
38 #include "runtime/arguments.hpp" | 38 #include "runtime/arguments.hpp" |
39 #include "runtime/compilationPolicy.hpp" | 39 #include "runtime/compilationPolicy.hpp" |
40 #include "runtime/init.hpp" | 40 #include "runtime/init.hpp" |
198 CompilationLog() : StringEventLog("Compilation events") { | 198 CompilationLog() : StringEventLog("Compilation events") { |
199 } | 199 } |
200 | 200 |
201 void log_compile(JavaThread* thread, CompileTask* task) { | 201 void log_compile(JavaThread* thread, CompileTask* task) { |
202 StringLogMessage lm; | 202 StringLogMessage lm; |
203 stringStream msg = lm.stream(); | 203 stringStream sstr = lm.stream(); |
204 // msg.time_stamp().update_to(tty->time_stamp().ticks()); | 204 // msg.time_stamp().update_to(tty->time_stamp().ticks()); |
205 task->print_compilation(&msg, true); | 205 task->print_compilation(&sstr, NULL, true); |
206 log(thread, "%s", (const char*)lm); | 206 log(thread, "%s", (const char*)lm); |
207 } | 207 } |
208 | 208 |
209 void log_nmethod(JavaThread* thread, nmethod* nm) { | 209 void log_nmethod(JavaThread* thread, nmethod* nm) { |
210 log(thread, "nmethod %d%s " INTPTR_FORMAT " code ["INTPTR_FORMAT ", " INTPTR_FORMAT "]", | 210 log(thread, "nmethod %d%s " INTPTR_FORMAT " code ["INTPTR_FORMAT ", " INTPTR_FORMAT "]", |
243 CompileTask* task = thread->task(); | 243 CompileTask* task = thread->task(); |
244 CompileLog* log = thread->log(); | 244 CompileLog* log = thread->log(); |
245 if (log != NULL) task->log_task_done(log); | 245 if (log != NULL) task->log_task_done(log); |
246 thread->set_task(NULL); | 246 thread->set_task(NULL); |
247 task->set_code_handle(NULL); | 247 task->set_code_handle(NULL); |
248 DEBUG_ONLY(thread->set_env((ciEnv*)badAddress)); | 248 thread->set_env(NULL); |
249 if (task->is_blocking()) { | 249 if (task->is_blocking()) { |
250 MutexLocker notifier(task->lock(), thread); | 250 MutexLocker notifier(task->lock(), thread); |
251 task->mark_complete(); | 251 task->mark_complete(); |
252 // Notify the waiting thread that the compilation has completed. | 252 // Notify the waiting thread that the compilation has completed. |
253 task->lock()->notify_all(); | 253 task->lock()->notify_all(); |
272 const char* comment, | 272 const char* comment, |
273 bool is_blocking) { | 273 bool is_blocking) { |
274 assert(!_lock->is_locked(), "bad locking"); | 274 assert(!_lock->is_locked(), "bad locking"); |
275 | 275 |
276 _compile_id = compile_id; | 276 _compile_id = compile_id; |
277 _method = JNIHandles::make_global(method); | 277 _method = method(); |
278 _method_loader = JNIHandles::make_global(_method->method_holder()->class_loader()); | |
278 _osr_bci = osr_bci; | 279 _osr_bci = osr_bci; |
279 _is_blocking = is_blocking; | 280 _is_blocking = is_blocking; |
280 _comp_level = comp_level; | 281 _comp_level = comp_level; |
281 _num_inlined_bytecodes = 0; | 282 _num_inlined_bytecodes = 0; |
282 | 283 |
283 _is_complete = false; | 284 _is_complete = false; |
284 _is_success = false; | 285 _is_success = false; |
285 _code_handle = NULL; | 286 _code_handle = NULL; |
286 | 287 |
287 _hot_method = NULL; | 288 _hot_method = NULL; |
289 _hot_method_loader = NULL; | |
288 _hot_count = hot_count; | 290 _hot_count = hot_count; |
289 _time_queued = 0; // tidy | 291 _time_queued = 0; // tidy |
290 _comment = comment; | 292 _comment = comment; |
291 | 293 |
292 if (LogCompilation) { | 294 if (LogCompilation) { |
293 _time_queued = os::elapsed_counter(); | 295 _time_queued = os::elapsed_counter(); |
294 if (hot_method.not_null()) { | 296 if (hot_method.not_null()) { |
295 if (hot_method == method) { | 297 if (hot_method == method) { |
296 _hot_method = _method; | 298 _hot_method = _method; |
297 } else { | 299 } else { |
298 _hot_method = JNIHandles::make_global(hot_method); | 300 _hot_method = hot_method(); |
299 } | 301 } |
302 _hot_method_loader = JNIHandles::make_global(_hot_method->method_holder()->class_loader()); | |
300 } | 303 } |
301 } | 304 } |
302 | 305 |
303 _next = NULL; | 306 _next = NULL; |
304 } | 307 } |
319 // ------------------------------------------------------------------ | 322 // ------------------------------------------------------------------ |
320 // CompileTask::free | 323 // CompileTask::free |
321 void CompileTask::free() { | 324 void CompileTask::free() { |
322 set_code(NULL); | 325 set_code(NULL); |
323 assert(!_lock->is_locked(), "Should not be locked when freed"); | 326 assert(!_lock->is_locked(), "Should not be locked when freed"); |
324 if (_hot_method != NULL && _hot_method != _method) { | 327 JNIHandles::destroy_global(_method_loader); |
325 JNIHandles::destroy_global(_hot_method); | 328 JNIHandles::destroy_global(_hot_method_loader); |
326 } | 329 } |
327 JNIHandles::destroy_global(_method); | 330 |
328 } | 331 |
329 | 332 void CompileTask::mark_on_stack() { |
333 // Mark these methods as something redefine classes cannot remove. | |
334 _method->set_on_stack(true); | |
335 if (_hot_method != NULL) { | |
336 _hot_method->set_on_stack(true); | |
337 } | |
338 } | |
330 | 339 |
331 // ------------------------------------------------------------------ | 340 // ------------------------------------------------------------------ |
332 // CompileTask::print | 341 // CompileTask::print |
333 void CompileTask::print() { | 342 void CompileTask::print() { |
334 tty->print("<CompileTask compile_id=%d ", _compile_id); | 343 tty->print("<CompileTask compile_id=%d ", _compile_id); |
335 tty->print("method="); | 344 tty->print("method="); |
336 ((methodOop)JNIHandles::resolve(_method))->print_name(tty); | 345 _method->print_name(tty); |
337 tty->print_cr(" osr_bci=%d is_blocking=%s is_complete=%s is_success=%s>", | 346 tty->print_cr(" osr_bci=%d is_blocking=%s is_complete=%s is_success=%s>", |
338 _osr_bci, bool_to_str(_is_blocking), | 347 _osr_bci, bool_to_str(_is_blocking), |
339 bool_to_str(_is_complete), bool_to_str(_is_success)); | 348 bool_to_str(_is_complete), bool_to_str(_is_success)); |
340 } | 349 } |
341 | 350 |
366 } | 375 } |
367 | 376 |
368 | 377 |
369 // ------------------------------------------------------------------ | 378 // ------------------------------------------------------------------ |
370 // CompileTask::print_compilation_impl | 379 // CompileTask::print_compilation_impl |
371 void CompileTask::print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, | 380 void CompileTask::print_compilation_impl(outputStream* st, Method* method, int compile_id, int comp_level, |
372 bool is_osr_method, int osr_bci, bool is_blocking, | 381 bool is_osr_method, int osr_bci, bool is_blocking, |
373 const char* msg, bool short_form) { | 382 const char* msg, bool short_form) { |
374 if (!short_form) { | 383 if (!short_form) { |
375 st->print("%7d ", (int) st->time_stamp().milliseconds()); // print timestamp | 384 st->print("%7d ", (int) st->time_stamp().milliseconds()); // print timestamp |
376 } | 385 } |
483 for (int i = 0; i < inline_level; i++) st->print(" "); | 492 for (int i = 0; i < inline_level; i++) st->print(" "); |
484 } | 493 } |
485 | 494 |
486 // ------------------------------------------------------------------ | 495 // ------------------------------------------------------------------ |
487 // CompileTask::print_compilation | 496 // CompileTask::print_compilation |
488 void CompileTask::print_compilation(outputStream* st, bool short_form) { | 497 void CompileTask::print_compilation(outputStream* st, const char* msg, bool short_form) { |
489 oop rem = JNIHandles::resolve(method_handle()); | |
490 assert(rem != NULL && rem->is_method(), "must be"); | |
491 methodOop method = (methodOop) rem; | |
492 bool is_osr_method = osr_bci() != InvocationEntryBci; | 498 bool is_osr_method = osr_bci() != InvocationEntryBci; |
493 print_compilation_impl(st, method, compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking(), NULL, short_form); | 499 print_compilation_impl(st, method(), compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking(), msg, short_form); |
494 } | 500 } |
495 | 501 |
496 // ------------------------------------------------------------------ | 502 // ------------------------------------------------------------------ |
497 // CompileTask::log_task | 503 // CompileTask::log_task |
498 void CompileTask::log_task(xmlStream* log) { | 504 void CompileTask::log_task(xmlStream* log) { |
499 Thread* thread = Thread::current(); | 505 Thread* thread = Thread::current(); |
500 methodHandle method(thread, | 506 methodHandle method(thread, this->method()); |
501 (methodOop)JNIHandles::resolve(method_handle())); | |
502 ResourceMark rm(thread); | 507 ResourceMark rm(thread); |
503 | 508 |
504 // <task id='9' method='M' osr_bci='X' level='1' blocking='1' stamp='1.234'> | 509 // <task id='9' method='M' osr_bci='X' level='1' blocking='1' stamp='1.234'> |
505 if (_compile_id != 0) log->print(" compile_id='%d'", _compile_id); | 510 if (_compile_id != 0) log->print(" compile_id='%d'", _compile_id); |
506 if (_osr_bci != CompileBroker::standard_entry_bci) { | 511 if (_osr_bci != CompileBroker::standard_entry_bci) { |
531 log_task(xtty); | 536 log_task(xtty); |
532 if (_comment != NULL) { | 537 if (_comment != NULL) { |
533 xtty->print(" comment='%s'", _comment); | 538 xtty->print(" comment='%s'", _comment); |
534 } | 539 } |
535 if (_hot_method != NULL) { | 540 if (_hot_method != NULL) { |
536 methodHandle hot(thread, | 541 methodHandle hot(thread, _hot_method); |
537 (methodOop)JNIHandles::resolve(_hot_method)); | 542 methodHandle method(thread, _method); |
538 methodHandle method(thread, | |
539 (methodOop)JNIHandles::resolve(_method)); | |
540 if (hot() != method()) { | 543 if (hot() != method()) { |
541 xtty->method(hot); | 544 xtty->method(hot); |
542 } | 545 } |
543 } | 546 } |
544 if (_hot_count != 0) { | 547 if (_hot_count != 0) { |
559 | 562 |
560 // ------------------------------------------------------------------ | 563 // ------------------------------------------------------------------ |
561 // CompileTask::log_task_done | 564 // CompileTask::log_task_done |
562 void CompileTask::log_task_done(CompileLog* log) { | 565 void CompileTask::log_task_done(CompileLog* log) { |
563 Thread* thread = Thread::current(); | 566 Thread* thread = Thread::current(); |
564 methodHandle method(thread, | 567 methodHandle method(thread, this->method()); |
565 (methodOop)JNIHandles::resolve(method_handle())); | |
566 ResourceMark rm(thread); | 568 ResourceMark rm(thread); |
567 | 569 |
568 // <task_done ... stamp='1.234'> </task> | 570 // <task_done ... stamp='1.234'> </task> |
569 nmethod* nm = code(); | 571 nmethod* nm = code(); |
570 log->begin_elem("task_done success='%d' nmsize='%d' count='%d'", | 572 log->begin_elem("task_done success='%d' nmsize='%d' count='%d'", |
611 _last = task; | 613 _last = task; |
612 } | 614 } |
613 ++_size; | 615 ++_size; |
614 | 616 |
615 // Mark the method as being in the compile queue. | 617 // Mark the method as being in the compile queue. |
616 ((methodOop)JNIHandles::resolve(task->method_handle()))->set_queued_for_compilation(); | 618 task->method()->set_queued_for_compilation(); |
617 | 619 |
618 if (CIPrintCompileQueue) { | 620 if (CIPrintCompileQueue) { |
619 print(); | 621 print(); |
620 } | 622 } |
621 | 623 |
675 _last = task->prev(); | 677 _last = task->prev(); |
676 } | 678 } |
677 --_size; | 679 --_size; |
678 } | 680 } |
679 | 681 |
682 // methods in the compile queue need to be marked as used on the stack | |
683 // so that they don't get reclaimed by Redefine Classes | |
684 void CompileQueue::mark_on_stack() { | |
685 CompileTask* task = _first; | |
686 while (task != NULL) { | |
687 task->mark_on_stack(); | |
688 task = task->next(); | |
689 } | |
690 } | |
691 | |
680 // ------------------------------------------------------------------ | 692 // ------------------------------------------------------------------ |
681 // CompileQueue::print | 693 // CompileQueue::print |
682 void CompileQueue::print() { | 694 void CompileQueue::print() { |
683 tty->print_cr("Contents of %s", name()); | 695 tty->print_cr("Contents of %s", name()); |
684 tty->print_cr("----------------------"); | 696 tty->print_cr("----------------------"); |
873 // ------------------------------------------------------------------ | 885 // ------------------------------------------------------------------ |
874 // CompileBroker::make_compiler_thread | 886 // CompileBroker::make_compiler_thread |
875 CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS) { | 887 CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS) { |
876 CompilerThread* compiler_thread = NULL; | 888 CompilerThread* compiler_thread = NULL; |
877 | 889 |
878 klassOop k = | 890 Klass* k = |
879 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), | 891 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), |
880 true, CHECK_0); | 892 true, CHECK_0); |
881 instanceKlassHandle klass (THREAD, k); | 893 instanceKlassHandle klass (THREAD, k); |
882 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_0); | 894 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_0); |
883 Handle string = java_lang_String::create_from_str(name, CHECK_0); | 895 Handle string = java_lang_String::create_from_str(name, CHECK_0); |
989 } | 1001 } |
990 | 1002 |
991 if (UsePerfData) { | 1003 if (UsePerfData) { |
992 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, | 1004 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, |
993 compiler_count, CHECK); | 1005 compiler_count, CHECK); |
1006 } | |
1007 } | |
1008 | |
1009 | |
1010 // Set the methods on the stack as on_stack so that redefine classes doesn't | |
1011 // reclaim them | |
1012 void CompileBroker::mark_on_stack() { | |
1013 if (_c2_method_queue != NULL) { | |
1014 _c2_method_queue->mark_on_stack(); | |
1015 } | |
1016 if (_c1_method_queue != NULL) { | |
1017 _c1_method_queue->mark_on_stack(); | |
994 } | 1018 } |
995 } | 1019 } |
996 | 1020 |
997 // ------------------------------------------------------------------ | 1021 // ------------------------------------------------------------------ |
998 // CompileBroker::is_idle | 1022 // CompileBroker::is_idle |
1031 if (!_initialized ) { | 1055 if (!_initialized ) { |
1032 return; | 1056 return; |
1033 } | 1057 } |
1034 | 1058 |
1035 guarantee(!method->is_abstract(), "cannot compile abstract methods"); | 1059 guarantee(!method->is_abstract(), "cannot compile abstract methods"); |
1036 assert(method->method_holder()->klass_part()->oop_is_instance(), | 1060 assert(method->method_holder()->oop_is_instance(), |
1037 "sanity check"); | 1061 "sanity check"); |
1038 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), | 1062 assert(!method->method_holder()->is_not_initialized(), |
1039 "method holder must be initialized"); | 1063 "method holder must be initialized"); |
1040 assert(!method->is_method_handle_intrinsic(), "do not enqueue these guys"); | 1064 assert(!method->is_method_handle_intrinsic(), "do not enqueue these guys"); |
1041 | 1065 |
1042 if (CIPrintRequests) { | 1066 if (CIPrintRequests) { |
1043 tty->print("request: "); | 1067 tty->print("request: "); |
1090 // If the requesting thread is holding the pending list lock | 1114 // If the requesting thread is holding the pending list lock |
1091 // then we just return. We can't risk blocking while holding | 1115 // then we just return. We can't risk blocking while holding |
1092 // the pending list lock or a 3-way deadlock may occur | 1116 // the pending list lock or a 3-way deadlock may occur |
1093 // between the reference handler thread, a GC (instigated | 1117 // between the reference handler thread, a GC (instigated |
1094 // by a compiler thread), and compiled method registration. | 1118 // by a compiler thread), and compiled method registration. |
1095 if (instanceRefKlass::owns_pending_list_lock(JavaThread::current())) { | 1119 if (InstanceRefKlass::owns_pending_list_lock(JavaThread::current())) { |
1096 return; | 1120 return; |
1097 } | 1121 } |
1098 #ifdef GRAAL | 1122 #ifdef GRAAL |
1099 if (!JavaThread::current()->is_compiling()) { | 1123 if (!JavaThread::current()->is_compiling()) { |
1100 method->set_queued_for_compilation(); | 1124 method->set_queued_for_compilation(); |
1194 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, | 1218 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, |
1195 int comp_level, | 1219 int comp_level, |
1196 methodHandle hot_method, int hot_count, | 1220 methodHandle hot_method, int hot_count, |
1197 const char* comment, Thread* THREAD) { | 1221 const char* comment, Thread* THREAD) { |
1198 // make sure arguments make sense | 1222 // make sure arguments make sense |
1199 assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method"); | 1223 assert(method->method_holder()->oop_is_instance(), "not an instance method"); |
1200 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); | 1224 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); |
1201 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); | 1225 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); |
1202 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized"); | 1226 assert(!method->method_holder()->is_not_initialized(), "method holder must be initialized"); |
1203 | 1227 |
1204 if (!TieredCompilation) { | 1228 if (!TieredCompilation) { |
1205 comp_level = CompLevel_highest_tier; | 1229 comp_level = CompLevel_highest_tier; |
1206 } | 1230 } |
1207 | 1231 |
1240 "all OSR compiles are assumed to be at a single compilation lavel"); | 1264 "all OSR compiles are assumed to be at a single compilation lavel"); |
1241 #endif // TIERED | 1265 #endif // TIERED |
1242 // We accept a higher level osr method | 1266 // We accept a higher level osr method |
1243 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false); | 1267 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false); |
1244 if (nm != NULL) return nm; | 1268 if (nm != NULL) return nm; |
1245 if (method->is_not_osr_compilable()) return NULL; | 1269 if (method->is_not_osr_compilable(comp_level)) return NULL; |
1246 } | 1270 } |
1247 | 1271 |
1248 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); | 1272 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); |
1249 // some prerequisites that are compiler specific | 1273 // some prerequisites that are compiler specific |
1250 if (compiler(comp_level)->is_c2() || compiler(comp_level)->is_shark()) { | 1274 if (compiler(comp_level)->is_c2() || compiler(comp_level)->is_shark()) { |
1251 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL); | 1275 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL); |
1252 // Resolve all classes seen in the signature of the method | 1276 // Resolve all classes seen in the signature of the method |
1253 // we are compiling. | 1277 // we are compiling. |
1254 methodOopDesc::load_signature_classes(method, CHECK_AND_CLEAR_NULL); | 1278 Method::load_signature_classes(method, CHECK_AND_CLEAR_NULL); |
1255 } | 1279 } |
1256 | 1280 |
1257 // If the method is native, do the lookup in the thread requesting | 1281 // If the method is native, do the lookup in the thread requesting |
1258 // the compilation. Native lookups can load code, which is not | 1282 // the compilation. Native lookups can load code, which is not |
1259 // permitted during compilation. | 1283 // permitted during compilation. |
1321 bool CompileBroker::compilation_is_complete(methodHandle method, | 1345 bool CompileBroker::compilation_is_complete(methodHandle method, |
1322 int osr_bci, | 1346 int osr_bci, |
1323 int comp_level) { | 1347 int comp_level) { |
1324 bool is_osr = (osr_bci != standard_entry_bci); | 1348 bool is_osr = (osr_bci != standard_entry_bci); |
1325 if (is_osr) { | 1349 if (is_osr) { |
1326 if (method->is_not_osr_compilable()) { | 1350 if (method->is_not_osr_compilable(comp_level)) { |
1327 return true; | 1351 return true; |
1328 } else { | 1352 } else { |
1329 nmethod* result = method->lookup_osr_nmethod_for(osr_bci, comp_level, true); | 1353 nmethod* result = method->lookup_osr_nmethod_for(osr_bci, comp_level, true); |
1330 return (result != NULL); | 1354 return (result != NULL); |
1331 } | 1355 } |
1372 | 1396 |
1373 bool is_osr = (osr_bci != standard_entry_bci); | 1397 bool is_osr = (osr_bci != standard_entry_bci); |
1374 // Some compilers may not support on stack replacement. | 1398 // Some compilers may not support on stack replacement. |
1375 if (is_osr && | 1399 if (is_osr && |
1376 (!CICompileOSR || !compiler(comp_level)->supports_osr())) { | 1400 (!CICompileOSR || !compiler(comp_level)->supports_osr())) { |
1377 method->set_not_osr_compilable(); | 1401 method->set_not_osr_compilable(comp_level); |
1378 return true; | 1402 return true; |
1379 } | 1403 } |
1380 | 1404 |
1381 // The method may be explicitly excluded by the user. | 1405 // The method may be explicitly excluded by the user. |
1382 bool quietly; | 1406 bool quietly; |
1431 // CompileBroker::is_compile_blocking | 1455 // CompileBroker::is_compile_blocking |
1432 // | 1456 // |
1433 // Should the current thread be blocked until this compilation request | 1457 // Should the current thread be blocked until this compilation request |
1434 // has been fulfilled? | 1458 // has been fulfilled? |
1435 bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) { | 1459 bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) { |
1436 assert(!instanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock"); | 1460 assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock"); |
1437 return !BackgroundCompilation; | 1461 return !BackgroundCompilation; |
1438 } | 1462 } |
1439 | 1463 |
1440 | 1464 |
1441 // ------------------------------------------------------------------ | 1465 // ------------------------------------------------------------------ |
1512 assert(task->is_blocking(), "can only wait on blocking task"); | 1536 assert(task->is_blocking(), "can only wait on blocking task"); |
1513 | 1537 |
1514 JavaThread *thread = JavaThread::current(); | 1538 JavaThread *thread = JavaThread::current(); |
1515 thread->set_blocked_on_compilation(true); | 1539 thread->set_blocked_on_compilation(true); |
1516 | 1540 |
1517 methodHandle method(thread, | 1541 methodHandle method(thread, task->method()); |
1518 (methodOop)JNIHandles::resolve(task->method_handle())); | |
1519 { | 1542 { |
1520 MutexLocker waiter(task->lock(), thread); | 1543 MutexLocker waiter(task->lock(), thread); |
1521 | 1544 |
1522 while (!task->is_complete()) | 1545 while (!task->is_complete()) |
1523 task->lock()->wait(); | 1546 task->lock()->wait(); |
1562 if (LogCompilation) { | 1585 if (LogCompilation) { |
1563 init_compiler_thread_log(); | 1586 init_compiler_thread_log(); |
1564 } | 1587 } |
1565 CompileLog* log = thread->log(); | 1588 CompileLog* log = thread->log(); |
1566 if (log != NULL) { | 1589 if (log != NULL) { |
1567 log->begin_elem("start_compile_thread thread='" UINTX_FORMAT "' process='%d'", | 1590 log->begin_elem("start_compile_thread name='%s' thread='" UINTX_FORMAT "' process='%d'", |
1591 thread->name(), | |
1568 os::current_thread_id(), | 1592 os::current_thread_id(), |
1569 os::current_process_id()); | 1593 os::current_process_id()); |
1570 log->stamp(); | 1594 log->stamp(); |
1571 log->end_elem(); | 1595 log->end_elem(); |
1572 } | 1596 } |
1598 // Assign the task to the current thread. Mark this compilation | 1622 // Assign the task to the current thread. Mark this compilation |
1599 // thread as active for the profiler. | 1623 // thread as active for the profiler. |
1600 CompileTaskWrapper ctw(task); | 1624 CompileTaskWrapper ctw(task); |
1601 nmethodLocker result_handle; // (handle for the nmethod produced by this task) | 1625 nmethodLocker result_handle; // (handle for the nmethod produced by this task) |
1602 task->set_code_handle(&result_handle); | 1626 task->set_code_handle(&result_handle); |
1603 methodHandle method(thread, | 1627 methodHandle method(thread, task->method()); |
1604 (methodOop)JNIHandles::resolve(task->method_handle())); | |
1605 | 1628 |
1606 // Never compile a method if breakpoints are present in it | 1629 // Never compile a method if breakpoints are present in it |
1607 if (method()->number_of_breakpoints() == 0) { | 1630 if (method()->number_of_breakpoints() == 0) { |
1608 // Compile the method. | 1631 // Compile the method. |
1609 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { | 1632 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { |
1705 #endif | 1728 #endif |
1706 ThreadInVMfromNative tivfn(JavaThread::current()); | 1729 ThreadInVMfromNative tivfn(JavaThread::current()); |
1707 } | 1730 } |
1708 } | 1731 } |
1709 | 1732 |
1710 | |
1711 // ------------------------------------------------------------------ | 1733 // ------------------------------------------------------------------ |
1712 // CompileBroker::invoke_compiler_on_method | 1734 // CompileBroker::invoke_compiler_on_method |
1713 // | 1735 // |
1714 // Compile a method. | 1736 // Compile a method. |
1715 // | 1737 // |
1736 { | 1758 { |
1737 // create the handle inside it's own block so it can't | 1759 // create the handle inside it's own block so it can't |
1738 // accidentally be referenced once the thread transitions to | 1760 // accidentally be referenced once the thread transitions to |
1739 // native. The NoHandleMark before the transition should catch | 1761 // native. The NoHandleMark before the transition should catch |
1740 // any cases where this occurs in the future. | 1762 // any cases where this occurs in the future. |
1741 methodHandle method(thread, | 1763 methodHandle method(thread, task->method()); |
1742 (methodOop)JNIHandles::resolve(task->method_handle())); | |
1743 should_break = check_break_at(method, compile_id, is_osr); | 1764 should_break = check_break_at(method, compile_id, is_osr); |
1744 if (should_log && !CompilerOracle::should_log(method)) { | 1765 if (should_log && !CompilerOracle::should_log(method)) { |
1745 should_log = false; | 1766 should_log = false; |
1746 } | 1767 } |
1747 assert(!method->is_native(), "no longer compile natives"); | 1768 assert(!method->is_native(), "no longer compile natives"); |
1752 DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler(task->comp_level()), method); | 1773 DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler(task->comp_level()), method); |
1753 } | 1774 } |
1754 | 1775 |
1755 // Allocate a new set of JNI handles. | 1776 // Allocate a new set of JNI handles. |
1756 push_jni_handle_block(); | 1777 push_jni_handle_block(); |
1757 jobject target_handle = JNIHandles::make_local(thread, JNIHandles::resolve(task->method_handle())); | 1778 Method* target_handle = task->method(); |
1758 int compilable = ciEnv::MethodCompilable; | 1779 int compilable = ciEnv::MethodCompilable; |
1759 { | 1780 { |
1760 int system_dictionary_modification_counter; | 1781 int system_dictionary_modification_counter; |
1761 { | 1782 { |
1762 MutexLocker locker(Compile_lock, thread); | 1783 MutexLocker locker(Compile_lock, thread); |
1802 const char* retry_message = ci_env.retry_message(); | 1823 const char* retry_message = ci_env.retry_message(); |
1803 if (_compilation_log != NULL) { | 1824 if (_compilation_log != NULL) { |
1804 _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message); | 1825 _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message); |
1805 } | 1826 } |
1806 if (PrintCompilation) { | 1827 if (PrintCompilation) { |
1807 tty->print("%4d COMPILE SKIPPED: %s", compile_id, ci_env.failure_reason()); | 1828 FormatBufferResource msg = retry_message != NULL ? |
1808 if (retry_message != NULL) { | 1829 err_msg_res("COMPILE SKIPPED: %s (%s)", ci_env.failure_reason(), retry_message) : |
1809 tty->print(" (%s)", retry_message); | 1830 err_msg_res("COMPILE SKIPPED: %s", ci_env.failure_reason()); |
1810 } | 1831 task->print_compilation(tty, msg); |
1811 tty->cr(); | |
1812 } | 1832 } |
1813 } else { | 1833 } else { |
1814 task->mark_success(); | 1834 task->mark_success(); |
1815 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes()); | 1835 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes()); |
1816 if (_compilation_log != NULL) { | 1836 if (_compilation_log != NULL) { |
1821 } | 1841 } |
1822 } | 1842 } |
1823 } | 1843 } |
1824 pop_jni_handle_block(); | 1844 pop_jni_handle_block(); |
1825 | 1845 |
1826 methodHandle method(thread, | 1846 methodHandle method(thread, task->method()); |
1827 (methodOop)JNIHandles::resolve(task->method_handle())); | |
1828 | 1847 |
1829 DTRACE_METHOD_COMPILE_END_PROBE(compiler(task->comp_level()), method, task->is_success()); | 1848 DTRACE_METHOD_COMPILE_END_PROBE(compiler(task->comp_level()), method, task->is_success()); |
1830 | 1849 |
1831 collect_statistics(thread, time, task); | 1850 collect_statistics(thread, time, task); |
1832 | 1851 |
1836 tty->print("%s ", (is_osr ? "%" : " ")); | 1855 tty->print("%s ", (is_osr ? "%" : " ")); |
1837 int code_size = (task->code() == NULL) ? 0 : task->code()->total_size(); | 1856 int code_size = (task->code() == NULL) ? 0 : task->code()->total_size(); |
1838 tty->print_cr("size: %d time: %d inlined: %d bytes", code_size, (int)time.milliseconds(), task->num_inlined_bytecodes()); | 1857 tty->print_cr("size: %d time: %d inlined: %d bytes", code_size, (int)time.milliseconds(), task->num_inlined_bytecodes()); |
1839 } | 1858 } |
1840 | 1859 |
1841 if (compilable == ciEnv::MethodCompilable_never) { | 1860 // Disable compilation, if required. |
1842 if (is_osr) { | 1861 switch (compilable) { |
1843 method->set_not_osr_compilable(); | 1862 case ciEnv::MethodCompilable_never: |
1844 } else { | 1863 if (is_osr) |
1864 method->set_not_osr_compilable_quietly(); | |
1865 else | |
1845 method->set_not_compilable_quietly(); | 1866 method->set_not_compilable_quietly(); |
1846 } | 1867 break; |
1847 } else if (compilable == ciEnv::MethodCompilable_not_at_tier) { | 1868 case ciEnv::MethodCompilable_not_at_tier: |
1848 method->set_not_compilable_quietly(task->comp_level()); | 1869 if (is_osr) |
1870 method->set_not_osr_compilable_quietly(task->comp_level()); | |
1871 else | |
1872 method->set_not_compilable_quietly(task->comp_level()); | |
1873 break; | |
1849 } | 1874 } |
1850 | 1875 |
1851 // Note that the queued_for_compilation bits are cleared without | 1876 // Note that the queued_for_compilation bits are cleared without |
1852 // protection of a mutex. [They were set by the requester thread, | 1877 // protection of a mutex. [They were set by the requester thread, |
1853 // when adding the task to the complie queue -- at which time the | 1878 // when adding the task to the complie queue -- at which time the |
1916 strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length); | 1941 strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length); |
1917 char current_method[CompilerCounters::cmname_buffer_length]; | 1942 char current_method[CompilerCounters::cmname_buffer_length]; |
1918 size_t maxLen = CompilerCounters::cmname_buffer_length; | 1943 size_t maxLen = CompilerCounters::cmname_buffer_length; |
1919 | 1944 |
1920 if (UsePerfData) { | 1945 if (UsePerfData) { |
1921 const char* class_name = method->method_holder()->klass_part()->name()->as_C_string(); | 1946 const char* class_name = method->method_holder()->name()->as_C_string(); |
1922 | 1947 |
1923 size_t s1len = strlen(class_name); | 1948 size_t s1len = strlen(class_name); |
1924 size_t s2len = strlen(method_name); | 1949 size_t s2len = strlen(method_name); |
1925 | 1950 |
1926 // check if we need to truncate the string | 1951 // check if we need to truncate the string |
2010 // | 2035 // |
2011 // Collect statistics about the compilation. | 2036 // Collect statistics about the compilation. |
2012 | 2037 |
2013 void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task) { | 2038 void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task) { |
2014 bool success = task->is_success(); | 2039 bool success = task->is_success(); |
2015 methodHandle method (thread, (methodOop)JNIHandles::resolve(task->method_handle())); | 2040 methodHandle method (thread, task->method()); |
2016 uint compile_id = task->compile_id(); | 2041 uint compile_id = task->compile_id(); |
2017 bool is_osr = (task->osr_bci() != standard_entry_bci); | 2042 bool is_osr = (task->osr_bci() != standard_entry_bci); |
2018 nmethod* code = task->code(); | 2043 nmethod* code = task->code(); |
2019 CompilerCounters* counters = thread->counters(); | 2044 CompilerCounters* counters = thread->counters(); |
2020 | 2045 |