Mercurial > hg > graal-compiler
comparison src/share/vm/compiler/compileBroker.cpp @ 4139:feb590a8497f
remove pollJavaQueue and related functionality, minimize diff against HotSpot in the compileBroker.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 18 Dec 2011 00:41:15 +0100 |
parents | 04b9a2566eec |
children | 3c21eee8ab4d |
comparison
equal
deleted
inserted
replaced
4138:82af018d61db | 4139:feb590a8497f |
---|---|
187 CompileQueue* CompileBroker::_c1_method_queue = NULL; | 187 CompileQueue* CompileBroker::_c1_method_queue = NULL; |
188 CompileTask* CompileBroker::_task_free_list = NULL; | 188 CompileTask* CompileBroker::_task_free_list = NULL; |
189 | 189 |
190 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; | 190 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; |
191 | 191 |
192 bool CompileBroker::_poll_java_queue = false; | |
193 | 192 |
194 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { | 193 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { |
195 CompilerThread* thread = CompilerThread::current(); | 194 CompilerThread* thread = CompilerThread::current(); |
196 thread->set_task(task); | 195 thread->set_task(task); |
197 CompileLog* log = thread->log(); | 196 CompileLog* log = thread->log(); |
572 | 571 |
573 // ------------------------------------------------------------------ | 572 // ------------------------------------------------------------------ |
574 // CompileQueue::get | 573 // CompileQueue::get |
575 // | 574 // |
576 // Get the next CompileTask from a CompileQueue | 575 // Get the next CompileTask from a CompileQueue |
577 CompileTask* CompileQueue::get(bool& interrupt) { | 576 CompileTask* CompileQueue::get() { |
578 NMethodSweeper::possibly_sweep(); | 577 NMethodSweeper::possibly_sweep(); |
579 | 578 |
580 MutexLocker locker(lock()); | 579 MutexLocker locker(lock()); |
581 // Wait for an available CompileTask. | 580 // Wait for an available CompileTask. |
582 while (_first == NULL) { | 581 while (_first == NULL) { |
583 if (interrupt) { | |
584 return NULL; | |
585 } | |
586 // There is no work to be done right now. Wait. | 582 // There is no work to be done right now. Wait. |
587 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) { | 583 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) { |
588 // During the emergency sweeping periods, wake up and sweep occasionally | 584 // During the emergency sweeping periods, wake up and sweep occasionally |
589 bool timedout = lock()->wait(!Mutex::_no_safepoint_check_flag, NmethodSweepCheckInterval*1000); | 585 bool timedout = lock()->wait(!Mutex::_no_safepoint_check_flag, NmethodSweepCheckInterval*1000); |
590 if (timedout) { | 586 if (timedout) { |
618 } else { | 614 } else { |
619 // max is the last element | 615 // max is the last element |
620 assert(task == _last, "Sanity"); | 616 assert(task == _last, "Sanity"); |
621 _last = task->prev(); | 617 _last = task->prev(); |
622 } | 618 } |
623 | |
624 --_size; | 619 --_size; |
625 } | 620 } |
626 | 621 |
627 // ------------------------------------------------------------------ | 622 // ------------------------------------------------------------------ |
628 // CompileQueue::print | 623 // CompileQueue::print |
671 name = PerfDataManager::counter_name(thread_i, "compiles"); | 666 name = PerfDataManager::counter_name(thread_i, "compiles"); |
672 _perf_compiles = PerfDataManager::create_counter(SUN_CI, name, | 667 _perf_compiles = PerfDataManager::create_counter(SUN_CI, name, |
673 PerfData::U_Events, CHECK); | 668 PerfData::U_Events, CHECK); |
674 } | 669 } |
675 } | 670 } |
676 | |
677 void CompileBroker::add_method_to_queue(klassOop k, Symbol* name, Symbol* signature) { | |
678 Thread* THREAD = Thread::current(); | |
679 instanceKlass* klass = instanceKlass::cast(k); | |
680 methodOop method = klass->find_method(name, signature); | |
681 CompileBroker::compile_method(method, -1, 0, method, 0, "initial compile of object initializer", THREAD); | |
682 if (HAS_PENDING_EXCEPTION) { | |
683 CLEAR_PENDING_EXCEPTION; | |
684 fatal("error inserting method into compile queue"); | |
685 } | |
686 } | |
687 | |
688 void CompileBroker::notify_java_queue() { | |
689 HandleMark hm; | |
690 ResourceMark rm; | |
691 | |
692 _poll_java_queue = true; | |
693 { | |
694 ThreadInVMfromNative tivm(JavaThread::current()); | |
695 MutexLocker locker(_c1_method_queue->lock(), Thread::current()); | |
696 | |
697 _c1_method_queue->lock()->notify_all(); | |
698 } | |
699 } | |
700 | |
701 | 671 |
702 // ------------------------------------------------------------------ | 672 // ------------------------------------------------------------------ |
703 // CompileBroker::compilation_init | 673 // CompileBroker::compilation_init |
704 // | 674 // |
705 // Initialize the Compilation object | 675 // Initialize the Compilation object |
714 if (UseGraal) { | 684 if (UseGraal) { |
715 _compilers[0] = new GraalCompiler(); | 685 _compilers[0] = new GraalCompiler(); |
716 } else if (c1_count > 0) { | 686 } else if (c1_count > 0) { |
717 _compilers[0] = new Compiler(); | 687 _compilers[0] = new Compiler(); |
718 } | 688 } |
719 #ifndef COMPILER2 | |
720 _compilers[1] = _compilers[0]; | |
721 #endif | |
722 #endif // COMPILER1 | 689 #endif // COMPILER1 |
723 | 690 |
724 #ifdef COMPILER2 | 691 #ifdef COMPILER2 |
725 if (c2_count > 0) { | 692 if (c2_count > 0) { |
726 _compilers[1] = new C2Compiler(); | 693 _compilers[1] = new C2Compiler(); |
1546 log->end_elem(); | 1513 log->end_elem(); |
1547 } | 1514 } |
1548 | 1515 |
1549 while (true) { | 1516 while (true) { |
1550 { | 1517 { |
1551 | |
1552 // We need this HandleMark to avoid leaking VM handles. | 1518 // We need this HandleMark to avoid leaking VM handles. |
1553 HandleMark hm(thread); | 1519 HandleMark hm(thread); |
1554 | 1520 |
1555 if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) { | 1521 if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) { |
1556 // the code cache is really full | 1522 // the code cache is really full |
1558 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { | 1524 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { |
1559 // Attempt to start cleaning the code cache while there is still a little headroom | 1525 // Attempt to start cleaning the code cache while there is still a little headroom |
1560 NMethodSweeper::handle_full_code_cache(false); | 1526 NMethodSweeper::handle_full_code_cache(false); |
1561 } | 1527 } |
1562 | 1528 |
1563 CompileTask* task = queue->get(_poll_java_queue); | 1529 CompileTask* task = queue->get(); |
1564 | 1530 |
1565 if (task != NULL) { | 1531 // Give compiler threads an extra quanta. They tend to be bursty and |
1566 // Give compiler threads an extra quanta. They tend to be bursty and | 1532 // this helps the compiler to finish up the job. |
1567 // this helps the compiler to finish up the job. | 1533 if( CompilerThreadHintNoPreempt ) |
1568 if( CompilerThreadHintNoPreempt ) | 1534 os::hint_no_preempt(); |
1569 os::hint_no_preempt(); | 1535 |
1570 | 1536 // trace per thread time and compile statistics |
1571 // trace per thread time and compile statistics | 1537 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); |
1572 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); | 1538 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); |
1573 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); | 1539 |
1574 | 1540 // Assign the task to the current thread. Mark this compilation |
1575 // Assign the task to the current thread. Mark this compilation | 1541 // thread as active for the profiler. |
1576 // thread as active for the profiler. | 1542 CompileTaskWrapper ctw(task); |
1577 CompileTaskWrapper ctw(task); | 1543 nmethodLocker result_handle; // (handle for the nmethod produced by this task) |
1578 nmethodLocker result_handle; // (handle for the nmethod produced by this task) | 1544 task->set_code_handle(&result_handle); |
1579 task->set_code_handle(&result_handle); | 1545 methodHandle method(thread, |
1580 methodHandle method(thread, | 1546 (methodOop)JNIHandles::resolve(task->method_handle())); |
1581 (methodOop)JNIHandles::resolve(task->method_handle())); | 1547 |
1582 | 1548 // Never compile a method if breakpoints are present in it |
1583 // Never compile a method if breakpoints are present in it | 1549 if (method()->number_of_breakpoints() == 0) { |
1584 if (method()->number_of_breakpoints() == 0) { | 1550 // Compile the method. |
1585 // Compile the method. | 1551 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { |
1586 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { | 1552 #ifdef COMPILER1 |
1587 #ifdef COMPILER1 | 1553 // Allow repeating compilations for the purpose of benchmarking |
1588 // Allow repeating compilations for the purpose of benchmarking | 1554 // compile speed. This is not useful for customers. |
1589 // compile speed. This is not useful for customers. | 1555 if (CompilationRepeat != 0) { |
1590 if (CompilationRepeat != 0) { | 1556 int compile_count = CompilationRepeat; |
1591 int compile_count = CompilationRepeat; | 1557 while (compile_count > 0) { |
1592 while (compile_count > 0) { | 1558 invoke_compiler_on_method(task); |
1593 invoke_compiler_on_method(task); | 1559 nmethod* nm = method->code(); |
1594 nmethod* nm = method->code(); | 1560 if (nm != NULL) { |
1595 if (nm != NULL) { | 1561 nm->make_zombie(); |
1596 nm->make_zombie(); | 1562 method->clear_code(); |
1597 method->clear_code(); | |
1598 } | |
1599 compile_count--; | |
1600 } | 1563 } |
1564 compile_count--; | |
1601 } | 1565 } |
1602 #endif /* COMPILER1 */ | |
1603 invoke_compiler_on_method(task); | |
1604 } else { | |
1605 // After compilation is disabled, remove remaining methods from queue | |
1606 method->clear_queued_for_compilation(); | |
1607 } | 1566 } |
1608 } | 1567 #endif /* COMPILER1 */ |
1609 } | 1568 invoke_compiler_on_method(task); |
1610 | 1569 } else { |
1611 if (_poll_java_queue) { | 1570 // After compilation is disabled, remove remaining methods from queue |
1612 _poll_java_queue = false; | 1571 method->clear_queued_for_compilation(); |
1613 if (UseGraal) { | |
1614 GraalCompiler::instance()->poll_java_queue(); | |
1615 } | 1572 } |
1616 } | 1573 } |
1617 } | 1574 } |
1618 } | 1575 } |
1619 } | 1576 } |
1699 // Compile a method. | 1656 // Compile a method. |
1700 // | 1657 // |
1701 void CompileBroker::invoke_compiler_on_method(CompileTask* task) { | 1658 void CompileBroker::invoke_compiler_on_method(CompileTask* task) { |
1702 if (PrintCompilation) { | 1659 if (PrintCompilation) { |
1703 ResourceMark rm; | 1660 ResourceMark rm; |
1704 tty->print("%s: ", compiler(task->comp_level())->name()); | |
1705 task->print_line(); | 1661 task->print_line(); |
1706 } | 1662 } |
1707 elapsedTimer time; | 1663 elapsedTimer time; |
1708 | 1664 |
1709 CompilerThread* thread = CompilerThread::current(); | 1665 CompilerThread* thread = CompilerThread::current(); |
1735 } | 1691 } |
1736 | 1692 |
1737 // Allocate a new set of JNI handles. | 1693 // Allocate a new set of JNI handles. |
1738 push_jni_handle_block(); | 1694 push_jni_handle_block(); |
1739 jobject target_handle = JNIHandles::make_local(thread, JNIHandles::resolve(task->method_handle())); | 1695 jobject target_handle = JNIHandles::make_local(thread, JNIHandles::resolve(task->method_handle())); |
1740 int compilable = ciEnv::MethodCompilable_never; | 1696 int compilable = ciEnv::MethodCompilable; |
1741 if (MaxCompilationID == -1 || compile_id <= (uint)MaxCompilationID) { | 1697 { |
1742 compilable = ciEnv::MethodCompilable; | |
1743 int system_dictionary_modification_counter; | 1698 int system_dictionary_modification_counter; |
1744 { | 1699 { |
1745 MutexLocker locker(Compile_lock, thread); | 1700 MutexLocker locker(Compile_lock, thread); |
1746 system_dictionary_modification_counter = SystemDictionary::number_of_modifications(); | 1701 system_dictionary_modification_counter = SystemDictionary::number_of_modifications(); |
1747 } | 1702 } |
1748 | 1703 |
1749 // (tw) Check if we may do this? | 1704 NoHandleMark nhm; |
1750 // NoHandleMark nhm; | |
1751 ThreadToNativeFromVM ttn(thread); | 1705 ThreadToNativeFromVM ttn(thread); |
1752 | 1706 |
1753 ciEnv ci_env(task, system_dictionary_modification_counter); | 1707 ciEnv ci_env(task, system_dictionary_modification_counter); |
1754 if (should_break) { | 1708 if (should_break) { |
1755 ci_env.set_break_at_compile(true); | 1709 ci_env.set_break_at_compile(true); |
1770 | 1724 |
1771 TraceTime t1("compilation", &time); | 1725 TraceTime t1("compilation", &time); |
1772 | 1726 |
1773 compiler(task->comp_level())->compile_method(&ci_env, target, osr_bci); | 1727 compiler(task->comp_level())->compile_method(&ci_env, target, osr_bci); |
1774 | 1728 |
1775 // TODO (tw): Check if this is OK. | 1729 if (!ci_env.failing() && task->code() == NULL) { |
1776 /*if (!ci_env.failing() && task->code() == NULL) { | |
1777 //assert(false, "compiler should always document failure"); | 1730 //assert(false, "compiler should always document failure"); |
1778 // The compiler elected, without comment, not to register a result. | 1731 // The compiler elected, without comment, not to register a result. |
1779 // Do not attempt further compilations of this method. | 1732 // Do not attempt further compilations of this method. |
1780 ci_env.record_method_not_compilable("compile failed", !TieredCompilation); | 1733 ci_env.record_method_not_compilable("compile failed", !TieredCompilation); |
1781 }*/ | 1734 } |
1782 | 1735 |
1783 if (ci_env.failing()) { | 1736 if (ci_env.failing()) { |
1784 // Copy this bit to the enclosing block: | 1737 // Copy this bit to the enclosing block: |
1785 compilable = ci_env.compilable(); | 1738 compilable = ci_env.compilable(); |
1786 if (PrintCompilation) { | 1739 if (PrintCompilation) { |