Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/ppc/vm/frame_ppc.cpp
32285 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 stack70bool unextended_sp_safe = (unextended_sp < thread->stack_base());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) sp.79// Moreover, it must be at least the size of the ijava_state structure.80bool fp_interp_safe = (fp <= thread->stack_base()) && (fp > sp) &&81((fp - sp) >= ijava_state_size);8283// We know sp/unextended_sp are safe, only fp is questionable here8485// If the current frame is known to the code cache then we can attempt to86// to construct the sender and do some validation of it. This goes a long way87// toward eliminating issues when we get in frame construction code8889if (_cb != NULL ){90// Entry frame checks91if (is_entry_frame()) {92// An entry frame must have a valid fp.93return fp_safe && is_entry_frame_valid(thread);94}9596// Now check if the frame is complete and the test is97// reliable. Unfortunately we can only check frame completeness for98// runtime stubs and nmethods. Other generic buffer blobs are more99// problematic so we just assume they are OK. Adapter blobs never have a100// complete frame and are never OK101if (!_cb->is_frame_complete_at(_pc)) {102if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {103return false;104}105}106107// Could just be some random pointer within the codeBlob.108if (!_cb->code_contains(_pc)) {109return false;110}111112if (is_interpreted_frame() && !fp_interp_safe) {113return false;114}115116abi_minframe* sender_abi = (abi_minframe*) fp;117intptr_t* sender_sp = (intptr_t*) fp;118address sender_pc = (address) sender_abi->lr;;119120// We must always be able to find a recognizable pc.121CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);122if (sender_blob == NULL) {123return false;124}125126// Could be a zombie method127if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {128return false;129}130131// It should be safe to construct the sender though it might not be valid.132133frame sender(sender_sp, sender_pc);134135// Do we have a valid fp?136address sender_fp = (address) sender.fp();137138// sender_fp must be within the stack and above (but not139// equal) current frame's fp.140if (sender_fp > thread->stack_base() || sender_fp <= fp) {141return false;142}143144// If the potential sender is the interpreter then we can do some more checking.145if (Interpreter::contains(sender_pc)) {146return sender.is_interpreted_frame_valid(thread);147}148149// Could just be some random pointer within the codeBlob.150if (!sender.cb()->code_contains(sender_pc)) {151return false;152}153154// We should never be able to see an adapter if the current frame is something from code cache.155if (sender_blob->is_adapter_blob()) {156return false;157}158159if (sender.is_entry_frame()) {160return sender.is_entry_frame_valid(thread);161}162163// Frame size is always greater than zero. If the sender frame size is zero or less,164// something is really weird and we better give up.165if (sender_blob->frame_size() <= 0) {166return false;167}168169return true;170}171172// Must be native-compiled frame. Since sender will try and use fp to find173// linkages it must be safe174175if (!fp_safe) {176return false;177}178179return true;180}181182bool frame::is_interpreted_frame() const {183return Interpreter::contains(pc());184}185186frame frame::sender_for_entry_frame(RegisterMap *map) const {187assert(map != NULL, "map must be set");188// Java frame called from C; skip all C frames and return top C189// frame of that chunk as the sender.190JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();191assert(!entry_frame_is_first(), "next Java fp must be non zero");192assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");193map->clear();194assert(map->include_argument_oops(), "should be set by clear");195196if (jfa->last_Java_pc() != NULL) {197frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());198return fr;199}200// Last_java_pc is not set, if we come here from compiled code. The201// constructor retrieves the PC from the stack.202frame fr(jfa->last_Java_sp());203return fr;204}205206frame frame::sender_for_interpreter_frame(RegisterMap *map) const {207// Pass callers initial_caller_sp as unextended_sp.208return frame(sender_sp(), sender_pc(),209CC_INTERP_ONLY((intptr_t*)((parent_ijava_frame_abi *)callers_abi())->initial_caller_sp)210NOT_CC_INTERP((intptr_t*)get_ijava_state()->sender_sp)211);212}213214frame frame::sender_for_compiled_frame(RegisterMap *map) const {215assert(map != NULL, "map must be set");216217// Frame owned by compiler.218address pc = *compiled_sender_pc_addr(_cb);219frame caller(compiled_sender_sp(_cb), pc);220221// Now adjust the map.222223// Get the rest.224if (map->update_map()) {225// Tell GC to use argument oopmaps for some runtime stubs that need it.226map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));227if (_cb->oop_maps() != NULL) {228OopMapSet::update_register_map(this, map);229}230}231232return caller;233}234235intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const {236return sender_sp();237}238239address* frame::compiled_sender_pc_addr(CodeBlob* cb) const {240return sender_pc_addr();241}242243frame frame::sender(RegisterMap* map) const {244// Default is we do have to follow them. The sender_for_xxx will245// update it accordingly.246map->set_include_argument_oops(false);247248if (is_entry_frame()) return sender_for_entry_frame(map);249if (is_interpreted_frame()) return sender_for_interpreter_frame(map);250assert(_cb == CodeCache::find_blob(pc()),"Must be the same");251252if (_cb != NULL) {253return sender_for_compiled_frame(map);254}255// Must be native-compiled frame, i.e. the marshaling code for native256// methods that exists in the core system.257return frame(sender_sp(), sender_pc());258}259260void frame::patch_pc(Thread* thread, address pc) {261if (TracePcPatching) {262tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "]",263p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));264}265own_abi()->lr = (uint64_t)pc;266_cb = CodeCache::find_blob(pc);267if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) {268address orig = (((nmethod*)_cb)->get_original_pc(this));269assert(orig == _pc, "expected original to be stored before patching");270_deopt_state = is_deoptimized;271// Leave _pc as is.272} else {273_deopt_state = not_deoptimized;274_pc = pc;275}276}277278void frame::pd_gc_epilog() {279if (is_interpreted_frame()) {280// Set constant pool cache entry for interpreter.281Method* m = interpreter_frame_method();282283*interpreter_frame_cpoolcache_addr() = m->constants()->cache();284}285}286287bool frame::is_interpreted_frame_valid(JavaThread* thread) const {288// Is there anything to do?289assert(is_interpreted_frame(), "Not an interpreted frame");290return true;291}292293BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {294assert(is_interpreted_frame(), "interpreted frame expected");295Method* method = interpreter_frame_method();296BasicType type = method->result_type();297298if (method->is_native()) {299// Prior to calling into the runtime to notify the method exit the possible300// result value is saved into the interpreter frame.301#ifdef CC_INTERP302interpreterState istate = get_interpreterState();303address lresult = (address)istate + in_bytes(BytecodeInterpreter::native_lresult_offset());304address fresult = (address)istate + in_bytes(BytecodeInterpreter::native_fresult_offset());305#else306address lresult = (address)&(get_ijava_state()->lresult);307address fresult = (address)&(get_ijava_state()->fresult);308#endif309310switch (method->result_type()) {311case T_OBJECT:312case T_ARRAY: {313*oop_result = JNIHandles::resolve(*(jobject*)lresult);314break;315}316// We use std/stfd to store the values.317case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;318case T_INT : value_result->i = (jint) *(long*)lresult; break;319case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;320case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;321case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;322case T_LONG : value_result->j = (jlong) *(long*)lresult; break;323case T_FLOAT : value_result->f = (jfloat) *(double*)fresult; break;324case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;325case T_VOID : /* Nothing to do */ break;326default : ShouldNotReachHere();327}328} else {329intptr_t* tos_addr = interpreter_frame_tos_address();330switch (method->result_type()) {331case T_OBJECT:332case T_ARRAY: {333oop obj = *(oop*)tos_addr;334assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");335*oop_result = obj;336}337case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;338case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;339case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;340case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;341case T_INT : value_result->i = *(jint*)tos_addr; break;342case T_LONG : value_result->j = *(jlong*)tos_addr; break;343case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;344case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;345case T_VOID : /* Nothing to do */ break;346default : ShouldNotReachHere();347}348}349return type;350}351352#ifndef PRODUCT353354void frame::describe_pd(FrameValues& values, int frame_no) {355if (is_interpreted_frame()) {356#ifdef CC_INTERP357interpreterState istate = get_interpreterState();358values.describe(frame_no, (intptr_t*)istate, "istate");359values.describe(frame_no, (intptr_t*)&(istate->_thread), " thread");360values.describe(frame_no, (intptr_t*)&(istate->_bcp), " bcp");361values.describe(frame_no, (intptr_t*)&(istate->_locals), " locals");362values.describe(frame_no, (intptr_t*)&(istate->_constants), " constants");363values.describe(frame_no, (intptr_t*)&(istate->_method), err_msg(" method = %s", istate->_method->name_and_sig_as_C_string()));364values.describe(frame_no, (intptr_t*)&(istate->_mdx), " mdx");365values.describe(frame_no, (intptr_t*)&(istate->_stack), " stack");366values.describe(frame_no, (intptr_t*)&(istate->_msg), err_msg(" msg = %s", BytecodeInterpreter::C_msg(istate->_msg)));367values.describe(frame_no, (intptr_t*)&(istate->_result), " result");368values.describe(frame_no, (intptr_t*)&(istate->_prev_link), " prev_link");369values.describe(frame_no, (intptr_t*)&(istate->_oop_temp), " oop_temp");370values.describe(frame_no, (intptr_t*)&(istate->_stack_base), " stack_base");371values.describe(frame_no, (intptr_t*)&(istate->_stack_limit), " stack_limit");372values.describe(frame_no, (intptr_t*)&(istate->_monitor_base), " monitor_base");373values.describe(frame_no, (intptr_t*)&(istate->_frame_bottom), " frame_bottom");374values.describe(frame_no, (intptr_t*)&(istate->_last_Java_pc), " last_Java_pc");375values.describe(frame_no, (intptr_t*)&(istate->_last_Java_fp), " last_Java_fp");376values.describe(frame_no, (intptr_t*)&(istate->_last_Java_sp), " last_Java_sp");377values.describe(frame_no, (intptr_t*)&(istate->_self_link), " self_link");378values.describe(frame_no, (intptr_t*)&(istate->_native_fresult), " native_fresult");379values.describe(frame_no, (intptr_t*)&(istate->_native_lresult), " native_lresult");380#else381#define DESCRIBE_ADDRESS(name) \382values.describe(frame_no, (intptr_t*)&(get_ijava_state()->name), #name);383384DESCRIBE_ADDRESS(method);385DESCRIBE_ADDRESS(locals);386DESCRIBE_ADDRESS(monitors);387DESCRIBE_ADDRESS(cpoolCache);388DESCRIBE_ADDRESS(bcp);389DESCRIBE_ADDRESS(esp);390DESCRIBE_ADDRESS(mdx);391DESCRIBE_ADDRESS(top_frame_sp);392DESCRIBE_ADDRESS(sender_sp);393DESCRIBE_ADDRESS(oop_tmp);394DESCRIBE_ADDRESS(lresult);395DESCRIBE_ADDRESS(fresult);396#endif397}398}399#endif400401void frame::adjust_unextended_sp() {402// If we are returning to a compiled MethodHandle call site, the403// saved_fp will in fact be a saved value of the unextended SP. The404// simplest way to tell whether we are returning to such a call site405// is as follows:406407if (is_compiled_frame() && false /*is_at_mh_callsite()*/) { // TODO PPC port408// If the sender PC is a deoptimization point, get the original409// PC. For MethodHandle call site the unextended_sp is stored in410// saved_fp.411_unextended_sp = _fp - _cb->frame_size();412413#ifdef ASSERT414nmethod *sender_nm = _cb->as_nmethod_or_null();415assert(sender_nm && *_sp == *_unextended_sp, "backlink changed");416417intptr_t* sp = _unextended_sp; // check if stack can be walked from here418for (int x = 0; x < 5; ++x) { // check up to a couple of backlinks419intptr_t* prev_sp = *(intptr_t**)sp;420if (prev_sp == 0) break; // end of stack421assert(prev_sp>sp, "broken stack");422sp = prev_sp;423}424425if (sender_nm->is_deopt_mh_entry(_pc)) { // checks for deoptimization426address original_pc = sender_nm->get_original_pc(this);427assert(sender_nm->insts_contains(original_pc), "original PC must be in nmethod");428assert(sender_nm->is_method_handle_return(original_pc), "must be");429}430#endif431}432}433434intptr_t *frame::initial_deoptimization_info() {435// unused... but returns fp() to minimize changes introduced by 7087445436return fp();437}438439#ifndef PRODUCT440// This is a generic constructor which is only used by pns() in debug.cpp.441frame::frame(void* sp, void* fp, void* pc) : _sp((intptr_t*)sp), _unextended_sp((intptr_t*)sp) {442find_codeblob_and_set_pc_and_deopt_state((address)pc); // also sets _fp and adjusts _unextended_sp443}444#endif445446447