579 { |
579 { |
580 { |
580 { |
581 debug_only(No_Safepoint_Verifier nsv;) |
581 debug_only(No_Safepoint_Verifier nsv;) |
582 assert_locked_or_safepoint(CodeCache_lock); |
582 assert_locked_or_safepoint(CodeCache_lock); |
583 |
583 |
584 NOT_PRODUCT(_has_debug_info = false; ) |
584 NOT_PRODUCT(_has_debug_info = false); |
|
585 _oops_do_mark_link = NULL; |
585 _method = method; |
586 _method = method; |
586 _entry_bci = InvocationEntryBci; |
587 _entry_bci = InvocationEntryBci; |
587 _link = NULL; |
588 _osr_link = NULL; |
|
589 _scavenge_root_link = NULL; |
|
590 _scavenge_root_state = 0; |
588 _compiler = NULL; |
591 _compiler = NULL; |
589 // We have no exception handler or deopt handler make the |
592 // We have no exception handler or deopt handler make the |
590 // values something that will never match a pc like the nmethod vtable entry |
593 // values something that will never match a pc like the nmethod vtable entry |
591 _exception_offset = 0; |
594 _exception_offset = 0; |
592 _deoptimize_offset = 0; |
595 _deoptimize_offset = 0; |
666 { |
669 { |
667 { |
670 { |
668 debug_only(No_Safepoint_Verifier nsv;) |
671 debug_only(No_Safepoint_Verifier nsv;) |
669 assert_locked_or_safepoint(CodeCache_lock); |
672 assert_locked_or_safepoint(CodeCache_lock); |
670 |
673 |
671 NOT_PRODUCT(_has_debug_info = false; ) |
674 NOT_PRODUCT(_has_debug_info = false); |
|
675 _oops_do_mark_link = NULL; |
672 _method = method; |
676 _method = method; |
673 _entry_bci = InvocationEntryBci; |
677 _entry_bci = InvocationEntryBci; |
674 _link = NULL; |
678 _osr_link = NULL; |
|
679 _scavenge_root_link = NULL; |
|
680 _scavenge_root_state = 0; |
675 _compiler = NULL; |
681 _compiler = NULL; |
676 // We have no exception handler or deopt handler make the |
682 // We have no exception handler or deopt handler make the |
677 // values something that will never match a pc like the nmethod vtable entry |
683 // values something that will never match a pc like the nmethod vtable entry |
678 _exception_offset = 0; |
684 _exception_offset = 0; |
679 _deoptimize_offset = 0; |
685 _deoptimize_offset = 0; |
768 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); |
774 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); |
769 { |
775 { |
770 debug_only(No_Safepoint_Verifier nsv;) |
776 debug_only(No_Safepoint_Verifier nsv;) |
771 assert_locked_or_safepoint(CodeCache_lock); |
777 assert_locked_or_safepoint(CodeCache_lock); |
772 |
778 |
773 NOT_PRODUCT(_has_debug_info = false; ) |
779 NOT_PRODUCT(_has_debug_info = false); |
|
780 _oops_do_mark_link = NULL; |
774 _method = method; |
781 _method = method; |
775 _compile_id = compile_id; |
782 _compile_id = compile_id; |
776 _comp_level = comp_level; |
783 _comp_level = comp_level; |
777 _entry_bci = entry_bci; |
784 _entry_bci = entry_bci; |
778 _link = NULL; |
785 _osr_link = NULL; |
|
786 _scavenge_root_link = NULL; |
|
787 _scavenge_root_state = 0; |
779 _compiler = compiler; |
788 _compiler = compiler; |
780 _orig_pc_offset = orig_pc_offset; |
789 _orig_pc_offset = orig_pc_offset; |
781 #ifdef HAVE_DTRACE_H |
790 #ifdef HAVE_DTRACE_H |
782 _trap_offset = 0; |
791 _trap_offset = 0; |
783 #endif // def HAVE_DTRACE_H |
792 #endif // def HAVE_DTRACE_H |
900 // Print out more verbose output usually for a newly created nmethod. |
912 // Print out more verbose output usually for a newly created nmethod. |
901 void nmethod::print_on(outputStream* st, const char* title) const { |
913 void nmethod::print_on(outputStream* st, const char* title) const { |
902 if (st != NULL) { |
914 if (st != NULL) { |
903 ttyLocker ttyl; |
915 ttyLocker ttyl; |
904 // Print a little tag line that looks like +PrintCompilation output: |
916 // Print a little tag line that looks like +PrintCompilation output: |
905 st->print("%3d%c %s", |
917 int tlen = (int) strlen(title); |
|
918 bool do_nl = false; |
|
919 if (tlen > 0 && title[tlen-1] == '\n') { tlen--; do_nl = true; } |
|
920 st->print("%3d%c %.*s", |
906 compile_id(), |
921 compile_id(), |
907 is_osr_method() ? '%' : |
922 is_osr_method() ? '%' : |
908 method() != NULL && |
923 method() != NULL && |
909 is_native_method() ? 'n' : ' ', |
924 is_native_method() ? 'n' : ' ', |
910 title); |
925 tlen, title); |
911 #ifdef TIERED |
926 #ifdef TIERED |
912 st->print(" (%d) ", comp_level()); |
927 st->print(" (%d) ", comp_level()); |
913 #endif // TIERED |
928 #endif // TIERED |
914 if (WizardMode) st->print(" (" INTPTR_FORMAT ")", this); |
929 if (WizardMode) st->print(" (" INTPTR_FORMAT ")", this); |
915 if (method() != NULL) { |
930 if (Universe::heap()->is_gc_active() && method() != NULL) { |
916 method()->print_short_name(st); |
931 st->print("(method)"); |
|
932 } else if (method() != NULL) { |
|
933 method()->print_short_name(st); |
917 if (is_osr_method()) |
934 if (is_osr_method()) |
918 st->print(" @ %d", osr_entry_bci()); |
935 st->print(" @ %d", osr_entry_bci()); |
919 if (method()->code_size() > 0) |
936 if (method()->code_size() > 0) |
920 st->print(" (%d bytes)", method()->code_size()); |
937 st->print(" (%d bytes)", method()->code_size()); |
921 } |
938 } |
|
939 |
|
940 if (do_nl) st->cr(); |
922 } |
941 } |
923 } |
942 } |
924 |
943 |
925 |
944 |
926 void nmethod::print_nmethod(bool printmethod) { |
945 void nmethod::print_nmethod(bool printmethod) { |
1075 if (TraceClassUnloading && WizardMode) { |
1095 if (TraceClassUnloading && WizardMode) { |
1076 tty->print_cr("[Class unloading: Making nmethod " INTPTR_FORMAT |
1096 tty->print_cr("[Class unloading: Making nmethod " INTPTR_FORMAT |
1077 " unloadable], methodOop(" INTPTR_FORMAT |
1097 " unloadable], methodOop(" INTPTR_FORMAT |
1078 "), cause(" INTPTR_FORMAT ")", |
1098 "), cause(" INTPTR_FORMAT ")", |
1079 this, (address)_method, (address)cause); |
1099 this, (address)_method, (address)cause); |
1080 cause->klass()->print(); |
1100 if (!Universe::heap()->is_gc_active()) |
|
1101 cause->klass()->print(); |
1081 } |
1102 } |
1082 // If _method is already NULL the methodOop is about to be unloaded, |
1103 // If _method is already NULL the methodOop is about to be unloaded, |
1083 // so we don't have to break the cycle. Note that it is possible to |
1104 // so we don't have to break the cycle. Note that it is possible to |
1084 // have the methodOop live here, in case we unload the nmethod because |
1105 // have the methodOop live here, in case we unload the nmethod because |
1085 // it is pointing to some oop (other than the methodOop) being unloaded. |
1106 // it is pointing to some oop (other than the methodOop) being unloaded. |
1556 } |
1585 } |
1557 } |
1586 } |
1558 } |
1587 } |
1559 |
1588 |
1560 // Scopes |
1589 // Scopes |
|
1590 // This includes oop constants not inlined in the code stream. |
1561 for (oop* p = oops_begin(); p < oops_end(); p++) { |
1591 for (oop* p = oops_begin(); p < oops_end(); p++) { |
1562 if (*p == Universe::non_oop_word()) continue; // skip non-oops |
1592 if (*p == Universe::non_oop_word()) continue; // skip non-oops |
1563 f->do_oop(p); |
1593 f->do_oop(p); |
1564 } |
1594 } |
|
1595 } |
|
1596 |
|
1597 #define NMETHOD_SENTINEL ((nmethod*)badAddress) |
|
1598 |
|
1599 nmethod* volatile nmethod::_oops_do_mark_nmethods; |
|
1600 |
|
1601 // An nmethod is "marked" if its _mark_link is set non-null. |
|
1602 // Even if it is the end of the linked list, it will have a non-null link value, |
|
1603 // as long as it is on the list. |
|
1604 // This code must be MP safe, because it is used from parallel GC passes. |
|
1605 bool nmethod::test_set_oops_do_mark() { |
|
1606 assert(nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called"); |
|
1607 nmethod* observed_mark_link = _oops_do_mark_link; |
|
1608 if (observed_mark_link == NULL) { |
|
1609 // Claim this nmethod for this thread to mark. |
|
1610 observed_mark_link = (nmethod*) |
|
1611 Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_link, NULL); |
|
1612 if (observed_mark_link == NULL) { |
|
1613 |
|
1614 // Atomically append this nmethod (now claimed) to the head of the list: |
|
1615 nmethod* observed_mark_nmethods = _oops_do_mark_nmethods; |
|
1616 for (;;) { |
|
1617 nmethod* required_mark_nmethods = observed_mark_nmethods; |
|
1618 _oops_do_mark_link = required_mark_nmethods; |
|
1619 observed_mark_nmethods = (nmethod*) |
|
1620 Atomic::cmpxchg_ptr(this, &_oops_do_mark_nmethods, required_mark_nmethods); |
|
1621 if (observed_mark_nmethods == required_mark_nmethods) |
|
1622 break; |
|
1623 } |
|
1624 // Mark was clear when we first saw this guy. |
|
1625 NOT_PRODUCT(if (TraceScavenge) print_on(tty, "oops_do, mark\n")); |
|
1626 return false; |
|
1627 } |
|
1628 } |
|
1629 // On fall through, another racing thread marked this nmethod before we did. |
|
1630 return true; |
|
1631 } |
|
1632 |
|
1633 void nmethod::oops_do_marking_prologue() { |
|
1634 NOT_PRODUCT(if (TraceScavenge) tty->print_cr("[oops_do_marking_prologue")); |
|
1635 assert(_oops_do_mark_nmethods == NULL, "must not call oops_do_marking_prologue twice in a row"); |
|
1636 // We use cmpxchg_ptr instead of regular assignment here because the user |
|
1637 // may fork a bunch of threads, and we need them all to see the same state. |
|
1638 void* observed = Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_nmethods, NULL); |
|
1639 guarantee(observed == NULL, "no races in this sequential code"); |
|
1640 } |
|
1641 |
|
1642 void nmethod::oops_do_marking_epilogue() { |
|
1643 assert(_oops_do_mark_nmethods != NULL, "must not call oops_do_marking_epilogue twice in a row"); |
|
1644 nmethod* cur = _oops_do_mark_nmethods; |
|
1645 while (cur != NMETHOD_SENTINEL) { |
|
1646 assert(cur != NULL, "not NULL-terminated"); |
|
1647 nmethod* next = cur->_oops_do_mark_link; |
|
1648 cur->_oops_do_mark_link = NULL; |
|
1649 NOT_PRODUCT(if (TraceScavenge) cur->print_on(tty, "oops_do, unmark\n")); |
|
1650 cur = next; |
|
1651 } |
|
1652 void* required = _oops_do_mark_nmethods; |
|
1653 void* observed = Atomic::cmpxchg_ptr(NULL, &_oops_do_mark_nmethods, required); |
|
1654 guarantee(observed == required, "no races in this sequential code"); |
|
1655 NOT_PRODUCT(if (TraceScavenge) tty->print_cr("oops_do_marking_epilogue]")); |
|
1656 } |
|
1657 |
|
1658 class DetectScavengeRoot: public OopClosure { |
|
1659 bool _detected_scavenge_root; |
|
1660 public: |
|
1661 DetectScavengeRoot() : _detected_scavenge_root(false) |
|
1662 { NOT_PRODUCT(_print_nm = NULL); } |
|
1663 bool detected_scavenge_root() { return _detected_scavenge_root; } |
|
1664 virtual void do_oop(oop* p) { |
|
1665 if ((*p) != NULL && (*p)->is_scavengable()) { |
|
1666 NOT_PRODUCT(maybe_print(p)); |
|
1667 _detected_scavenge_root = true; |
|
1668 } |
|
1669 } |
|
1670 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
|
1671 |
|
1672 #ifndef PRODUCT |
|
1673 nmethod* _print_nm; |
|
1674 void maybe_print(oop* p) { |
|
1675 if (_print_nm == NULL) return; |
|
1676 if (!_detected_scavenge_root) _print_nm->print_on(tty, "new scavenge root"); |
|
1677 tty->print_cr(""PTR_FORMAT"[offset=%d] detected non-perm oop "PTR_FORMAT" (found at "PTR_FORMAT")", |
|
1678 _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm), |
|
1679 (intptr_t)(*p), (intptr_t)p); |
|
1680 (*p)->print(); |
|
1681 } |
|
1682 #endif //PRODUCT |
|
1683 }; |
|
1684 |
|
1685 bool nmethod::detect_scavenge_root_oops() { |
|
1686 DetectScavengeRoot detect_scavenge_root; |
|
1687 NOT_PRODUCT(if (TraceScavenge) detect_scavenge_root._print_nm = this); |
|
1688 oops_do(&detect_scavenge_root); |
|
1689 return detect_scavenge_root.detected_scavenge_root(); |
1565 } |
1690 } |
1566 |
1691 |
1567 // Method that knows how to preserve outgoing arguments at call. This method must be |
1692 // Method that knows how to preserve outgoing arguments at call. This method must be |
1568 // called with a frame corresponding to a Java invoke |
1693 // called with a frame corresponding to a Java invoke |
1569 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { |
1694 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { |
1972 |
2120 |
1973 // ----------------------------------------------------------------------------- |
2121 // ----------------------------------------------------------------------------- |
1974 // Non-product code |
2122 // Non-product code |
1975 #ifndef PRODUCT |
2123 #ifndef PRODUCT |
1976 |
2124 |
1977 void nmethod::check_store() { |
2125 class DebugScavengeRoot: public OopClosure { |
1978 // Make sure all oops in the compiled code are tenured |
2126 nmethod* _nm; |
1979 |
2127 bool _ok; |
1980 RelocIterator iter(this); |
2128 public: |
1981 while (iter.next()) { |
2129 DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { } |
1982 if (iter.type() == relocInfo::oop_type) { |
2130 bool ok() { return _ok; } |
1983 oop_Relocation* reloc = iter.oop_reloc(); |
2131 virtual void do_oop(oop* p) { |
1984 oop obj = reloc->oop_value(); |
2132 if ((*p) == NULL || !(*p)->is_scavengable()) return; |
1985 if (obj != NULL && !obj->is_perm()) { |
2133 if (_ok) { |
1986 fatal("must be permanent oop in compiled code"); |
2134 _nm->print_nmethod(true); |
1987 } |
2135 _ok = false; |
1988 } |
2136 } |
1989 } |
2137 tty->print_cr("*** non-perm oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", |
|
2138 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); |
|
2139 (*p)->print(); |
|
2140 } |
|
2141 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
|
2142 }; |
|
2143 |
|
2144 void nmethod::verify_scavenge_root_oops() { |
|
2145 if (!on_scavenge_root_list()) { |
|
2146 // Actually look inside, to verify the claim that it's clean. |
|
2147 DebugScavengeRoot debug_scavenge_root(this); |
|
2148 oops_do(&debug_scavenge_root); |
|
2149 if (!debug_scavenge_root.ok()) |
|
2150 fatal("found an unadvertised bad non-perm oop in the code cache"); |
|
2151 } |
|
2152 assert(scavenge_root_not_marked(), ""); |
1990 } |
2153 } |
1991 |
2154 |
1992 #endif // PRODUCT |
2155 #endif // PRODUCT |
1993 |
2156 |
1994 // Printing operations |
2157 // Printing operations |
2017 if (level()) tty->print("l%d ", level()); |
2180 if (level()) tty->print("l%d ", level()); |
2018 if (is_in_use()) tty->print("in_use "); |
2181 if (is_in_use()) tty->print("in_use "); |
2019 if (is_not_entrant()) tty->print("not_entrant "); |
2182 if (is_not_entrant()) tty->print("not_entrant "); |
2020 if (is_zombie()) tty->print("zombie "); |
2183 if (is_zombie()) tty->print("zombie "); |
2021 if (is_unloaded()) tty->print("unloaded "); |
2184 if (is_unloaded()) tty->print("unloaded "); |
|
2185 if (on_scavenge_root_list()) tty->print("scavenge_root "); |
2022 tty->print_cr("}:"); |
2186 tty->print_cr("}:"); |
2023 } |
2187 } |
2024 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2188 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2025 (address)this, |
2189 (address)this, |
2026 (address)this + size(), |
2190 (address)this + size(), |