# HG changeset patch # User mdoerr # Date 1571927331 -7200 # Node ID c6cbcc673cd3a0d271e06bc05b6c224d4c393847 # Parent 9019c186ae990dbc402a0b3f412c337bfd767401 8231949: [PPC64, s390]: Make async profiling more reliable Summary: Better checks if method from interpreter frame is valid. Reviewed-by: rrich, ghaug, goetz diff -r 9019c186ae99 -r c6cbcc673cd3 src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp --- a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp Thu Oct 24 16:28:49 2019 +0200 +++ b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp Thu Oct 24 16:28:51 2019 +0200 @@ -65,21 +65,22 @@ } if (ret_frame.is_interpreted_frame()) { - frame::ijava_state* istate = ret_frame.get_ijava_state(); - if (MetaspaceObj::is_valid((Method*)(istate->method)) == false) { - return false; - } - uint64_t reg_bcp = uc->uc_mcontext.regs->gpr[14/*R14_bcp*/]; - uint64_t istate_bcp = istate->bcp; - uint64_t code_start = (uint64_t)(((Method*)(istate->method))->code_base()); - uint64_t code_end = (uint64_t)(((Method*)istate->method)->code_base() + ((Method*)istate->method)->code_size()); - if (istate_bcp >= code_start && istate_bcp < code_end) { - // we have a valid bcp, don't touch it, do nothing - } else if (reg_bcp >= code_start && reg_bcp < code_end) { - istate->bcp = reg_bcp; + frame::ijava_state *istate = ret_frame.get_ijava_state(); + const Method *m = (const Method*)(istate->method); + if (!Method::is_valid_method(m)) return false; + if (!Metaspace::contains(m->constMethod())) return false; + + uint64_t reg_bcp = uc->uc_mcontext.regs->gpr[14/*R14_bcp*/]; + uint64_t istate_bcp = istate->bcp; + uint64_t code_start = (uint64_t)(m->code_base()); + uint64_t code_end = (uint64_t)(m->code_base() + m->code_size()); + if (istate_bcp >= code_start && istate_bcp < code_end) { + // we have a valid bcp, don't touch it, do nothing + } else if (reg_bcp >= code_start && reg_bcp < code_end) { + istate->bcp = reg_bcp; } else { - return false; - } + return false; + } } if (!ret_frame.safe_for_sender(this)) { // nothing else to try if the frame isn't good diff -r 9019c186ae99 -r c6cbcc673cd3 src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp --- a/src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp Thu Oct 24 16:28:49 2019 +0200 +++ b/src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp Thu Oct 24 16:28:51 2019 +0200 @@ -63,21 +63,24 @@ if (ret_frame.is_interpreted_frame()) { frame::z_ijava_state* istate = ret_frame.ijava_state_unchecked(); - if ((stack_base() >= (address)istate && (address)istate > stack_end()) || - MetaspaceObj::is_valid((Method*)(istate->method)) == false) { - return false; - } - uint64_t reg_bcp = uc->uc_mcontext.gregs[13/*Z_BCP*/]; - uint64_t istate_bcp = istate->bcp; - uint64_t code_start = (uint64_t)(((Method*)(istate->method))->code_base()); - uint64_t code_end = (uint64_t)(((Method*)istate->method)->code_base() + ((Method*)istate->method)->code_size()); - if (istate_bcp >= code_start && istate_bcp < code_end) { - // we have a valid bcp, don't touch it, do nothing - } else if (reg_bcp >= code_start && reg_bcp < code_end) { - istate->bcp = reg_bcp; - } else { - return false; - } + if (stack_base() >= (address)istate && (address)istate > stack_end()) { + return false; + } + const Method *m = (const Method*)(istate->method); + if (!Method::is_valid_method(m)) return false; + if (!Metaspace::contains(m->constMethod())) return false; + + uint64_t reg_bcp = uc->uc_mcontext.gregs[13/*Z_BCP*/]; + uint64_t istate_bcp = istate->bcp; + uint64_t code_start = (uint64_t)(m->code_base()); + uint64_t code_end = (uint64_t)(m->code_base() + m->code_size()); + if (istate_bcp >= code_start && istate_bcp < code_end) { + // we have a valid bcp, don't touch it, do nothing + } else if (reg_bcp >= code_start && reg_bcp < code_end) { + istate->bcp = reg_bcp; + } else { + return false; + } } if (!ret_frame.safe_for_sender(this)) { // nothing else to try if the frame isn't good