Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/aarch32/vm/frame_aarch32.cpp
32285 views
/*1* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2014, Red Hat Inc. All rights reserved.3* Copyright (c) 2015, Linaro Ltd. 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_aarch32.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// unextended sp must be within the stack and above or equal sp74bool unextended_sp_safe = (unextended_sp < thread->stack_base()) &&75(unextended_sp >= sp);7677if (!unextended_sp_safe) {78return false;79}8081// an fp must be within the stack and above (but not equal) sp82// second evaluation on fp+ is added to handle situation where fp is -183bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));8485// We know sp/unextended_sp are safe only fp is questionable here8687// If the current frame is known to the code cache then we can attempt to88// to construct the sender and do some validation of it. This goes a long way89// toward eliminating issues when we get in frame construction code9091if (_cb != NULL ) {9293// First check if frame is complete and tester is reliable94// Unfortunately we can only check frame complete for runtime stubs and nmethod95// other generic buffer blobs are more problematic so we just assume they are96// ok. adapter blobs never have a frame complete and are never ok.9798if (!_cb->is_frame_complete_at(_pc)) {99if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {100return false;101}102}103104// Could just be some random pointer within the codeBlob105if (!_cb->code_contains(_pc)) {106return false;107}108109// Entry frame checks110if (is_entry_frame()) {111// an entry frame must have a valid fp.112113if (!fp_safe) return false;114115// Validate the JavaCallWrapper an entry frame must have116117address jcw = (address)entry_frame_call_wrapper();118119bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > fp);120121return jcw_safe;122123}124125intptr_t* sender_sp = NULL;126intptr_t* sender_unextended_sp = NULL;127address sender_pc = NULL;128intptr_t* saved_fp = NULL;129130if (is_interpreted_frame()) {131// fp must be safe132if (!fp_safe) {133return false;134}135136sender_pc = (address) this->fp()[return_addr_offset];137// for interpreted frames, the value below is the sender "raw" sp,138// which can be different from the sender unextended sp (the sp seen139// by the sender) because of current frame local variables140sender_sp = (intptr_t*) addr_at(sender_sp_offset);141sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];142saved_fp = (intptr_t*) this->fp()[link_offset];143144} else {145// must be some sort of compiled/runtime frame146// fp does not have to be safe (although it could be check for c1?)147148// check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc149if (_cb->frame_size() <= 0) {150return false;151}152153sender_sp = _unextended_sp + _cb->frame_size();154sender_unextended_sp = sender_sp;155sender_pc = (address) *(sender_sp - 1);156// Note: frame::sender_sp_offset is only valid for compiled frame157saved_fp = (intptr_t*) *(sender_sp - 2);158}159160161// If the potential sender is the interpreter then we can do some more checking162if (Interpreter::contains(sender_pc)) {163164// fp is always saved in a recognizable place in any code we generate. However165// only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved fp166// is really a frame pointer.167168bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);169170if (!saved_fp_safe) {171return false;172}173174// construct the potential sender175176frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);177178return sender.is_interpreted_frame_valid(thread);179180}181182// We must always be able to find a recognizable pc183CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);184if (sender_pc == NULL || sender_blob == NULL) {185return false;186}187188// Could be a zombie method189if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {190return false;191}192193// Could just be some random pointer within the codeBlob194if (!sender_blob->code_contains(sender_pc)) {195return false;196}197198// We should never be able to see an adapter if the current frame is something from code cache199if (sender_blob->is_adapter_blob()) {200return false;201}202203// Could be the call_stub204if (StubRoutines::returns_to_call_stub(sender_pc)) {205bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);206207if (!saved_fp_safe) {208return false;209}210211// construct the potential sender212213frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);214215// Validate the JavaCallWrapper an entry frame must have216address jcw = (address)sender.entry_frame_call_wrapper();217218bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp());219220return jcw_safe;221}222223if (sender_blob->is_nmethod()) {224nmethod* nm = sender_blob->as_nmethod_or_null();225if (nm != NULL) {226if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc) ||227nm->method()->is_method_handle_intrinsic()) {228return false;229}230}231}232233// If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size234// because the return address counts against the callee's frame.235236if (sender_blob->frame_size() <= 0) {237assert(!sender_blob->is_nmethod(), "should count return address at least");238return false;239}240241// We should never be able to see anything here except an nmethod. If something in the242// code cache (current frame) is called by an entity within the code cache that entity243// should not be anything but the call stub (already covered), the interpreter (already covered)244// or an nmethod.245246if (!sender_blob->is_nmethod()) {247return false;248}249250// Could put some more validation for the potential non-interpreted sender251// frame we'd create by calling sender if I could think of any. Wait for next crash in forte...252253// One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb254255// We've validated the potential sender that would be created256return true;257}258259// Must be native-compiled frame. Since sender will try and use fp to find260// linkages it must be safe261262if (!fp_safe) {263return false;264}265266// Will the pc we fetch be non-zero (which we'll find at the oldest frame)267268if ( (address) this->fp()[return_addr_offset] == NULL) return false;269270271// could try and do some more potential verification of native frame if we could think of some...272273return true;274275}276277void frame::patch_pc(Thread* thread, address pc) {278address* pc_addr = &(((address*) sp())[-1]);279if (TracePcPatching) {280tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",281p2i(pc_addr), p2i(*pc_addr), p2i(pc));282}283// Either the return address is the original one or we are going to284// patch in the same address that's already there.285assert(_pc == *pc_addr || pc == *pc_addr, "must be");286*pc_addr = pc;287_cb = CodeCache::find_blob(pc);288address original_pc = nmethod::get_deopt_original_pc(this);289if (original_pc != NULL) {290assert(original_pc == _pc, "expected original PC to be stored before patching");291_deopt_state = is_deoptimized;292// leave _pc as is293} else {294_deopt_state = not_deoptimized;295_pc = pc;296}297}298299bool frame::is_interpreted_frame() const {300return Interpreter::contains(pc());301}302303int frame::frame_size(RegisterMap* map) const {304frame sender = this->sender(map);305return sender.sp() - sp();306}307308intptr_t* frame::entry_frame_argument_at(int offset) const {309// convert offset to index to deal with tsi310int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);311// Entry frame's arguments are always in relation to unextended_sp()312return &unextended_sp()[index];313}314315// sender_sp316#ifdef CC_INTERP317intptr_t* frame::interpreter_frame_sender_sp() const {318assert(is_interpreted_frame(), "interpreted frame expected");319// QQQ why does this specialize method exist if frame::sender_sp() does same thing?320// seems odd and if we always know interpreted vs. non then sender_sp() is really321// doing too much work.322return get_interpreterState()->sender_sp();323}324325// monitor elements326327BasicObjectLock* frame::interpreter_frame_monitor_begin() const {328return get_interpreterState()->monitor_base();329}330331BasicObjectLock* frame::interpreter_frame_monitor_end() const {332return (BasicObjectLock*) get_interpreterState()->stack_base();333}334335#else // CC_INTERP336337intptr_t* frame::interpreter_frame_sender_sp() const {338assert(is_interpreted_frame(), "interpreted frame expected");339return (intptr_t*) at(interpreter_frame_sender_sp_offset);340}341342void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {343assert(is_interpreted_frame(), "interpreted frame expected");344ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);345}346347348// monitor elements349350BasicObjectLock* frame::interpreter_frame_monitor_begin() const {351return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);352}353354BasicObjectLock* frame::interpreter_frame_monitor_end() const {355BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);356// make sure the pointer points inside the frame357assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");358assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer");359return result;360}361362void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {363*((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;364}365366// Used by template based interpreter deoptimization367void frame::interpreter_frame_set_last_sp(intptr_t* sp) {368*((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;369}370#endif // CC_INTERP371372frame frame::sender_for_entry_frame(RegisterMap* map) const {373assert(map != NULL, "map must be set");374// Java frame called from C; skip all C frames and return top C375// frame of that chunk as the sender376JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();377assert(!entry_frame_is_first(), "next Java fp must be non zero");378assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");379// Since we are walking the stack now this nested anchor is obviously walkable380// even if it wasn't when it was stacked.381if (!jfa->walkable()) {382// Capture _last_Java_pc (if needed) and mark anchor walkable.383jfa->capture_last_Java_pc();384}385map->clear();386assert(map->include_argument_oops(), "should be set by clear");387assert(jfa->last_Java_pc() != NULL, "not walkable");388frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());389return fr;390}391392//------------------------------------------------------------------------------393// frame::verify_deopt_original_pc394//395// Verifies the calculated original PC of a deoptimization PC for the396// given unextended SP.397#ifdef ASSERT398void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp) {399frame fr;400401// This is ugly but it's better than to change {get,set}_original_pc402// to take an SP value as argument. And it's only a debugging403// method anyway.404fr._unextended_sp = unextended_sp;405406address original_pc = nm->get_original_pc(&fr);407assert(nm->insts_contains(original_pc), "original PC must be in nmethod");408}409#endif410411//------------------------------------------------------------------------------412// frame::adjust_unextended_sp413void frame::adjust_unextended_sp() {414// On aarch32, sites calling method handle intrinsics and lambda forms are treated415// as any other call site. Therefore, no special action is needed when we are416// returning to any of these call sites.417418nmethod* sender_nm = (_cb == NULL) ? NULL : _cb->as_nmethod_or_null();419if (sender_nm != NULL) {420// If the sender PC is a deoptimization point, get the original PC.421if (sender_nm->is_deopt_entry(_pc) ||422sender_nm->is_deopt_mh_entry(_pc)) {423DEBUG_ONLY(verify_deopt_original_pc(sender_nm, _unextended_sp));424}425}426}427428//------------------------------------------------------------------------------429// frame::update_map_with_saved_link430void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {431// The interpreter and compiler(s) always save fp in a known432// location on entry. We must record where that location is433// so that if fp was live on callout from c2 we can find434// the saved copy no matter what it called.435436// Since the interpreter always saves fp if we record where it is then437// we don't have to always save fp on entry and exit to c2 compiled438// code, on entry will be enough.439map->set_location(rfp->as_VMReg(), (address) link_addr);440}441442443//------------------------------------------------------------------------------444// frame::sender_for_interpreter_frame445frame frame::sender_for_interpreter_frame(RegisterMap* map) const {446// SP is the raw SP from the sender after adapter or interpreter447// extension.448intptr_t* sender_sp = this->sender_sp();449450// This is the sp before any possible extension (adapter/locals).451intptr_t* unextended_sp = interpreter_frame_sender_sp();452453#ifdef COMPILER2454if (map->update_map()) {455update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));456}457#endif // COMPILER2458459return frame(sender_sp, unextended_sp, link(), sender_pc());460}461462463//------------------------------------------------------------------------------464// frame::sender_for_compiled_frame465/*frame frame::sender_for_compiled_frame(RegisterMap* map) const {466// we cannot rely upon the last fp having been saved to the thread467// in C2 code but it will have been pushed onto the stack. so we468// have to find it relative to the unextended sp469470assert(_cb->frame_size() >= 0, "must have non-zero frame size");471intptr_t* l_sender_sp = unextended_sp() + _cb->frame_size();472intptr_t* unextended_sp = l_sender_sp;473474// the return_address is always the word on the stack475address sender_pc = (address) *(l_sender_sp-1);476477intptr_t** saved_fp_addr = (intptr_t**) (l_sender_sp - frame::sender_sp_offset);478intptr_t** saved_fp_addr = (intptr_t**)(_fp + link_offset);479480// assert (sender_sp() == l_sender_sp, "should be");481// assert (*saved_fp_addr == link(), "should be");482483if (map->update_map()) {484// Tell GC to use argument oopmaps for some runtime stubs that need it.485// For C1, the runtime stub might not have oop maps, so set this flag486// outside of update_register_map.487map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));488if (_cb->oop_maps() != NULL) {489OopMapSet::update_register_map(this, map);490}491492// Since the prolog does the save and restore of FP there is no493// oopmap for it so we must fill in its location as if there was494// an oopmap entry since if our caller was compiled code there495// could be live jvm state in it.496update_map_with_saved_link(map, saved_fp_addr);497}498499return frame(l_sender_sp, unextended_sp, *saved_fp_addr, sender_pc);500}*/501502frame frame::sender_for_compiled_frame(RegisterMap* map) const {503// we cannot rely upon the last fp having been saved to the thread504// in C2 code but it will have been pushed onto the stack. so we505// have to find it relative to the unextended sp506507assert(_cb->frame_size() >= 0, "must have non-zero frame size");508intptr_t* l_sender_sp = unextended_sp() + _cb->frame_size();509intptr_t* unextended_sp = l_sender_sp;510511// the return_address is always the word on the stack512address sender_pc = (address) *(l_sender_sp - 1);513514intptr_t** saved_fp_addr = (intptr_t**)(l_sender_sp - 2);515516// assert (sender_sp() == l_sender_sp, "should be");517// assert (*saved_fp_addr == link(), "should be");518519if (map->update_map()) {520// Tell GC to use argument oopmaps for some runtime stubs that need it.521// For C1, the runtime stub might not have oop maps, so set this flag522// outside of update_register_map.523map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));524if (_cb->oop_maps() != NULL) {525OopMapSet::update_register_map(this, map);526}527528// Since the prolog does the save and restore of FP there is no529// oopmap for it so we must fill in its location as if there was530// an oopmap entry since if our caller was compiled code there531// could be live jvm state in it.532update_map_with_saved_link(map, saved_fp_addr);533}534535return frame(l_sender_sp, unextended_sp, *saved_fp_addr, sender_pc);536}537538//------------------------------------------------------------------------------539// frame::sender540frame frame::sender(RegisterMap* map) const {541// Default is we done have to follow them. The sender_for_xxx will542// update it accordingly543map->set_include_argument_oops(false);544//printf("Called frame::sender\n");545546//printf("fp is %p, _call_stub_return_address is %p\n", _fp, StubRoutines::_call_stub_return_address);547548if (is_entry_frame()) {549//printf("Is entry frame\n");550return sender_for_entry_frame(map);551}552if (is_interpreted_frame()) {553//printf("Is interpreted frame\n");554return sender_for_interpreter_frame(map);555}556assert(_cb == CodeCache::find_blob(pc()),"Must be the same");557558// This test looks odd: why is it not is_compiled_frame() ? That's559// because stubs also have OOP maps.560if (_cb != NULL) {561//printf("Is compiled frame\n");562return sender_for_compiled_frame(map);563}564565//printf("Is default frame\n");566// Must be native-compiled frame, i.e. the marshaling code for native567// methods that exists in the core system.568return frame(sender_sp(), link(), sender_pc());569}570571bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {572assert(is_interpreted_frame(), "must be interpreter frame");573Method* method = interpreter_frame_method();574// When unpacking an optimized frame the frame pointer is575// adjusted with:576int diff = (method->max_locals() - method->size_of_parameters()) *577Interpreter::stackElementWords;578return _fp == (fp - diff);579}580581void frame::pd_gc_epilog() {582// Nothing to do here for now583}584585bool frame::is_interpreted_frame_valid(JavaThread* thread) const {586// QQQ587#ifdef CC_INTERP588#else589assert(is_interpreted_frame(), "Not an interpreted frame");590// These are reasonable sanity checks591if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {592return false;593}594if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {595return false;596}597if (fp() + interpreter_frame_initial_sp_offset < sp()) {598return false;599}600// These are hacks to keep us out of trouble.601// The problem with these is that they mask other problems602if (fp() <= sp()) { // this attempts to deal with unsigned comparison above603return false;604}605606// do some validation of frame elements607608// first the method609610Method* m = *interpreter_frame_method_addr();611612// validate the method we'd find in this potential sender613if (!m->is_valid_method()) return false;614615// stack frames shouldn't be much larger than max_stack elements616// this test requires the use of unextended_sp which is the sp as seen by617// the current frame, and not sp which is the "raw" pc which could point618// further because of local variables of the callee method inserted after619// method arguments620if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {621return false;622}623624// Validate bci/bcx625intptr_t bcx = interpreter_frame_bcx();626if (m->validate_bci_from_bcx(bcx) < 0) {627return false;628}629630// validate constantPoolCache*631ConstantPoolCache* cp = *interpreter_frame_cache_addr();632if (cp == NULL || !cp->is_metaspace_object()) return false;633634// validate locals635636address locals = (address) *interpreter_frame_locals_addr();637638if (locals > thread->stack_base() || locals < (address) fp()) return false;639640// We'd have to be pretty unlucky to be mislead at this point641642#endif // CC_INTERP643return true;644}645646BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {647#ifdef CC_INTERP648// Needed for JVMTI. The result should always be in the649// interpreterState object650interpreterState istate = get_interpreterState();651#endif // CC_INTERP652assert(is_interpreted_frame(), "interpreted frame expected");653Method* method = interpreter_frame_method();654BasicType type = method->result_type();655656intptr_t* tos_addr;657if (method->is_native()) {658tos_addr = (intptr_t*)sp();659if (type == T_FLOAT || type == T_DOUBLE) {660// This is times two because we do a push(ltos) after pushing D0661// and that takes two interpreter stack slots.662#ifdef HARD_FLOAT_CC663tos_addr += 2 * Interpreter::stackElementWords;664#endif665}666} else {667tos_addr = (intptr_t*)interpreter_frame_tos_address();668}669670switch (type) {671case T_OBJECT :672case T_ARRAY : {673oop obj;674if (method->is_native()) {675#ifdef CC_INTERP676obj = istate->_oop_temp;677#else678obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));679#endif // CC_INTERP680} else {681oop* obj_p = (oop*)tos_addr;682obj = (obj_p == NULL) ? (oop)NULL : *obj_p;683}684assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");685*oop_result = obj;686break;687}688case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;689case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;690case T_CHAR : value_result->c = *(jchar*)tos_addr; break;691case T_SHORT : value_result->s = *(jshort*)tos_addr; break;692case T_INT : value_result->i = *(jint*)tos_addr; break;693case T_LONG : value_result->j = *(jlong*)tos_addr; break;694case T_FLOAT : {695value_result->f = *(jfloat*)tos_addr;696break;697}698case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;699case T_VOID : /* Nothing to do */ break;700default : ShouldNotReachHere();701}702703return type;704}705706707intptr_t* frame::interpreter_frame_tos_at(jint offset) const {708int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);709return &interpreter_frame_tos_address()[index];710}711712#ifndef PRODUCT713714#define DESCRIBE_FP_OFFSET(name) \715values.describe(frame_no, fp() + frame::name##_offset, #name)716717void frame::describe_pd(FrameValues& values, int frame_no) {718if (is_interpreted_frame()) {719DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);720DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);721DESCRIBE_FP_OFFSET(interpreter_frame_method);722DESCRIBE_FP_OFFSET(interpreter_frame_mdx);723DESCRIBE_FP_OFFSET(interpreter_frame_cache);724DESCRIBE_FP_OFFSET(interpreter_frame_locals);725DESCRIBE_FP_OFFSET(interpreter_frame_bcx);726DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);727}728}729730#endif // PRODUCT731732intptr_t *frame::initial_deoptimization_info() {733// Not used on aarch32, but we must return something.734return NULL;735}736737intptr_t* frame::real_fp() const {738// Currently we have a fp for all frames739/*if (_cb != NULL) {740// use the frame size if valid741int size = _cb->frame_size();742if (size > 0) {743return unextended_sp() + size;744}745}*/746// else rely on fp()747//assert(! is_compiled_frame(), "unknown compiled frame size");748return fp();749}750751#undef DESCRIBE_FP_OFFSET752753#define DESCRIBE_FP_OFFSET(name) \754{ \755unsigned long *p = (unsigned long *)fp; \756printf("0x%016lx 0x%016lx %s\n", (unsigned long)(p + frame::name##_offset), \757p[frame::name##_offset], #name); \758}759760static __thread unsigned long nextfp;761static __thread unsigned long nextpc;762static __thread unsigned long nextsp;763static __thread RegisterMap *reg_map;764765static void printbc(Method* m, intptr_t bcx) {766const char* name;767char buf[16];768if (m->validate_bci_from_bcx(bcx) < 0 || !m->contains((address) bcx)) {769name = "???";770snprintf(buf, sizeof buf, "(bad)");771} else {772int bci = m->bci_from((address) bcx);773snprintf(buf, sizeof buf, "%d", bci);774name = Bytecodes::name(m->code_at(bci));775}776ResourceMark rm;777printf("%s : %s ==> %s\n", m->name_and_sig_as_C_string(), buf, name);778}779780void internal_pf(unsigned long sp, unsigned long fp, unsigned long pc, unsigned long bcx) {781if (! fp)782return;783784DESCRIBE_FP_OFFSET(return_addr);785DESCRIBE_FP_OFFSET(link);786DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);787DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);788DESCRIBE_FP_OFFSET(interpreter_frame_method);789DESCRIBE_FP_OFFSET(interpreter_frame_mdx);790DESCRIBE_FP_OFFSET(interpreter_frame_cache);791DESCRIBE_FP_OFFSET(interpreter_frame_locals);792DESCRIBE_FP_OFFSET(interpreter_frame_bcx);793DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);794795unsigned long* p = (unsigned long*) fp;796797// We want to see all frames, native and Java. For compiled and798// interpreted frames we have special information that allows us to799// unwind them; for everything else we assume that the native frame800// pointer chain is intact.801frame this_frame((intptr_t*)sp, (intptr_t*)fp, (address)pc);802if (this_frame.is_compiled_frame() ||803this_frame.is_interpreted_frame()) {804frame sender = this_frame.sender(reg_map);805nextfp = (unsigned long)sender.fp();806nextpc = (unsigned long)sender.pc();807nextsp = (unsigned long)sender.unextended_sp();808} else {809nextfp = p[frame::link_offset];810nextpc = p[frame::return_addr_offset];811nextsp = (unsigned long)&p[frame::sender_sp_offset];812}813814if (bcx == -1ul) {815bcx = p[frame::interpreter_frame_bcx_offset];816}817818if (Interpreter::contains((address)pc)) {819Method* m = (Method*)p[frame::interpreter_frame_method_offset];820if(m && m->is_method()) {821printbc(m, bcx);822} else823printf("not a Method\n");824} else {825CodeBlob *cb = CodeCache::find_blob((address)pc);826if (cb != NULL) {827if (cb->is_nmethod()) {828ResourceMark rm;829nmethod* nm = (nmethod*)cb;830printf("nmethod %s\n", nm->method()->name_and_sig_as_C_string());831} else if (cb->name()) {832printf("CodeBlob %s\n", cb->name());833}834}835}836}837838extern "C" void npf() {839CodeBlob *cb = CodeCache::find_blob((address)nextpc);840// C2 does not always chain the frame pointers when it can, instead841// preferring to use fixed offsets from SP, so a simple leave() does842// not work. Instead, it adds the frame size to SP then pops FP and843// LR. We have to do the same thing to get a good call chain.844if (cb && cb->frame_size())845nextfp = nextsp + wordSize * (cb->frame_size() - 2);846internal_pf (nextsp, nextfp, nextpc, -1);847}848849extern "C" void pf(unsigned long sp, unsigned long fp, unsigned long pc,850unsigned long bcx, unsigned long thread) {851RegisterMap map((JavaThread*)thread, false);852if (!reg_map) {853reg_map = (RegisterMap*)os::malloc(sizeof map, mtNone);854}855memcpy(reg_map, &map, sizeof map);856{857CodeBlob *cb = CodeCache::find_blob((address)pc);858if (cb && cb->frame_size())859fp = sp + wordSize * (cb->frame_size() - 2);860}861internal_pf(sp, fp, pc, bcx);862}863864// support for printing out where we are in a Java method865// needs to be passed current fp and bcp register values866// prints method name, bc index and bytecode name867extern "C" void pm(unsigned long fp, unsigned long bcx) {868DESCRIBE_FP_OFFSET(interpreter_frame_method);869unsigned long *p = (unsigned long *)fp;870Method* m = (Method*)p[frame::interpreter_frame_method_offset];871printbc(m, bcx);872}873874#ifndef PRODUCT875// This is a generic constructor which is only used by pns() in debug.cpp.876frame::frame(void* sp, void* fp, void* pc) {877init((intptr_t*)sp, (intptr_t*)fp, (address)pc);878}879#endif880881void JavaFrameAnchor::make_walkable(JavaThread* thread) {882// last frame set?883if (last_Java_sp() == NULL) return;884// already walkable?885if (walkable()) return;886assert(Thread::current() == (Thread*)thread, "not current thread");887assert(last_Java_sp() != NULL, "not called from Java code?");888assert(last_Java_pc() == NULL, "already walkable");889capture_last_Java_pc();890assert(walkable(), "something went wrong");891}892893void JavaFrameAnchor::capture_last_Java_pc() {894assert(_last_Java_sp != NULL, "no last frame set");895assert(_last_Java_pc == NULL, "already walkable");896_last_Java_pc = (address)_last_Java_sp[-1];897}898899900