Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/cpu/ppc/vm/frame_ppc.cpp
83402 views
/*1* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012, 2017 SAP AG. 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 "interpreter/interpreter.hpp"27#include "memory/resourceArea.hpp"28#include "oops/markOop.hpp"29#include "oops/method.hpp"30#include "oops/oop.inline.hpp"31#include "runtime/frame.inline.hpp"32#include "runtime/handles.inline.hpp"33#include "runtime/javaCalls.hpp"34#include "runtime/monitorChunk.hpp"35#include "runtime/signature.hpp"36#include "runtime/stubCodeGenerator.hpp"37#include "runtime/stubRoutines.hpp"38#include "vmreg_ppc.inline.hpp"39#ifdef COMPILER140#include "c1/c1_Runtime1.hpp"41#include "runtime/vframeArray.hpp"42#endif4344#ifdef ASSERT45void RegisterMap::check_location_valid() {46}47#endif // ASSERT4849bool frame::safe_for_sender(JavaThread *thread) {50bool safe = false;51address sp = (address)_sp;52address fp = (address)_fp;53address unextended_sp = (address)_unextended_sp;5455// Consider stack guards when trying to determine "safe" stack pointers56static size_t stack_guard_size = os::uses_stack_guard_pages() ?57thread->stack_red_zone_size() + thread->stack_yellow_zone_size() : 0;58size_t usable_stack_size = thread->stack_size() - stack_guard_size;5960// sp must be within the usable part of the stack (not in guards)61bool sp_safe = (sp < thread->stack_base()) &&62(sp >= thread->stack_base() - usable_stack_size);636465if (!sp_safe) {66return false;67}6869// Unextended sp must be within the stack and above or equal sp70bool unextended_sp_safe = (unextended_sp < thread->stack_base()) && (unextended_sp >= sp);7172if (!unextended_sp_safe) {73return false;74}7576// An fp must be within the stack and above (but not equal) sp.77bool fp_safe = (fp <= thread->stack_base()) && (fp > sp);78// an interpreter fp must be within the stack and above (but not equal) sp79bool fp_interp_safe = (fp <= thread->stack_base()) && (fp > sp) &&80((fp - sp) >= (ijava_state_size + top_ijava_frame_abi_size));8182// We know sp/unextended_sp are safe, only fp is questionable here8384// If the current frame is known to the code cache then we can attempt to85// to construct the sender and do some validation of it. This goes a long way86// toward eliminating issues when we get in frame construction code8788if (_cb != NULL ){89// Entry frame checks90if (is_entry_frame()) {91// An entry frame must have a valid fp.92return fp_safe && is_entry_frame_valid(thread);93}9495// Now check if the frame is complete and the test is96// reliable. Unfortunately we can only check frame completeness for97// runtime stubs and nmethods. Other generic buffer blobs are more98// problematic so we just assume they are OK. Adapter blobs never have a99// complete frame and are never OK100if (!_cb->is_frame_complete_at(_pc)) {101if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {102return false;103}104}105106// Could just be some random pointer within the codeBlob.107if (!_cb->code_contains(_pc)) {108return false;109}110111if (is_interpreted_frame() && !fp_interp_safe) {112return false;113}114115abi_minframe* sender_abi = (abi_minframe*) fp;116intptr_t* sender_sp = (intptr_t*) fp;117address sender_pc = (address) sender_abi->lr;;118119// We must always be able to find a recognizable pc.120CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);121if (sender_blob == NULL) {122return false;123}124125// Could be a zombie method126if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {127return false;128}129130// It should be safe to construct the sender though it might not be valid.131132frame sender(sender_sp, sender_pc);133134// Do we have a valid fp?135address sender_fp = (address) sender.fp();136137// sender_fp must be within the stack and above (but not138// equal) current frame's fp.139if (sender_fp > thread->stack_base() || sender_fp <= fp) {140return false;141}142143// If the potential sender is the interpreter then we can do some more checking.144if (Interpreter::contains(sender_pc)) {145return sender.is_interpreted_frame_valid(thread);146}147148// Could just be some random pointer within the codeBlob.149if (!sender.cb()->code_contains(sender_pc)) {150return false;151}152153// We should never be able to see an adapter if the current frame is something from code cache.154if (sender_blob->is_adapter_blob()) {155return false;156}157158if (sender.is_entry_frame()) {159return sender.is_entry_frame_valid(thread);160}161162// Frame size is always greater than zero. If the sender frame size is zero or less,163// something is really weird and we better give up.164if (sender_blob->frame_size() <= 0) {165return false;166}167168return true;169}170171// Must be native-compiled frame. Since sender will try and use fp to find172// linkages it must be safe173174if (!fp_safe) {175return false;176}177178return true;179}180181bool frame::is_interpreted_frame() const {182return Interpreter::contains(pc());183}184185frame frame::sender_for_entry_frame(RegisterMap *map) const {186assert(map != NULL, "map must be set");187// Java frame called from C; skip all C frames and return top C188// frame of that chunk as the sender.189JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();190assert(!entry_frame_is_first(), "next Java fp must be non zero");191assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");192map->clear();193assert(map->include_argument_oops(), "should be set by clear");194195if (jfa->last_Java_pc() != NULL) {196frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());197return fr;198}199// Last_java_pc is not set, if we come here from compiled code. The200// constructor retrieves the PC from the stack.201frame fr(jfa->last_Java_sp());202return fr;203}204205frame frame::sender_for_interpreter_frame(RegisterMap *map) const {206// Pass callers initial_caller_sp as unextended_sp.207return frame(sender_sp(), sender_pc(),208CC_INTERP_ONLY((intptr_t*)((parent_ijava_frame_abi *)callers_abi())->initial_caller_sp)209NOT_CC_INTERP((intptr_t*)get_ijava_state()->sender_sp)210);211}212213frame frame::sender_for_compiled_frame(RegisterMap *map) const {214assert(map != NULL, "map must be set");215216// Frame owned by compiler.217address pc = *compiled_sender_pc_addr(_cb);218frame caller(compiled_sender_sp(_cb), pc);219220// Now adjust the map.221222// Get the rest.223if (map->update_map()) {224// Tell GC to use argument oopmaps for some runtime stubs that need it.225map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));226if (_cb->oop_maps() != NULL) {227OopMapSet::update_register_map(this, map);228}229}230231return caller;232}233234intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const {235return sender_sp();236}237238address* frame::compiled_sender_pc_addr(CodeBlob* cb) const {239return sender_pc_addr();240}241242frame frame::sender(RegisterMap* map) const {243// Default is we do have to follow them. The sender_for_xxx will244// update it accordingly.245map->set_include_argument_oops(false);246247if (is_entry_frame()) return sender_for_entry_frame(map);248if (is_interpreted_frame()) return sender_for_interpreter_frame(map);249assert(_cb == CodeCache::find_blob(pc()),"Must be the same");250251if (_cb != NULL) {252return sender_for_compiled_frame(map);253}254// Must be native-compiled frame, i.e. the marshaling code for native255// methods that exists in the core system.256return frame(sender_sp(), sender_pc());257}258259void frame::patch_pc(Thread* thread, address pc) {260if (TracePcPatching) {261tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "]",262p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));263}264own_abi()->lr = (uint64_t)pc;265_cb = CodeCache::find_blob(pc);266if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) {267address orig = (((nmethod*)_cb)->get_original_pc(this));268assert(orig == _pc, "expected original to be stored before patching");269_deopt_state = is_deoptimized;270// Leave _pc as is.271} else {272_deopt_state = not_deoptimized;273_pc = pc;274}275}276277void frame::pd_gc_epilog() {278if (is_interpreted_frame()) {279// Set constant pool cache entry for interpreter.280Method* m = interpreter_frame_method();281282*interpreter_frame_cpoolcache_addr() = m->constants()->cache();283}284}285286bool frame::is_interpreted_frame_valid(JavaThread* thread) const {287// Is there anything to do?288assert(is_interpreted_frame(), "Not an interpreted frame");289return true;290}291292BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {293assert(is_interpreted_frame(), "interpreted frame expected");294Method* method = interpreter_frame_method();295BasicType type = method->result_type();296297if (method->is_native()) {298// Prior to calling into the runtime to notify the method exit the possible299// result value is saved into the interpreter frame.300#ifdef CC_INTERP301interpreterState istate = get_interpreterState();302address lresult = (address)istate + in_bytes(BytecodeInterpreter::native_lresult_offset());303address fresult = (address)istate + in_bytes(BytecodeInterpreter::native_fresult_offset());304#else305address lresult = (address)&(get_ijava_state()->lresult);306address fresult = (address)&(get_ijava_state()->fresult);307#endif308309switch (method->result_type()) {310case T_OBJECT:311case T_ARRAY: {312*oop_result = JNIHandles::resolve(*(jobject*)lresult);313break;314}315// We use std/stfd to store the values.316case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;317case T_INT : value_result->i = (jint) *(long*)lresult; break;318case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;319case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;320case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;321case T_LONG : value_result->j = (jlong) *(long*)lresult; break;322case T_FLOAT : value_result->f = (jfloat) *(double*)fresult; break;323case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;324case T_VOID : /* Nothing to do */ break;325default : ShouldNotReachHere();326}327} else {328intptr_t* tos_addr = interpreter_frame_tos_address();329switch (method->result_type()) {330case T_OBJECT:331case T_ARRAY: {332oop obj = *(oop*)tos_addr;333assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");334*oop_result = obj;335}336case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;337case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;338case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;339case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;340case T_INT : value_result->i = *(jint*)tos_addr; break;341case T_LONG : value_result->j = *(jlong*)tos_addr; break;342case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;343case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;344case T_VOID : /* Nothing to do */ break;345default : ShouldNotReachHere();346}347}348return type;349}350351#ifndef PRODUCT352353void frame::describe_pd(FrameValues& values, int frame_no) {354if (is_interpreted_frame()) {355#ifdef CC_INTERP356interpreterState istate = get_interpreterState();357values.describe(frame_no, (intptr_t*)istate, "istate");358values.describe(frame_no, (intptr_t*)&(istate->_thread), " thread");359values.describe(frame_no, (intptr_t*)&(istate->_bcp), " bcp");360values.describe(frame_no, (intptr_t*)&(istate->_locals), " locals");361values.describe(frame_no, (intptr_t*)&(istate->_constants), " constants");362values.describe(frame_no, (intptr_t*)&(istate->_method), err_msg(" method = %s", istate->_method->name_and_sig_as_C_string()));363values.describe(frame_no, (intptr_t*)&(istate->_mdx), " mdx");364values.describe(frame_no, (intptr_t*)&(istate->_stack), " stack");365values.describe(frame_no, (intptr_t*)&(istate->_msg), err_msg(" msg = %s", BytecodeInterpreter::C_msg(istate->_msg)));366values.describe(frame_no, (intptr_t*)&(istate->_result), " result");367values.describe(frame_no, (intptr_t*)&(istate->_prev_link), " prev_link");368values.describe(frame_no, (intptr_t*)&(istate->_oop_temp), " oop_temp");369values.describe(frame_no, (intptr_t*)&(istate->_stack_base), " stack_base");370values.describe(frame_no, (intptr_t*)&(istate->_stack_limit), " stack_limit");371values.describe(frame_no, (intptr_t*)&(istate->_monitor_base), " monitor_base");372values.describe(frame_no, (intptr_t*)&(istate->_frame_bottom), " frame_bottom");373values.describe(frame_no, (intptr_t*)&(istate->_last_Java_pc), " last_Java_pc");374values.describe(frame_no, (intptr_t*)&(istate->_last_Java_fp), " last_Java_fp");375values.describe(frame_no, (intptr_t*)&(istate->_last_Java_sp), " last_Java_sp");376values.describe(frame_no, (intptr_t*)&(istate->_self_link), " self_link");377values.describe(frame_no, (intptr_t*)&(istate->_native_fresult), " native_fresult");378values.describe(frame_no, (intptr_t*)&(istate->_native_lresult), " native_lresult");379#else380#define DESCRIBE_ADDRESS(name) \381values.describe(frame_no, (intptr_t*)&(get_ijava_state()->name), #name);382383DESCRIBE_ADDRESS(method);384DESCRIBE_ADDRESS(locals);385DESCRIBE_ADDRESS(monitors);386DESCRIBE_ADDRESS(cpoolCache);387DESCRIBE_ADDRESS(bcp);388DESCRIBE_ADDRESS(esp);389DESCRIBE_ADDRESS(mdx);390DESCRIBE_ADDRESS(top_frame_sp);391DESCRIBE_ADDRESS(sender_sp);392DESCRIBE_ADDRESS(oop_tmp);393DESCRIBE_ADDRESS(lresult);394DESCRIBE_ADDRESS(fresult);395#endif396}397}398#endif399400void frame::adjust_unextended_sp() {401// If we are returning to a compiled MethodHandle call site, the402// saved_fp will in fact be a saved value of the unextended SP. The403// simplest way to tell whether we are returning to such a call site404// is as follows:405406if (is_compiled_frame() && false /*is_at_mh_callsite()*/) { // TODO PPC port407// If the sender PC is a deoptimization point, get the original408// PC. For MethodHandle call site the unextended_sp is stored in409// saved_fp.410_unextended_sp = _fp - _cb->frame_size();411412#ifdef ASSERT413nmethod *sender_nm = _cb->as_nmethod_or_null();414assert(sender_nm && *_sp == *_unextended_sp, "backlink changed");415416intptr_t* sp = _unextended_sp; // check if stack can be walked from here417for (int x = 0; x < 5; ++x) { // check up to a couple of backlinks418intptr_t* prev_sp = *(intptr_t**)sp;419if (prev_sp == 0) break; // end of stack420assert(prev_sp>sp, "broken stack");421sp = prev_sp;422}423424if (sender_nm->is_deopt_mh_entry(_pc)) { // checks for deoptimization425address original_pc = sender_nm->get_original_pc(this);426assert(sender_nm->insts_contains(original_pc), "original PC must be in nmethod");427assert(sender_nm->is_method_handle_return(original_pc), "must be");428}429#endif430}431}432433intptr_t *frame::initial_deoptimization_info() {434// unused... but returns fp() to minimize changes introduced by 7087445435return fp();436}437438#ifndef PRODUCT439// This is a generic constructor which is only used by pns() in debug.cpp.440frame::frame(void* sp, void* fp, void* pc) : _sp((intptr_t*)sp), _unextended_sp((intptr_t*)sp) {441find_codeblob_and_set_pc_and_deopt_state((address)pc); // also sets _fp and adjusts _unextended_sp442}443#endif444445446