Path: blob/master/src/hotspot/cpu/s390/frame_s390.cpp
40930 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016, 2019 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/oop.inline.hpp"32#include "runtime/frame.inline.hpp"33#include "runtime/handles.inline.hpp"34#include "runtime/javaCalls.hpp"35#include "runtime/monitorChunk.hpp"36#include "runtime/os.inline.hpp"37#include "runtime/signature.hpp"38#include "runtime/stubCodeGenerator.hpp"39#include "runtime/stubRoutines.hpp"40#include "vmreg_s390.inline.hpp"41#ifdef COMPILER142#include "c1/c1_Runtime1.hpp"43#include "runtime/vframeArray.hpp"44#endif4546// Major contributions by Aha, AS.4748#ifdef ASSERT49void RegisterMap::check_location_valid() {50}51#endif // ASSERT525354// Profiling/safepoint support5556bool frame::safe_for_sender(JavaThread *thread) {57bool safe = false;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// Unextended sp must be within the stack69if (!thread->is_in_full_stack_checked(unextended_sp)) {70return false;71}7273// An fp must be within the stack and above (but not equal) sp.74bool fp_safe = thread->is_in_stack_range_excl(fp, sp);75// An interpreter fp must be within the stack and above (but not equal) sp.76// Moreover, it must be at least the size of the z_ijava_state structure.77bool fp_interp_safe = fp_safe && ((fp - sp) >= z_ijava_state_size);7879// We know sp/unextended_sp are safe, only fp is questionable here8081// If the current frame is known to the code cache then we can attempt to82// to construct the sender and do some validation of it. This goes a long way83// toward eliminating issues when we get in frame construction code8485if (_cb != NULL ) {86// Entry frame checks87if (is_entry_frame()) {88// An entry frame must have a valid fp.89return fp_safe && is_entry_frame_valid(thread);90}9192// Now check if the frame is complete and the test is93// reliable. Unfortunately we can only check frame completeness for94// runtime stubs. Other generic buffer blobs are more95// problematic so we just assume they are OK. Adapter blobs never have a96// complete frame and are never OK. nmethods should be OK on s390.97if (!_cb->is_frame_complete_at(_pc)) {98if (_cb->is_adapter_blob() || _cb->is_runtime_stub()) {99return false;100}101}102103// Could just be some random pointer within the codeBlob.104if (!_cb->code_contains(_pc)) {105return false;106}107108if (is_interpreted_frame() && !fp_interp_safe) {109return false;110}111112z_abi_160* sender_abi = (z_abi_160*) fp;113intptr_t* sender_sp = (intptr_t*) sender_abi->callers_sp;114address sender_pc = (address) sender_abi->return_pc;115116// We must always be able to find a recognizable pc.117CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);118if (sender_blob == NULL) {119return false;120}121122// Could be a zombie method123if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {124return false;125}126127// It should be safe to construct the sender though it might not be valid.128129frame sender(sender_sp, sender_pc);130131// Do we have a valid fp?132address sender_fp = (address) sender.fp();133134// sender_fp must be within the stack and above (but not135// equal) current frame's fp.136if (!thread->is_in_stack_range_excl(sender_fp, fp)) {137return false;138}139140// If the potential sender is the interpreter then we can do some more checking.141if (Interpreter::contains(sender_pc)) {142return sender.is_interpreted_frame_valid(thread);143}144145// Could just be some random pointer within the codeBlob.146if (!sender.cb()->code_contains(sender_pc)) {147return false;148}149150// We should never be able to see an adapter if the current frame is something from code cache.151if (sender_blob->is_adapter_blob()) {152return false;153}154155if (sender.is_entry_frame()) {156return sender.is_entry_frame_valid(thread);157}158159// Frame size is always greater than zero. If the sender frame size is zero or less,160// something is really weird and we better give up.161if (sender_blob->frame_size() <= 0) {162return false;163}164165return true;166}167168// Must be native-compiled frame. Since sender will try and use fp to find169// linkages it must be safe170171if (!fp_safe) {172return false;173}174175return true;176}177178bool frame::is_interpreted_frame() const {179return Interpreter::contains(pc());180}181182// sender_sp183184intptr_t* frame::interpreter_frame_sender_sp() const {185return sender_sp();186}187188frame frame::sender_for_entry_frame(RegisterMap *map) const {189assert(map != NULL, "map must be set");190// Java frame called from C. Skip all C frames and return top C191// frame of that chunk as the sender.192JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();193194assert(!entry_frame_is_first(), "next Java sp must be non zero");195assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");196197map->clear();198199assert(map->include_argument_oops(), "should be set by clear");200201if (jfa->last_Java_pc() != NULL) {202frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());203return fr;204}205// Last_java_pc is not set if we come here from compiled code.206frame fr(jfa->last_Java_sp());207return fr;208}209210frame frame::sender_for_interpreter_frame(RegisterMap *map) const {211// Pass callers sender_sp as unextended_sp.212return frame(sender_sp(), sender_pc(), (intptr_t*)(ijava_state()->sender_sp));213}214215frame frame::sender_for_compiled_frame(RegisterMap *map) const {216assert(map != NULL, "map must be set");217// Frame owned by compiler.218219address pc = *compiled_sender_pc_addr(_cb);220frame caller(compiled_sender_sp(_cb), pc);221222// Now adjust the map.223224// Get the rest.225if (map->update_map()) {226// Tell GC to use argument oopmaps for some runtime stubs that need it.227map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));228if (_cb->oop_maps() != NULL) {229OopMapSet::update_register_map(this, map);230}231}232233return caller;234}235236intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const {237return sender_sp();238}239240address* frame::compiled_sender_pc_addr(CodeBlob* cb) const {241return sender_pc_addr();242}243244frame frame::sender(RegisterMap* map) const {245// Default is we don't have to follow them. The sender_for_xxx will246// update it accordingly.247map->set_include_argument_oops(false);248249if (is_entry_frame()) {250return sender_for_entry_frame(map);251}252if (is_interpreted_frame()) {253return sender_for_interpreter_frame(map);254}255assert(_cb == CodeCache::find_blob(pc()),"Must be the same");256if (_cb != NULL) {257return sender_for_compiled_frame(map);258}259// Must be native-compiled frame, i.e. the marshaling code for native260// methods that exists in the core system.261return frame(sender_sp(), sender_pc());262}263264void frame::patch_pc(Thread* thread, address pc) {265assert(_cb == CodeCache::find_blob(pc), "unexpected pc");266if (TracePcPatching) {267tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "] ",268p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));269}270own_abi()->return_pc = (uint64_t)pc;271address original_pc = CompiledMethod::get_deopt_original_pc(this);272if (original_pc != NULL) {273assert(original_pc == _pc, "expected original to be stored before patching");274_deopt_state = is_deoptimized;275// Leave _pc as is.276} else {277_deopt_state = not_deoptimized;278_pc = pc;279}280}281282bool frame::is_interpreted_frame_valid(JavaThread* thread) const {283// Is there anything to do?284assert(is_interpreted_frame(), "Not an interpreted frame");285return true;286}287288BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {289assert(is_interpreted_frame(), "interpreted frame expected");290Method* method = interpreter_frame_method();291BasicType type = method->result_type();292293if (method->is_native()) {294address lresult = (address)&(ijava_state()->lresult);295address fresult = (address)&(ijava_state()->fresult);296297switch (type) {298case T_OBJECT:299case T_ARRAY: {300*oop_result = cast_to_oop((void*) ijava_state()->oop_tmp);301break;302}303// We use std/stfd to store the values.304case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;305case T_INT : value_result->i = (jint) *(long*)lresult; break;306case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;307case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;308case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;309case T_LONG : value_result->j = (jlong) *(long*)lresult; break;310case T_FLOAT : value_result->f = (jfloat) *(float*)fresult; break;311case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;312case T_VOID : break; // Nothing to do.313default : ShouldNotReachHere();314}315} else {316intptr_t* tos_addr = interpreter_frame_tos_address();317switch (type) {318case T_OBJECT:319case T_ARRAY: {320oop obj = *(oop*)tos_addr;321assert(Universe::is_in_heap_or_null(obj), "sanity check");322*oop_result = obj;323break;324}325case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;326case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;327case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;328case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;329case T_INT : value_result->i = *(jint*)tos_addr; break;330case T_LONG : value_result->j = *(jlong*)tos_addr; break;331case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;332case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;333case T_VOID : break; // Nothing to do.334default : ShouldNotReachHere();335}336}337338return type;339}340341342// Dump all frames starting a given C stack-pointer.343// Use max_frames to limit the number of traced frames.344void frame::back_trace(outputStream* st, intptr_t* start_sp, intptr_t* top_pc, unsigned long flags, int max_frames) {345346static char buf[ 150 ];347348bool print_outgoing_arguments = flags & 0x1;349bool print_istate_pointers = flags & 0x2;350int num = 0;351352intptr_t* current_sp = (intptr_t*) start_sp;353int last_num_jargs = 0;354int frame_type = 0;355int last_frame_type = 0;356357while (current_sp) {358intptr_t* current_fp = (intptr_t*) *current_sp;359address current_pc = (num == 0)360? (address) top_pc361: (address) *((intptr_t*)(((address) current_sp) + _z_abi(return_pc)));362363if ((intptr_t*) current_fp != 0 && (intptr_t*) current_fp <= current_sp) {364st->print_cr("ERROR: corrupt stack");365return;366}367368st->print("#%-3d ", num);369const char* type_name = " ";370const char* function_name = NULL;371372// Detect current frame's frame_type, default to 'C frame'.373frame_type = 0;374375CodeBlob* blob = NULL;376377if (Interpreter::contains(current_pc)) {378frame_type = 1;379} else if (StubRoutines::contains(current_pc)) {380if (StubRoutines::returns_to_call_stub(current_pc)) {381frame_type = 2;382} else {383frame_type = 4;384type_name = "stu";385StubCodeDesc* desc = StubCodeDesc::desc_for (current_pc);386if (desc) {387function_name = desc->name();388} else {389function_name = "unknown stub";390}391}392} else if (CodeCache::contains(current_pc)) {393blob = CodeCache::find_blob_unsafe(current_pc);394if (blob) {395if (blob->is_nmethod()) {396frame_type = 3;397} else if (blob->is_deoptimization_stub()) {398frame_type = 4;399type_name = "deo";400function_name = "deoptimization blob";401} else if (blob->is_uncommon_trap_stub()) {402frame_type = 4;403type_name = "uct";404function_name = "uncommon trap blob";405} else if (blob->is_exception_stub()) {406frame_type = 4;407type_name = "exc";408function_name = "exception blob";409} else if (blob->is_safepoint_stub()) {410frame_type = 4;411type_name = "saf";412function_name = "safepoint blob";413} else if (blob->is_runtime_stub()) {414frame_type = 4;415type_name = "run";416function_name = ((RuntimeStub *)blob)->name();417} else if (blob->is_method_handles_adapter_blob()) {418frame_type = 4;419type_name = "mha";420function_name = "method handles adapter blob";421} else {422frame_type = 4;423type_name = "blo";424function_name = "unknown code blob";425}426} else {427frame_type = 4;428type_name = "blo";429function_name = "unknown code blob";430}431}432433st->print("sp=" PTR_FORMAT " ", p2i(current_sp));434435if (frame_type == 0) {436current_pc = (address) *((intptr_t*)(((address) current_sp) + _z_abi(gpr14)));437}438439st->print("pc=" PTR_FORMAT " ", p2i(current_pc));440st->print(" ");441442switch (frame_type) {443case 0: // C frame:444{445st->print(" ");446if (current_pc == 0) {447st->print("? ");448} else {449// name450int func_offset;451char demangled_name[256];452int demangled_name_len = 256;453if (os::dll_address_to_function_name(current_pc, demangled_name, demangled_name_len, &func_offset)) {454demangled_name[demangled_name_len-1] = '\0';455st->print(func_offset == -1 ? "%s " : "%s+0x%x", demangled_name, func_offset);456} else {457st->print("? ");458}459}460}461break;462463case 1: // interpreter frame:464{465st->print(" i ");466467if (last_frame_type != 1) last_num_jargs = 8;468469// name470Method* method = *(Method**)((address)current_fp + _z_ijava_state_neg(method));471if (method) {472ResourceMark rm;473if (method->is_synchronized()) st->print("synchronized ");474if (method->is_static()) st->print("static ");475if (method->is_native()) st->print("native ");476method->name_and_sig_as_C_string(buf, sizeof(buf));477st->print("%s ", buf);478}479else480st->print("? ");481482intptr_t* tos = (intptr_t*) *(intptr_t*)((address)current_fp + _z_ijava_state_neg(esp));483if (print_istate_pointers) {484st->cr();485st->print(" ");486st->print("ts=" PTR_FORMAT " ", p2i(tos));487}488489// Dump some Java stack slots.490if (print_outgoing_arguments) {491if (method->is_native()) {492#ifdef ASSERT493intptr_t* cargs = (intptr_t*) (((address)current_sp) + _z_abi(carg_1));494for (int i = 0; i < last_num_jargs; i++) {495// Cargs is not prepushed.496st->cr();497st->print(" ");498st->print(PTR_FORMAT, *(cargs));499cargs++;500}501#endif /* ASSERT */502}503else {504if (tos) {505for (int i = 0; i < last_num_jargs; i++) {506// tos+0 is prepushed, ignore.507tos++;508if (tos >= (intptr_t *)((address)current_fp + _z_ijava_state_neg(monitors)))509break;510st->cr();511st->print(" ");512st->print(PTR_FORMAT " %+.3e %+.3le", *(tos), *(float*)(tos), *(double*)(tos));513}514}515}516last_num_jargs = method->size_of_parameters();517}518}519break;520521case 2: // entry frame:522{523st->print("v2i ");524525// name526st->print("call stub");527}528break;529530case 3: // compiled frame:531{532st->print(" c ");533534// name535Method* method = ((nmethod *)blob)->method();536if (method) {537ResourceMark rm;538method->name_and_sig_as_C_string(buf, sizeof(buf));539st->print("%s ", buf);540}541else542st->print("? ");543}544break;545546case 4: // named frames547{548st->print("%s ", type_name);549550// name551if (function_name)552st->print("%s", function_name);553}554break;555556default:557break;558}559560st->cr();561st->flush();562563current_sp = current_fp;564last_frame_type = frame_type;565num++;566// Check for maximum # of frames, and stop when reached.567if (max_frames > 0 && --max_frames == 0)568break;569}570571}572573// Convenience function for calls from the debugger.574575extern "C" void bt(intptr_t* start_sp,intptr_t* top_pc) {576frame::back_trace(tty,start_sp, top_pc, 0);577}578579extern "C" void bt_full(intptr_t* start_sp,intptr_t* top_pc) {580frame::back_trace(tty,start_sp, top_pc, (unsigned long)(long)-1);581}582583584// Function for tracing a limited number of frames.585// Use this one if you only need to see the "top of stack" frames.586extern "C" void bt_max(intptr_t *start_sp, intptr_t *top_pc, int max_frames) {587frame::back_trace(tty, start_sp, top_pc, 0, max_frames);588}589590#if !defined(PRODUCT)591592#define DESCRIBE_ADDRESS(name) \593values.describe(frame_no, (intptr_t*)&ijava_state()->name, #name);594595void frame::describe_pd(FrameValues& values, int frame_no) {596if (is_interpreted_frame()) {597// Describe z_ijava_state elements.598DESCRIBE_ADDRESS(method);599DESCRIBE_ADDRESS(locals);600DESCRIBE_ADDRESS(monitors);601DESCRIBE_ADDRESS(cpoolCache);602DESCRIBE_ADDRESS(bcp);603DESCRIBE_ADDRESS(mdx);604DESCRIBE_ADDRESS(esp);605DESCRIBE_ADDRESS(sender_sp);606DESCRIBE_ADDRESS(top_frame_sp);607DESCRIBE_ADDRESS(oop_tmp);608DESCRIBE_ADDRESS(lresult);609DESCRIBE_ADDRESS(fresult);610}611}612613614void frame::pd_ps() {}615#endif // !PRODUCT616617intptr_t *frame::initial_deoptimization_info() {618// Used to reset the saved FP.619return fp();620}621622623