Path: blob/master/src/hotspot/cpu/ppc/frame_ppc.cpp
40930 views
/*1* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012, 2021 SAP SE. 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 "runtime/frame.inline.hpp"34#include "runtime/handles.inline.hpp"35#include "runtime/javaCalls.hpp"36#include "runtime/jniHandles.inline.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#ifdef COMPILER144#include "c1/c1_Runtime1.hpp"45#include "runtime/vframeArray.hpp"46#endif4748#ifdef ASSERT49void RegisterMap::check_location_valid() {50}51#endif // ASSERT5253bool frame::safe_for_sender(JavaThread *thread) {54bool safe = false;55address sp = (address)_sp;56address fp = (address)_fp;57address unextended_sp = (address)_unextended_sp;5859// consider stack guards when trying to determine "safe" stack pointers60// sp must be within the usable part of the stack (not in guards)61if (!thread->is_in_usable_stack(sp)) {62return false;63}6465// Unextended sp must be within the stack66if (!thread->is_in_full_stack_checked(unextended_sp)) {67return false;68}6970// An fp must be within the stack and above (but not equal) sp.71bool fp_safe = thread->is_in_stack_range_excl(fp, sp);72// An interpreter fp must be within the stack and above (but not equal) sp.73// Moreover, it must be at least the size of the ijava_state structure.74bool fp_interp_safe = fp_safe && ((fp - sp) >= ijava_state_size);7576// We know sp/unextended_sp are safe, only fp is questionable here7778// If the current frame is known to the code cache then we can attempt to79// to construct the sender and do some validation of it. This goes a long way80// toward eliminating issues when we get in frame construction code8182if (_cb != NULL ){83// Entry frame checks84if (is_entry_frame()) {85// An entry frame must have a valid fp.86return fp_safe && is_entry_frame_valid(thread);87}8889// Now check if the frame is complete and the test is90// reliable. Unfortunately we can only check frame completeness for91// runtime stubs and nmethods. Other generic buffer blobs are more92// problematic so we just assume they are OK. Adapter blobs never have a93// complete frame and are never OK94if (!_cb->is_frame_complete_at(_pc)) {95if (_cb->is_compiled() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {96return false;97}98}99100// Could just be some random pointer within the codeBlob.101if (!_cb->code_contains(_pc)) {102return false;103}104105if (is_interpreted_frame() && !fp_interp_safe) {106return false;107}108109abi_minframe* sender_abi = (abi_minframe*) fp;110intptr_t* sender_sp = (intptr_t*) fp;111address sender_pc = (address) sender_abi->lr;;112113// We must always be able to find a recognizable pc.114CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);115if (sender_blob == NULL) {116return false;117}118119// Could be a zombie method120if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {121return false;122}123124// It should be safe to construct the sender though it might not be valid.125126frame sender(sender_sp, sender_pc);127128// Do we have a valid fp?129address sender_fp = (address) sender.fp();130131// sender_fp must be within the stack and above (but not132// equal) current frame's fp.133if (!thread->is_in_stack_range_excl(sender_fp, fp)) {134return false;135}136137// If the potential sender is the interpreter then we can do some more checking.138if (Interpreter::contains(sender_pc)) {139return sender.is_interpreted_frame_valid(thread);140}141142// Could just be some random pointer within the codeBlob.143if (!sender.cb()->code_contains(sender_pc)) {144return false;145}146147// We should never be able to see an adapter if the current frame is something from code cache.148if (sender_blob->is_adapter_blob()) {149return false;150}151152if (sender.is_entry_frame()) {153return sender.is_entry_frame_valid(thread);154}155156// Frame size is always greater than zero. If the sender frame size is zero or less,157// something is really weird and we better give up.158if (sender_blob->frame_size() <= 0) {159return false;160}161162return true;163}164165// Must be native-compiled frame. Since sender will try and use fp to find166// linkages it must be safe167168if (!fp_safe) {169return false;170}171172return true;173}174175bool frame::is_interpreted_frame() const {176return Interpreter::contains(pc());177}178179frame frame::sender_for_entry_frame(RegisterMap *map) const {180assert(map != NULL, "map must be set");181// Java frame called from C; skip all C frames and return top C182// frame of that chunk as the sender.183JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();184assert(!entry_frame_is_first(), "next Java fp must be non zero");185assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");186map->clear();187assert(map->include_argument_oops(), "should be set by clear");188189if (jfa->last_Java_pc() != NULL) {190frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());191return fr;192}193// Last_java_pc is not set, if we come here from compiled code. The194// constructor retrieves the PC from the stack.195frame fr(jfa->last_Java_sp());196return fr;197}198199frame frame::sender_for_interpreter_frame(RegisterMap *map) const {200// Pass callers initial_caller_sp as unextended_sp.201return frame(sender_sp(), sender_pc(), (intptr_t*)get_ijava_state()->sender_sp);202}203204frame frame::sender_for_compiled_frame(RegisterMap *map) const {205assert(map != NULL, "map must be set");206207// Frame owned by compiler.208address pc = *compiled_sender_pc_addr(_cb);209frame caller(compiled_sender_sp(_cb), pc);210211// Now adjust the map.212213// Get the rest.214if (map->update_map()) {215// Tell GC to use argument oopmaps for some runtime stubs that need it.216map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));217if (_cb->oop_maps() != NULL) {218OopMapSet::update_register_map(this, map);219}220}221222return caller;223}224225intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const {226return sender_sp();227}228229address* frame::compiled_sender_pc_addr(CodeBlob* cb) const {230return sender_pc_addr();231}232233frame frame::sender_raw(RegisterMap* map) const {234// Default is we do have to follow them. The sender_for_xxx will235// update it accordingly.236map->set_include_argument_oops(false);237238if (is_entry_frame()) return sender_for_entry_frame(map);239if (is_interpreted_frame()) return sender_for_interpreter_frame(map);240assert(_cb == CodeCache::find_blob(pc()),"Must be the same");241242if (_cb != NULL) {243return sender_for_compiled_frame(map);244}245// Must be native-compiled frame, i.e. the marshaling code for native246// methods that exists in the core system.247return frame(sender_sp(), sender_pc());248}249250frame frame::sender(RegisterMap* map) const {251frame result = sender_raw(map);252253if (map->process_frames()) {254StackWatermarkSet::on_iteration(map->thread(), result);255}256257return result;258}259260void frame::patch_pc(Thread* thread, address pc) {261assert(_cb == CodeCache::find_blob(pc), "unexpected pc");262if (TracePcPatching) {263tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "]",264p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));265}266own_abi()->lr = (uint64_t)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}277278bool frame::is_interpreted_frame_valid(JavaThread* thread) const {279// Is there anything to do?280assert(is_interpreted_frame(), "Not an interpreted frame");281return true;282}283284BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {285assert(is_interpreted_frame(), "interpreted frame expected");286Method* method = interpreter_frame_method();287BasicType type = method->result_type();288289if (method->is_native()) {290// Prior to calling into the runtime to notify the method exit the possible291// result value is saved into the interpreter frame.292address lresult = (address)&(get_ijava_state()->lresult);293address fresult = (address)&(get_ijava_state()->fresult);294295switch (method->result_type()) {296case T_OBJECT:297case T_ARRAY: {298*oop_result = JNIHandles::resolve(*(jobject*)lresult);299break;300}301// We use std/stfd to store the values.302case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;303case T_INT : value_result->i = (jint) *(long*)lresult; break;304case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;305case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;306case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;307case T_LONG : value_result->j = (jlong) *(long*)lresult; break;308case T_FLOAT : value_result->f = (jfloat) *(double*)fresult; break;309case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;310case T_VOID : /* Nothing to do */ break;311default : ShouldNotReachHere();312}313} else {314intptr_t* tos_addr = interpreter_frame_tos_address();315switch (method->result_type()) {316case T_OBJECT:317case T_ARRAY: {318oop obj = *(oop*)tos_addr;319assert(Universe::is_in_heap_or_null(obj), "sanity check");320*oop_result = obj;321}322case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;323case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;324case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;325case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;326case T_INT : value_result->i = *(jint*)tos_addr; break;327case T_LONG : value_result->j = *(jlong*)tos_addr; break;328case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;329case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;330case T_VOID : /* Nothing to do */ break;331default : ShouldNotReachHere();332}333}334return type;335}336337#ifndef PRODUCT338339void frame::describe_pd(FrameValues& values, int frame_no) {340if (is_interpreted_frame()) {341#define DESCRIBE_ADDRESS(name) \342values.describe(frame_no, (intptr_t*)&(get_ijava_state()->name), #name);343344DESCRIBE_ADDRESS(method);345DESCRIBE_ADDRESS(mirror);346DESCRIBE_ADDRESS(locals);347DESCRIBE_ADDRESS(monitors);348DESCRIBE_ADDRESS(cpoolCache);349DESCRIBE_ADDRESS(bcp);350DESCRIBE_ADDRESS(esp);351DESCRIBE_ADDRESS(mdx);352DESCRIBE_ADDRESS(top_frame_sp);353DESCRIBE_ADDRESS(sender_sp);354DESCRIBE_ADDRESS(oop_tmp);355DESCRIBE_ADDRESS(lresult);356DESCRIBE_ADDRESS(fresult);357}358}359#endif360361intptr_t *frame::initial_deoptimization_info() {362// unused... but returns fp() to minimize changes introduced by 7087445363return fp();364}365366#ifndef PRODUCT367// This is a generic constructor which is only used by pns() in debug.cpp.368frame::frame(void* sp, void* fp, void* pc) : _sp((intptr_t*)sp), _unextended_sp((intptr_t*)sp) {369find_codeblob_and_set_pc_and_deopt_state((address)pc); // also sets _fp and adjusts _unextended_sp370}371372void frame::pd_ps() {}373#endif374375376