Path: blob/master/src/hotspot/cpu/aarch64/frame_aarch64.cpp
64441 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "compiler/oopMap.hpp"27#include "interpreter/interpreter.hpp"28#include "memory/resourceArea.hpp"29#include "memory/universe.hpp"30#include "oops/markWord.hpp"31#include "oops/method.hpp"32#include "oops/oop.inline.hpp"33#include "prims/methodHandles.hpp"34#include "runtime/frame.inline.hpp"35#include "runtime/handles.inline.hpp"36#include "runtime/javaCalls.hpp"37#include "runtime/monitorChunk.hpp"38#include "runtime/os.inline.hpp"39#include "runtime/signature.hpp"40#include "runtime/stackWatermarkSet.hpp"41#include "runtime/stubCodeGenerator.hpp"42#include "runtime/stubRoutines.hpp"43#include "vmreg_aarch64.inline.hpp"44#ifdef COMPILER145#include "c1/c1_Runtime1.hpp"46#include "runtime/vframeArray.hpp"47#endif4849#ifdef ASSERT50void RegisterMap::check_location_valid() {51}52#endif535455// Profiling/safepoint support5657bool frame::safe_for_sender(JavaThread *thread) {58address sp = (address)_sp;59address fp = (address)_fp;60address unextended_sp = (address)_unextended_sp;6162// consider stack guards when trying to determine "safe" stack pointers63// sp must be within the usable part of the stack (not in guards)64if (!thread->is_in_usable_stack(sp)) {65return false;66}6768// When we are running interpreted code the machine stack pointer, SP, is69// set low enough so that the Java expression stack can grow and shrink70// without ever exceeding the machine stack bounds. So, ESP >= SP.7172// When we call out of an interpreted method, SP is incremented so that73// the space between SP and ESP is removed. The SP saved in the callee's74// frame is the SP *before* this increment. So, when we walk a stack of75// interpreter frames the sender's SP saved in a frame might be less than76// the SP at the point of call.7778// So unextended sp must be within the stack but we need not to check79// that unextended sp >= sp80if (!thread->is_in_full_stack_checked(unextended_sp)) {81return false;82}8384// an fp must be within the stack and above (but not equal) sp85// second evaluation on fp+ is added to handle situation where fp is -186bool fp_safe = thread->is_in_stack_range_excl(fp, sp) &&87thread->is_in_full_stack_checked(fp + (return_addr_offset * sizeof(void*)));8889// We know sp/unextended_sp are safe only fp is questionable here9091// If the current frame is known to the code cache then we can attempt to92// to construct the sender and do some validation of it. This goes a long way93// toward eliminating issues when we get in frame construction code9495if (_cb != NULL ) {9697// First check if frame is complete and tester is reliable98// Unfortunately we can only check frame complete for runtime stubs and nmethod99// other generic buffer blobs are more problematic so we just assume they are100// ok. adapter blobs never have a frame complete and are never ok.101102if (!_cb->is_frame_complete_at(_pc)) {103if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {104return false;105}106}107108// Could just be some random pointer within the codeBlob109if (!_cb->code_contains(_pc)) {110return false;111}112113// Entry frame checks114if (is_entry_frame()) {115// an entry frame must have a valid fp.116return fp_safe && is_entry_frame_valid(thread);117}118119intptr_t* sender_sp = NULL;120intptr_t* sender_unextended_sp = NULL;121address sender_pc = NULL;122intptr_t* saved_fp = NULL;123124if (is_interpreted_frame()) {125// fp must be safe126if (!fp_safe) {127return false;128}129130sender_pc = (address) this->fp()[return_addr_offset];131// for interpreted frames, the value below is the sender "raw" sp,132// which can be different from the sender unextended sp (the sp seen133// by the sender) because of current frame local variables134sender_sp = (intptr_t*) addr_at(sender_sp_offset);135sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];136saved_fp = (intptr_t*) this->fp()[link_offset];137138} else {139// must be some sort of compiled/runtime frame140// fp does not have to be safe (although it could be check for c1?)141142// check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc143if (_cb->frame_size() <= 0) {144return false;145}146147sender_sp = _unextended_sp + _cb->frame_size();148// Is sender_sp safe?149if (!thread->is_in_full_stack_checked((address)sender_sp)) {150return false;151}152sender_unextended_sp = sender_sp;153sender_pc = (address) *(sender_sp-1);154// Note: frame::sender_sp_offset is only valid for compiled frame155saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);156}157158159// If the potential sender is the interpreter then we can do some more checking160if (Interpreter::contains(sender_pc)) {161162// fp is always saved in a recognizable place in any code we generate. However163// only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved fp164// is really a frame pointer.165166if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {167return false;168}169170// construct the potential sender171172frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);173174return sender.is_interpreted_frame_valid(thread);175176}177178// We must always be able to find a recognizable pc179CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);180if (sender_pc == NULL || sender_blob == NULL) {181return false;182}183184// Could be a zombie method185if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {186return false;187}188189// Could just be some random pointer within the codeBlob190if (!sender_blob->code_contains(sender_pc)) {191return false;192}193194// We should never be able to see an adapter if the current frame is something from code cache195if (sender_blob->is_adapter_blob()) {196return false;197}198199// Could be the call_stub200if (StubRoutines::returns_to_call_stub(sender_pc)) {201if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {202return false;203}204205// construct the potential sender206207frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);208209// Validate the JavaCallWrapper an entry frame must have210address jcw = (address)sender.entry_frame_call_wrapper();211212return thread->is_in_stack_range_excl(jcw, (address)sender.fp());213}214215CompiledMethod* nm = sender_blob->as_compiled_method_or_null();216if (nm != NULL) {217if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc) ||218nm->method()->is_method_handle_intrinsic()) {219return false;220}221}222223// If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size224// because the return address counts against the callee's frame.225226if (sender_blob->frame_size() <= 0) {227assert(!sender_blob->is_compiled(), "should count return address at least");228return false;229}230231// We should never be able to see anything here except an nmethod. If something in the232// code cache (current frame) is called by an entity within the code cache that entity233// should not be anything but the call stub (already covered), the interpreter (already covered)234// or an nmethod.235236if (!sender_blob->is_compiled()) {237return false;238}239240// Could put some more validation for the potential non-interpreted sender241// frame we'd create by calling sender if I could think of any. Wait for next crash in forte...242243// One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb244245// We've validated the potential sender that would be created246return true;247}248249// Must be native-compiled frame. Since sender will try and use fp to find250// linkages it must be safe251252if (!fp_safe) {253return false;254}255256// Will the pc we fetch be non-zero (which we'll find at the oldest frame)257258if ( (address) this->fp()[return_addr_offset] == NULL) return false;259260261// could try and do some more potential verification of native frame if we could think of some...262263return true;264265}266267void frame::patch_pc(Thread* thread, address pc) {268assert(_cb == CodeCache::find_blob(pc), "unexpected pc");269address* pc_addr = &(((address*) sp())[-1]);270if (TracePcPatching) {271tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",272p2i(pc_addr), p2i(*pc_addr), p2i(pc));273}274275// Only generated code frames should be patched, therefore the return address will not be signed.276assert(pauth_ptr_is_raw(*pc_addr), "cannot be signed");277// Either the return address is the original one or we are going to278// patch in the same address that's already there.279assert(_pc == *pc_addr || pc == *pc_addr, "must be");280*pc_addr = pc;281address original_pc = CompiledMethod::get_deopt_original_pc(this);282if (original_pc != NULL) {283assert(original_pc == _pc, "expected original PC to be stored before patching");284_deopt_state = is_deoptimized;285// leave _pc as is286} else {287_deopt_state = not_deoptimized;288_pc = pc;289}290}291292bool frame::is_interpreted_frame() const {293return Interpreter::contains(pc());294}295296int frame::frame_size(RegisterMap* map) const {297frame sender = this->sender(map);298return sender.sp() - sp();299}300301intptr_t* frame::entry_frame_argument_at(int offset) const {302// convert offset to index to deal with tsi303int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);304// Entry frame's arguments are always in relation to unextended_sp()305return &unextended_sp()[index];306}307308// sender_sp309intptr_t* frame::interpreter_frame_sender_sp() const {310assert(is_interpreted_frame(), "interpreted frame expected");311return (intptr_t*) at(interpreter_frame_sender_sp_offset);312}313314void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {315assert(is_interpreted_frame(), "interpreted frame expected");316ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);317}318319320// monitor elements321322BasicObjectLock* frame::interpreter_frame_monitor_begin() const {323return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);324}325326BasicObjectLock* frame::interpreter_frame_monitor_end() const {327BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);328// make sure the pointer points inside the frame329assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");330assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer");331return result;332}333334void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {335*((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;336}337338// Used by template based interpreter deoptimization339void frame::interpreter_frame_set_last_sp(intptr_t* sp) {340*((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;341}342343frame frame::sender_for_entry_frame(RegisterMap* map) const {344assert(map != NULL, "map must be set");345// Java frame called from C; skip all C frames and return top C346// frame of that chunk as the sender347JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();348assert(!entry_frame_is_first(), "next Java fp must be non zero");349assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");350// Since we are walking the stack now this nested anchor is obviously walkable351// even if it wasn't when it was stacked.352jfa->make_walkable();353map->clear();354assert(map->include_argument_oops(), "should be set by clear");355frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());356357return fr;358}359360OptimizedEntryBlob::FrameData* OptimizedEntryBlob::frame_data_for_frame(const frame& frame) const {361ShouldNotCallThis();362return nullptr;363}364365bool frame::optimized_entry_frame_is_first() const {366ShouldNotCallThis();367return false;368}369370frame frame::sender_for_optimized_entry_frame(RegisterMap* map) const {371ShouldNotCallThis();372return {};373}374375//------------------------------------------------------------------------------376// frame::verify_deopt_original_pc377//378// Verifies the calculated original PC of a deoptimization PC for the379// given unextended SP.380#ifdef ASSERT381void frame::verify_deopt_original_pc(CompiledMethod* nm, intptr_t* unextended_sp) {382frame fr;383384// This is ugly but it's better than to change {get,set}_original_pc385// to take an SP value as argument. And it's only a debugging386// method anyway.387fr._unextended_sp = unextended_sp;388389address original_pc = nm->get_original_pc(&fr);390assert(nm->insts_contains_inclusive(original_pc),391"original PC must be in the main code section of the the compiled method (or must be immediately following it)");392}393#endif394395//------------------------------------------------------------------------------396// frame::adjust_unextended_sp397void frame::adjust_unextended_sp() {398// On aarch64, sites calling method handle intrinsics and lambda forms are treated399// as any other call site. Therefore, no special action is needed when we are400// returning to any of these call sites.401402if (_cb != NULL) {403CompiledMethod* sender_cm = _cb->as_compiled_method_or_null();404if (sender_cm != NULL) {405// If the sender PC is a deoptimization point, get the original PC.406if (sender_cm->is_deopt_entry(_pc) ||407sender_cm->is_deopt_mh_entry(_pc)) {408DEBUG_ONLY(verify_deopt_original_pc(sender_cm, _unextended_sp));409}410}411}412}413414//------------------------------------------------------------------------------415// frame::update_map_with_saved_link416void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {417// The interpreter and compiler(s) always save fp in a known418// location on entry. We must record where that location is419// so that if fp was live on callout from c2 we can find420// the saved copy no matter what it called.421422// Since the interpreter always saves fp if we record where it is then423// we don't have to always save fp on entry and exit to c2 compiled424// code, on entry will be enough.425map->set_location(rfp->as_VMReg(), (address) link_addr);426// this is weird "H" ought to be at a higher address however the427// oopMaps seems to have the "H" regs at the same address and the428// vanilla register.429// XXXX make this go away430if (true) {431map->set_location(rfp->as_VMReg()->next(), (address) link_addr);432}433}434435436//------------------------------------------------------------------------------437// frame::sender_for_interpreter_frame438frame frame::sender_for_interpreter_frame(RegisterMap* map) const {439// SP is the raw SP from the sender after adapter or interpreter440// extension.441intptr_t* sender_sp = this->sender_sp();442443// This is the sp before any possible extension (adapter/locals).444intptr_t* unextended_sp = interpreter_frame_sender_sp();445446#if COMPILER2_OR_JVMCI447if (map->update_map()) {448update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));449}450#endif // COMPILER2_OR_JVMCI451452// Use the raw version of pc - the interpreter should not have signed it.453454return frame(sender_sp, unextended_sp, link(), sender_pc_maybe_signed());455}456457458//------------------------------------------------------------------------------459// frame::sender_for_compiled_frame460frame frame::sender_for_compiled_frame(RegisterMap* map) const {461// we cannot rely upon the last fp having been saved to the thread462// in C2 code but it will have been pushed onto the stack. so we463// have to find it relative to the unextended sp464465assert(_cb->frame_size() >= 0, "must have non-zero frame size");466intptr_t* l_sender_sp = unextended_sp() + _cb->frame_size();467intptr_t* unextended_sp = l_sender_sp;468469// the return_address is always the word on the stack470address sender_pc = (address) *(l_sender_sp-1);471472intptr_t** saved_fp_addr = (intptr_t**) (l_sender_sp - frame::sender_sp_offset);473474// assert (sender_sp() == l_sender_sp, "should be");475// assert (*saved_fp_addr == link(), "should be");476477if (map->update_map()) {478// Tell GC to use argument oopmaps for some runtime stubs that need it.479// For C1, the runtime stub might not have oop maps, so set this flag480// outside of update_register_map.481map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));482if (_cb->oop_maps() != NULL) {483OopMapSet::update_register_map(this, map);484}485486// Since the prolog does the save and restore of FP there is no487// oopmap for it so we must fill in its location as if there was488// an oopmap entry since if our caller was compiled code there489// could be live jvm state in it.490update_map_with_saved_link(map, saved_fp_addr);491}492493return frame(l_sender_sp, unextended_sp, *saved_fp_addr, sender_pc);494}495496//------------------------------------------------------------------------------497// frame::sender_raw498frame frame::sender_raw(RegisterMap* map) const {499// Default is we done have to follow them. The sender_for_xxx will500// update it accordingly501map->set_include_argument_oops(false);502503if (is_entry_frame())504return sender_for_entry_frame(map);505if (is_interpreted_frame())506return sender_for_interpreter_frame(map);507assert(_cb == CodeCache::find_blob(pc()),"Must be the same");508509// This test looks odd: why is it not is_compiled_frame() ? That's510// because stubs also have OOP maps.511if (_cb != NULL) {512return sender_for_compiled_frame(map);513}514515// Must be native-compiled frame, i.e. the marshaling code for native516// methods that exists in the core system.517518return frame(sender_sp(), link(), sender_pc());519}520521frame frame::sender(RegisterMap* map) const {522frame result = sender_raw(map);523524if (map->process_frames()) {525StackWatermarkSet::on_iteration(map->thread(), result);526}527528return result;529}530531bool frame::is_interpreted_frame_valid(JavaThread* thread) const {532assert(is_interpreted_frame(), "Not an interpreted frame");533// These are reasonable sanity checks534if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {535return false;536}537if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {538return false;539}540if (fp() + interpreter_frame_initial_sp_offset < sp()) {541return false;542}543// These are hacks to keep us out of trouble.544// The problem with these is that they mask other problems545if (fp() <= sp()) { // this attempts to deal with unsigned comparison above546return false;547}548549// do some validation of frame elements550551// first the method552553Method* m = *interpreter_frame_method_addr();554555// validate the method we'd find in this potential sender556if (!Method::is_valid_method(m)) return false;557558// stack frames shouldn't be much larger than max_stack elements559// this test requires the use of unextended_sp which is the sp as seen by560// the current frame, and not sp which is the "raw" pc which could point561// further because of local variables of the callee method inserted after562// method arguments563if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {564return false;565}566567// validate bci/bcx568569address bcp = interpreter_frame_bcp();570if (m->validate_bci_from_bcp(bcp) < 0) {571return false;572}573574// validate constantPoolCache*575ConstantPoolCache* cp = *interpreter_frame_cache_addr();576if (MetaspaceObj::is_valid(cp) == false) return false;577578// validate locals579580address locals = (address) *interpreter_frame_locals_addr();581return thread->is_in_stack_range_incl(locals, (address)fp());582}583584BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {585assert(is_interpreted_frame(), "interpreted frame expected");586Method* method = interpreter_frame_method();587BasicType type = method->result_type();588589intptr_t* tos_addr;590if (method->is_native()) {591// TODO : ensure AARCH64 does the same as Intel here i.e. push v0 then r0592// Prior to calling into the runtime to report the method_exit the possible593// return value is pushed to the native stack. If the result is a jfloat/jdouble594// then ST0 is saved before EAX/EDX. See the note in generate_native_result595tos_addr = (intptr_t*)sp();596if (type == T_FLOAT || type == T_DOUBLE) {597// This is times two because we do a push(ltos) after pushing XMM0598// and that takes two interpreter stack slots.599tos_addr += 2 * Interpreter::stackElementWords;600}601} else {602tos_addr = (intptr_t*)interpreter_frame_tos_address();603}604605switch (type) {606case T_OBJECT :607case T_ARRAY : {608oop obj;609if (method->is_native()) {610obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));611} else {612oop* obj_p = (oop*)tos_addr;613obj = (obj_p == NULL) ? (oop)NULL : *obj_p;614}615assert(Universe::is_in_heap_or_null(obj), "sanity check");616*oop_result = obj;617break;618}619case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;620case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;621case T_CHAR : value_result->c = *(jchar*)tos_addr; break;622case T_SHORT : value_result->s = *(jshort*)tos_addr; break;623case T_INT : value_result->i = *(jint*)tos_addr; break;624case T_LONG : value_result->j = *(jlong*)tos_addr; break;625case T_FLOAT : {626value_result->f = *(jfloat*)tos_addr;627break;628}629case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;630case T_VOID : /* Nothing to do */ break;631default : ShouldNotReachHere();632}633634return type;635}636637638intptr_t* frame::interpreter_frame_tos_at(jint offset) const {639int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);640return &interpreter_frame_tos_address()[index];641}642643#ifndef PRODUCT644645#define DESCRIBE_FP_OFFSET(name) \646values.describe(frame_no, fp() + frame::name##_offset, #name)647648void frame::describe_pd(FrameValues& values, int frame_no) {649if (is_interpreted_frame()) {650DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);651DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);652DESCRIBE_FP_OFFSET(interpreter_frame_method);653DESCRIBE_FP_OFFSET(interpreter_frame_mdp);654DESCRIBE_FP_OFFSET(interpreter_frame_mirror);655DESCRIBE_FP_OFFSET(interpreter_frame_cache);656DESCRIBE_FP_OFFSET(interpreter_frame_locals);657DESCRIBE_FP_OFFSET(interpreter_frame_bcp);658DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);659}660}661#endif662663intptr_t *frame::initial_deoptimization_info() {664// Not used on aarch64, but we must return something.665return NULL;666}667668intptr_t* frame::real_fp() const {669if (_cb != NULL) {670// use the frame size if valid671int size = _cb->frame_size();672if (size > 0) {673return unextended_sp() + size;674}675}676// else rely on fp()677assert(! is_compiled_frame(), "unknown compiled frame size");678return fp();679}680681#undef DESCRIBE_FP_OFFSET682683#define DESCRIBE_FP_OFFSET(name) \684{ \685uintptr_t *p = (uintptr_t *)fp; \686printf(INTPTR_FORMAT " " INTPTR_FORMAT " %s\n", \687(uintptr_t)(p + frame::name##_offset), \688p[frame::name##_offset], #name); \689}690691static THREAD_LOCAL uintptr_t nextfp;692static THREAD_LOCAL uintptr_t nextpc;693static THREAD_LOCAL uintptr_t nextsp;694static THREAD_LOCAL RegisterMap *reg_map;695696static void printbc(Method *m, intptr_t bcx) {697const char *name;698char buf[16];699if (m->validate_bci_from_bcp((address)bcx) < 0700|| !m->contains((address)bcx)) {701name = "???";702snprintf(buf, sizeof buf, "(bad)");703} else {704int bci = m->bci_from((address)bcx);705snprintf(buf, sizeof buf, "%d", bci);706name = Bytecodes::name(m->code_at(bci));707}708ResourceMark rm;709printf("%s : %s ==> %s\n", m->name_and_sig_as_C_string(), buf, name);710}711712void internal_pf(uintptr_t sp, uintptr_t fp, uintptr_t pc, uintptr_t bcx) {713if (! fp)714return;715716DESCRIBE_FP_OFFSET(return_addr);717DESCRIBE_FP_OFFSET(link);718DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);719DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);720DESCRIBE_FP_OFFSET(interpreter_frame_method);721DESCRIBE_FP_OFFSET(interpreter_frame_mdp);722DESCRIBE_FP_OFFSET(interpreter_frame_cache);723DESCRIBE_FP_OFFSET(interpreter_frame_locals);724DESCRIBE_FP_OFFSET(interpreter_frame_bcp);725DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);726uintptr_t *p = (uintptr_t *)fp;727728// We want to see all frames, native and Java. For compiled and729// interpreted frames we have special information that allows us to730// unwind them; for everything else we assume that the native frame731// pointer chain is intact.732frame this_frame((intptr_t*)sp, (intptr_t*)fp, (address)pc);733if (this_frame.is_compiled_frame() ||734this_frame.is_interpreted_frame()) {735frame sender = this_frame.sender(reg_map);736nextfp = (uintptr_t)sender.fp();737nextpc = (uintptr_t)sender.pc();738nextsp = (uintptr_t)sender.unextended_sp();739} else {740nextfp = p[frame::link_offset];741nextpc = p[frame::return_addr_offset];742nextsp = (uintptr_t)&p[frame::sender_sp_offset];743}744745if (bcx == -1ULL)746bcx = p[frame::interpreter_frame_bcp_offset];747748if (Interpreter::contains((address)pc)) {749Method* m = (Method*)p[frame::interpreter_frame_method_offset];750if(m && m->is_method()) {751printbc(m, bcx);752} else753printf("not a Method\n");754} else {755CodeBlob *cb = CodeCache::find_blob((address)pc);756if (cb != NULL) {757if (cb->is_nmethod()) {758ResourceMark rm;759nmethod* nm = (nmethod*)cb;760printf("nmethod %s\n", nm->method()->name_and_sig_as_C_string());761} else if (cb->name()) {762printf("CodeBlob %s\n", cb->name());763}764}765}766}767768extern "C" void npf() {769CodeBlob *cb = CodeCache::find_blob((address)nextpc);770// C2 does not always chain the frame pointers when it can, instead771// preferring to use fixed offsets from SP, so a simple leave() does772// not work. Instead, it adds the frame size to SP then pops FP and773// LR. We have to do the same thing to get a good call chain.774if (cb && cb->frame_size())775nextfp = nextsp + wordSize * (cb->frame_size() - 2);776internal_pf (nextsp, nextfp, nextpc, -1);777}778779extern "C" void pf(uintptr_t sp, uintptr_t fp, uintptr_t pc,780uintptr_t bcx, uintptr_t thread) {781if (!reg_map) {782reg_map = NEW_C_HEAP_OBJ(RegisterMap, mtInternal);783::new (reg_map) RegisterMap((JavaThread*)thread, false);784} else {785*reg_map = RegisterMap((JavaThread*)thread, false);786}787788{789CodeBlob *cb = CodeCache::find_blob((address)pc);790if (cb && cb->frame_size())791fp = sp + wordSize * (cb->frame_size() - 2);792}793internal_pf(sp, fp, pc, bcx);794}795796// support for printing out where we are in a Java method797// needs to be passed current fp and bcp register values798// prints method name, bc index and bytecode name799extern "C" void pm(uintptr_t fp, uintptr_t bcx) {800DESCRIBE_FP_OFFSET(interpreter_frame_method);801uintptr_t *p = (uintptr_t *)fp;802Method* m = (Method*)p[frame::interpreter_frame_method_offset];803printbc(m, bcx);804}805806#ifndef PRODUCT807// This is a generic constructor which is only used by pns() in debug.cpp.808frame::frame(void* sp, void* fp, void* pc) {809init((intptr_t*)sp, (intptr_t*)fp, (address)pc);810}811812void frame::pd_ps() {}813#endif814815void JavaFrameAnchor::make_walkable() {816// last frame set?817if (last_Java_sp() == NULL) return;818// already walkable?819if (walkable()) return;820vmassert(last_Java_sp() != NULL, "not called from Java code?");821vmassert(last_Java_pc() == NULL, "already walkable");822_last_Java_pc = (address)_last_Java_sp[-1];823vmassert(walkable(), "something went wrong");824}825826827828