Path: blob/master/src/hotspot/cpu/aarch64/frame_aarch64.cpp
40930 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}274// Either the return address is the original one or we are going to275// patch in the same address that's already there.276assert(_pc == *pc_addr || pc == *pc_addr, "must be");277*pc_addr = pc;278address original_pc = CompiledMethod::get_deopt_original_pc(this);279if (original_pc != NULL) {280assert(original_pc == _pc, "expected original PC to be stored before patching");281_deopt_state = is_deoptimized;282// leave _pc as is283} else {284_deopt_state = not_deoptimized;285_pc = pc;286}287}288289bool frame::is_interpreted_frame() const {290return Interpreter::contains(pc());291}292293int frame::frame_size(RegisterMap* map) const {294frame sender = this->sender(map);295return sender.sp() - sp();296}297298intptr_t* frame::entry_frame_argument_at(int offset) const {299// convert offset to index to deal with tsi300int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);301// Entry frame's arguments are always in relation to unextended_sp()302return &unextended_sp()[index];303}304305// sender_sp306intptr_t* frame::interpreter_frame_sender_sp() const {307assert(is_interpreted_frame(), "interpreted frame expected");308return (intptr_t*) at(interpreter_frame_sender_sp_offset);309}310311void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {312assert(is_interpreted_frame(), "interpreted frame expected");313ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);314}315316317// monitor elements318319BasicObjectLock* frame::interpreter_frame_monitor_begin() const {320return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);321}322323BasicObjectLock* frame::interpreter_frame_monitor_end() const {324BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);325// make sure the pointer points inside the frame326assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");327assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer");328return result;329}330331void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {332*((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;333}334335// Used by template based interpreter deoptimization336void frame::interpreter_frame_set_last_sp(intptr_t* sp) {337*((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;338}339340frame frame::sender_for_entry_frame(RegisterMap* map) const {341assert(map != NULL, "map must be set");342// Java frame called from C; skip all C frames and return top C343// frame of that chunk as the sender344JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();345assert(!entry_frame_is_first(), "next Java fp must be non zero");346assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");347// Since we are walking the stack now this nested anchor is obviously walkable348// even if it wasn't when it was stacked.349if (!jfa->walkable()) {350// Capture _last_Java_pc (if needed) and mark anchor walkable.351jfa->capture_last_Java_pc();352}353map->clear();354assert(map->include_argument_oops(), "should be set by clear");355vmassert(jfa->last_Java_pc() != NULL, "not walkable");356frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());357358return fr;359}360361JavaFrameAnchor* OptimizedEntryBlob::jfa_for_frame(const frame& frame) const {362ShouldNotCallThis();363return nullptr;364}365366frame frame::sender_for_optimized_entry_frame(RegisterMap* map) const {367ShouldNotCallThis();368return {};369}370371//------------------------------------------------------------------------------372// frame::verify_deopt_original_pc373//374// Verifies the calculated original PC of a deoptimization PC for the375// given unextended SP.376#ifdef ASSERT377void frame::verify_deopt_original_pc(CompiledMethod* nm, intptr_t* unextended_sp) {378frame fr;379380// This is ugly but it's better than to change {get,set}_original_pc381// to take an SP value as argument. And it's only a debugging382// method anyway.383fr._unextended_sp = unextended_sp;384385address original_pc = nm->get_original_pc(&fr);386assert(nm->insts_contains_inclusive(original_pc),387"original PC must be in the main code section of the the compiled method (or must be immediately following it)");388}389#endif390391//------------------------------------------------------------------------------392// frame::adjust_unextended_sp393void frame::adjust_unextended_sp() {394// On aarch64, sites calling method handle intrinsics and lambda forms are treated395// as any other call site. Therefore, no special action is needed when we are396// returning to any of these call sites.397398if (_cb != NULL) {399CompiledMethod* sender_cm = _cb->as_compiled_method_or_null();400if (sender_cm != NULL) {401// If the sender PC is a deoptimization point, get the original PC.402if (sender_cm->is_deopt_entry(_pc) ||403sender_cm->is_deopt_mh_entry(_pc)) {404DEBUG_ONLY(verify_deopt_original_pc(sender_cm, _unextended_sp));405}406}407}408}409410//------------------------------------------------------------------------------411// frame::update_map_with_saved_link412void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {413// The interpreter and compiler(s) always save fp in a known414// location on entry. We must record where that location is415// so that if fp was live on callout from c2 we can find416// the saved copy no matter what it called.417418// Since the interpreter always saves fp if we record where it is then419// we don't have to always save fp on entry and exit to c2 compiled420// code, on entry will be enough.421map->set_location(rfp->as_VMReg(), (address) link_addr);422// this is weird "H" ought to be at a higher address however the423// oopMaps seems to have the "H" regs at the same address and the424// vanilla register.425// XXXX make this go away426if (true) {427map->set_location(rfp->as_VMReg()->next(), (address) link_addr);428}429}430431432//------------------------------------------------------------------------------433// frame::sender_for_interpreter_frame434frame frame::sender_for_interpreter_frame(RegisterMap* map) const {435// SP is the raw SP from the sender after adapter or interpreter436// extension.437intptr_t* sender_sp = this->sender_sp();438439// This is the sp before any possible extension (adapter/locals).440intptr_t* unextended_sp = interpreter_frame_sender_sp();441442#if COMPILER2_OR_JVMCI443if (map->update_map()) {444update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));445}446#endif // COMPILER2_OR_JVMCI447448return frame(sender_sp, unextended_sp, link(), sender_pc());449}450451452//------------------------------------------------------------------------------453// frame::sender_for_compiled_frame454frame frame::sender_for_compiled_frame(RegisterMap* map) const {455// we cannot rely upon the last fp having been saved to the thread456// in C2 code but it will have been pushed onto the stack. so we457// have to find it relative to the unextended sp458459assert(_cb->frame_size() >= 0, "must have non-zero frame size");460intptr_t* l_sender_sp = unextended_sp() + _cb->frame_size();461intptr_t* unextended_sp = l_sender_sp;462463// the return_address is always the word on the stack464address sender_pc = (address) *(l_sender_sp-1);465466intptr_t** saved_fp_addr = (intptr_t**) (l_sender_sp - frame::sender_sp_offset);467468// assert (sender_sp() == l_sender_sp, "should be");469// assert (*saved_fp_addr == link(), "should be");470471if (map->update_map()) {472// Tell GC to use argument oopmaps for some runtime stubs that need it.473// For C1, the runtime stub might not have oop maps, so set this flag474// outside of update_register_map.475map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));476if (_cb->oop_maps() != NULL) {477OopMapSet::update_register_map(this, map);478}479480// Since the prolog does the save and restore of FP there is no481// oopmap for it so we must fill in its location as if there was482// an oopmap entry since if our caller was compiled code there483// could be live jvm state in it.484update_map_with_saved_link(map, saved_fp_addr);485}486487return frame(l_sender_sp, unextended_sp, *saved_fp_addr, sender_pc);488}489490//------------------------------------------------------------------------------491// frame::sender_raw492frame frame::sender_raw(RegisterMap* map) const {493// Default is we done have to follow them. The sender_for_xxx will494// update it accordingly495map->set_include_argument_oops(false);496497if (is_entry_frame())498return sender_for_entry_frame(map);499if (is_interpreted_frame())500return sender_for_interpreter_frame(map);501assert(_cb == CodeCache::find_blob(pc()),"Must be the same");502503// This test looks odd: why is it not is_compiled_frame() ? That's504// because stubs also have OOP maps.505if (_cb != NULL) {506return sender_for_compiled_frame(map);507}508509// Must be native-compiled frame, i.e. the marshaling code for native510// methods that exists in the core system.511return frame(sender_sp(), link(), sender_pc());512}513514frame frame::sender(RegisterMap* map) const {515frame result = sender_raw(map);516517if (map->process_frames()) {518StackWatermarkSet::on_iteration(map->thread(), result);519}520521return result;522}523524bool frame::is_interpreted_frame_valid(JavaThread* thread) const {525assert(is_interpreted_frame(), "Not an interpreted frame");526// These are reasonable sanity checks527if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {528return false;529}530if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {531return false;532}533if (fp() + interpreter_frame_initial_sp_offset < sp()) {534return false;535}536// These are hacks to keep us out of trouble.537// The problem with these is that they mask other problems538if (fp() <= sp()) { // this attempts to deal with unsigned comparison above539return false;540}541542// do some validation of frame elements543544// first the method545546Method* m = *interpreter_frame_method_addr();547548// validate the method we'd find in this potential sender549if (!Method::is_valid_method(m)) return false;550551// stack frames shouldn't be much larger than max_stack elements552// this test requires the use of unextended_sp which is the sp as seen by553// the current frame, and not sp which is the "raw" pc which could point554// further because of local variables of the callee method inserted after555// method arguments556if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {557return false;558}559560// validate bci/bcx561562address bcp = interpreter_frame_bcp();563if (m->validate_bci_from_bcp(bcp) < 0) {564return false;565}566567// validate constantPoolCache*568ConstantPoolCache* cp = *interpreter_frame_cache_addr();569if (MetaspaceObj::is_valid(cp) == false) return false;570571// validate locals572573address locals = (address) *interpreter_frame_locals_addr();574return thread->is_in_stack_range_incl(locals, (address)fp());575}576577BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {578assert(is_interpreted_frame(), "interpreted frame expected");579Method* method = interpreter_frame_method();580BasicType type = method->result_type();581582intptr_t* tos_addr;583if (method->is_native()) {584// TODO : ensure AARCH64 does the same as Intel here i.e. push v0 then r0585// Prior to calling into the runtime to report the method_exit the possible586// return value is pushed to the native stack. If the result is a jfloat/jdouble587// then ST0 is saved before EAX/EDX. See the note in generate_native_result588tos_addr = (intptr_t*)sp();589if (type == T_FLOAT || type == T_DOUBLE) {590// This is times two because we do a push(ltos) after pushing XMM0591// and that takes two interpreter stack slots.592tos_addr += 2 * Interpreter::stackElementWords;593}594} else {595tos_addr = (intptr_t*)interpreter_frame_tos_address();596}597598switch (type) {599case T_OBJECT :600case T_ARRAY : {601oop obj;602if (method->is_native()) {603obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));604} else {605oop* obj_p = (oop*)tos_addr;606obj = (obj_p == NULL) ? (oop)NULL : *obj_p;607}608assert(Universe::is_in_heap_or_null(obj), "sanity check");609*oop_result = obj;610break;611}612case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;613case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;614case T_CHAR : value_result->c = *(jchar*)tos_addr; break;615case T_SHORT : value_result->s = *(jshort*)tos_addr; break;616case T_INT : value_result->i = *(jint*)tos_addr; break;617case T_LONG : value_result->j = *(jlong*)tos_addr; break;618case T_FLOAT : {619value_result->f = *(jfloat*)tos_addr;620break;621}622case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;623case T_VOID : /* Nothing to do */ break;624default : ShouldNotReachHere();625}626627return type;628}629630631intptr_t* frame::interpreter_frame_tos_at(jint offset) const {632int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);633return &interpreter_frame_tos_address()[index];634}635636#ifndef PRODUCT637638#define DESCRIBE_FP_OFFSET(name) \639values.describe(frame_no, fp() + frame::name##_offset, #name)640641void frame::describe_pd(FrameValues& values, int frame_no) {642if (is_interpreted_frame()) {643DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);644DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);645DESCRIBE_FP_OFFSET(interpreter_frame_method);646DESCRIBE_FP_OFFSET(interpreter_frame_mdp);647DESCRIBE_FP_OFFSET(interpreter_frame_mirror);648DESCRIBE_FP_OFFSET(interpreter_frame_cache);649DESCRIBE_FP_OFFSET(interpreter_frame_locals);650DESCRIBE_FP_OFFSET(interpreter_frame_bcp);651DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);652}653}654#endif655656intptr_t *frame::initial_deoptimization_info() {657// Not used on aarch64, but we must return something.658return NULL;659}660661intptr_t* frame::real_fp() const {662if (_cb != NULL) {663// use the frame size if valid664int size = _cb->frame_size();665if (size > 0) {666return unextended_sp() + size;667}668}669// else rely on fp()670assert(! is_compiled_frame(), "unknown compiled frame size");671return fp();672}673674#undef DESCRIBE_FP_OFFSET675676#define DESCRIBE_FP_OFFSET(name) \677{ \678uintptr_t *p = (uintptr_t *)fp; \679printf(INTPTR_FORMAT " " INTPTR_FORMAT " %s\n", \680(uintptr_t)(p + frame::name##_offset), \681p[frame::name##_offset], #name); \682}683684static THREAD_LOCAL uintptr_t nextfp;685static THREAD_LOCAL uintptr_t nextpc;686static THREAD_LOCAL uintptr_t nextsp;687static THREAD_LOCAL RegisterMap *reg_map;688689static void printbc(Method *m, intptr_t bcx) {690const char *name;691char buf[16];692if (m->validate_bci_from_bcp((address)bcx) < 0693|| !m->contains((address)bcx)) {694name = "???";695snprintf(buf, sizeof buf, "(bad)");696} else {697int bci = m->bci_from((address)bcx);698snprintf(buf, sizeof buf, "%d", bci);699name = Bytecodes::name(m->code_at(bci));700}701ResourceMark rm;702printf("%s : %s ==> %s\n", m->name_and_sig_as_C_string(), buf, name);703}704705void internal_pf(uintptr_t sp, uintptr_t fp, uintptr_t pc, uintptr_t bcx) {706if (! fp)707return;708709DESCRIBE_FP_OFFSET(return_addr);710DESCRIBE_FP_OFFSET(link);711DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);712DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);713DESCRIBE_FP_OFFSET(interpreter_frame_method);714DESCRIBE_FP_OFFSET(interpreter_frame_mdp);715DESCRIBE_FP_OFFSET(interpreter_frame_cache);716DESCRIBE_FP_OFFSET(interpreter_frame_locals);717DESCRIBE_FP_OFFSET(interpreter_frame_bcp);718DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);719uintptr_t *p = (uintptr_t *)fp;720721// We want to see all frames, native and Java. For compiled and722// interpreted frames we have special information that allows us to723// unwind them; for everything else we assume that the native frame724// pointer chain is intact.725frame this_frame((intptr_t*)sp, (intptr_t*)fp, (address)pc);726if (this_frame.is_compiled_frame() ||727this_frame.is_interpreted_frame()) {728frame sender = this_frame.sender(reg_map);729nextfp = (uintptr_t)sender.fp();730nextpc = (uintptr_t)sender.pc();731nextsp = (uintptr_t)sender.unextended_sp();732} else {733nextfp = p[frame::link_offset];734nextpc = p[frame::return_addr_offset];735nextsp = (uintptr_t)&p[frame::sender_sp_offset];736}737738if (bcx == -1ULL)739bcx = p[frame::interpreter_frame_bcp_offset];740741if (Interpreter::contains((address)pc)) {742Method* m = (Method*)p[frame::interpreter_frame_method_offset];743if(m && m->is_method()) {744printbc(m, bcx);745} else746printf("not a Method\n");747} else {748CodeBlob *cb = CodeCache::find_blob((address)pc);749if (cb != NULL) {750if (cb->is_nmethod()) {751ResourceMark rm;752nmethod* nm = (nmethod*)cb;753printf("nmethod %s\n", nm->method()->name_and_sig_as_C_string());754} else if (cb->name()) {755printf("CodeBlob %s\n", cb->name());756}757}758}759}760761extern "C" void npf() {762CodeBlob *cb = CodeCache::find_blob((address)nextpc);763// C2 does not always chain the frame pointers when it can, instead764// preferring to use fixed offsets from SP, so a simple leave() does765// not work. Instead, it adds the frame size to SP then pops FP and766// LR. We have to do the same thing to get a good call chain.767if (cb && cb->frame_size())768nextfp = nextsp + wordSize * (cb->frame_size() - 2);769internal_pf (nextsp, nextfp, nextpc, -1);770}771772extern "C" void pf(uintptr_t sp, uintptr_t fp, uintptr_t pc,773uintptr_t bcx, uintptr_t thread) {774if (!reg_map) {775reg_map = NEW_C_HEAP_OBJ(RegisterMap, mtInternal);776::new (reg_map) RegisterMap((JavaThread*)thread, false);777} else {778*reg_map = RegisterMap((JavaThread*)thread, false);779}780781{782CodeBlob *cb = CodeCache::find_blob((address)pc);783if (cb && cb->frame_size())784fp = sp + wordSize * (cb->frame_size() - 2);785}786internal_pf(sp, fp, pc, bcx);787}788789// support for printing out where we are in a Java method790// needs to be passed current fp and bcp register values791// prints method name, bc index and bytecode name792extern "C" void pm(uintptr_t fp, uintptr_t bcx) {793DESCRIBE_FP_OFFSET(interpreter_frame_method);794uintptr_t *p = (uintptr_t *)fp;795Method* m = (Method*)p[frame::interpreter_frame_method_offset];796printbc(m, bcx);797}798799#ifndef PRODUCT800// This is a generic constructor which is only used by pns() in debug.cpp.801frame::frame(void* sp, void* fp, void* pc) {802init((intptr_t*)sp, (intptr_t*)fp, (address)pc);803}804805void frame::pd_ps() {}806#endif807808void JavaFrameAnchor::make_walkable(JavaThread* thread) {809// last frame set?810if (last_Java_sp() == NULL) return;811// already walkable?812if (walkable()) return;813vmassert(Thread::current() == (Thread*)thread, "not current thread");814vmassert(last_Java_sp() != NULL, "not called from Java code?");815vmassert(last_Java_pc() == NULL, "already walkable");816capture_last_Java_pc();817vmassert(walkable(), "something went wrong");818}819820void JavaFrameAnchor::capture_last_Java_pc() {821vmassert(_last_Java_sp != NULL, "no last frame set");822vmassert(_last_Java_pc == NULL, "already walkable");823_last_Java_pc = (address)_last_Java_sp[-1];824}825826827