Mercurial > hg > truffle
comparison src/share/vm/compiler/compileBroker.cpp @ 14422:2b8e28fdf503
Merge
author | kvn |
---|---|
date | Tue, 05 Nov 2013 17:38:04 -0800 |
parents | b5c8a61d7fa0 a196f1aaec86 |
children | da862781b584 |
comparison
equal
deleted
inserted
replaced
14421:3068270ba476 | 14422:2b8e28fdf503 |
---|---|
184 | 184 |
185 CompileQueue* CompileBroker::_c2_method_queue = NULL; | 185 CompileQueue* CompileBroker::_c2_method_queue = NULL; |
186 CompileQueue* CompileBroker::_c1_method_queue = NULL; | 186 CompileQueue* CompileBroker::_c1_method_queue = NULL; |
187 CompileTask* CompileBroker::_task_free_list = NULL; | 187 CompileTask* CompileBroker::_task_free_list = NULL; |
188 | 188 |
189 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; | 189 GrowableArray<CompilerThread*>* CompileBroker::_compiler_threads = NULL; |
190 | 190 |
191 | 191 |
192 class CompilationLog : public StringEventLog { | 192 class CompilationLog : public StringEventLog { |
193 public: | 193 public: |
194 CompilationLog() : StringEventLog("Compilation events") { | 194 CompilationLog() : StringEventLog("Compilation events") { |
585 log->mark_file_end(); | 585 log->mark_file_end(); |
586 } | 586 } |
587 | 587 |
588 | 588 |
589 | 589 |
590 // ------------------------------------------------------------------ | |
591 // CompileQueue::add | |
592 // | |
593 // Add a CompileTask to a CompileQueue | 590 // Add a CompileTask to a CompileQueue |
594 void CompileQueue::add(CompileTask* task) { | 591 void CompileQueue::add(CompileTask* task) { |
595 assert(lock()->owned_by_self(), "must own lock"); | 592 assert(lock()->owned_by_self(), "must own lock"); |
596 | 593 |
597 task->set_next(NULL); | 594 task->set_next(NULL); |
624 | 621 |
625 // Notify CompilerThreads that a task is available. | 622 // Notify CompilerThreads that a task is available. |
626 lock()->notify_all(); | 623 lock()->notify_all(); |
627 } | 624 } |
628 | 625 |
626 void CompileQueue::delete_all() { | |
627 assert(lock()->owned_by_self(), "must own lock"); | |
628 if (_first != NULL) { | |
629 for (CompileTask* task = _first; task != NULL; task = task->next()) { | |
630 delete task; | |
631 } | |
632 _first = NULL; | |
633 } | |
634 } | |
635 | |
629 // ------------------------------------------------------------------ | 636 // ------------------------------------------------------------------ |
630 // CompileQueue::get | 637 // CompileQueue::get |
631 // | 638 // |
632 // Get the next CompileTask from a CompileQueue | 639 // Get the next CompileTask from a CompileQueue |
633 CompileTask* CompileQueue::get() { | 640 CompileTask* CompileQueue::get() { |
634 NMethodSweeper::possibly_sweep(); | 641 NMethodSweeper::possibly_sweep(); |
635 | 642 |
636 MutexLocker locker(lock()); | 643 MutexLocker locker(lock()); |
637 // Wait for an available CompileTask. | 644 // If _first is NULL we have no more compile jobs. There are two reasons for |
645 // having no compile jobs: First, we compiled everything we wanted. Second, | |
646 // we ran out of code cache so compilation has been disabled. In the latter | |
647 // case we perform code cache sweeps to free memory such that we can re-enable | |
648 // compilation. | |
638 while (_first == NULL) { | 649 while (_first == NULL) { |
639 // There is no work to be done right now. Wait. | 650 // Exit loop if compilation is disabled forever |
640 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) { | 651 if (CompileBroker::is_compilation_disabled_forever()) { |
641 // During the emergency sweeping periods, wake up and sweep occasionally | 652 return NULL; |
642 bool timedout = lock()->wait(!Mutex::_no_safepoint_check_flag, NmethodSweepCheckInterval*1000); | 653 } |
643 if (timedout) { | 654 |
655 if (UseCodeCacheFlushing && !CompileBroker::should_compile_new_jobs()) { | |
656 // Wait a certain amount of time to possibly do another sweep. | |
657 // We must wait until stack scanning has happened so that we can | |
658 // transition a method's state from 'not_entrant' to 'zombie'. | |
659 long wait_time = NmethodSweepCheckInterval * 1000; | |
660 if (FLAG_IS_DEFAULT(NmethodSweepCheckInterval)) { | |
661 // Only one thread at a time can do sweeping. Scale the | |
662 // wait time according to the number of compiler threads. | |
663 // As a result, the next sweep is likely to happen every 100ms | |
664 // with an arbitrary number of threads that do sweeping. | |
665 wait_time = 100 * CICompilerCount; | |
666 } | |
667 bool timeout = lock()->wait(!Mutex::_no_safepoint_check_flag, wait_time); | |
668 if (timeout) { | |
644 MutexUnlocker ul(lock()); | 669 MutexUnlocker ul(lock()); |
645 // When otherwise not busy, run nmethod sweeping | |
646 NMethodSweeper::possibly_sweep(); | 670 NMethodSweeper::possibly_sweep(); |
647 } | 671 } |
648 } else { | 672 } else { |
649 // During normal operation no need to wake up on timer | 673 // If there are no compilation tasks and we can compile new jobs |
650 lock()->wait(); | 674 // (i.e., there is enough free space in the code cache) there is |
651 } | 675 // no need to invoke the sweeper. As a result, the hotness of methods |
652 } | 676 // remains unchanged. This behavior is desired, since we want to keep |
677 // the stable state, i.e., we do not want to evict methods from the | |
678 // code cache if it is unnecessary. | |
679 // We need a timed wait here, since compiler threads can exit if compilation | |
680 // is disabled forever. We use 5 seconds wait time; the exiting of compiler threads | |
681 // is not critical and we do not want idle compiler threads to wake up too often. | |
682 lock()->wait(!Mutex::_no_safepoint_check_flag, 5*1000); | |
683 } | |
684 } | |
685 | |
686 if (CompileBroker::is_compilation_disabled_forever()) { | |
687 return NULL; | |
688 } | |
689 | |
653 CompileTask* task = CompilationPolicy::policy()->select_task(this); | 690 CompileTask* task = CompilationPolicy::policy()->select_task(this); |
654 remove(task); | 691 remove(task); |
655 return task; | 692 return task; |
656 } | 693 } |
657 | 694 |
741 // | 778 // |
742 // Initialize the Compilation object | 779 // Initialize the Compilation object |
743 void CompileBroker::compilation_init() { | 780 void CompileBroker::compilation_init() { |
744 _last_method_compiled[0] = '\0'; | 781 _last_method_compiled[0] = '\0'; |
745 | 782 |
783 // No need to initialize compilation system if we do not use it. | |
784 if (!UseCompiler) { | |
785 return; | |
786 } | |
746 #ifndef SHARK | 787 #ifndef SHARK |
747 // Set the interface to the current compiler(s). | 788 // Set the interface to the current compiler(s). |
748 int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple); | 789 int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple); |
749 int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization); | 790 int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization); |
750 #ifdef COMPILER1 | 791 #ifdef COMPILER1 |
872 | 913 |
873 _initialized = true; | 914 _initialized = true; |
874 } | 915 } |
875 | 916 |
876 | 917 |
877 | 918 CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, |
878 // ------------------------------------------------------------------ | 919 AbstractCompiler* comp, TRAPS) { |
879 // CompileBroker::make_compiler_thread | |
880 CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS) { | |
881 CompilerThread* compiler_thread = NULL; | 920 CompilerThread* compiler_thread = NULL; |
882 | 921 |
883 Klass* k = | 922 Klass* k = |
884 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), | 923 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), |
885 true, CHECK_0); | 924 true, CHECK_0); |
942 os::set_native_priority(compiler_thread, native_prio); | 981 os::set_native_priority(compiler_thread, native_prio); |
943 | 982 |
944 java_lang_Thread::set_daemon(thread_oop()); | 983 java_lang_Thread::set_daemon(thread_oop()); |
945 | 984 |
946 compiler_thread->set_threadObj(thread_oop()); | 985 compiler_thread->set_threadObj(thread_oop()); |
986 compiler_thread->set_compiler(comp); | |
947 Threads::add(compiler_thread); | 987 Threads::add(compiler_thread); |
948 Thread::start(compiler_thread); | 988 Thread::start(compiler_thread); |
949 } | 989 } |
950 | 990 |
951 // Let go of Threads_lock before yielding | 991 // Let go of Threads_lock before yielding |
953 | 993 |
954 return compiler_thread; | 994 return compiler_thread; |
955 } | 995 } |
956 | 996 |
957 | 997 |
958 // ------------------------------------------------------------------ | |
959 // CompileBroker::init_compiler_threads | |
960 // | |
961 // Initialize the compilation queue | |
962 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) { | 998 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) { |
963 EXCEPTION_MARK; | 999 EXCEPTION_MARK; |
964 #if !defined(ZERO) && !defined(SHARK) && !defined(PPC64) | 1000 #if !defined(ZERO) && !defined(SHARK) && !defined(PPC64) |
965 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?"); | 1001 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?"); |
966 #endif // !ZERO && !SHARK | 1002 #endif // !ZERO && !SHARK |
1003 // Initialize the compilation queue | |
967 if (c2_compiler_count > 0) { | 1004 if (c2_compiler_count > 0) { |
968 _c2_method_queue = new CompileQueue("C2MethodQueue", MethodCompileQueue_lock); | 1005 _c2_method_queue = new CompileQueue("C2MethodQueue", MethodCompileQueue_lock); |
1006 _compilers[1]->set_num_compiler_threads(c2_compiler_count); | |
969 } | 1007 } |
970 if (c1_compiler_count > 0) { | 1008 if (c1_compiler_count > 0) { |
971 _c1_method_queue = new CompileQueue("C1MethodQueue", MethodCompileQueue_lock); | 1009 _c1_method_queue = new CompileQueue("C1MethodQueue", MethodCompileQueue_lock); |
1010 _compilers[0]->set_num_compiler_threads(c1_compiler_count); | |
972 } | 1011 } |
973 | 1012 |
974 int compiler_count = c1_compiler_count + c2_compiler_count; | 1013 int compiler_count = c1_compiler_count + c2_compiler_count; |
975 | 1014 |
976 _method_threads = | 1015 _compiler_threads = |
977 new (ResourceObj::C_HEAP, mtCompiler) GrowableArray<CompilerThread*>(compiler_count, true); | 1016 new (ResourceObj::C_HEAP, mtCompiler) GrowableArray<CompilerThread*>(compiler_count, true); |
978 | 1017 |
979 char name_buffer[256]; | 1018 char name_buffer[256]; |
980 for (int i = 0; i < c2_compiler_count; i++) { | 1019 for (int i = 0; i < c2_compiler_count; i++) { |
981 // Create a name for our thread. | 1020 // Create a name for our thread. |
982 sprintf(name_buffer, "C2 CompilerThread%d", i); | 1021 sprintf(name_buffer, "C2 CompilerThread%d", i); |
983 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); | 1022 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); |
984 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, CHECK); | 1023 // Shark and C2 |
985 _method_threads->append(new_thread); | 1024 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, _compilers[1], CHECK); |
1025 _compiler_threads->append(new_thread); | |
986 } | 1026 } |
987 | 1027 |
988 for (int i = c2_compiler_count; i < compiler_count; i++) { | 1028 for (int i = c2_compiler_count; i < compiler_count; i++) { |
989 // Create a name for our thread. | 1029 // Create a name for our thread. |
990 sprintf(name_buffer, "C1 CompilerThread%d", i); | 1030 sprintf(name_buffer, "C1 CompilerThread%d", i); |
991 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); | 1031 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); |
992 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c1_method_queue, counters, CHECK); | 1032 // C1 |
993 _method_threads->append(new_thread); | 1033 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c1_method_queue, counters, _compilers[0], CHECK); |
1034 _compiler_threads->append(new_thread); | |
994 } | 1035 } |
995 | 1036 |
996 if (UsePerfData) { | 1037 if (UsePerfData) { |
997 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, | 1038 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, compiler_count, CHECK); |
998 compiler_count, CHECK); | |
999 } | 1039 } |
1000 } | 1040 } |
1001 | 1041 |
1002 | 1042 |
1003 // Set the methods on the stack as on_stack so that redefine classes doesn't | 1043 // Set the methods on the stack as on_stack so that redefine classes doesn't |
1008 } | 1048 } |
1009 if (_c1_method_queue != NULL) { | 1049 if (_c1_method_queue != NULL) { |
1010 _c1_method_queue->mark_on_stack(); | 1050 _c1_method_queue->mark_on_stack(); |
1011 } | 1051 } |
1012 } | 1052 } |
1013 | |
1014 // ------------------------------------------------------------------ | |
1015 // CompileBroker::is_idle | |
1016 bool CompileBroker::is_idle() { | |
1017 if (_c2_method_queue != NULL && !_c2_method_queue->is_empty()) { | |
1018 return false; | |
1019 } else if (_c1_method_queue != NULL && !_c1_method_queue->is_empty()) { | |
1020 return false; | |
1021 } else { | |
1022 int num_threads = _method_threads->length(); | |
1023 for (int i=0; i<num_threads; i++) { | |
1024 if (_method_threads->at(i)->task() != NULL) { | |
1025 return false; | |
1026 } | |
1027 } | |
1028 | |
1029 // No pending or active compilations. | |
1030 return true; | |
1031 } | |
1032 } | |
1033 | |
1034 | 1053 |
1035 // ------------------------------------------------------------------ | 1054 // ------------------------------------------------------------------ |
1036 // CompileBroker::compile_method | 1055 // CompileBroker::compile_method |
1037 // | 1056 // |
1038 // Request compilation of a method. | 1057 // Request compilation of a method. |
1225 if (method_code != NULL) { | 1244 if (method_code != NULL) { |
1226 if (compilation_is_complete(method, osr_bci, comp_level)) { | 1245 if (compilation_is_complete(method, osr_bci, comp_level)) { |
1227 return method_code; | 1246 return method_code; |
1228 } | 1247 } |
1229 } | 1248 } |
1230 if (method->is_not_compilable(comp_level)) return NULL; | 1249 if (method->is_not_compilable(comp_level)) { |
1231 | 1250 return NULL; |
1232 if (UseCodeCacheFlushing) { | 1251 } |
1233 nmethod* saved = CodeCache::reanimate_saved_code(method()); | |
1234 if (saved != NULL) { | |
1235 method->set_code(method, saved); | |
1236 return saved; | |
1237 } | |
1238 } | |
1239 | |
1240 } else { | 1252 } else { |
1241 // osr compilation | 1253 // osr compilation |
1242 #ifndef TIERED | 1254 #ifndef TIERED |
1243 // seems like an assert of dubious value | 1255 // seems like an assert of dubious value |
1244 assert(comp_level == CompLevel_highest_tier, | 1256 assert(comp_level == CompLevel_highest_tier, |
1287 // a lock the compiling thread can not acquire. Prefetch it here. | 1299 // a lock the compiling thread can not acquire. Prefetch it here. |
1288 if (JvmtiExport::should_post_compiled_method_load()) { | 1300 if (JvmtiExport::should_post_compiled_method_load()) { |
1289 method->jmethod_id(); | 1301 method->jmethod_id(); |
1290 } | 1302 } |
1291 | 1303 |
1292 // If the compiler is shut off due to code cache getting full | |
1293 // fail out now so blocking compiles dont hang the java thread | |
1294 if (!should_compile_new_jobs()) { | |
1295 CompilationPolicy::policy()->delay_compilation(method()); | |
1296 return NULL; | |
1297 } | |
1298 | |
1299 // do the compilation | 1304 // do the compilation |
1300 if (method->is_native()) { | 1305 if (method->is_native()) { |
1301 if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) { | 1306 if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) { |
1302 // Acquire our lock. | 1307 // Acquire our lock. |
1303 int compile_id; | 1308 int compile_id; |
1304 { | 1309 { |
1305 MutexLocker locker(MethodCompileQueue_lock, THREAD); | 1310 MutexLocker locker(MethodCompileQueue_lock, THREAD); |
1306 compile_id = assign_compile_id(method, standard_entry_bci); | 1311 compile_id = assign_compile_id(method, standard_entry_bci); |
1307 } | 1312 } |
1313 // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that | |
1314 // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime). | |
1315 // | |
1316 // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter | |
1317 // in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls. | |
1308 (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id); | 1318 (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id); |
1309 } else { | 1319 } else { |
1310 return NULL; | 1320 return NULL; |
1311 } | 1321 } |
1312 } else { | 1322 } else { |
1323 // If the compiler is shut off due to code cache getting full | |
1324 // fail out now so blocking compiles dont hang the java thread | |
1325 if (!should_compile_new_jobs()) { | |
1326 CompilationPolicy::policy()->delay_compilation(method()); | |
1327 return NULL; | |
1328 } | |
1313 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD); | 1329 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD); |
1314 } | 1330 } |
1315 | 1331 |
1316 // return requested nmethod | 1332 // return requested nmethod |
1317 // We accept a higher level osr method | 1333 // We accept a higher level osr method |
1539 // waiting on a CompileTask, we know that no one else will | 1555 // waiting on a CompileTask, we know that no one else will |
1540 // be using this CompileTask; we can free it. | 1556 // be using this CompileTask; we can free it. |
1541 free_task(task); | 1557 free_task(task); |
1542 } | 1558 } |
1543 | 1559 |
1560 // Initialize compiler thread(s) + compiler object(s). The postcondition | |
1561 // of this function is that the compiler runtimes are initialized and that | |
1562 //compiler threads can start compiling. | |
1563 bool CompileBroker::init_compiler_runtime() { | |
1564 CompilerThread* thread = CompilerThread::current(); | |
1565 AbstractCompiler* comp = thread->compiler(); | |
1566 // Final sanity check - the compiler object must exist | |
1567 guarantee(comp != NULL, "Compiler object must exist"); | |
1568 | |
1569 int system_dictionary_modification_counter; | |
1570 { | |
1571 MutexLocker locker(Compile_lock, thread); | |
1572 system_dictionary_modification_counter = SystemDictionary::number_of_modifications(); | |
1573 } | |
1574 | |
1575 { | |
1576 // Must switch to native to allocate ci_env | |
1577 ThreadToNativeFromVM ttn(thread); | |
1578 ciEnv ci_env(NULL, system_dictionary_modification_counter); | |
1579 // Cache Jvmti state | |
1580 ci_env.cache_jvmti_state(); | |
1581 // Cache DTrace flags | |
1582 ci_env.cache_dtrace_flags(); | |
1583 | |
1584 // Switch back to VM state to do compiler initialization | |
1585 ThreadInVMfromNative tv(thread); | |
1586 ResetNoHandleMark rnhm; | |
1587 | |
1588 | |
1589 if (!comp->is_shark()) { | |
1590 // Perform per-thread and global initializations | |
1591 comp->initialize(); | |
1592 } | |
1593 } | |
1594 | |
1595 if (comp->is_failed()) { | |
1596 disable_compilation_forever(); | |
1597 // If compiler initialization failed, no compiler thread that is specific to a | |
1598 // particular compiler runtime will ever start to compile methods. | |
1599 | |
1600 shutdown_compiler_runtime(comp, thread); | |
1601 return false; | |
1602 } | |
1603 | |
1604 // C1 specific check | |
1605 if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) { | |
1606 warning("Initialization of %s thread failed (no space to run compilers)", thread->name()); | |
1607 return false; | |
1608 } | |
1609 | |
1610 return true; | |
1611 } | |
1612 | |
1613 // If C1 and/or C2 initialization failed, we shut down all compilation. | |
1614 // We do this to keep things simple. This can be changed if it ever turns out to be | |
1615 // a problem. | |
1616 void CompileBroker::shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread) { | |
1617 // Free buffer blob, if allocated | |
1618 if (thread->get_buffer_blob() != NULL) { | |
1619 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
1620 CodeCache::free(thread->get_buffer_blob()); | |
1621 } | |
1622 | |
1623 if (comp->should_perform_shutdown()) { | |
1624 // There are two reasons for shutting down the compiler | |
1625 // 1) compiler runtime initialization failed | |
1626 // 2) The code cache is full and the following flag is set: -XX:-UseCodeCacheFlushing | |
1627 warning("Shutting down compiler %s (no space to run compilers)", comp->name()); | |
1628 | |
1629 // Only one thread per compiler runtime object enters here | |
1630 // Set state to shut down | |
1631 comp->set_shut_down(); | |
1632 | |
1633 MutexLocker mu(MethodCompileQueue_lock, thread); | |
1634 CompileQueue* queue; | |
1635 if (_c1_method_queue != NULL) { | |
1636 _c1_method_queue->delete_all(); | |
1637 queue = _c1_method_queue; | |
1638 _c1_method_queue = NULL; | |
1639 delete _c1_method_queue; | |
1640 } | |
1641 | |
1642 if (_c2_method_queue != NULL) { | |
1643 _c2_method_queue->delete_all(); | |
1644 queue = _c2_method_queue; | |
1645 _c2_method_queue = NULL; | |
1646 delete _c2_method_queue; | |
1647 } | |
1648 | |
1649 // We could delete compiler runtimes also. However, there are references to | |
1650 // the compiler runtime(s) (e.g., nmethod::is_compiled_by_c1()) which then | |
1651 // fail. This can be done later if necessary. | |
1652 } | |
1653 } | |
1654 | |
1544 // ------------------------------------------------------------------ | 1655 // ------------------------------------------------------------------ |
1545 // CompileBroker::compiler_thread_loop | 1656 // CompileBroker::compiler_thread_loop |
1546 // | 1657 // |
1547 // The main loop run by a CompilerThread. | 1658 // The main loop run by a CompilerThread. |
1548 void CompileBroker::compiler_thread_loop() { | 1659 void CompileBroker::compiler_thread_loop() { |
1549 CompilerThread* thread = CompilerThread::current(); | 1660 CompilerThread* thread = CompilerThread::current(); |
1550 CompileQueue* queue = thread->queue(); | 1661 CompileQueue* queue = thread->queue(); |
1551 | |
1552 // For the thread that initializes the ciObjectFactory | 1662 // For the thread that initializes the ciObjectFactory |
1553 // this resource mark holds all the shared objects | 1663 // this resource mark holds all the shared objects |
1554 ResourceMark rm; | 1664 ResourceMark rm; |
1555 | 1665 |
1556 // First thread to get here will initialize the compiler interface | 1666 // First thread to get here will initialize the compiler interface |
1575 os::current_process_id()); | 1685 os::current_process_id()); |
1576 log->stamp(); | 1686 log->stamp(); |
1577 log->end_elem(); | 1687 log->end_elem(); |
1578 } | 1688 } |
1579 | 1689 |
1580 while (true) { | 1690 // If compiler thread/runtime initialization fails, exit the compiler thread |
1581 { | 1691 if (!init_compiler_runtime()) { |
1582 // We need this HandleMark to avoid leaking VM handles. | 1692 return; |
1583 HandleMark hm(thread); | 1693 } |
1584 | 1694 |
1585 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { | 1695 // Poll for new compilation tasks as long as the JVM runs. Compilation |
1586 // the code cache is really full | 1696 // should only be disabled if something went wrong while initializing the |
1587 handle_full_code_cache(); | 1697 // compiler runtimes. This, in turn, should not happen. The only known case |
1588 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { | 1698 // when compiler runtime initialization fails is if there is not enough free |
1589 // Attempt to start cleaning the code cache while there is still a little headroom | 1699 // space in the code cache to generate the necessary stubs, etc. |
1590 NMethodSweeper::handle_full_code_cache(false); | 1700 while (!is_compilation_disabled_forever()) { |
1701 // We need this HandleMark to avoid leaking VM handles. | |
1702 HandleMark hm(thread); | |
1703 | |
1704 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { | |
1705 // the code cache is really full | |
1706 handle_full_code_cache(); | |
1707 } | |
1708 | |
1709 CompileTask* task = queue->get(); | |
1710 if (task == NULL) { | |
1711 continue; | |
1712 } | |
1713 | |
1714 // Give compiler threads an extra quanta. They tend to be bursty and | |
1715 // this helps the compiler to finish up the job. | |
1716 if( CompilerThreadHintNoPreempt ) | |
1717 os::hint_no_preempt(); | |
1718 | |
1719 // trace per thread time and compile statistics | |
1720 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); | |
1721 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); | |
1722 | |
1723 // Assign the task to the current thread. Mark this compilation | |
1724 // thread as active for the profiler. | |
1725 CompileTaskWrapper ctw(task); | |
1726 nmethodLocker result_handle; // (handle for the nmethod produced by this task) | |
1727 task->set_code_handle(&result_handle); | |
1728 methodHandle method(thread, task->method()); | |
1729 | |
1730 // Never compile a method if breakpoints are present in it | |
1731 if (method()->number_of_breakpoints() == 0) { | |
1732 // Compile the method. | |
1733 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { | |
1734 #ifdef COMPILER1 | |
1735 // Allow repeating compilations for the purpose of benchmarking | |
1736 // compile speed. This is not useful for customers. | |
1737 if (CompilationRepeat != 0) { | |
1738 int compile_count = CompilationRepeat; | |
1739 while (compile_count > 0) { | |
1740 invoke_compiler_on_method(task); | |
1741 nmethod* nm = method->code(); | |
1742 if (nm != NULL) { | |
1743 nm->make_zombie(); | |
1744 method->clear_code(); | |
1745 } | |
1746 compile_count--; | |
1747 } | |
1748 } | |
1749 #endif /* COMPILER1 */ | |
1750 invoke_compiler_on_method(task); | |
1751 } else { | |
1752 // After compilation is disabled, remove remaining methods from queue | |
1753 method->clear_queued_for_compilation(); | |
1591 } | 1754 } |
1592 | 1755 } |
1593 CompileTask* task = queue->get(); | 1756 } |
1594 | 1757 |
1595 // Give compiler threads an extra quanta. They tend to be bursty and | 1758 // Shut down compiler runtime |
1596 // this helps the compiler to finish up the job. | 1759 shutdown_compiler_runtime(thread->compiler(), thread); |
1597 if( CompilerThreadHintNoPreempt ) | 1760 } |
1598 os::hint_no_preempt(); | |
1599 | |
1600 // trace per thread time and compile statistics | |
1601 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); | |
1602 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); | |
1603 | |
1604 // Assign the task to the current thread. Mark this compilation | |
1605 // thread as active for the profiler. | |
1606 CompileTaskWrapper ctw(task); | |
1607 nmethodLocker result_handle; // (handle for the nmethod produced by this task) | |
1608 task->set_code_handle(&result_handle); | |
1609 methodHandle method(thread, task->method()); | |
1610 | |
1611 // Never compile a method if breakpoints are present in it | |
1612 if (method()->number_of_breakpoints() == 0) { | |
1613 // Compile the method. | |
1614 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { | |
1615 #ifdef COMPILER1 | |
1616 // Allow repeating compilations for the purpose of benchmarking | |
1617 // compile speed. This is not useful for customers. | |
1618 if (CompilationRepeat != 0) { | |
1619 int compile_count = CompilationRepeat; | |
1620 while (compile_count > 0) { | |
1621 invoke_compiler_on_method(task); | |
1622 nmethod* nm = method->code(); | |
1623 if (nm != NULL) { | |
1624 nm->make_zombie(); | |
1625 method->clear_code(); | |
1626 } | |
1627 compile_count--; | |
1628 } | |
1629 } | |
1630 #endif /* COMPILER1 */ | |
1631 invoke_compiler_on_method(task); | |
1632 } else { | |
1633 // After compilation is disabled, remove remaining methods from queue | |
1634 method->clear_queued_for_compilation(); | |
1635 } | |
1636 } | |
1637 } | |
1638 } | |
1639 } | |
1640 | |
1641 | 1761 |
1642 // ------------------------------------------------------------------ | 1762 // ------------------------------------------------------------------ |
1643 // CompileBroker::init_compiler_thread_log | 1763 // CompileBroker::init_compiler_thread_log |
1644 // | 1764 // |
1645 // Set up state required by +LogCompilation. | 1765 // Set up state required by +LogCompilation. |
1716 { | 1836 { |
1717 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | 1837 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
1718 CodeCache::print_summary(&s, detailed); | 1838 CodeCache::print_summary(&s, detailed); |
1719 } | 1839 } |
1720 ttyLocker ttyl; | 1840 ttyLocker ttyl; |
1721 tty->print_cr(s.as_string()); | 1841 tty->print(s.as_string()); |
1722 } | 1842 } |
1723 | 1843 |
1724 // ------------------------------------------------------------------ | 1844 // ------------------------------------------------------------------ |
1725 // CompileBroker::invoke_compiler_on_method | 1845 // CompileBroker::invoke_compiler_on_method |
1726 // | 1846 // |
1941 exit_globals(); // will delete tty | 2061 exit_globals(); // will delete tty |
1942 vm_direct_exit(CompileTheWorld ? 0 : 1); | 2062 vm_direct_exit(CompileTheWorld ? 0 : 1); |
1943 } | 2063 } |
1944 #endif | 2064 #endif |
1945 if (UseCodeCacheFlushing) { | 2065 if (UseCodeCacheFlushing) { |
1946 NMethodSweeper::handle_full_code_cache(true); | 2066 // Since code cache is full, immediately stop new compiles |
2067 if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) { | |
2068 NMethodSweeper::log_sweep("disable_compiler"); | |
2069 | |
2070 // Switch to 'vm_state'. This ensures that possibly_sweep() can be called | |
2071 // without having to consider the state in which the current thread is. | |
2072 ThreadInVMfromUnknown in_vm; | |
2073 NMethodSweeper::possibly_sweep(); | |
2074 } | |
1947 } else { | 2075 } else { |
1948 UseCompiler = false; | 2076 disable_compilation_forever(); |
1949 AlwaysCompileLoopMethods = false; | |
1950 } | 2077 } |
1951 } | 2078 } |
1952 codecache_print(/* detailed= */ true); | 2079 codecache_print(/* detailed= */ true); |
1953 } | 2080 } |
1954 | 2081 |