Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/aarch64/vm/frame_aarch64.cpp
32285 views
/*1* Copyright (c) 2013, Red Hat Inc.2* Copyright (c) 1997, 2019, Oracle and/or its affiliates.3* All rights reserved.4* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5*6* This code is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License version 2 only, as8* published by the Free Software Foundation.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*24*/2526#include "precompiled.hpp"27#include "interpreter/interpreter.hpp"28#include "memory/resourceArea.hpp"29#include "oops/markOop.hpp"30#include "oops/method.hpp"31#include "oops/oop.inline.hpp"32#include "prims/methodHandles.hpp"33#include "runtime/frame.inline.hpp"34#include "runtime/handles.inline.hpp"35#include "runtime/javaCalls.hpp"36#include "runtime/monitorChunk.hpp"37#include "runtime/os.hpp"38#include "runtime/signature.hpp"39#include "runtime/stubCodeGenerator.hpp"40#include "runtime/stubRoutines.hpp"41#include "vmreg_aarch64.inline.hpp"42#ifdef COMPILER143#include "c1/c1_Runtime1.hpp"44#include "runtime/vframeArray.hpp"45#endif4647#ifdef ASSERT48void RegisterMap::check_location_valid() {49}50#endif515253// Profiling/safepoint support5455bool frame::safe_for_sender(JavaThread *thread) {56address sp = (address)_sp;57address fp = (address)_fp;58address unextended_sp = (address)_unextended_sp;5960// consider stack guards when trying to determine "safe" stack pointers61static size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0;62size_t usable_stack_size = thread->stack_size() - stack_guard_size;6364// sp must be within the usable part of the stack (not in guards)65bool sp_safe = (sp < thread->stack_base()) &&66(sp >= thread->stack_base() - usable_stack_size);676869if (!sp_safe) {70return false;71}7273// When we are running interpreted code the machine stack pointer, SP, is74// set low enough so that the Java expression stack can grow and shrink75// without ever exceeding the machine stack bounds. So, ESP >= SP.7677// When we call out of an interpreted method, SP is incremented so that78// the space between SP and ESP is removed. The SP saved in the callee's79// frame is the SP *before* this increment. So, when we walk a stack of80// interpreter frames the sender's SP saved in a frame might be less than81// the SP at the point of call.8283// So unextended sp must be within the stack but we need not to check84// that unextended sp >= sp8586bool unextended_sp_safe = (unextended_sp < thread->stack_base());8788if (!unextended_sp_safe) {89return false;90}9192// an fp must be within the stack and above (but not equal) sp93// second evaluation on fp+ is added to handle situation where fp is -194bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));9596// We know sp/unextended_sp are safe only fp is questionable here9798// If the current frame is known to the code cache then we can attempt to99// to construct the sender and do some validation of it. This goes a long way100// toward eliminating issues when we get in frame construction code101102if (_cb != NULL ) {103104// First check if frame is complete and tester is reliable105// Unfortunately we can only check frame complete for runtime stubs and nmethod106// other generic buffer blobs are more problematic so we just assume they are107// ok. adapter blobs never have a frame complete and are never ok.108109if (!_cb->is_frame_complete_at(_pc)) {110if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {111return false;112}113}114115// Could just be some random pointer within the codeBlob116if (!_cb->code_contains(_pc)) {117return false;118}119120// Entry frame checks121if (is_entry_frame()) {122// an entry frame must have a valid fp.123124if (!fp_safe) return false;125126// Validate the JavaCallWrapper an entry frame must have127128address jcw = (address)entry_frame_call_wrapper();129130bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > fp);131132return jcw_safe;133134}135136intptr_t* sender_sp = NULL;137intptr_t* sender_unextended_sp = NULL;138address sender_pc = NULL;139intptr_t* saved_fp = NULL;140141if (is_interpreted_frame()) {142// fp must be safe143if (!fp_safe) {144return false;145}146147sender_pc = (address) this->fp()[return_addr_offset];148// for interpreted frames, the value below is the sender "raw" sp,149// which can be different from the sender unextended sp (the sp seen150// by the sender) because of current frame local variables151sender_sp = (intptr_t*) addr_at(sender_sp_offset);152sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];153saved_fp = (intptr_t*) this->fp()[link_offset];154155} else {156// must be some sort of compiled/runtime frame157// fp does not have to be safe (although it could be check for c1?)158159// check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc160if (_cb->frame_size() <= 0) {161return false;162}163164sender_sp = _unextended_sp + _cb->frame_size();165sender_unextended_sp = sender_sp;166sender_pc = (address) *(sender_sp-1);167// Note: frame::sender_sp_offset is only valid for compiled frame168saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);169}170171172// If the potential sender is the interpreter then we can do some more checking173if (Interpreter::contains(sender_pc)) {174175// fp is always saved in a recognizable place in any code we generate. However176// only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved fp177// is really a frame pointer.178179bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);180181if (!saved_fp_safe) {182return false;183}184185// construct the potential sender186187frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);188189return sender.is_interpreted_frame_valid(thread);190191}192193// We must always be able to find a recognizable pc194CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);195if (sender_pc == NULL || sender_blob == NULL) {196return false;197}198199// Could be a zombie method200if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {201return false;202}203204// Could just be some random pointer within the codeBlob205if (!sender_blob->code_contains(sender_pc)) {206return false;207}208209// We should never be able to see an adapter if the current frame is something from code cache210if (sender_blob->is_adapter_blob()) {211return false;212}213214// Could be the call_stub215if (StubRoutines::returns_to_call_stub(sender_pc)) {216bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);217218if (!saved_fp_safe) {219return false;220}221222// construct the potential sender223224frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);225226// Validate the JavaCallWrapper an entry frame must have227address jcw = (address)sender.entry_frame_call_wrapper();228229bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp());230231return jcw_safe;232}233234if (sender_blob->is_nmethod()) {235nmethod* nm = sender_blob->as_nmethod_or_null();236if (nm != NULL) {237if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc)) {238return false;239}240}241}242243// If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size244// because the return address counts against the callee's frame.245246if (sender_blob->frame_size() <= 0) {247assert(!sender_blob->is_nmethod(), "should count return address at least");248return false;249}250251// We should never be able to see anything here except an nmethod. If something in the252// code cache (current frame) is called by an entity within the code cache that entity253// should not be anything but the call stub (already covered), the interpreter (already covered)254// or an nmethod.255256if (!sender_blob->is_nmethod()) {257return false;258}259260// Could put some more validation for the potential non-interpreted sender261// frame we'd create by calling sender if I could think of any. Wait for next crash in forte...262263// One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb264265// We've validated the potential sender that would be created266return true;267}268269// Must be native-compiled frame. Since sender will try and use fp to find270// linkages it must be safe271272if (!fp_safe) {273return false;274}275276// Will the pc we fetch be non-zero (which we'll find at the oldest frame)277278if ( (address) this->fp()[return_addr_offset] == NULL) return false;279280281// could try and do some more potential verification of native frame if we could think of some...282283return true;284285}286287void frame::patch_pc(Thread* thread, address pc) {288address* pc_addr = &(((address*) sp())[-1]);289if (TracePcPatching) {290tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",291p2i(pc_addr), p2i(*pc_addr), p2i(pc));292}293// Either the return address is the original one or we are going to294// patch in the same address that's already there.295assert(_pc == *pc_addr || pc == *pc_addr, "must be");296*pc_addr = pc;297_cb = CodeCache::find_blob(pc);298address original_pc = nmethod::get_deopt_original_pc(this);299if (original_pc != NULL) {300assert(original_pc == _pc, "expected original PC to be stored before patching");301_deopt_state = is_deoptimized;302// leave _pc as is303} else {304_deopt_state = not_deoptimized;305_pc = pc;306}307}308309bool frame::is_interpreted_frame() const {310return Interpreter::contains(pc());311}312313int frame::frame_size(RegisterMap* map) const {314frame sender = this->sender(map);315return sender.sp() - sp();316}317318intptr_t* frame::entry_frame_argument_at(int offset) const {319// convert offset to index to deal with tsi320int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);321// Entry frame's arguments are always in relation to unextended_sp()322return &unextended_sp()[index];323}324325// sender_sp326#ifdef CC_INTERP327intptr_t* frame::interpreter_frame_sender_sp() const {328assert(is_interpreted_frame(), "interpreted frame expected");329// QQQ why does this specialize method exist if frame::sender_sp() does same thing?330// seems odd and if we always know interpreted vs. non then sender_sp() is really331// doing too much work.332return get_interpreterState()->sender_sp();333}334335// monitor elements336337BasicObjectLock* frame::interpreter_frame_monitor_begin() const {338return get_interpreterState()->monitor_base();339}340341BasicObjectLock* frame::interpreter_frame_monitor_end() const {342return (BasicObjectLock*) get_interpreterState()->stack_base();343}344345#else // CC_INTERP346347intptr_t* frame::interpreter_frame_sender_sp() const {348assert(is_interpreted_frame(), "interpreted frame expected");349return (intptr_t*) at(interpreter_frame_sender_sp_offset);350}351352void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {353assert(is_interpreted_frame(), "interpreted frame expected");354ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);355}356357358// monitor elements359360BasicObjectLock* frame::interpreter_frame_monitor_begin() const {361return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);362}363364BasicObjectLock* frame::interpreter_frame_monitor_end() const {365BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);366// make sure the pointer points inside the frame367assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");368assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer");369return result;370}371372void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {373*((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;374}375376// Used by template based interpreter deoptimization377void frame::interpreter_frame_set_last_sp(intptr_t* sp) {378*((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;379}380#endif // CC_INTERP381382frame frame::sender_for_entry_frame(RegisterMap* map) const {383assert(map != NULL, "map must be set");384// Java frame called from C; skip all C frames and return top C385// frame of that chunk as the sender386JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();387assert(!entry_frame_is_first(), "next Java fp must be non zero");388assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");389// Since we are walking the stack now this nested anchor is obviously walkable390// even if it wasn't when it was stacked.391if (!jfa->walkable()) {392// Capture _last_Java_pc (if needed) and mark anchor walkable.393jfa->capture_last_Java_pc();394}395map->clear();396assert(map->include_argument_oops(), "should be set by clear");397assert(jfa->last_Java_pc() != NULL, "not walkable");398frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());399return fr;400}401402//------------------------------------------------------------------------------403// frame::verify_deopt_original_pc404//405// Verifies the calculated original PC of a deoptimization PC for the406// given unextended SP. The unextended SP might also be the saved SP407// for MethodHandle call sites.408#ifdef ASSERT409void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return) {410frame fr;411412// This is ugly but it's better than to change {get,set}_original_pc413// to take an SP value as argument. And it's only a debugging414// method anyway.415fr._unextended_sp = unextended_sp;416417address original_pc = nm->get_original_pc(&fr);418assert(nm->insts_contains(original_pc), "original PC must be in nmethod");419assert(nm->is_method_handle_return(original_pc) == is_method_handle_return, "must be");420}421#endif422423//------------------------------------------------------------------------------424// frame::adjust_unextended_sp425void frame::adjust_unextended_sp() {426// If we are returning to a compiled MethodHandle call site, the427// saved_fp will in fact be a saved value of the unextended SP. The428// simplest way to tell whether we are returning to such a call site429// is as follows:430431nmethod* sender_nm = (_cb == NULL) ? NULL : _cb->as_nmethod_or_null();432if (sender_nm != NULL) {433// If the sender PC is a deoptimization point, get the original434// PC. For MethodHandle call site the unextended_sp is stored in435// saved_fp.436if (sender_nm->is_deopt_mh_entry(_pc)) {437DEBUG_ONLY(verify_deopt_mh_original_pc(sender_nm, _fp));438_unextended_sp = _fp;439}440else if (sender_nm->is_deopt_entry(_pc)) {441DEBUG_ONLY(verify_deopt_original_pc(sender_nm, _unextended_sp));442}443else if (sender_nm->is_method_handle_return(_pc)) {444_unextended_sp = _fp;445}446}447}448449//------------------------------------------------------------------------------450// frame::update_map_with_saved_link451void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {452// The interpreter and compiler(s) always save fp in a known453// location on entry. We must record where that location is454// so that if fp was live on callout from c2 we can find455// the saved copy no matter what it called.456457// Since the interpreter always saves fp if we record where it is then458// we don't have to always save fp on entry and exit to c2 compiled459// code, on entry will be enough.460map->set_location(rfp->as_VMReg(), (address) link_addr);461// this is weird "H" ought to be at a higher address however the462// oopMaps seems to have the "H" regs at the same address and the463// vanilla register.464// XXXX make this go away465if (true) {466map->set_location(rfp->as_VMReg()->next(), (address) link_addr);467}468}469470471//------------------------------------------------------------------------------472// frame::sender_for_interpreter_frame473frame frame::sender_for_interpreter_frame(RegisterMap* map) const {474// SP is the raw SP from the sender after adapter or interpreter475// extension.476intptr_t* sender_sp = this->sender_sp();477478// This is the sp before any possible extension (adapter/locals).479intptr_t* unextended_sp = interpreter_frame_sender_sp();480481#ifdef COMPILER2482if (map->update_map()) {483update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));484}485#endif // COMPILER2486487return frame(sender_sp, unextended_sp, link(), sender_pc());488}489490491//------------------------------------------------------------------------------492// frame::sender_for_compiled_frame493frame frame::sender_for_compiled_frame(RegisterMap* map) const {494// we cannot rely upon the last fp having been saved to the thread495// in C2 code but it will have been pushed onto the stack. so we496// have to find it relative to the unextended sp497498assert(_cb->frame_size() >= 0, "must have non-zero frame size");499intptr_t* l_sender_sp = unextended_sp() + _cb->frame_size();500intptr_t* unextended_sp = l_sender_sp;501502// the return_address is always the word on the stack503address sender_pc = (address) *(l_sender_sp-1);504505intptr_t** saved_fp_addr = (intptr_t**) (l_sender_sp - frame::sender_sp_offset);506507// assert (sender_sp() == l_sender_sp, "should be");508// assert (*saved_fp_addr == link(), "should be");509510if (map->update_map()) {511// Tell GC to use argument oopmaps for some runtime stubs that need it.512// For C1, the runtime stub might not have oop maps, so set this flag513// outside of update_register_map.514map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));515if (_cb->oop_maps() != NULL) {516OopMapSet::update_register_map(this, map);517}518519// Since the prolog does the save and restore of EBP there is no oopmap520// for it so we must fill in its location as if there was an oopmap entry521// since if our caller was compiled code there could be live jvm state in it.522update_map_with_saved_link(map, saved_fp_addr);523}524525return frame(l_sender_sp, unextended_sp, *saved_fp_addr, sender_pc);526}527528//------------------------------------------------------------------------------529// frame::sender530frame frame::sender(RegisterMap* map) const {531// Default is we done have to follow them. The sender_for_xxx will532// update it accordingly533map->set_include_argument_oops(false);534535if (is_entry_frame())536return sender_for_entry_frame(map);537if (is_interpreted_frame())538return sender_for_interpreter_frame(map);539assert(_cb == CodeCache::find_blob(pc()),"Must be the same");540541// This test looks odd: why is it not is_compiled_frame() ? That's542// because stubs also have OOP maps.543if (_cb != NULL) {544return sender_for_compiled_frame(map);545}546547// Must be native-compiled frame, i.e. the marshaling code for native548// methods that exists in the core system.549return frame(sender_sp(), link(), sender_pc());550}551552bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {553assert(is_interpreted_frame(), "must be interpreter frame");554Method* method = interpreter_frame_method();555// When unpacking an optimized frame the frame pointer is556// adjusted with:557int diff = (method->max_locals() - method->size_of_parameters()) *558Interpreter::stackElementWords;559return _fp == (fp - diff);560}561562void frame::pd_gc_epilog() {563// nothing done here now564}565566bool frame::is_interpreted_frame_valid(JavaThread* thread) const {567// QQQ568#ifdef CC_INTERP569#else570assert(is_interpreted_frame(), "Not an interpreted frame");571// These are reasonable sanity checks572if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {573return false;574}575if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {576return false;577}578if (fp() + interpreter_frame_initial_sp_offset < sp()) {579return false;580}581// These are hacks to keep us out of trouble.582// The problem with these is that they mask other problems583if (fp() <= sp()) { // this attempts to deal with unsigned comparison above584return false;585}586587// do some validation of frame elements588589// first the method590591Method* m = *interpreter_frame_method_addr();592593// validate the method we'd find in this potential sender594if (!m->is_valid_method()) return false;595596// stack frames shouldn't be much larger than max_stack elements597// this test requires the use of unextended_sp which is the sp as seen by598// the current frame, and not sp which is the "raw" pc which could point599// further because of local variables of the callee method inserted after600// method arguments601if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {602return false;603}604605// validate bci/bcx606607intptr_t bcx = interpreter_frame_bcx();608if (m->validate_bci_from_bcx(bcx) < 0) {609return false;610}611612// validate constantPoolCache*613ConstantPoolCache* cp = *interpreter_frame_cache_addr();614if (cp == NULL || !cp->is_metaspace_object()) return false;615616// validate locals617618address locals = (address) *interpreter_frame_locals_addr();619620if (locals > thread->stack_base() || locals < (address) fp()) return false;621622// We'd have to be pretty unlucky to be mislead at this point623624#endif // CC_INTERP625return true;626}627628BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {629#ifdef CC_INTERP630// Needed for JVMTI. The result should always be in the631// interpreterState object632interpreterState istate = get_interpreterState();633#endif // CC_INTERP634assert(is_interpreted_frame(), "interpreted frame expected");635Method* method = interpreter_frame_method();636BasicType type = method->result_type();637638intptr_t* tos_addr;639if (method->is_native()) {640// TODO : ensure AARCH64 does the same as Intel here i.e. push v0 then r0641// Prior to calling into the runtime to report the method_exit the possible642// return value is pushed to the native stack. If the result is a jfloat/jdouble643// then ST0 is saved before EAX/EDX. See the note in generate_native_result644tos_addr = (intptr_t*)sp();645if (type == T_FLOAT || type == T_DOUBLE) {646// This is times two because we do a push(ltos) after pushing XMM0647// and that takes two interpreter stack slots.648tos_addr += 2 * Interpreter::stackElementWords;649}650} else {651tos_addr = (intptr_t*)interpreter_frame_tos_address();652}653654switch (type) {655case T_OBJECT :656case T_ARRAY : {657oop obj;658if (method->is_native()) {659#ifdef CC_INTERP660obj = istate->_oop_temp;661#else662obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));663#endif // CC_INTERP664} else {665oop* obj_p = (oop*)tos_addr;666obj = (obj_p == NULL) ? (oop)NULL : *obj_p;667}668assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");669*oop_result = obj;670break;671}672case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;673case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;674case T_CHAR : value_result->c = *(jchar*)tos_addr; break;675case T_SHORT : value_result->s = *(jshort*)tos_addr; break;676case T_INT : value_result->i = *(jint*)tos_addr; break;677case T_LONG : value_result->j = *(jlong*)tos_addr; break;678case T_FLOAT : {679value_result->f = *(jfloat*)tos_addr;680break;681}682case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;683case T_VOID : /* Nothing to do */ break;684default : ShouldNotReachHere();685}686687return type;688}689690691intptr_t* frame::interpreter_frame_tos_at(jint offset) const {692int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);693return &interpreter_frame_tos_address()[index];694}695696#ifndef PRODUCT697698#define DESCRIBE_FP_OFFSET(name) \699values.describe(frame_no, fp() + frame::name##_offset, #name)700701void frame::describe_pd(FrameValues& values, int frame_no) {702if (is_interpreted_frame()) {703DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);704DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);705DESCRIBE_FP_OFFSET(interpreter_frame_method);706DESCRIBE_FP_OFFSET(interpreter_frame_mdx);707DESCRIBE_FP_OFFSET(interpreter_frame_cache);708DESCRIBE_FP_OFFSET(interpreter_frame_locals);709DESCRIBE_FP_OFFSET(interpreter_frame_bcx);710DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);711}712}713#endif714715intptr_t *frame::initial_deoptimization_info() {716// Not used on aarch64, but we must return something.717return NULL;718}719720intptr_t* frame::real_fp() const {721if (_cb != NULL) {722// use the frame size if valid723int size = _cb->frame_size();724if (size > 0) {725return unextended_sp() + size;726}727}728// else rely on fp()729assert(! is_compiled_frame(), "unknown compiled frame size");730return fp();731}732733#undef DESCRIBE_FP_OFFSET734735#define DESCRIBE_FP_OFFSET(name) \736{ \737unsigned long *p = (unsigned long *)fp; \738printf("0x%016lx 0x%016lx %s\n", (unsigned long)(p + frame::name##_offset), \739p[frame::name##_offset], #name); \740}741742static __thread unsigned long nextfp;743static __thread unsigned long nextpc;744static __thread unsigned long nextsp;745static __thread RegisterMap *reg_map;746747static void printbc(Method *m, intptr_t bcx) {748const char *name;749char buf[16];750if (m->validate_bci_from_bcx(bcx) < 0751|| !m->contains((address)bcx)) {752name = "???";753snprintf(buf, sizeof buf, "(bad)");754} else {755int bci = m->bci_from((address)bcx);756snprintf(buf, sizeof buf, "%d", bci);757name = Bytecodes::name(m->code_at(bci));758}759ResourceMark rm;760printf("%s : %s ==> %s\n", m->name_and_sig_as_C_string(), buf, name);761}762763void internal_pf(unsigned long sp, unsigned long fp, unsigned long pc, unsigned long bcx) {764if (! fp)765return;766767DESCRIBE_FP_OFFSET(return_addr);768DESCRIBE_FP_OFFSET(link);769DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);770DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);771DESCRIBE_FP_OFFSET(interpreter_frame_method);772DESCRIBE_FP_OFFSET(interpreter_frame_mdx);773DESCRIBE_FP_OFFSET(interpreter_frame_cache);774DESCRIBE_FP_OFFSET(interpreter_frame_locals);775DESCRIBE_FP_OFFSET(interpreter_frame_bcx);776DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);777unsigned long *p = (unsigned long *)fp;778779// We want to see all frames, native and Java. For compiled and780// interpreted frames we have special information that allows us to781// unwind them; for everything else we assume that the native frame782// pointer chain is intact.783frame this_frame((intptr_t*)sp, (intptr_t*)fp, (address)pc);784if (this_frame.is_compiled_frame() ||785this_frame.is_interpreted_frame()) {786frame sender = this_frame.sender(reg_map);787nextfp = (unsigned long)sender.fp();788nextpc = (unsigned long)sender.pc();789nextsp = (unsigned long)sender.unextended_sp();790} else {791nextfp = p[frame::link_offset];792nextpc = p[frame::return_addr_offset];793nextsp = (unsigned long)&p[frame::sender_sp_offset];794}795796if (bcx == -1ul)797bcx = p[frame::interpreter_frame_bcx_offset];798799if (Interpreter::contains((address)pc)) {800Method* m = (Method*)p[frame::interpreter_frame_method_offset];801if(m && m->is_method()) {802printbc(m, bcx);803} else804printf("not a Method\n");805} else {806CodeBlob *cb = CodeCache::find_blob((address)pc);807if (cb != NULL) {808if (cb->is_nmethod()) {809ResourceMark rm;810nmethod* nm = (nmethod*)cb;811printf("nmethod %s\n", nm->method()->name_and_sig_as_C_string());812} else if (cb->name()) {813printf("CodeBlob %s\n", cb->name());814}815}816}817}818819extern "C" void npf() {820CodeBlob *cb = CodeCache::find_blob((address)nextpc);821// C2 does not always chain the frame pointers when it can, instead822// preferring to use fixed offsets from SP, so a simple leave() does823// not work. Instead, it adds the frame size to SP then pops FP and824// LR. We have to do the same thing to get a good call chain.825if (cb && cb->frame_size())826nextfp = nextsp + wordSize * (cb->frame_size() - 2);827internal_pf (nextsp, nextfp, nextpc, -1);828}829830extern "C" void pf(unsigned long sp, unsigned long fp, unsigned long pc,831unsigned long bcx, unsigned long thread) {832if (!reg_map) {833reg_map = NEW_C_HEAP_OBJ(RegisterMap, mtNone);834::new (reg_map) RegisterMap((JavaThread*)thread, false);835} else {836*reg_map = RegisterMap((JavaThread*)thread, false);837}838839{840CodeBlob *cb = CodeCache::find_blob((address)pc);841if (cb && cb->frame_size())842fp = sp + wordSize * (cb->frame_size() - 2);843}844internal_pf(sp, fp, pc, bcx);845}846847// support for printing out where we are in a Java method848// needs to be passed current fp and bcp register values849// prints method name, bc index and bytecode name850extern "C" void pm(unsigned long fp, unsigned long bcx) {851DESCRIBE_FP_OFFSET(interpreter_frame_method);852unsigned long *p = (unsigned long *)fp;853Method* m = (Method*)p[frame::interpreter_frame_method_offset];854printbc(m, bcx);855}856857#ifndef PRODUCT858// This is a generic constructor which is only used by pns() in debug.cpp.859frame::frame(void* sp, void* fp, void* pc) {860init((intptr_t*)sp, (intptr_t*)fp, (address)pc);861}862#endif863864void JavaFrameAnchor::make_walkable(JavaThread* thread) {865// last frame set?866if (last_Java_sp() == NULL) return;867// already walkable?868if (walkable()) return;869assert(Thread::current() == (Thread*)thread, "not current thread");870assert(last_Java_sp() != NULL, "not called from Java code?");871assert(last_Java_pc() == NULL, "already walkable");872capture_last_Java_pc();873assert(walkable(), "something went wrong");874}875876void JavaFrameAnchor::capture_last_Java_pc() {877assert(_last_Java_sp != NULL, "no last frame set");878assert(_last_Java_pc == NULL, "already walkable");879_last_Java_pc = (address)_last_Java_sp[-1];880}881882883