686 |
686 |
687 if (CompileBroker::is_compilation_disabled_forever()) { |
687 if (CompileBroker::is_compilation_disabled_forever()) { |
688 return NULL; |
688 return NULL; |
689 } |
689 } |
690 |
690 |
691 CompileTask* task = CompilationPolicy::policy()->select_task(this); |
691 CompileTask* task; |
|
692 { |
|
693 No_Safepoint_Verifier nsv; |
|
694 task = CompilationPolicy::policy()->select_task(this); |
|
695 } |
692 remove(task); |
696 remove(task); |
|
697 purge_stale_tasks(); // may temporarily release MCQ lock |
693 return task; |
698 return task; |
694 } |
699 } |
695 |
700 |
696 void CompileQueue::remove(CompileTask* task) |
701 // Clean & deallocate stale compile tasks. |
697 { |
702 // Temporarily releases MethodCompileQueue lock. |
|
703 void CompileQueue::purge_stale_tasks() { |
|
704 assert(lock()->owned_by_self(), "must own lock"); |
|
705 if (_first_stale != NULL) { |
|
706 // Stale tasks are purged when MCQ lock is released, |
|
707 // but _first_stale updates are protected by MCQ lock. |
|
708 // Once task processing starts and MCQ lock is released, |
|
709 // other compiler threads can reuse _first_stale. |
|
710 CompileTask* head = _first_stale; |
|
711 _first_stale = NULL; |
|
712 { |
|
713 MutexUnlocker ul(lock()); |
|
714 for (CompileTask* task = head; task != NULL; ) { |
|
715 CompileTask* next_task = task->next(); |
|
716 CompileTaskWrapper ctw(task); // Frees the task |
|
717 task = next_task; |
|
718 } |
|
719 } |
|
720 } |
|
721 } |
|
722 |
|
723 void CompileQueue::remove(CompileTask* task) { |
698 assert(lock()->owned_by_self(), "must own lock"); |
724 assert(lock()->owned_by_self(), "must own lock"); |
699 if (task->prev() != NULL) { |
725 if (task->prev() != NULL) { |
700 task->prev()->set_next(task->next()); |
726 task->prev()->set_next(task->next()); |
701 } else { |
727 } else { |
702 // max is the first element |
728 // max is the first element |
710 // max is the last element |
736 // max is the last element |
711 assert(task == _last, "Sanity"); |
737 assert(task == _last, "Sanity"); |
712 _last = task->prev(); |
738 _last = task->prev(); |
713 } |
739 } |
714 --_size; |
740 --_size; |
|
741 } |
|
742 |
|
743 void CompileQueue::remove_and_mark_stale(CompileTask* task) { |
|
744 assert(lock()->owned_by_self(), "must own lock"); |
|
745 remove(task); |
|
746 |
|
747 // Enqueue the task for reclamation (should be done outside MCQ lock) |
|
748 task->set_next(_first_stale); |
|
749 task->set_prev(NULL); |
|
750 _first_stale = task; |
715 } |
751 } |
716 |
752 |
717 // methods in the compile queue need to be marked as used on the stack |
753 // methods in the compile queue need to be marked as used on the stack |
718 // so that they don't get reclaimed by Redefine Classes |
754 // so that they don't get reclaimed by Redefine Classes |
719 void CompileQueue::mark_on_stack() { |
755 void CompileQueue::mark_on_stack() { |
2009 break; |
2045 break; |
2010 } |
2046 } |
2011 |
2047 |
2012 // Note that the queued_for_compilation bits are cleared without |
2048 // Note that the queued_for_compilation bits are cleared without |
2013 // protection of a mutex. [They were set by the requester thread, |
2049 // protection of a mutex. [They were set by the requester thread, |
2014 // when adding the task to the complie queue -- at which time the |
2050 // when adding the task to the compile queue -- at which time the |
2015 // compile queue lock was held. Subsequently, we acquired the compile |
2051 // compile queue lock was held. Subsequently, we acquired the compile |
2016 // queue lock to get this task off the compile queue; thus (to belabour |
2052 // queue lock to get this task off the compile queue; thus (to belabour |
2017 // the point somewhat) our clearing of the bits must be occurring |
2053 // the point somewhat) our clearing of the bits must be occurring |
2018 // only after the setting of the bits. See also 14012000 above. |
2054 // only after the setting of the bits. See also 14012000 above. |
2019 method->clear_queued_for_compilation(); |
2055 method->clear_queued_for_compilation(); |