Mercurial > hg > graal-compiler
comparison src/share/vm/compiler/compileBroker.cpp @ 20588:41dcdd636080
8040798: compiler/startup/SmallCodeCacheStartup.java timed out in RT_Baseline
Summary: Fixes broken memory freeing of compile queue tasks and makes sure that blocking compiles do not hang the VM if compilation gets disabled due to a full code cache.
Reviewed-by: kvn, iveresov
author | anoll |
---|---|
date | Tue, 29 Apr 2014 07:59:22 +0200 |
parents | b9c94af14fd0 |
children | 0c0e68524c17 |
comparison
equal
deleted
inserted
replaced
20584:ef9eda2c1abe | 20588:41dcdd636080 |
---|---|
181 int CompileBroker::_sum_nmethod_size = 0; | 181 int CompileBroker::_sum_nmethod_size = 0; |
182 int CompileBroker::_sum_nmethod_code_size = 0; | 182 int CompileBroker::_sum_nmethod_code_size = 0; |
183 | 183 |
184 long CompileBroker::_peak_compilation_time = 0; | 184 long CompileBroker::_peak_compilation_time = 0; |
185 | 185 |
186 CompileQueue* CompileBroker::_c2_method_queue = NULL; | 186 CompileQueue* CompileBroker::_c2_compile_queue = NULL; |
187 CompileQueue* CompileBroker::_c1_method_queue = NULL; | 187 CompileQueue* CompileBroker::_c1_compile_queue = NULL; |
188 CompileTask* CompileBroker::_task_free_list = NULL; | |
189 | 188 |
190 GrowableArray<CompilerThread*>* CompileBroker::_compiler_threads = NULL; | 189 GrowableArray<CompilerThread*>* CompileBroker::_compiler_threads = NULL; |
191 | 190 |
192 | 191 |
193 class CompilationLog : public StringEventLog { | 192 class CompilationLog : public StringEventLog { |
251 } else { | 250 } else { |
252 task->mark_complete(); | 251 task->mark_complete(); |
253 | 252 |
254 // By convention, the compiling thread is responsible for | 253 // By convention, the compiling thread is responsible for |
255 // recycling a non-blocking CompileTask. | 254 // recycling a non-blocking CompileTask. |
256 CompileBroker::free_task(task); | 255 CompileTask::free(task); |
257 } | 256 } |
258 } | 257 } |
259 | 258 |
260 | 259 |
261 // ------------------------------------------------------------------ | 260 CompileTask* CompileTask::_task_free_list = NULL; |
262 // CompileTask::initialize | 261 #ifdef ASSERT |
262 int CompileTask::_num_allocated_tasks = 0; | |
263 #endif | |
264 /** | |
265 * Allocate a CompileTask, from the free list if possible. | |
266 */ | |
267 CompileTask* CompileTask::allocate() { | |
268 MutexLocker locker(CompileTaskAlloc_lock); | |
269 CompileTask* task = NULL; | |
270 | |
271 if (_task_free_list != NULL) { | |
272 task = _task_free_list; | |
273 _task_free_list = task->next(); | |
274 task->set_next(NULL); | |
275 } else { | |
276 task = new CompileTask(); | |
277 DEBUG_ONLY(_num_allocated_tasks++;) | |
278 assert (_num_allocated_tasks < 10000, "Leaking compilation tasks?"); | |
279 task->set_next(NULL); | |
280 task->set_is_free(true); | |
281 } | |
282 assert(task->is_free(), "Task must be free."); | |
283 task->set_is_free(false); | |
284 return task; | |
285 } | |
286 | |
287 | |
288 /** | |
289 * Add a task to the free list. | |
290 */ | |
291 void CompileTask::free(CompileTask* task) { | |
292 MutexLocker locker(CompileTaskAlloc_lock); | |
293 if (!task->is_free()) { | |
294 task->set_code(NULL); | |
295 assert(!task->lock()->is_locked(), "Should not be locked when freed"); | |
296 JNIHandles::destroy_global(task->_method_holder); | |
297 JNIHandles::destroy_global(task->_hot_method_holder); | |
298 | |
299 task->set_is_free(true); | |
300 task->set_next(_task_free_list); | |
301 _task_free_list = task; | |
302 } | |
303 } | |
304 | |
263 void CompileTask::initialize(int compile_id, | 305 void CompileTask::initialize(int compile_id, |
264 methodHandle method, | 306 methodHandle method, |
265 int osr_bci, | 307 int osr_bci, |
266 int comp_level, | 308 int comp_level, |
267 methodHandle hot_method, | 309 methodHandle hot_method, |
314 void CompileTask::set_code(nmethod* nm) { | 356 void CompileTask::set_code(nmethod* nm) { |
315 if (_code_handle == NULL && nm == NULL) return; | 357 if (_code_handle == NULL && nm == NULL) return; |
316 guarantee(_code_handle != NULL, ""); | 358 guarantee(_code_handle != NULL, ""); |
317 _code_handle->set_code(nm); | 359 _code_handle->set_code(nm); |
318 if (nm == NULL) _code_handle = NULL; // drop the handle also | 360 if (nm == NULL) _code_handle = NULL; // drop the handle also |
319 } | |
320 | |
321 // ------------------------------------------------------------------ | |
322 // CompileTask::free | |
323 void CompileTask::free() { | |
324 set_code(NULL); | |
325 assert(!_lock->is_locked(), "Should not be locked when freed"); | |
326 JNIHandles::destroy_global(_method_holder); | |
327 JNIHandles::destroy_global(_hot_method_holder); | |
328 } | 361 } |
329 | 362 |
330 | 363 |
331 void CompileTask::mark_on_stack() { | 364 void CompileTask::mark_on_stack() { |
332 // Mark these methods as something redefine classes cannot remove. | 365 // Mark these methods as something redefine classes cannot remove. |
592 log->mark_file_end(); | 625 log->mark_file_end(); |
593 } | 626 } |
594 | 627 |
595 | 628 |
596 | 629 |
597 // Add a CompileTask to a CompileQueue | 630 /** |
631 * Add a CompileTask to a CompileQueue | |
632 */ | |
598 void CompileQueue::add(CompileTask* task) { | 633 void CompileQueue::add(CompileTask* task) { |
599 assert(lock()->owned_by_self(), "must own lock"); | 634 assert(lock()->owned_by_self(), "must own lock"); |
635 assert(!CompileBroker::is_compilation_disabled_forever(), "Do not add task if compilation is turned off forever"); | |
600 | 636 |
601 task->set_next(NULL); | 637 task->set_next(NULL); |
602 task->set_prev(NULL); | 638 task->set_prev(NULL); |
603 | 639 |
604 if (_last == NULL) { | 640 if (_last == NULL) { |
616 ++_size; | 652 ++_size; |
617 | 653 |
618 // Mark the method as being in the compile queue. | 654 // Mark the method as being in the compile queue. |
619 task->method()->set_queued_for_compilation(); | 655 task->method()->set_queued_for_compilation(); |
620 | 656 |
621 if (CIPrintCompileQueue) { | 657 NOT_PRODUCT(print();) |
622 print(); | |
623 } | |
624 | 658 |
625 if (LogCompilation && xtty != NULL) { | 659 if (LogCompilation && xtty != NULL) { |
626 task->log_task_queued(); | 660 task->log_task_queued(); |
627 } | 661 } |
628 | 662 |
629 // Notify CompilerThreads that a task is available. | 663 // Notify CompilerThreads that a task is available. |
630 lock()->notify_all(); | 664 lock()->notify_all(); |
631 } | 665 } |
632 | 666 |
633 void CompileQueue::delete_all() { | 667 void CompileQueue::free_all() { |
634 assert(lock()->owned_by_self(), "must own lock"); | 668 MutexLocker mu(lock()); |
635 if (_first != NULL) { | 669 if (_first != NULL) { |
636 for (CompileTask* task = _first; task != NULL; task = task->next()) { | 670 for (CompileTask* task = _first; task != NULL; task = task->next()) { |
637 delete task; | 671 // Wake up thread that blocks on the compile task. |
672 task->lock()->notify(); | |
673 // Puts task back on the freelist. | |
674 CompileTask::free(task); | |
638 } | 675 } |
639 _first = NULL; | 676 _first = NULL; |
640 } | 677 } |
678 // Wake up all threads that block on the queue. | |
679 lock()->notify_all(); | |
641 } | 680 } |
642 | 681 |
643 // ------------------------------------------------------------------ | 682 // ------------------------------------------------------------------ |
644 // CompileQueue::get | 683 // CompileQueue::get |
645 // | 684 // |
765 task->mark_on_stack(); | 804 task->mark_on_stack(); |
766 task = task->next(); | 805 task = task->next(); |
767 } | 806 } |
768 } | 807 } |
769 | 808 |
770 // ------------------------------------------------------------------ | 809 #ifndef PRODUCT |
771 // CompileQueue::print | 810 /** |
811 * Print entire compilation queue. | |
812 */ | |
772 void CompileQueue::print() { | 813 void CompileQueue::print() { |
773 tty->print_cr("Contents of %s", name()); | 814 if (CIPrintCompileQueue) { |
774 tty->print_cr("----------------------"); | 815 ttyLocker ttyl; |
775 CompileTask* task = _first; | 816 tty->print_cr("Contents of %s", name()); |
776 while (task != NULL) { | 817 tty->print_cr("----------------------"); |
777 task->print_line(); | 818 CompileTask* task = _first; |
778 task = task->next(); | 819 while (task != NULL) { |
779 } | 820 task->print_line(); |
780 tty->print_cr("----------------------"); | 821 task = task->next(); |
781 } | 822 } |
823 tty->print_cr("----------------------"); | |
824 } | |
825 } | |
826 #endif // PRODUCT | |
782 | 827 |
783 CompilerCounters::CompilerCounters(const char* thread_name, int instance, TRAPS) { | 828 CompilerCounters::CompilerCounters(const char* thread_name, int instance, TRAPS) { |
784 | 829 |
785 _current_method[0] = '\0'; | 830 _current_method[0] = '\0'; |
786 _compile_type = CompileBroker::no_compile; | 831 _compile_type = CompileBroker::no_compile; |
848 int c1_count = 0; | 893 int c1_count = 0; |
849 int c2_count = 1; | 894 int c2_count = 1; |
850 | 895 |
851 _compilers[1] = new SharkCompiler(); | 896 _compilers[1] = new SharkCompiler(); |
852 #endif // SHARK | 897 #endif // SHARK |
853 | |
854 // Initialize the CompileTask free list | |
855 _task_free_list = NULL; | |
856 | 898 |
857 // Start the CompilerThreads | 899 // Start the CompilerThreads |
858 init_compiler_threads(c1_count, c2_count); | 900 init_compiler_threads(c1_count, c2_count); |
859 // totalTime performance counter is always created as it is required | 901 // totalTime performance counter is always created as it is required |
860 // by the implementation of java.lang.management.CompilationMBean. | 902 // by the implementation of java.lang.management.CompilationMBean. |
1044 #if !defined(ZERO) && !defined(SHARK) | 1086 #if !defined(ZERO) && !defined(SHARK) |
1045 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?"); | 1087 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?"); |
1046 #endif // !ZERO && !SHARK | 1088 #endif // !ZERO && !SHARK |
1047 // Initialize the compilation queue | 1089 // Initialize the compilation queue |
1048 if (c2_compiler_count > 0) { | 1090 if (c2_compiler_count > 0) { |
1049 _c2_method_queue = new CompileQueue("C2MethodQueue", MethodCompileQueue_lock); | 1091 _c2_compile_queue = new CompileQueue("C2 CompileQueue", MethodCompileQueue_lock); |
1050 _compilers[1]->set_num_compiler_threads(c2_compiler_count); | 1092 _compilers[1]->set_num_compiler_threads(c2_compiler_count); |
1051 } | 1093 } |
1052 if (c1_compiler_count > 0) { | 1094 if (c1_compiler_count > 0) { |
1053 _c1_method_queue = new CompileQueue("C1MethodQueue", MethodCompileQueue_lock); | 1095 _c1_compile_queue = new CompileQueue("C1 CompileQueue", MethodCompileQueue_lock); |
1054 _compilers[0]->set_num_compiler_threads(c1_compiler_count); | 1096 _compilers[0]->set_num_compiler_threads(c1_compiler_count); |
1055 } | 1097 } |
1056 | 1098 |
1057 int compiler_count = c1_compiler_count + c2_compiler_count; | 1099 int compiler_count = c1_compiler_count + c2_compiler_count; |
1058 | 1100 |
1063 for (int i = 0; i < c2_compiler_count; i++) { | 1105 for (int i = 0; i < c2_compiler_count; i++) { |
1064 // Create a name for our thread. | 1106 // Create a name for our thread. |
1065 sprintf(name_buffer, "C2 CompilerThread%d", i); | 1107 sprintf(name_buffer, "C2 CompilerThread%d", i); |
1066 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); | 1108 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); |
1067 // Shark and C2 | 1109 // Shark and C2 |
1068 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, _compilers[1], CHECK); | 1110 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_compile_queue, counters, _compilers[1], CHECK); |
1069 _compiler_threads->append(new_thread); | 1111 _compiler_threads->append(new_thread); |
1070 } | 1112 } |
1071 | 1113 |
1072 for (int i = c2_compiler_count; i < compiler_count; i++) { | 1114 for (int i = c2_compiler_count; i < compiler_count; i++) { |
1073 // Create a name for our thread. | 1115 // Create a name for our thread. |
1074 sprintf(name_buffer, "C1 CompilerThread%d", i); | 1116 sprintf(name_buffer, "C1 CompilerThread%d", i); |
1075 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); | 1117 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); |
1076 // C1 | 1118 // C1 |
1077 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c1_method_queue, counters, _compilers[0], CHECK); | 1119 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c1_compile_queue, counters, _compilers[0], CHECK); |
1078 _compiler_threads->append(new_thread); | 1120 _compiler_threads->append(new_thread); |
1079 } | 1121 } |
1080 | 1122 |
1081 if (UsePerfData) { | 1123 if (UsePerfData) { |
1082 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, compiler_count, CHECK); | 1124 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, compiler_count, CHECK); |
1083 } | 1125 } |
1084 } | 1126 } |
1085 | 1127 |
1086 | 1128 |
1087 // Set the methods on the stack as on_stack so that redefine classes doesn't | 1129 /** |
1088 // reclaim them | 1130 * Set the methods on the stack as on_stack so that redefine classes doesn't |
1131 * reclaim them | |
1132 */ | |
1089 void CompileBroker::mark_on_stack() { | 1133 void CompileBroker::mark_on_stack() { |
1090 if (_c2_method_queue != NULL) { | 1134 if (_c2_compile_queue != NULL) { |
1091 _c2_method_queue->mark_on_stack(); | 1135 MutexLocker locker(_c2_compile_queue->lock()); |
1092 } | 1136 _c2_compile_queue->mark_on_stack(); |
1093 if (_c1_method_queue != NULL) { | 1137 } |
1094 _c1_method_queue->mark_on_stack(); | 1138 if (_c1_compile_queue != NULL) { |
1139 MutexLocker locker(_c1_compile_queue->lock()); | |
1140 _c1_compile_queue->mark_on_stack(); | |
1095 } | 1141 } |
1096 } | 1142 } |
1097 | 1143 |
1098 // ------------------------------------------------------------------ | 1144 // ------------------------------------------------------------------ |
1099 // CompileBroker::compile_method | 1145 // CompileBroker::compile_method |
1105 methodHandle hot_method, | 1151 methodHandle hot_method, |
1106 int hot_count, | 1152 int hot_count, |
1107 const char* comment, | 1153 const char* comment, |
1108 Thread* thread) { | 1154 Thread* thread) { |
1109 // do nothing if compiler thread(s) is not available | 1155 // do nothing if compiler thread(s) is not available |
1110 if (!_initialized ) { | 1156 if (!_initialized) { |
1111 return; | 1157 return; |
1112 } | 1158 } |
1113 | 1159 |
1114 guarantee(!method->is_abstract(), "cannot compile abstract methods"); | 1160 guarantee(!method->is_abstract(), "cannot compile abstract methods"); |
1115 assert(method->method_holder()->oop_is_instance(), | 1161 assert(method->method_holder()->oop_is_instance(), |
1152 } | 1198 } |
1153 #endif | 1199 #endif |
1154 | 1200 |
1155 // If this method is already in the compile queue, then | 1201 // If this method is already in the compile queue, then |
1156 // we do not block the current thread. | 1202 // we do not block the current thread. |
1157 if (compilation_is_in_queue(method, osr_bci)) { | 1203 if (compilation_is_in_queue(method)) { |
1158 // We may want to decay our counter a bit here to prevent | 1204 // We may want to decay our counter a bit here to prevent |
1159 // multiple denied requests for compilation. This is an | 1205 // multiple denied requests for compilation. This is an |
1160 // open compilation policy issue. Note: The other possibility, | 1206 // open compilation policy issue. Note: The other possibility, |
1161 // in the case that this is a blocking compile request, is to have | 1207 // in the case that this is a blocking compile request, is to have |
1162 // all subsequent blocking requesters wait for completion of | 1208 // all subsequent blocking requesters wait for completion of |
1191 MutexLocker locker(queue->lock(), thread); | 1237 MutexLocker locker(queue->lock(), thread); |
1192 | 1238 |
1193 // Make sure the method has not slipped into the queues since | 1239 // Make sure the method has not slipped into the queues since |
1194 // last we checked; note that those checks were "fast bail-outs". | 1240 // last we checked; note that those checks were "fast bail-outs". |
1195 // Here we need to be more careful, see 14012000 below. | 1241 // Here we need to be more careful, see 14012000 below. |
1196 if (compilation_is_in_queue(method, osr_bci)) { | 1242 if (compilation_is_in_queue(method)) { |
1197 return; | 1243 return; |
1198 } | 1244 } |
1199 | 1245 |
1200 // We need to check again to see if the compilation has | 1246 // We need to check again to see if the compilation has |
1201 // completed. A previous compilation may have registered | 1247 // completed. A previous compilation may have registered |
1212 // The compilation falls outside the allowed range. | 1258 // The compilation falls outside the allowed range. |
1213 return; | 1259 return; |
1214 } | 1260 } |
1215 | 1261 |
1216 // Should this thread wait for completion of the compile? | 1262 // Should this thread wait for completion of the compile? |
1217 blocking = is_compile_blocking(method, osr_bci); | 1263 blocking = is_compile_blocking(); |
1218 | 1264 |
1219 // We will enter the compilation in the queue. | 1265 // We will enter the compilation in the queue. |
1220 // 14012000: Note that this sets the queued_for_compile bits in | 1266 // 14012000: Note that this sets the queued_for_compile bits in |
1221 // the target method. We can now reason that a method cannot be | 1267 // the target method. We can now reason that a method cannot be |
1222 // queued for compilation more than once, as follows: | 1268 // queued for compilation more than once, as follows: |
1404 } | 1450 } |
1405 } | 1451 } |
1406 } | 1452 } |
1407 | 1453 |
1408 | 1454 |
1409 // ------------------------------------------------------------------ | 1455 /** |
1410 // CompileBroker::compilation_is_in_queue | 1456 * See if this compilation is already requested. |
1411 // | 1457 * |
1412 // See if this compilation is already requested. | 1458 * Implementation note: there is only a single "is in queue" bit |
1413 // | 1459 * for each method. This means that the check below is overly |
1414 // Implementation note: there is only a single "is in queue" bit | 1460 * conservative in the sense that an osr compilation in the queue |
1415 // for each method. This means that the check below is overly | 1461 * will block a normal compilation from entering the queue (and vice |
1416 // conservative in the sense that an osr compilation in the queue | 1462 * versa). This can be remedied by a full queue search to disambiguate |
1417 // will block a normal compilation from entering the queue (and vice | 1463 * cases. If it is deemed profitable, this may be done. |
1418 // versa). This can be remedied by a full queue search to disambiguate | 1464 */ |
1419 // cases. If it is deemed profitible, this may be done. | 1465 bool CompileBroker::compilation_is_in_queue(methodHandle method) { |
1420 bool CompileBroker::compilation_is_in_queue(methodHandle method, | |
1421 int osr_bci) { | |
1422 return method->queued_for_compilation(); | 1466 return method->queued_for_compilation(); |
1423 } | 1467 } |
1424 | 1468 |
1425 // ------------------------------------------------------------------ | 1469 // ------------------------------------------------------------------ |
1426 // CompileBroker::compilation_is_prohibited | 1470 // CompileBroker::compilation_is_prohibited |
1496 // only _compilation_id is incremented. | 1540 // only _compilation_id is incremented. |
1497 return Atomic::add(1, &_compilation_id); | 1541 return Atomic::add(1, &_compilation_id); |
1498 #endif | 1542 #endif |
1499 } | 1543 } |
1500 | 1544 |
1501 | 1545 /** |
1502 // ------------------------------------------------------------------ | 1546 * Should the current thread block until this compilation request |
1503 // CompileBroker::is_compile_blocking | 1547 * has been fulfilled? |
1504 // | 1548 */ |
1505 // Should the current thread be blocked until this compilation request | 1549 bool CompileBroker::is_compile_blocking() { |
1506 // has been fulfilled? | |
1507 bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) { | |
1508 assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock"); | 1550 assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock"); |
1509 return !BackgroundCompilation; | 1551 return !BackgroundCompilation; |
1510 } | 1552 } |
1511 | 1553 |
1512 | 1554 |
1530 int comp_level, | 1572 int comp_level, |
1531 methodHandle hot_method, | 1573 methodHandle hot_method, |
1532 int hot_count, | 1574 int hot_count, |
1533 const char* comment, | 1575 const char* comment, |
1534 bool blocking) { | 1576 bool blocking) { |
1535 CompileTask* new_task = allocate_task(); | 1577 CompileTask* new_task = CompileTask::allocate(); |
1536 new_task->initialize(compile_id, method, osr_bci, comp_level, | 1578 new_task->initialize(compile_id, method, osr_bci, comp_level, |
1537 hot_method, hot_count, comment, | 1579 hot_method, hot_count, comment, |
1538 blocking); | 1580 blocking); |
1539 queue->add(new_task); | 1581 queue->add(new_task); |
1540 return new_task; | 1582 return new_task; |
1541 } | 1583 } |
1542 | 1584 |
1543 | 1585 |
1544 // ------------------------------------------------------------------ | 1586 /** |
1545 // CompileBroker::allocate_task | 1587 * Wait for the compilation task to complete. |
1546 // | 1588 */ |
1547 // Allocate a CompileTask, from the free list if possible. | |
1548 CompileTask* CompileBroker::allocate_task() { | |
1549 MutexLocker locker(CompileTaskAlloc_lock); | |
1550 CompileTask* task = NULL; | |
1551 if (_task_free_list != NULL) { | |
1552 task = _task_free_list; | |
1553 _task_free_list = task->next(); | |
1554 task->set_next(NULL); | |
1555 } else { | |
1556 task = new CompileTask(); | |
1557 task->set_next(NULL); | |
1558 } | |
1559 return task; | |
1560 } | |
1561 | |
1562 | |
1563 // ------------------------------------------------------------------ | |
1564 // CompileBroker::free_task | |
1565 // | |
1566 // Add a task to the free list. | |
1567 void CompileBroker::free_task(CompileTask* task) { | |
1568 MutexLocker locker(CompileTaskAlloc_lock); | |
1569 task->free(); | |
1570 task->set_next(_task_free_list); | |
1571 _task_free_list = task; | |
1572 } | |
1573 | |
1574 | |
1575 // ------------------------------------------------------------------ | |
1576 // CompileBroker::wait_for_completion | |
1577 // | |
1578 // Wait for the given method CompileTask to complete. | |
1579 void CompileBroker::wait_for_completion(CompileTask* task) { | 1589 void CompileBroker::wait_for_completion(CompileTask* task) { |
1580 if (CIPrintCompileQueue) { | 1590 if (CIPrintCompileQueue) { |
1591 ttyLocker ttyl; | |
1581 tty->print_cr("BLOCKING FOR COMPILE"); | 1592 tty->print_cr("BLOCKING FOR COMPILE"); |
1582 } | 1593 } |
1583 | 1594 |
1584 assert(task->is_blocking(), "can only wait on blocking task"); | 1595 assert(task->is_blocking(), "can only wait on blocking task"); |
1585 | 1596 |
1586 JavaThread *thread = JavaThread::current(); | 1597 JavaThread* thread = JavaThread::current(); |
1587 thread->set_blocked_on_compilation(true); | 1598 thread->set_blocked_on_compilation(true); |
1588 | 1599 |
1589 methodHandle method(thread, task->method()); | 1600 methodHandle method(thread, task->method()); |
1590 { | 1601 { |
1591 MutexLocker waiter(task->lock(), thread); | 1602 MutexLocker waiter(task->lock(), thread); |
1592 | 1603 |
1593 while (!task->is_complete()) | 1604 while (!task->is_complete() && !is_compilation_disabled_forever()) { |
1594 task->lock()->wait(); | 1605 task->lock()->wait(); |
1595 } | 1606 } |
1607 } | |
1608 | |
1609 thread->set_blocked_on_compilation(false); | |
1610 if (is_compilation_disabled_forever()) { | |
1611 CompileTask::free(task); | |
1612 return; | |
1613 } | |
1614 | |
1596 // It is harmless to check this status without the lock, because | 1615 // It is harmless to check this status without the lock, because |
1597 // completion is a stable property (until the task object is recycled). | 1616 // completion is a stable property (until the task object is recycled). |
1598 assert(task->is_complete(), "Compilation should have completed"); | 1617 assert(task->is_complete(), "Compilation should have completed"); |
1599 assert(task->code_handle() == NULL, "must be reset"); | 1618 assert(task->code_handle() == NULL, "must be reset"); |
1600 | 1619 |
1601 thread->set_blocked_on_compilation(false); | |
1602 | |
1603 // By convention, the waiter is responsible for recycling a | 1620 // By convention, the waiter is responsible for recycling a |
1604 // blocking CompileTask. Since there is only one waiter ever | 1621 // blocking CompileTask. Since there is only one waiter ever |
1605 // waiting on a CompileTask, we know that no one else will | 1622 // waiting on a CompileTask, we know that no one else will |
1606 // be using this CompileTask; we can free it. | 1623 // be using this CompileTask; we can free it. |
1607 free_task(task); | 1624 CompileTask::free(task); |
1608 } | 1625 } |
1609 | 1626 |
1610 // Initialize compiler thread(s) + compiler object(s). The postcondition | 1627 /** |
1611 // of this function is that the compiler runtimes are initialized and that | 1628 * Initialize compiler thread(s) + compiler object(s). The postcondition |
1612 //compiler threads can start compiling. | 1629 * of this function is that the compiler runtimes are initialized and that |
1630 * compiler threads can start compiling. | |
1631 */ | |
1613 bool CompileBroker::init_compiler_runtime() { | 1632 bool CompileBroker::init_compiler_runtime() { |
1614 CompilerThread* thread = CompilerThread::current(); | 1633 CompilerThread* thread = CompilerThread::current(); |
1615 AbstractCompiler* comp = thread->compiler(); | 1634 AbstractCompiler* comp = thread->compiler(); |
1616 // Final sanity check - the compiler object must exist | 1635 // Final sanity check - the compiler object must exist |
1617 guarantee(comp != NULL, "Compiler object must exist"); | 1636 guarantee(comp != NULL, "Compiler object must exist"); |
1644 | 1663 |
1645 if (comp->is_failed()) { | 1664 if (comp->is_failed()) { |
1646 disable_compilation_forever(); | 1665 disable_compilation_forever(); |
1647 // If compiler initialization failed, no compiler thread that is specific to a | 1666 // If compiler initialization failed, no compiler thread that is specific to a |
1648 // particular compiler runtime will ever start to compile methods. | 1667 // particular compiler runtime will ever start to compile methods. |
1649 | |
1650 shutdown_compiler_runtime(comp, thread); | 1668 shutdown_compiler_runtime(comp, thread); |
1651 return false; | 1669 return false; |
1652 } | 1670 } |
1653 | 1671 |
1654 // C1 specific check | 1672 // C1 specific check |
1658 } | 1676 } |
1659 | 1677 |
1660 return true; | 1678 return true; |
1661 } | 1679 } |
1662 | 1680 |
1663 // If C1 and/or C2 initialization failed, we shut down all compilation. | 1681 /** |
1664 // We do this to keep things simple. This can be changed if it ever turns out to be | 1682 * If C1 and/or C2 initialization failed, we shut down all compilation. |
1665 // a problem. | 1683 * We do this to keep things simple. This can be changed if it ever turns |
1684 * out to be a problem. | |
1685 */ | |
1666 void CompileBroker::shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread) { | 1686 void CompileBroker::shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread) { |
1667 // Free buffer blob, if allocated | 1687 // Free buffer blob, if allocated |
1668 if (thread->get_buffer_blob() != NULL) { | 1688 if (thread->get_buffer_blob() != NULL) { |
1669 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | 1689 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
1670 CodeCache::free(thread->get_buffer_blob()); | 1690 CodeCache::free(thread->get_buffer_blob()); |
1672 | 1692 |
1673 if (comp->should_perform_shutdown()) { | 1693 if (comp->should_perform_shutdown()) { |
1674 // There are two reasons for shutting down the compiler | 1694 // There are two reasons for shutting down the compiler |
1675 // 1) compiler runtime initialization failed | 1695 // 1) compiler runtime initialization failed |
1676 // 2) The code cache is full and the following flag is set: -XX:-UseCodeCacheFlushing | 1696 // 2) The code cache is full and the following flag is set: -XX:-UseCodeCacheFlushing |
1677 warning("Shutting down compiler %s (no space to run compilers)", comp->name()); | 1697 warning("%s initialization failed. Shutting down all compilers", comp->name()); |
1678 | 1698 |
1679 // Only one thread per compiler runtime object enters here | 1699 // Only one thread per compiler runtime object enters here |
1680 // Set state to shut down | 1700 // Set state to shut down |
1681 comp->set_shut_down(); | 1701 comp->set_shut_down(); |
1682 | 1702 |
1683 MutexLocker mu(MethodCompileQueue_lock, thread); | 1703 // Delete all queued compilation tasks to make compiler threads exit faster. |
1684 CompileQueue* queue; | 1704 if (_c1_compile_queue != NULL) { |
1685 if (_c1_method_queue != NULL) { | 1705 _c1_compile_queue->free_all(); |
1686 _c1_method_queue->delete_all(); | 1706 } |
1687 queue = _c1_method_queue; | 1707 |
1688 _c1_method_queue = NULL; | 1708 if (_c2_compile_queue != NULL) { |
1689 delete _c1_method_queue; | 1709 _c2_compile_queue->free_all(); |
1690 } | 1710 } |
1691 | 1711 |
1692 if (_c2_method_queue != NULL) { | 1712 // Set flags so that we continue execution with using interpreter only. |
1693 _c2_method_queue->delete_all(); | 1713 UseCompiler = false; |
1694 queue = _c2_method_queue; | 1714 UseInterpreter = true; |
1695 _c2_method_queue = NULL; | |
1696 delete _c2_method_queue; | |
1697 } | |
1698 | 1715 |
1699 // We could delete compiler runtimes also. However, there are references to | 1716 // We could delete compiler runtimes also. However, there are references to |
1700 // the compiler runtime(s) (e.g., nmethod::is_compiled_by_c1()) which then | 1717 // the compiler runtime(s) (e.g., nmethod::is_compiled_by_c1()) which then |
1701 // fail. This can be done later if necessary. | 1718 // fail. This can be done later if necessary. |
1702 } | 1719 } |