comparison src/share/vm/compiler/compileBroker.cpp @ 13086:096c224171c4

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 20 Nov 2013 00:10:38 +0100
parents f6c511451e4a 78da3894b86f
children 77fbf02f701c
comparison
equal deleted inserted replaced
12782:92b7ec34ddfa 13086:096c224171c4
127 127
128 #endif // ndef DTRACE_ENABLED 128 #endif // ndef DTRACE_ENABLED
129 129
130 bool CompileBroker::_initialized = false; 130 bool CompileBroker::_initialized = false;
131 volatile bool CompileBroker::_should_block = false; 131 volatile bool CompileBroker::_should_block = false;
132 volatile jint CompileBroker::_print_compilation_warning = 0;
132 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation; 133 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
133 134
134 // The installed compiler(s) 135 // The installed compiler(s)
135 AbstractCompiler* CompileBroker::_compilers[2]; 136 AbstractCompiler* CompileBroker::_compilers[2];
136 137
187 188
188 CompileQueue* CompileBroker::_c2_method_queue = NULL; 189 CompileQueue* CompileBroker::_c2_method_queue = NULL;
189 CompileQueue* CompileBroker::_c1_method_queue = NULL; 190 CompileQueue* CompileBroker::_c1_method_queue = NULL;
190 CompileTask* CompileBroker::_task_free_list = NULL; 191 CompileTask* CompileBroker::_task_free_list = NULL;
191 192
192 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; 193 GrowableArray<CompilerThread*>* CompileBroker::_compiler_threads = NULL;
193 194
194 195
195 class CompilationLog : public StringEventLog { 196 class CompilationLog : public StringEventLog {
196 public: 197 public:
197 CompilationLog() : StringEventLog("Compilation events") { 198 CompilationLog() : StringEventLog("Compilation events") {
588 log->mark_file_end(); 589 log->mark_file_end();
589 } 590 }
590 591
591 592
592 593
593 // ------------------------------------------------------------------
594 // CompileQueue::add
595 //
596 // Add a CompileTask to a CompileQueue 594 // Add a CompileTask to a CompileQueue
597 void CompileQueue::add(CompileTask* task) { 595 void CompileQueue::add(CompileTask* task) {
598 assert(lock()->owned_by_self(), "must own lock"); 596 assert(lock()->owned_by_self(), "must own lock");
599 597
600 task->set_next(NULL); 598 task->set_next(NULL);
627 625
628 // Notify CompilerThreads that a task is available. 626 // Notify CompilerThreads that a task is available.
629 lock()->notify_all(); 627 lock()->notify_all();
630 } 628 }
631 629
630 void CompileQueue::delete_all() {
631 assert(lock()->owned_by_self(), "must own lock");
632 if (_first != NULL) {
633 for (CompileTask* task = _first; task != NULL; task = task->next()) {
634 delete task;
635 }
636 _first = NULL;
637 }
638 }
639
632 // ------------------------------------------------------------------ 640 // ------------------------------------------------------------------
633 // CompileQueue::get 641 // CompileQueue::get
634 // 642 //
635 // Get the next CompileTask from a CompileQueue 643 // Get the next CompileTask from a CompileQueue
636 CompileTask* CompileQueue::get() { 644 CompileTask* CompileQueue::get() {
641 // having no compile jobs: First, we compiled everything we wanted. Second, 649 // having no compile jobs: First, we compiled everything we wanted. Second,
642 // we ran out of code cache so compilation has been disabled. In the latter 650 // we ran out of code cache so compilation has been disabled. In the latter
643 // case we perform code cache sweeps to free memory such that we can re-enable 651 // case we perform code cache sweeps to free memory such that we can re-enable
644 // compilation. 652 // compilation.
645 while (_first == NULL) { 653 while (_first == NULL) {
654 // Exit loop if compilation is disabled forever
655 if (CompileBroker::is_compilation_disabled_forever()) {
656 return NULL;
657 }
658
646 if (UseCodeCacheFlushing && !CompileBroker::should_compile_new_jobs()) { 659 if (UseCodeCacheFlushing && !CompileBroker::should_compile_new_jobs()) {
647 // Wait a certain amount of time to possibly do another sweep. 660 // Wait a certain amount of time to possibly do another sweep.
648 // We must wait until stack scanning has happened so that we can 661 // We must wait until stack scanning has happened so that we can
649 // transition a method's state from 'not_entrant' to 'zombie'. 662 // transition a method's state from 'not_entrant' to 'zombie'.
650 long wait_time = NmethodSweepCheckInterval * 1000; 663 long wait_time = NmethodSweepCheckInterval * 1000;
665 // (i.e., there is enough free space in the code cache) there is 678 // (i.e., there is enough free space in the code cache) there is
666 // no need to invoke the sweeper. As a result, the hotness of methods 679 // no need to invoke the sweeper. As a result, the hotness of methods
667 // remains unchanged. This behavior is desired, since we want to keep 680 // remains unchanged. This behavior is desired, since we want to keep
668 // the stable state, i.e., we do not want to evict methods from the 681 // the stable state, i.e., we do not want to evict methods from the
669 // code cache if it is unnecessary. 682 // code cache if it is unnecessary.
670 lock()->wait(); 683 // We need a timed wait here, since compiler threads can exit if compilation
671 } 684 // is disabled forever. We use 5 seconds wait time; the exiting of compiler threads
672 } 685 // is not critical and we do not want idle compiler threads to wake up too often.
686 lock()->wait(!Mutex::_no_safepoint_check_flag, 5*1000);
687 }
688 }
689
690 if (CompileBroker::is_compilation_disabled_forever()) {
691 return NULL;
692 }
693
673 CompileTask* task = CompilationPolicy::policy()->select_task(this); 694 CompileTask* task = CompilationPolicy::policy()->select_task(this);
674 remove(task); 695 remove(task);
675 return task; 696 return task;
676 } 697 }
677 698
761 // 782 //
762 // Initialize the Compilation object 783 // Initialize the Compilation object
763 void CompileBroker::compilation_init() { 784 void CompileBroker::compilation_init() {
764 _last_method_compiled[0] = '\0'; 785 _last_method_compiled[0] = '\0';
765 786
787 // No need to initialize compilation system if we do not use it.
788 if (!UseCompiler) {
789 return;
790 }
766 #ifndef SHARK 791 #ifndef SHARK
767 // Set the interface to the current compiler(s). 792 // Set the interface to the current compiler(s).
768 int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple); 793 int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
769 int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization); 794 int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
770 #ifdef GRAAL 795 #ifdef GRAAL
900 925
901 _initialized = true; 926 _initialized = true;
902 } 927 }
903 928
904 929
905 930 CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters,
906 // ------------------------------------------------------------------ 931 AbstractCompiler* comp, TRAPS) {
907 // CompileBroker::make_compiler_thread
908 CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS) {
909 CompilerThread* compiler_thread = NULL; 932 CompilerThread* compiler_thread = NULL;
910 933
911 Klass* k = 934 Klass* k =
912 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), 935 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(),
913 true, CHECK_0); 936 true, CHECK_0);
970 os::set_native_priority(compiler_thread, native_prio); 993 os::set_native_priority(compiler_thread, native_prio);
971 994
972 java_lang_Thread::set_daemon(thread_oop()); 995 java_lang_Thread::set_daemon(thread_oop());
973 996
974 compiler_thread->set_threadObj(thread_oop()); 997 compiler_thread->set_threadObj(thread_oop());
998 compiler_thread->set_compiler(comp);
975 Threads::add(compiler_thread); 999 Threads::add(compiler_thread);
976 Thread::start(compiler_thread); 1000 Thread::start(compiler_thread);
977 } 1001 }
978 1002
979 // Let go of Threads_lock before yielding 1003 // Let go of Threads_lock before yielding
981 1005
982 return compiler_thread; 1006 return compiler_thread;
983 } 1007 }
984 1008
985 1009
986 // ------------------------------------------------------------------
987 // CompileBroker::init_compiler_threads
988 //
989 // Initialize the compilation queue
990 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) { 1010 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) {
991 EXCEPTION_MARK; 1011 EXCEPTION_MARK;
992 #if !defined(ZERO) && !defined(SHARK) && !defined(GRAALVM) 1012 #if !defined(ZERO) && !defined(SHARK) && !defined(GRAALVM)
993 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?"); 1013 assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
994 #endif // !ZERO && !SHARK && !GRAALVM 1014 #endif // !ZERO && !SHARK && !GRAALVM
1015 // Initialize the compilation queue
995 if (c2_compiler_count > 0) { 1016 if (c2_compiler_count > 0) {
996 _c2_method_queue = new CompileQueue("C2MethodQueue", MethodCompileQueue_lock); 1017 _c2_method_queue = new CompileQueue("C2MethodQueue", MethodCompileQueue_lock);
1018 _compilers[1]->set_num_compiler_threads(c2_compiler_count);
997 } 1019 }
998 if (c1_compiler_count > 0) { 1020 if (c1_compiler_count > 0) {
999 _c1_method_queue = new CompileQueue("C1MethodQueue", MethodCompileQueue_lock); 1021 _c1_method_queue = new CompileQueue("C1MethodQueue", MethodCompileQueue_lock);
1022 _compilers[0]->set_num_compiler_threads(c1_compiler_count);
1000 } 1023 }
1001 1024
1002 int compiler_count = c1_compiler_count + c2_compiler_count; 1025 int compiler_count = c1_compiler_count + c2_compiler_count;
1003 1026
1004 _method_threads = 1027 _compiler_threads =
1005 new (ResourceObj::C_HEAP, mtCompiler) GrowableArray<CompilerThread*>(compiler_count, true); 1028 new (ResourceObj::C_HEAP, mtCompiler) GrowableArray<CompilerThread*>(compiler_count, true);
1006 1029
1007 char name_buffer[256]; 1030 char name_buffer[256];
1008 for (int i = 0; i < c2_compiler_count; i++) { 1031 for (int i = 0; i < c2_compiler_count; i++) {
1009 // Create a name for our thread. 1032 // Create a name for our thread.
1010 sprintf(name_buffer, "C2 CompilerThread%d", i); 1033 sprintf(name_buffer, "C2 CompilerThread%d", i);
1011 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); 1034 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
1012 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, CHECK); 1035 // Shark and C2
1013 _method_threads->append(new_thread); 1036 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, _compilers[1], CHECK);
1037 _compiler_threads->append(new_thread);
1014 } 1038 }
1015 1039
1016 for (int i = c2_compiler_count; i < compiler_count; i++) { 1040 for (int i = c2_compiler_count; i < compiler_count; i++) {
1017 // Create a name for our thread. 1041 // Create a name for our thread.
1018 sprintf(name_buffer, "C1 CompilerThread%d", i); 1042 sprintf(name_buffer, "C1 CompilerThread%d", i);
1019 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); 1043 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
1020 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c1_method_queue, counters, CHECK); 1044 // C1
1021 _method_threads->append(new_thread); 1045 CompilerThread* new_thread = make_compiler_thread(name_buffer, _c1_method_queue, counters, _compilers[0], CHECK);
1046 _compiler_threads->append(new_thread);
1022 } 1047 }
1023 1048
1024 if (UsePerfData) { 1049 if (UsePerfData) {
1025 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, 1050 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, compiler_count, CHECK);
1026 compiler_count, CHECK);
1027 } 1051 }
1028 } 1052 }
1029 1053
1030 1054
1031 // Set the methods on the stack as on_stack so that redefine classes doesn't 1055 // Set the methods on the stack as on_stack so that redefine classes doesn't
1036 } 1060 }
1037 if (_c1_method_queue != NULL) { 1061 if (_c1_method_queue != NULL) {
1038 _c1_method_queue->mark_on_stack(); 1062 _c1_method_queue->mark_on_stack();
1039 } 1063 }
1040 } 1064 }
1041
1042 // ------------------------------------------------------------------
1043 // CompileBroker::is_idle
1044 bool CompileBroker::is_idle() {
1045 if (_c2_method_queue != NULL && !_c2_method_queue->is_empty()) {
1046 return false;
1047 } else if (_c1_method_queue != NULL && !_c1_method_queue->is_empty()) {
1048 return false;
1049 } else {
1050 int num_threads = _method_threads->length();
1051 for (int i=0; i<num_threads; i++) {
1052 if (_method_threads->at(i)->task() != NULL) {
1053 return false;
1054 }
1055 }
1056
1057 // No pending or active compilations.
1058 return true;
1059 }
1060 }
1061
1062 1065
1063 // ------------------------------------------------------------------ 1066 // ------------------------------------------------------------------
1064 // CompileBroker::compile_method 1067 // CompileBroker::compile_method
1065 // 1068 //
1066 // Request compilation of a method. 1069 // Request compilation of a method.
1138 // by a compiler thread), and compiled method registration. 1141 // by a compiler thread), and compiled method registration.
1139 if (InstanceRefKlass::owns_pending_list_lock(JavaThread::current())) { 1142 if (InstanceRefKlass::owns_pending_list_lock(JavaThread::current())) {
1140 return; 1143 return;
1141 } 1144 }
1142 #ifdef GRAALVM 1145 #ifdef GRAALVM
1143 if (!JavaThread::current()->is_compiling()) { 1146 // Detect recursive request in Java
1144 GraalCompiler::instance()->compile_method(method, osr_bci, is_compile_blocking(method, osr_bci)); 1147 GraalCompiler::instance()->compile_method(method, osr_bci, is_compile_blocking(method, osr_bci));
1145 } else {
1146 // Recursive compile request => ignore.
1147 }
1148 #else 1148 #else
1149 1149
1150 // Outputs from the following MutexLocker block: 1150 // Outputs from the following MutexLocker block:
1151 CompileTask* task = NULL; 1151 CompileTask* task = NULL;
1152 bool blocking = false; 1152 bool blocking = false;
1316 // a lock the compiling thread can not acquire. Prefetch it here. 1316 // a lock the compiling thread can not acquire. Prefetch it here.
1317 if (JvmtiExport::should_post_compiled_method_load()) { 1317 if (JvmtiExport::should_post_compiled_method_load()) {
1318 method->jmethod_id(); 1318 method->jmethod_id();
1319 } 1319 }
1320 1320
1321 // If the compiler is shut off due to code cache getting full
1322 // fail out now so blocking compiles dont hang the java thread
1323 if (!should_compile_new_jobs()) {
1324 CompilationPolicy::policy()->delay_compilation(method());
1325 return NULL;
1326 }
1327
1328 // do the compilation 1321 // do the compilation
1329 if (method->is_native()) { 1322 if (method->is_native()) {
1330 if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) { 1323 if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {
1331 // Acquire our lock. 1324 // Acquire our lock.
1332 int compile_id; 1325 int compile_id;
1333 { 1326 {
1334 MutexLocker locker(MethodCompileQueue_lock, THREAD); 1327 MutexLocker locker(MethodCompileQueue_lock, THREAD);
1335 compile_id = assign_compile_id(method, standard_entry_bci); 1328 compile_id = assign_compile_id(method, standard_entry_bci);
1336 } 1329 }
1330 // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
1331 // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1332 //
1333 // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1334 // in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls.
1337 (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id); 1335 (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id);
1338 } else { 1336 } else {
1339 return NULL; 1337 return NULL;
1340 } 1338 }
1341 } else { 1339 } else {
1340 // If the compiler is shut off due to code cache getting full
1341 // fail out now so blocking compiles dont hang the java thread
1342 if (!should_compile_new_jobs()) {
1343 CompilationPolicy::policy()->delay_compilation(method());
1344 return NULL;
1345 }
1342 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD); 1346 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD);
1343 } 1347 }
1344 1348
1345 // return requested nmethod 1349 // return requested nmethod
1346 // We accept a higher level osr method 1350 // We accept a higher level osr method
1568 // waiting on a CompileTask, we know that no one else will 1572 // waiting on a CompileTask, we know that no one else will
1569 // be using this CompileTask; we can free it. 1573 // be using this CompileTask; we can free it.
1570 free_task(task); 1574 free_task(task);
1571 } 1575 }
1572 1576
1577 // Initialize compiler thread(s) + compiler object(s). The postcondition
1578 // of this function is that the compiler runtimes are initialized and that
1579 //compiler threads can start compiling.
1580 bool CompileBroker::init_compiler_runtime() {
1581 CompilerThread* thread = CompilerThread::current();
1582 AbstractCompiler* comp = thread->compiler();
1583 // Final sanity check - the compiler object must exist
1584 guarantee(comp != NULL, "Compiler object must exist");
1585
1586 int system_dictionary_modification_counter;
1587 {
1588 MutexLocker locker(Compile_lock, thread);
1589 system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1590 }
1591
1592 {
1593 // Must switch to native to allocate ci_env
1594 ThreadToNativeFromVM ttn(thread);
1595 ciEnv ci_env(NULL, system_dictionary_modification_counter);
1596 // Cache Jvmti state
1597 ci_env.cache_jvmti_state();
1598 // Cache DTrace flags
1599 ci_env.cache_dtrace_flags();
1600
1601 // Switch back to VM state to do compiler initialization
1602 ThreadInVMfromNative tv(thread);
1603 ResetNoHandleMark rnhm;
1604
1605
1606 if (!comp->is_shark()) {
1607 // Perform per-thread and global initializations
1608 comp->initialize();
1609 }
1610 }
1611
1612 if (comp->is_failed()) {
1613 disable_compilation_forever();
1614 // If compiler initialization failed, no compiler thread that is specific to a
1615 // particular compiler runtime will ever start to compile methods.
1616
1617 shutdown_compiler_runtime(comp, thread);
1618 return false;
1619 }
1620
1621 // C1 specific check
1622 if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1623 warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1624 return false;
1625 }
1626
1627 return true;
1628 }
1629
1630 // If C1 and/or C2 initialization failed, we shut down all compilation.
1631 // We do this to keep things simple. This can be changed if it ever turns out to be
1632 // a problem.
1633 void CompileBroker::shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread) {
1634 // Free buffer blob, if allocated
1635 if (thread->get_buffer_blob() != NULL) {
1636 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1637 CodeCache::free(thread->get_buffer_blob());
1638 }
1639
1640 if (comp->should_perform_shutdown()) {
1641 // There are two reasons for shutting down the compiler
1642 // 1) compiler runtime initialization failed
1643 // 2) The code cache is full and the following flag is set: -XX:-UseCodeCacheFlushing
1644 warning("Shutting down compiler %s (no space to run compilers)", comp->name());
1645
1646 // Only one thread per compiler runtime object enters here
1647 // Set state to shut down
1648 comp->set_shut_down();
1649
1650 MutexLocker mu(MethodCompileQueue_lock, thread);
1651 CompileQueue* queue;
1652 if (_c1_method_queue != NULL) {
1653 _c1_method_queue->delete_all();
1654 queue = _c1_method_queue;
1655 _c1_method_queue = NULL;
1656 delete _c1_method_queue;
1657 }
1658
1659 if (_c2_method_queue != NULL) {
1660 _c2_method_queue->delete_all();
1661 queue = _c2_method_queue;
1662 _c2_method_queue = NULL;
1663 delete _c2_method_queue;
1664 }
1665
1666 // We could delete compiler runtimes also. However, there are references to
1667 // the compiler runtime(s) (e.g., nmethod::is_compiled_by_c1()) which then
1668 // fail. This can be done later if necessary.
1669 }
1670 }
1671
1573 // ------------------------------------------------------------------ 1672 // ------------------------------------------------------------------
1574 // CompileBroker::compiler_thread_loop 1673 // CompileBroker::compiler_thread_loop
1575 // 1674 //
1576 // The main loop run by a CompilerThread. 1675 // The main loop run by a CompilerThread.
1577 void CompileBroker::compiler_thread_loop() { 1676 void CompileBroker::compiler_thread_loop() {
1578 CompilerThread* thread = CompilerThread::current(); 1677 CompilerThread* thread = CompilerThread::current();
1579 CompileQueue* queue = thread->queue(); 1678 CompileQueue* queue = thread->queue();
1580
1581 // For the thread that initializes the ciObjectFactory 1679 // For the thread that initializes the ciObjectFactory
1582 // this resource mark holds all the shared objects 1680 // this resource mark holds all the shared objects
1583 ResourceMark rm; 1681 ResourceMark rm;
1584 1682
1585 // First thread to get here will initialize the compiler interface 1683 // First thread to get here will initialize the compiler interface
1604 os::current_process_id()); 1702 os::current_process_id());
1605 log->stamp(); 1703 log->stamp();
1606 log->end_elem(); 1704 log->end_elem();
1607 } 1705 }
1608 1706
1609 while (true) { 1707 // If compiler thread/runtime initialization fails, exit the compiler thread
1610 { 1708 if (!init_compiler_runtime()) {
1611 // We need this HandleMark to avoid leaking VM handles. 1709 return;
1612 HandleMark hm(thread); 1710 }
1613 1711
1614 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { 1712 // Poll for new compilation tasks as long as the JVM runs. Compilation
1615 // the code cache is really full 1713 // should only be disabled if something went wrong while initializing the
1616 handle_full_code_cache(); 1714 // compiler runtimes. This, in turn, should not happen. The only known case
1715 // when compiler runtime initialization fails is if there is not enough free
1716 // space in the code cache to generate the necessary stubs, etc.
1717 while (!is_compilation_disabled_forever()) {
1718 // We need this HandleMark to avoid leaking VM handles.
1719 HandleMark hm(thread);
1720
1721 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
1722 // the code cache is really full
1723 handle_full_code_cache();
1724 }
1725
1726 CompileTask* task = queue->get();
1727 if (task == NULL) {
1728 continue;
1729 }
1730
1731 // Give compiler threads an extra quanta. They tend to be bursty and
1732 // this helps the compiler to finish up the job.
1733 if( CompilerThreadHintNoPreempt )
1734 os::hint_no_preempt();
1735
1736 // trace per thread time and compile statistics
1737 CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1738 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1739
1740 // Assign the task to the current thread. Mark this compilation
1741 // thread as active for the profiler.
1742 CompileTaskWrapper ctw(task);
1743 nmethodLocker result_handle; // (handle for the nmethod produced by this task)
1744 task->set_code_handle(&result_handle);
1745 methodHandle method(thread, task->method());
1746
1747 // Never compile a method if breakpoints are present in it
1748 if (method()->number_of_breakpoints() == 0) {
1749 // Compile the method.
1750 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
1751 #ifdef COMPILER1
1752 // Allow repeating compilations for the purpose of benchmarking
1753 // compile speed. This is not useful for customers.
1754 if (CompilationRepeat != 0) {
1755 int compile_count = CompilationRepeat;
1756 while (compile_count > 0) {
1757 invoke_compiler_on_method(task);
1758 nmethod* nm = method->code();
1759 if (nm != NULL) {
1760 nm->make_zombie();
1761 method->clear_code();
1762 }
1763 compile_count--;
1764 }
1765 }
1766 #endif /* COMPILER1 */
1767 invoke_compiler_on_method(task);
1768 } else {
1769 // After compilation is disabled, remove remaining methods from queue
1770 method->clear_queued_for_compilation();
1617 } 1771 }
1618 1772 }
1619 CompileTask* task = queue->get(); 1773 }
1620 1774
1621 // Give compiler threads an extra quanta. They tend to be bursty and 1775 // Shut down compiler runtime
1622 // this helps the compiler to finish up the job. 1776 shutdown_compiler_runtime(thread->compiler(), thread);
1623 if( CompilerThreadHintNoPreempt ) 1777 }
1624 os::hint_no_preempt();
1625
1626 // trace per thread time and compile statistics
1627 CompilerCounters* counters = ((CompilerThread*)thread)->counters();
1628 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
1629
1630 // Assign the task to the current thread. Mark this compilation
1631 // thread as active for the profiler.
1632 CompileTaskWrapper ctw(task);
1633 nmethodLocker result_handle; // (handle for the nmethod produced by this task)
1634 task->set_code_handle(&result_handle);
1635 methodHandle method(thread, task->method());
1636
1637 // Never compile a method if breakpoints are present in it
1638 if (method()->number_of_breakpoints() == 0) {
1639 // Compile the method.
1640 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
1641 #ifdef COMPILER1
1642 // Allow repeating compilations for the purpose of benchmarking
1643 // compile speed. This is not useful for customers.
1644 if (CompilationRepeat != 0) {
1645 int compile_count = CompilationRepeat;
1646 while (compile_count > 0) {
1647 invoke_compiler_on_method(task);
1648 nmethod* nm = method->code();
1649 if (nm != NULL) {
1650 nm->make_zombie();
1651 method->clear_code();
1652 }
1653 compile_count--;
1654 }
1655 }
1656 #endif /* COMPILER1 */
1657 invoke_compiler_on_method(task);
1658 } else {
1659 // After compilation is disabled, remove remaining methods from queue
1660 method->clear_queued_for_compilation();
1661 }
1662 }
1663 }
1664 }
1665 }
1666
1667 1778
1668 // ------------------------------------------------------------------ 1779 // ------------------------------------------------------------------
1669 // CompileBroker::init_compiler_thread_log 1780 // CompileBroker::init_compiler_thread_log
1670 // 1781 //
1671 // Set up state required by +LogCompilation. 1782 // Set up state required by +LogCompilation.
1931 vm_exit(0); 2042 vm_exit(0);
1932 } 2043 }
1933 #endif 2044 #endif
1934 } 2045 }
1935 2046
1936 // ------------------------------------------------------------------ 2047 /**
1937 // CompileBroker::handle_full_code_cache 2048 * The CodeCache is full. Print out warning and disable compilation
1938 // 2049 * or try code cache cleaning so compilation can continue later.
1939 // The CodeCache is full. Print out warning and disable compilation or 2050 */
1940 // try code cache cleaning so compilation can continue later.
1941 void CompileBroker::handle_full_code_cache() { 2051 void CompileBroker::handle_full_code_cache() {
1942 UseInterpreter = true; 2052 UseInterpreter = true;
1943 if (UseCompiler || AlwaysCompileLoopMethods ) { 2053 if (UseCompiler || AlwaysCompileLoopMethods ) {
1944 if (xtty != NULL) { 2054 if (xtty != NULL) {
1945 ResourceMark rm; 2055 ResourceMark rm;
1952 xtty->begin_elem("code_cache_full"); 2062 xtty->begin_elem("code_cache_full");
1953 xtty->print(s.as_string()); 2063 xtty->print(s.as_string());
1954 xtty->stamp(); 2064 xtty->stamp();
1955 xtty->end_elem(); 2065 xtty->end_elem();
1956 } 2066 }
1957 warning("CodeCache is full. Compiler has been disabled.");
1958 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
1959 2067
1960 CodeCache::report_codemem_full(); 2068 CodeCache::report_codemem_full();
1961
1962 2069
1963 #ifndef PRODUCT 2070 #ifndef PRODUCT
1964 if (CompileTheWorld || ExitOnFullCodeCache) { 2071 if (CompileTheWorld || ExitOnFullCodeCache) {
1965 codecache_print(/* detailed= */ true); 2072 codecache_print(/* detailed= */ true);
1966 before_exit(JavaThread::current()); 2073 before_exit(JavaThread::current());
1970 #endif 2077 #endif
1971 if (UseCodeCacheFlushing) { 2078 if (UseCodeCacheFlushing) {
1972 // Since code cache is full, immediately stop new compiles 2079 // Since code cache is full, immediately stop new compiles
1973 if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) { 2080 if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) {
1974 NMethodSweeper::log_sweep("disable_compiler"); 2081 NMethodSweeper::log_sweep("disable_compiler");
1975 NMethodSweeper::possibly_sweep();
1976 } 2082 }
2083 // Switch to 'vm_state'. This ensures that possibly_sweep() can be called
2084 // without having to consider the state in which the current thread is.
2085 ThreadInVMfromUnknown in_vm;
2086 NMethodSweeper::possibly_sweep();
1977 } else { 2087 } else {
1978 UseCompiler = false; 2088 disable_compilation_forever();
1979 AlwaysCompileLoopMethods = false; 2089 }
1980 } 2090
1981 } 2091 // Print warning only once
1982 codecache_print(/* detailed= */ true); 2092 if (should_print_compiler_warning()) {
2093 warning("CodeCache is full. Compiler has been disabled.");
2094 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
2095 codecache_print(/* detailed= */ true);
2096 }
2097 }
1983 } 2098 }
1984 2099
1985 // ------------------------------------------------------------------ 2100 // ------------------------------------------------------------------
1986 // CompileBroker::set_last_compile 2101 // CompileBroker::set_last_compile
1987 // 2102 //