652 // and then loops to find more work. |
652 // and then loops to find more work. |
653 |
653 |
654 GCTask* GCTaskManager::get_task(uint which) { |
654 GCTask* GCTaskManager::get_task(uint which) { |
655 GCTask* result = NULL; |
655 GCTask* result = NULL; |
656 // Grab the queue lock. |
656 // Grab the queue lock. |
657 MutexLocker ml(monitor(), Mutex::_no_safepoint_check_flag); |
657 MonitorLocker ml(monitor(), Mutex::_no_safepoint_check_flag); |
658 // Wait while the queue is block or |
658 // Wait while the queue is block or |
659 // there is nothing to do, except maybe release resources. |
659 // there is nothing to do, except maybe release resources. |
660 while (is_blocked() || |
660 while (is_blocked() || |
661 (queue()->is_empty() && !should_release_resources(which))) { |
661 (queue()->is_empty() && !should_release_resources(which))) { |
662 if (TraceGCTaskManager) { |
662 if (TraceGCTaskManager) { |
669 queue()->is_empty() ? "true" : "false", |
669 queue()->is_empty() ? "true" : "false", |
670 should_release_resources(which) ? "true" : "false"); |
670 should_release_resources(which) ? "true" : "false"); |
671 tty->print_cr(" => (%s)->wait()", |
671 tty->print_cr(" => (%s)->wait()", |
672 monitor()->name()); |
672 monitor()->name()); |
673 } |
673 } |
674 monitor()->wait_without_safepoint_check(0); |
674 ml.wait(0); |
675 } |
675 } |
676 // We've reacquired the queue lock here. |
676 // We've reacquired the queue lock here. |
677 // Figure out which condition caused us to exit the loop above. |
677 // Figure out which condition caused us to exit the loop above. |
678 if (!queue()->is_empty()) { |
678 if (!queue()->is_empty()) { |
679 if (UseGCTaskAffinity) { |
679 if (UseGCTaskAffinity) { |
870 void IdleGCTask::do_it(GCTaskManager* manager, uint which) { |
870 void IdleGCTask::do_it(GCTaskManager* manager, uint which) { |
871 WaitHelper* wait_helper = manager->wait_helper(); |
871 WaitHelper* wait_helper = manager->wait_helper(); |
872 log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask:::do_it() should_wait: %s", |
872 log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask:::do_it() should_wait: %s", |
873 p2i(this), wait_helper->should_wait() ? "true" : "false"); |
873 p2i(this), wait_helper->should_wait() ? "true" : "false"); |
874 |
874 |
875 MutexLocker ml(manager->monitor(), Mutex::_no_safepoint_check_flag); |
875 MonitorLocker ml(manager->monitor(), Mutex::_no_safepoint_check_flag); |
876 log_trace(gc, task)("--- idle %d", which); |
876 log_trace(gc, task)("--- idle %d", which); |
877 // Increment has to be done when the idle tasks are created. |
877 // Increment has to be done when the idle tasks are created. |
878 // manager->increment_idle_workers(); |
878 // manager->increment_idle_workers(); |
879 manager->monitor()->notify_all(); |
879 ml.notify_all(); |
880 while (wait_helper->should_wait()) { |
880 while (wait_helper->should_wait()) { |
881 log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask::do_it() [" INTPTR_FORMAT "] (%s)->wait()", |
881 log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask::do_it() [" INTPTR_FORMAT "] (%s)->wait()", |
882 p2i(this), p2i(manager->monitor()), manager->monitor()->name()); |
882 p2i(this), p2i(manager->monitor()), manager->monitor()->name()); |
883 manager->monitor()->wait_without_safepoint_check(0); |
883 ml.wait(0); |
884 } |
884 } |
885 manager->decrement_idle_workers(); |
885 manager->decrement_idle_workers(); |
886 |
886 |
887 log_trace(gc, task)("--- release %d", which); |
887 log_trace(gc, task)("--- release %d", which); |
888 log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask::do_it() returns should_wait: %s", |
888 log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask::do_it() returns should_wait: %s", |
989 " should_wait: %s", |
989 " should_wait: %s", |
990 p2i(this), should_wait() ? "true" : "false"); |
990 p2i(this), should_wait() ? "true" : "false"); |
991 } |
991 } |
992 { |
992 { |
993 // Grab the lock and check again. |
993 // Grab the lock and check again. |
994 MutexLocker ml(monitor(), Mutex::_no_safepoint_check_flag); |
994 MonitorLocker ml(monitor(), Mutex::_no_safepoint_check_flag); |
995 while (should_wait()) { |
995 while (should_wait()) { |
996 if (TraceGCTaskManager) { |
996 if (TraceGCTaskManager) { |
997 tty->print_cr("[" INTPTR_FORMAT "]" |
997 tty->print_cr("[" INTPTR_FORMAT "]" |
998 " WaitForBarrierGCTask::wait_for()" |
998 " WaitForBarrierGCTask::wait_for()" |
999 " [" INTPTR_FORMAT "] (%s)->wait()", |
999 " [" INTPTR_FORMAT "] (%s)->wait()", |
1000 p2i(this), p2i(monitor()), monitor()->name()); |
1000 p2i(this), p2i(monitor()), monitor()->name()); |
1001 } |
1001 } |
1002 monitor()->wait_without_safepoint_check(0); |
1002 ml.wait(0); |
1003 } |
1003 } |
1004 // Reset the flag in case someone reuses this task. |
1004 // Reset the flag in case someone reuses this task. |
1005 if (reset) { |
1005 if (reset) { |
1006 set_should_wait(true); |
1006 set_should_wait(true); |
1007 } |
1007 } |