687 NMethodSweeper::possibly_sweep();
688 }
689 } else {
690 // If there are no compilation tasks and we can compile new jobs
691 // (i.e., there is enough free space in the code cache) there is
692 // no need to invoke the sweeper. As a result, the hotness of methods
693 // remains unchanged. This behavior is desired, since we want to keep
694 // the stable state, i.e., we do not want to evict methods from the
695 // code cache if it is unnecessary.
696 // We need a timed wait here, since compiler threads can exit if compilation
697 // is disabled forever. We use 5 seconds wait time; the exiting of compiler threads
698 // is not critical and we do not want idle compiler threads to wake up too often.
699 lock()->wait(!Mutex::_no_safepoint_check_flag, 5*1000);
700 }
701 }
702
703 if (CompileBroker::is_compilation_disabled_forever()) {
704 return NULL;
705 }
706
707 CompileTask* task = CompilationPolicy::policy()->select_task(this);
708 remove(task);
709 return task;
710 }
711
712 void CompileQueue::remove(CompileTask* task)
713 {
714 assert(lock()->owned_by_self(), "must own lock");
715 if (task->prev() != NULL) {
716 task->prev()->set_next(task->next());
717 } else {
718 // max is the first element
719 assert(task == _first, "Sanity");
720 _first = task->next();
721 }
722
723 if (task->next() != NULL) {
724 task->next()->set_prev(task->prev());
725 } else {
726 // max is the last element
727 assert(task == _last, "Sanity");
728 _last = task->prev();
729 }
730 --_size;
731 }
732
733 // methods in the compile queue need to be marked as used on the stack
734 // so that they don't get reclaimed by Redefine Classes
735 void CompileQueue::mark_on_stack() {
736 CompileTask* task = _first;
737 while (task != NULL) {
738 task->mark_on_stack();
739 task = task->next();
740 }
741 }
742
743 #ifndef PRODUCT
744 /**
745 * Print entire compilation queue.
746 */
747 void CompileQueue::print() {
748 if (CIPrintCompileQueue) {
749 ttyLocker ttyl;
750 tty->print_cr("Contents of %s", name());
751 tty->print_cr("----------------------");
752 CompileTask* task = _first;
1989 codecache_print(/* detailed= */ false);
1990
1991 // Disable compilation, if required.
1992 switch (compilable) {
1993 case ciEnv::MethodCompilable_never:
1994 if (is_osr)
1995 method->set_not_osr_compilable_quietly();
1996 else
1997 method->set_not_compilable_quietly();
1998 break;
1999 case ciEnv::MethodCompilable_not_at_tier:
2000 if (is_osr)
2001 method->set_not_osr_compilable_quietly(task_level);
2002 else
2003 method->set_not_compilable_quietly(task_level);
2004 break;
2005 }
2006
2007 // Note that the queued_for_compilation bits are cleared without
2008 // protection of a mutex. [They were set by the requester thread,
2009 // when adding the task to the complie queue -- at which time the
2010 // compile queue lock was held. Subsequently, we acquired the compile
2011 // queue lock to get this task off the compile queue; thus (to belabour
2012 // the point somewhat) our clearing of the bits must be occurring
2013 // only after the setting of the bits. See also 14012000 above.
2014 method->clear_queued_for_compilation();
2015
2016 #ifdef ASSERT
2017 if (CollectedHeap::fired_fake_oom()) {
2018 // The current compile received a fake OOM during compilation so
2019 // go ahead and exit the VM since the test apparently succeeded
2020 tty->print_cr("*** Shutting down VM after successful fake OOM");
2021 vm_exit(0);
2022 }
2023 #endif
2024 }
2025
2026 /**
2027 * The CodeCache is full. Print out warning and disable compilation
2028 * or try code cache cleaning so compilation can continue later.
2029 */
|
687 NMethodSweeper::possibly_sweep();
688 }
689 } else {
690 // If there are no compilation tasks and we can compile new jobs
691 // (i.e., there is enough free space in the code cache) there is
692 // no need to invoke the sweeper. As a result, the hotness of methods
693 // remains unchanged. This behavior is desired, since we want to keep
694 // the stable state, i.e., we do not want to evict methods from the
695 // code cache if it is unnecessary.
696 // We need a timed wait here, since compiler threads can exit if compilation
697 // is disabled forever. We use 5 seconds wait time; the exiting of compiler threads
698 // is not critical and we do not want idle compiler threads to wake up too often.
699 lock()->wait(!Mutex::_no_safepoint_check_flag, 5*1000);
700 }
701 }
702
703 if (CompileBroker::is_compilation_disabled_forever()) {
704 return NULL;
705 }
706
707 CompileTask* task;
708 {
709 No_Safepoint_Verifier nsv;
710 task = CompilationPolicy::policy()->select_task(this);
711 }
712 remove(task);
713 purge_stale_tasks(); // may temporarily release MCQ lock
714 return task;
715 }
716
717 // Clean & deallocate stale compile tasks.
718 // Temporarily releases MethodCompileQueue lock.
719 void CompileQueue::purge_stale_tasks() {
720 assert(lock()->owned_by_self(), "must own lock");
721 if (_first_stale != NULL) {
722 // Stale tasks are purged when MCQ lock is released,
723 // but _first_stale updates are protected by MCQ lock.
724 // Once task processing starts and MCQ lock is released,
725 // other compiler threads can reuse _first_stale.
726 CompileTask* head = _first_stale;
727 _first_stale = NULL;
728 {
729 MutexUnlocker ul(lock());
730 for (CompileTask* task = head; task != NULL; ) {
731 CompileTask* next_task = task->next();
732 CompileTaskWrapper ctw(task); // Frees the task
733 task->method()->clear_queued_for_compilation();
734 task = next_task;
735 }
736 }
737 }
738 }
739
740 void CompileQueue::remove(CompileTask* task) {
741 assert(lock()->owned_by_self(), "must own lock");
742 if (task->prev() != NULL) {
743 task->prev()->set_next(task->next());
744 } else {
745 // max is the first element
746 assert(task == _first, "Sanity");
747 _first = task->next();
748 }
749
750 if (task->next() != NULL) {
751 task->next()->set_prev(task->prev());
752 } else {
753 // max is the last element
754 assert(task == _last, "Sanity");
755 _last = task->prev();
756 }
757 --_size;
758 }
759
760 void CompileQueue::remove_and_mark_stale(CompileTask* task) {
761 assert(lock()->owned_by_self(), "must own lock");
762 remove(task);
763
764 // Enqueue the task for reclamation (should be done outside MCQ lock)
765 task->set_next(_first_stale);
766 task->set_prev(NULL);
767 _first_stale = task;
768 }
769
770 // methods in the compile queue need to be marked as used on the stack
771 // so that they don't get reclaimed by Redefine Classes
772 void CompileQueue::mark_on_stack() {
773 CompileTask* task = _first;
774 while (task != NULL) {
775 task->mark_on_stack();
776 task = task->next();
777 }
778 }
779
780 #ifndef PRODUCT
781 /**
782 * Print entire compilation queue.
783 */
784 void CompileQueue::print() {
785 if (CIPrintCompileQueue) {
786 ttyLocker ttyl;
787 tty->print_cr("Contents of %s", name());
788 tty->print_cr("----------------------");
789 CompileTask* task = _first;
2026 codecache_print(/* detailed= */ false);
2027
2028 // Disable compilation, if required.
2029 switch (compilable) {
2030 case ciEnv::MethodCompilable_never:
2031 if (is_osr)
2032 method->set_not_osr_compilable_quietly();
2033 else
2034 method->set_not_compilable_quietly();
2035 break;
2036 case ciEnv::MethodCompilable_not_at_tier:
2037 if (is_osr)
2038 method->set_not_osr_compilable_quietly(task_level);
2039 else
2040 method->set_not_compilable_quietly(task_level);
2041 break;
2042 }
2043
2044 // Note that the queued_for_compilation bits are cleared without
2045 // protection of a mutex. [They were set by the requester thread,
2046 // when adding the task to the compile queue -- at which time the
2047 // compile queue lock was held. Subsequently, we acquired the compile
2048 // queue lock to get this task off the compile queue; thus (to belabour
2049 // the point somewhat) our clearing of the bits must be occurring
2050 // only after the setting of the bits. See also 14012000 above.
2051 method->clear_queued_for_compilation();
2052
2053 #ifdef ASSERT
2054 if (CollectedHeap::fired_fake_oom()) {
2055 // The current compile received a fake OOM during compilation so
2056 // go ahead and exit the VM since the test apparently succeeded
2057 tty->print_cr("*** Shutting down VM after successful fake OOM");
2058 vm_exit(0);
2059 }
2060 #endif
2061 }
2062
2063 /**
2064 * The CodeCache is full. Print out warning and disable compilation
2065 * or try code cache cleaning so compilation can continue later.
2066 */
|