Mercurial > hg > graal-compiler
comparison src/share/vm/compiler/compileBroker.cpp @ 3619:5e9645341ec3
support for new RiRuntime features: add code without making it the default for the method, executing Java tasks on the compile thread, communicate nmethod reference to Java code as HotSpotCompiledMethod
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 09 Nov 2011 11:27:38 +0100 |
parents | 22d11b3bc561 |
children | 9c2c0a182f13 |
comparison
equal
deleted
inserted
replaced
3601:3822c5969a8b | 3619:5e9645341ec3 |
---|---|
157 CompileQueue* CompileBroker::_c1_method_queue = NULL; | 157 CompileQueue* CompileBroker::_c1_method_queue = NULL; |
158 CompileTask* CompileBroker::_task_free_list = NULL; | 158 CompileTask* CompileBroker::_task_free_list = NULL; |
159 | 159 |
160 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; | 160 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; |
161 | 161 |
162 bool CompileBroker::_poll_java_queue = false; | |
162 | 163 |
163 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { | 164 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { |
164 CompilerThread* thread = CompilerThread::current(); | 165 CompilerThread* thread = CompilerThread::current(); |
165 thread->set_task(task); | 166 thread->set_task(task); |
166 CompileLog* log = thread->log(); | 167 CompileLog* log = thread->log(); |
541 | 542 |
542 // ------------------------------------------------------------------ | 543 // ------------------------------------------------------------------ |
543 // CompileQueue::get | 544 // CompileQueue::get |
544 // | 545 // |
545 // Get the next CompileTask from a CompileQueue | 546 // Get the next CompileTask from a CompileQueue |
546 CompileTask* CompileQueue::get() { | 547 CompileTask* CompileQueue::get(bool& interrupt) { |
547 NMethodSweeper::possibly_sweep(); | 548 NMethodSweeper::possibly_sweep(); |
548 | 549 |
549 MutexLocker locker(lock()); | 550 MutexLocker locker(lock()); |
550 // Wait for an available CompileTask. | 551 // Wait for an available CompileTask. |
551 while (_first == NULL) { | 552 while (_first == NULL) { |
553 if (interrupt) { | |
554 return NULL; | |
555 } | |
552 // There is no work to be done right now. Wait. | 556 // There is no work to be done right now. Wait. |
553 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) { | 557 if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) { |
554 // During the emergency sweeping periods, wake up and sweep occasionally | 558 // During the emergency sweeping periods, wake up and sweep occasionally |
555 bool timedout = lock()->wait(!Mutex::_no_safepoint_check_flag, NmethodSweepCheckInterval*1000); | 559 bool timedout = lock()->wait(!Mutex::_no_safepoint_check_flag, NmethodSweepCheckInterval*1000); |
556 if (timedout) { | 560 if (timedout) { |
712 | 716 |
713 jlong diff = os::javaTimeMillis() - start; | 717 jlong diff = os::javaTimeMillis() - start; |
714 tty->print_cr("Finished bootstrap in %d ms", diff); | 718 tty->print_cr("Finished bootstrap in %d ms", diff); |
715 if (CITime) CompileBroker::print_times(); | 719 if (CITime) CompileBroker::print_times(); |
716 tty->print_cr("==========================================================================="); | 720 tty->print_cr("==========================================================================="); |
721 } | |
722 | |
723 | |
724 void CompileBroker::notify_java_queue() { | |
725 HandleMark hm; | |
726 ResourceMark rm; | |
727 | |
728 _poll_java_queue = true; | |
729 { | |
730 ThreadInVMfromNative tivm(JavaThread::current()); | |
731 MutexLocker locker(_c1_method_queue->lock(), Thread::current()); | |
732 | |
733 _c1_method_queue->lock()->notify_all(); | |
734 } | |
717 } | 735 } |
718 | 736 |
719 | 737 |
720 // ------------------------------------------------------------------ | 738 // ------------------------------------------------------------------ |
721 // CompileBroker::compilation_init | 739 // CompileBroker::compilation_init |
1577 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { | 1595 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { |
1578 // Attempt to start cleaning the code cache while there is still a little headroom | 1596 // Attempt to start cleaning the code cache while there is still a little headroom |
1579 NMethodSweeper::handle_full_code_cache(false); | 1597 NMethodSweeper::handle_full_code_cache(false); |
1580 } | 1598 } |
1581 | 1599 |
1582 CompileTask* task = queue->get(); | 1600 CompileTask* task = queue->get(_poll_java_queue); |
1583 | 1601 |
1584 // Give compiler threads an extra quanta. They tend to be bursty and | 1602 if (task != NULL) { |
1585 // this helps the compiler to finish up the job. | 1603 // Give compiler threads an extra quanta. They tend to be bursty and |
1586 if( CompilerThreadHintNoPreempt ) | 1604 // this helps the compiler to finish up the job. |
1587 os::hint_no_preempt(); | 1605 if( CompilerThreadHintNoPreempt ) |
1588 | 1606 os::hint_no_preempt(); |
1589 // trace per thread time and compile statistics | 1607 |
1590 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); | 1608 // trace per thread time and compile statistics |
1591 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); | 1609 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); |
1592 | 1610 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); |
1593 // Assign the task to the current thread. Mark this compilation | 1611 |
1594 // thread as active for the profiler. | 1612 // Assign the task to the current thread. Mark this compilation |
1595 CompileTaskWrapper ctw(task); | 1613 // thread as active for the profiler. |
1596 nmethodLocker result_handle; // (handle for the nmethod produced by this task) | 1614 CompileTaskWrapper ctw(task); |
1597 task->set_code_handle(&result_handle); | 1615 nmethodLocker result_handle; // (handle for the nmethod produced by this task) |
1598 methodHandle method(thread, | 1616 task->set_code_handle(&result_handle); |
1599 (methodOop)JNIHandles::resolve(task->method_handle())); | 1617 methodHandle method(thread, |
1600 | 1618 (methodOop)JNIHandles::resolve(task->method_handle())); |
1601 // Never compile a method if breakpoints are present in it | 1619 |
1602 if (method()->number_of_breakpoints() == 0) { | 1620 // Never compile a method if breakpoints are present in it |
1603 // Compile the method. | 1621 if (method()->number_of_breakpoints() == 0) { |
1604 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { | 1622 // Compile the method. |
1605 #ifdef COMPILER1 | 1623 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { |
1606 // Allow repeating compilations for the purpose of benchmarking | 1624 #ifdef COMPILER1 |
1607 // compile speed. This is not useful for customers. | 1625 // Allow repeating compilations for the purpose of benchmarking |
1608 if (CompilationRepeat != 0) { | 1626 // compile speed. This is not useful for customers. |
1609 int compile_count = CompilationRepeat; | 1627 if (CompilationRepeat != 0) { |
1610 while (compile_count > 0) { | 1628 int compile_count = CompilationRepeat; |
1611 invoke_compiler_on_method(task); | 1629 while (compile_count > 0) { |
1612 nmethod* nm = method->code(); | 1630 invoke_compiler_on_method(task); |
1613 if (nm != NULL) { | 1631 nmethod* nm = method->code(); |
1614 nm->make_zombie(); | 1632 if (nm != NULL) { |
1615 method->clear_code(); | 1633 nm->make_zombie(); |
1634 method->clear_code(); | |
1635 } | |
1636 compile_count--; | |
1616 } | 1637 } |
1617 compile_count--; | |
1618 } | 1638 } |
1639 #endif /* COMPILER1 */ | |
1640 invoke_compiler_on_method(task); | |
1641 } else { | |
1642 // After compilation is disabled, remove remaining methods from queue | |
1643 method->clear_queued_for_compilation(); | |
1619 } | 1644 } |
1620 #endif /* COMPILER1 */ | 1645 } |
1621 invoke_compiler_on_method(task); | 1646 } |
1622 } else { | 1647 |
1623 // After compilation is disabled, remove remaining methods from queue | 1648 if (_poll_java_queue) { |
1624 method->clear_queued_for_compilation(); | 1649 _poll_java_queue = false; |
1650 if (UseGraal) { | |
1651 GraalCompiler::instance()->poll_java_queue(); | |
1625 } | 1652 } |
1626 } | 1653 } |
1627 } | 1654 } |
1628 } | 1655 } |
1629 } | 1656 } |