1737 }
1738
1739
1740 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) {
1741 assert(count >= 2, "must be sentinel values, at least");
1742
1743 #ifdef ASSERT
1744 // must be sorted and unique; we do a binary search in find_pc_desc()
1745 int prev_offset = pcs[0].pc_offset();
1746 assert(prev_offset == PcDesc::lower_offset_limit,
1747 "must start with a sentinel");
1748 for (int i = 1; i < count; i++) {
1749 int this_offset = pcs[i].pc_offset();
1750 assert(this_offset > prev_offset, "offsets must be sorted");
1751 prev_offset = this_offset;
1752 }
1753 assert(prev_offset == PcDesc::upper_offset_limit,
1754 "must end with a sentinel");
1755 #endif //ASSERT
1756
1757 int size = count * sizeof(PcDesc);
1758 assert(scopes_pcs_size() >= size, "oob");
1759 memcpy(scopes_pcs_begin(), pcs, size);
1760
1761 // Adjust the final sentinel downward.
1762 PcDesc* last_pc = &scopes_pcs_begin()[count-1];
1763 assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity");
1764 last_pc->set_pc_offset(instructions_size() + 1);
1765 for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) {
1766 // Fill any rounding gaps with copies of the last record.
1767 last_pc[1] = last_pc[0];
1768 }
1769 // The following assert could fail if sizeof(PcDesc) is not
1770 // an integral multiple of oopSize (the rounding term).
1771 // If it fails, change the logic to always allocate a multiple
1772 // of sizeof(PcDesc), and fill unused words with copies of *last_pc.
1773 assert(last_pc + 1 == scopes_pcs_end(), "must match exactly");
1774 }
1775
1776 void nmethod::copy_scopes_data(u_char* buffer, int size) {
2004
2005 void nmethodLocker::lock_nmethod(nmethod* nm) {
2006 if (nm == NULL) return;
2007 Atomic::inc(&nm->_lock_count);
2008 guarantee(!nm->is_zombie(), "cannot lock a zombie method");
2009 }
2010
2011 void nmethodLocker::unlock_nmethod(nmethod* nm) {
2012 if (nm == NULL) return;
2013 Atomic::dec(&nm->_lock_count);
2014 guarantee(nm->_lock_count >= 0, "unmatched nmethod lock/unlock");
2015 }
2016
2017 bool nmethod::is_deopt_pc(address pc) {
2018 bool ret = pc == deopt_handler_begin();
2019 return ret;
2020 }
2021
2022
2023 // -----------------------------------------------------------------------------
2024 // Verification
2025
2026 class VerifyOopsClosure: public OopClosure {
2027 nmethod* _nm;
2028 bool _ok;
2029 public:
2030 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
2031 bool ok() { return _ok; }
2032 virtual void do_oop(oop* p) {
2033 if ((*p) == NULL || (*p)->is_oop()) return;
2034 if (_ok) {
2035 _nm->print_nmethod(true);
2036 _ok = false;
2037 }
2038 tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)",
2039 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm));
2040 }
2041 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2042 };
2043
|
1737 }
1738
1739
1740 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) {
1741 assert(count >= 2, "must be sentinel values, at least");
1742
1743 #ifdef ASSERT
1744 // must be sorted and unique; we do a binary search in find_pc_desc()
1745 int prev_offset = pcs[0].pc_offset();
1746 assert(prev_offset == PcDesc::lower_offset_limit,
1747 "must start with a sentinel");
1748 for (int i = 1; i < count; i++) {
1749 int this_offset = pcs[i].pc_offset();
1750 assert(this_offset > prev_offset, "offsets must be sorted");
1751 prev_offset = this_offset;
1752 }
1753 assert(prev_offset == PcDesc::upper_offset_limit,
1754 "must end with a sentinel");
1755 #endif //ASSERT
1756
1757 // Search for MethodHandle invokes and tag the nmethod.
1758 for (int i = 0; i < count; i++) {
1759 if (pcs[i].is_method_handle_invoke()) {
1760 set_has_method_handle_invokes(true);
1761 break;
1762 }
1763 }
1764
1765 int size = count * sizeof(PcDesc);
1766 assert(scopes_pcs_size() >= size, "oob");
1767 memcpy(scopes_pcs_begin(), pcs, size);
1768
1769 // Adjust the final sentinel downward.
1770 PcDesc* last_pc = &scopes_pcs_begin()[count-1];
1771 assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity");
1772 last_pc->set_pc_offset(instructions_size() + 1);
1773 for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) {
1774 // Fill any rounding gaps with copies of the last record.
1775 last_pc[1] = last_pc[0];
1776 }
1777 // The following assert could fail if sizeof(PcDesc) is not
1778 // an integral multiple of oopSize (the rounding term).
1779 // If it fails, change the logic to always allocate a multiple
1780 // of sizeof(PcDesc), and fill unused words with copies of *last_pc.
1781 assert(last_pc + 1 == scopes_pcs_end(), "must match exactly");
1782 }
1783
1784 void nmethod::copy_scopes_data(u_char* buffer, int size) {
2012
2013 void nmethodLocker::lock_nmethod(nmethod* nm) {
2014 if (nm == NULL) return;
2015 Atomic::inc(&nm->_lock_count);
2016 guarantee(!nm->is_zombie(), "cannot lock a zombie method");
2017 }
2018
2019 void nmethodLocker::unlock_nmethod(nmethod* nm) {
2020 if (nm == NULL) return;
2021 Atomic::dec(&nm->_lock_count);
2022 guarantee(nm->_lock_count >= 0, "unmatched nmethod lock/unlock");
2023 }
2024
2025 bool nmethod::is_deopt_pc(address pc) {
2026 bool ret = pc == deopt_handler_begin();
2027 return ret;
2028 }
2029
2030
2031 // -----------------------------------------------------------------------------
2032 // MethodHandle
2033
2034 bool nmethod::is_method_handle_return(address return_pc) {
2035 if (!has_method_handle_invokes()) return false;
2036 PcDesc* pd = pc_desc_at(return_pc);
2037 if (pd == NULL)
2038 return false;
2039 return pd->is_method_handle_invoke();
2040 }
2041
2042
2043 // -----------------------------------------------------------------------------
2044 // Verification
2045
2046 class VerifyOopsClosure: public OopClosure {
2047 nmethod* _nm;
2048 bool _ok;
2049 public:
2050 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
2051 bool ok() { return _ok; }
2052 virtual void do_oop(oop* p) {
2053 if ((*p) == NULL || (*p)->is_oop()) return;
2054 if (_ok) {
2055 _nm->print_nmethod(true);
2056 _ok = false;
2057 }
2058 tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)",
2059 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm));
2060 }
2061 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2062 };
2063
|