651 int CodeCache::alignment_offset() {
652 return (int)_heaps->first()->alignment_offset();
653 }
654
655 // Mark nmethods for unloading if they contain otherwise unreachable oops.
656 void CodeCache::do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred) {
657 assert_locked_or_safepoint(CodeCache_lock);
658 CompiledMethodIterator iter;
659 while(iter.next_alive()) {
660 iter.method()->do_unloading(is_alive, unloading_occurred);
661 }
662 }
663
664 void CodeCache::blobs_do(CodeBlobClosure* f) {
665 assert_locked_or_safepoint(CodeCache_lock);
666 FOR_ALL_NMETHOD_HEAPS(heap) {
667 FOR_ALL_BLOBS(cb, *heap) {
668 if (cb->is_alive()) {
669 f->do_code_blob(cb);
670 #ifdef ASSERT
671 if (cb->is_nmethod())
672 ((nmethod*)cb)->verify_scavenge_root_oops();
673 #endif //ASSERT
674 }
675 }
676 }
677 }
678
679 // Walk the list of methods which might contain non-perm oops.
680 void CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure* f) {
681 assert_locked_or_safepoint(CodeCache_lock);
682
683 if (UseG1GC) {
684 return;
685 }
686
687 const bool fix_relocations = f->fix_relocations();
688 debug_only(mark_scavenge_root_nmethods());
689
690 nmethod* prev = NULL;
691 nmethod* cur = scavenge_root_nmethods();
692 while (cur != NULL) {
693 debug_only(cur->clear_scavenge_root_marked());
694 assert(cur->scavenge_root_not_marked(), "");
695 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
696
697 bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
698 if (TraceScavenge) {
699 cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
700 }
701 if (is_live) {
702 // Perform cur->oops_do(f), maybe just once per nmethod.
703 f->do_code_blob(cur);
704 }
705 nmethod* const next = cur->scavenge_root_link();
706 // The scavengable nmethod list must contain all methods with scavengable
707 // oops. It is safe to include more nmethod on the list, but we do not
708 // expect any live non-scavengable nmethods on the list.
709 if (fix_relocations) {
710 if (!is_live || !cur->detect_scavenge_root_oops()) {
711 unlink_scavenge_root_nmethod(cur, prev);
712 } else {
713 prev = cur;
714 }
715 }
716 cur = next;
717 }
718
719 // Check for stray marks.
720 debug_only(verify_perm_nmethods(NULL));
721 }
722
723 void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
724 assert_locked_or_safepoint(CodeCache_lock);
725
726 if (UseG1GC) {
727 return;
728 }
729
730 nm->set_on_scavenge_root_list();
731 nm->set_scavenge_root_link(_scavenge_root_nmethods);
732 set_scavenge_root_nmethods(nm);
733 print_trace("add_scavenge_root", nm);
734 }
735
736 void CodeCache::unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev) {
737 assert_locked_or_safepoint(CodeCache_lock);
738
739 assert((prev == NULL && scavenge_root_nmethods() == nm) ||
740 (prev != NULL && prev->scavenge_root_link() == nm), "precondition");
741
742 assert(!UseG1GC, "G1 does not use the scavenge_root_nmethods list");
743
744 print_trace("unlink_scavenge_root", nm);
745 if (prev == NULL) {
746 set_scavenge_root_nmethods(nm->scavenge_root_link());
747 } else {
748 prev->set_scavenge_root_link(nm->scavenge_root_link());
749 }
750 nm->set_scavenge_root_link(NULL);
751 nm->clear_on_scavenge_root_list();
752 }
753
754 void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
755 assert_locked_or_safepoint(CodeCache_lock);
756
757 if (UseG1GC) {
758 return;
759 }
760
761 print_trace("drop_scavenge_root", nm);
762 nmethod* prev = NULL;
763 for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
764 if (cur == nm) {
765 unlink_scavenge_root_nmethod(cur, prev);
766 return;
767 }
768 prev = cur;
769 }
770 assert(false, "should have been on list");
771 }
772
773 void CodeCache::prune_scavenge_root_nmethods() {
774 assert_locked_or_safepoint(CodeCache_lock);
775
776 if (UseG1GC) {
777 return;
778 }
779
780 debug_only(mark_scavenge_root_nmethods());
781
782 nmethod* last = NULL;
783 nmethod* cur = scavenge_root_nmethods();
784 while (cur != NULL) {
785 nmethod* next = cur->scavenge_root_link();
786 debug_only(cur->clear_scavenge_root_marked());
787 assert(cur->scavenge_root_not_marked(), "");
788 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
789
790 if (!cur->is_zombie() && !cur->is_unloaded()
791 && cur->detect_scavenge_root_oops()) {
792 // Keep it. Advance 'last' to prevent deletion.
793 last = cur;
794 } else {
795 // Prune it from the list, so we don't have to look at it any more.
796 print_trace("prune_scavenge_root", cur);
797 unlink_scavenge_root_nmethod(cur, last);
798 }
799 cur = next;
800 }
801
802 // Check for stray marks.
803 debug_only(verify_perm_nmethods(NULL));
804 }
805
806 #ifndef PRODUCT
807 void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
808 if (UseG1GC) {
809 return;
810 }
811
812 // While we are here, verify the integrity of the list.
813 mark_scavenge_root_nmethods();
814 for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
815 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
816 cur->clear_scavenge_root_marked();
817 }
818 verify_perm_nmethods(f);
819 }
820
821 // Temporarily mark nmethods that are claimed to be on the non-perm list.
822 void CodeCache::mark_scavenge_root_nmethods() {
823 NMethodIterator iter;
824 while(iter.next_alive()) {
825 nmethod* nm = iter.method();
826 assert(nm->scavenge_root_not_marked(), "clean state");
827 if (nm->on_scavenge_root_list())
828 nm->set_scavenge_root_marked();
829 }
830 }
831
832 // If the closure is given, run it on the unlisted nmethods.
833 // Also make sure that the effects of mark_scavenge_root_nmethods is gone.
834 void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
835 NMethodIterator iter;
836 while(iter.next_alive()) {
837 nmethod* nm = iter.method();
838 bool call_f = (f_or_null != NULL);
839 assert(nm->scavenge_root_not_marked(), "must be already processed");
840 if (nm->on_scavenge_root_list())
841 call_f = false; // don't show this one to the client
842 nm->verify_scavenge_root_oops();
843 if (call_f) f_or_null->do_code_blob(nm);
844 }
845 }
846 #endif //PRODUCT
847
848 void CodeCache::verify_clean_inline_caches() {
849 #ifdef ASSERT
850 NMethodIterator iter;
851 while(iter.next_alive()) {
852 nmethod* nm = iter.method();
853 assert(!nm->is_unloaded(), "Tautology");
854 nm->verify_clean_inline_caches();
855 nm->verify();
856 }
857 #endif
858 }
859
860 void CodeCache::verify_icholder_relocations() {
861 #ifdef ASSERT
862 // make sure that we aren't leaking icholders
1607 ResourceMark rm;
1608 char *method_name = nm->method()->name_and_sig_as_C_string();
1609 st->print_cr("%d %d %s [" INTPTR_FORMAT ", " INTPTR_FORMAT " - " INTPTR_FORMAT "]",
1610 nm->compile_id(), nm->comp_level(), method_name, (intptr_t)nm->header_begin(),
1611 (intptr_t)nm->code_begin(), (intptr_t)nm->code_end());
1612 }
1613 }
1614
1615 void CodeCache::print_layout(outputStream* st) {
1616 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1617 ResourceMark rm;
1618 print_summary(st, true);
1619 }
1620
1621 void CodeCache::log_state(outputStream* st) {
1622 st->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'"
1623 " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
1624 blob_count(), nmethod_count(), adapter_count(),
1625 unallocated_capacity());
1626 }
1627
|
651 int CodeCache::alignment_offset() {
652 return (int)_heaps->first()->alignment_offset();
653 }
654
655 // Mark nmethods for unloading if they contain otherwise unreachable oops.
656 void CodeCache::do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred) {
657 assert_locked_or_safepoint(CodeCache_lock);
658 CompiledMethodIterator iter;
659 while(iter.next_alive()) {
660 iter.method()->do_unloading(is_alive, unloading_occurred);
661 }
662 }
663
664 void CodeCache::blobs_do(CodeBlobClosure* f) {
665 assert_locked_or_safepoint(CodeCache_lock);
666 FOR_ALL_NMETHOD_HEAPS(heap) {
667 FOR_ALL_BLOBS(cb, *heap) {
668 if (cb->is_alive()) {
669 f->do_code_blob(cb);
670 #ifdef ASSERT
671 if (cb->is_nmethod()) {
672 Universe::heap()->verify_nmethod_roots((nmethod*)cb);
673 }
674 #endif //ASSERT
675 }
676 }
677 }
678 }
679
680 // Walk the list of methods which might contain non-perm oops.
681 void CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure* f) {
682 assert_locked_or_safepoint(CodeCache_lock);
683
684 const bool fix_relocations = f->fix_relocations();
685 debug_only(mark_scavenge_root_nmethods());
686
687 nmethod* prev = NULL;
688 nmethod* cur = scavenge_root_nmethods();
689 while (cur != NULL) {
690 debug_only(cur->clear_scavenge_root_marked());
691 assert(cur->scavenge_root_not_marked(), "");
692 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
693
694 bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
695 if (TraceScavenge) {
696 cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
697 }
698 if (is_live) {
699 // Perform cur->oops_do(f), maybe just once per nmethod.
700 f->do_code_blob(cur);
701 }
702 nmethod* const next = cur->scavenge_root_link();
703 // The scavengable nmethod list must contain all methods with scavengable
704 // oops. It is safe to include more nmethod on the list, but we do not
705 // expect any live non-scavengable nmethods on the list.
706 if (fix_relocations) {
707 if (!is_live || !cur->detect_scavenge_root_oops()) {
708 unlink_scavenge_root_nmethod(cur, prev);
709 } else {
710 prev = cur;
711 }
712 }
713 cur = next;
714 }
715
716 // Check for stray marks.
717 debug_only(verify_perm_nmethods(NULL));
718 }
719
720 void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
721 assert_locked_or_safepoint(CodeCache_lock);
722
723 nm->set_on_scavenge_root_list();
724 nm->set_scavenge_root_link(_scavenge_root_nmethods);
725 set_scavenge_root_nmethods(nm);
726 print_trace("add_scavenge_root", nm);
727 }
728
729 void CodeCache::unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev) {
730 assert_locked_or_safepoint(CodeCache_lock);
731
732 assert((prev == NULL && scavenge_root_nmethods() == nm) ||
733 (prev != NULL && prev->scavenge_root_link() == nm), "precondition");
734
735 print_trace("unlink_scavenge_root", nm);
736 if (prev == NULL) {
737 set_scavenge_root_nmethods(nm->scavenge_root_link());
738 } else {
739 prev->set_scavenge_root_link(nm->scavenge_root_link());
740 }
741 nm->set_scavenge_root_link(NULL);
742 nm->clear_on_scavenge_root_list();
743 }
744
745 void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
746 assert_locked_or_safepoint(CodeCache_lock);
747
748 print_trace("drop_scavenge_root", nm);
749 nmethod* prev = NULL;
750 for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
751 if (cur == nm) {
752 unlink_scavenge_root_nmethod(cur, prev);
753 return;
754 }
755 prev = cur;
756 }
757 assert(false, "should have been on list");
758 }
759
760 void CodeCache::prune_scavenge_root_nmethods() {
761 assert_locked_or_safepoint(CodeCache_lock);
762
763 debug_only(mark_scavenge_root_nmethods());
764
765 nmethod* last = NULL;
766 nmethod* cur = scavenge_root_nmethods();
767 while (cur != NULL) {
768 nmethod* next = cur->scavenge_root_link();
769 debug_only(cur->clear_scavenge_root_marked());
770 assert(cur->scavenge_root_not_marked(), "");
771 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
772
773 if (!cur->is_zombie() && !cur->is_unloaded()
774 && cur->detect_scavenge_root_oops()) {
775 // Keep it. Advance 'last' to prevent deletion.
776 last = cur;
777 } else {
778 // Prune it from the list, so we don't have to look at it any more.
779 print_trace("prune_scavenge_root", cur);
780 unlink_scavenge_root_nmethod(cur, last);
781 }
782 cur = next;
783 }
784
785 // Check for stray marks.
786 debug_only(verify_perm_nmethods(NULL));
787 }
788
789 #ifndef PRODUCT
790 void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
791 // While we are here, verify the integrity of the list.
792 mark_scavenge_root_nmethods();
793 for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
794 assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
795 cur->clear_scavenge_root_marked();
796 }
797 verify_perm_nmethods(f);
798 }
799
800 // Temporarily mark nmethods that are claimed to be on the non-perm list.
801 void CodeCache::mark_scavenge_root_nmethods() {
802 NMethodIterator iter;
803 while(iter.next_alive()) {
804 nmethod* nm = iter.method();
805 assert(nm->scavenge_root_not_marked(), "clean state");
806 if (nm->on_scavenge_root_list())
807 nm->set_scavenge_root_marked();
808 }
809 }
810
811 // If the closure is given, run it on the unlisted nmethods.
812 // Also make sure that the effects of mark_scavenge_root_nmethods is gone.
813 void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
814 NMethodIterator iter;
815 while(iter.next_alive()) {
816 nmethod* nm = iter.method();
817 bool call_f = (f_or_null != NULL);
818 assert(nm->scavenge_root_not_marked(), "must be already processed");
819 if (nm->on_scavenge_root_list())
820 call_f = false; // don't show this one to the client
821 Universe::heap()->verify_nmethod_roots(nm);
822 if (call_f) f_or_null->do_code_blob(nm);
823 }
824 }
825 #endif //PRODUCT
826
827 void CodeCache::verify_clean_inline_caches() {
828 #ifdef ASSERT
829 NMethodIterator iter;
830 while(iter.next_alive()) {
831 nmethod* nm = iter.method();
832 assert(!nm->is_unloaded(), "Tautology");
833 nm->verify_clean_inline_caches();
834 nm->verify();
835 }
836 #endif
837 }
838
839 void CodeCache::verify_icholder_relocations() {
840 #ifdef ASSERT
841 // make sure that we aren't leaking icholders
1586 ResourceMark rm;
1587 char *method_name = nm->method()->name_and_sig_as_C_string();
1588 st->print_cr("%d %d %s [" INTPTR_FORMAT ", " INTPTR_FORMAT " - " INTPTR_FORMAT "]",
1589 nm->compile_id(), nm->comp_level(), method_name, (intptr_t)nm->header_begin(),
1590 (intptr_t)nm->code_begin(), (intptr_t)nm->code_end());
1591 }
1592 }
1593
1594 void CodeCache::print_layout(outputStream* st) {
1595 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1596 ResourceMark rm;
1597 print_summary(st, true);
1598 }
1599
1600 void CodeCache::log_state(outputStream* st) {
1601 st->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'"
1602 " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
1603 blob_count(), nmethod_count(), adapter_count(),
1604 unallocated_capacity());
1605 }
|