Path: blob/master/src/hotspot/cpu/s390/frame_s390.cpp
64440 views
/*1* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016, 2022 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) {57address sp = (address)_sp;58address fp = (address)_fp;59address unextended_sp = (address)_unextended_sp;6061// consider stack guards when trying to determine "safe" stack pointers62// sp must be within the usable part of the stack (not in guards)63if (!thread->is_in_usable_stack(sp)) {64return false;65}6667// Unextended sp must be within the stack68if (!thread->is_in_full_stack_checked(unextended_sp)) {69return false;70}7172// An fp must be within the stack and above (but not equal) sp.73bool fp_safe = thread->is_in_stack_range_excl(fp, sp);74// An interpreter fp must be fp_safe.75// Moreover, it must be at a distance at least the size of the z_ijava_state structure.76bool fp_interp_safe = fp_safe && ((fp - sp) >= z_ijava_state_size);7778// We know sp/unextended_sp are safe, only fp is questionable here7980// If the current frame is known to the code cache then we can attempt to81// construct the sender and do some validation of it. This goes a long way82// toward eliminating issues when we get in frame construction code8384if (_cb != NULL ) {8586// First check if the frame is complete and the test is reliable.87// Unfortunately we can only check frame completeness for runtime stubs.88// Other generic buffer blobs are more problematic so we just assume they are OK.89// Adapter blobs never have a complete frame and are never OK.90// nmethods should be OK on s390.91if (!_cb->is_frame_complete_at(_pc)) {92if (_cb->is_adapter_blob() || _cb->is_runtime_stub()) {93return false;94}95}9697// Could just be some random pointer within the codeBlob.98if (!_cb->code_contains(_pc)) {99return false;100}101102// Entry frame checks103if (is_entry_frame()) {104// An entry frame must have a valid fp.105return fp_safe && is_entry_frame_valid(thread);106}107108if (is_interpreted_frame() && !fp_interp_safe) {109return false;110}111112// At this point, there still is a chance that fp_safe is false.113// In particular, (fp == NULL) might be true. So let's check and114// bail out before we actually dereference from fp.115if (!fp_safe) {116return false;117}118119z_abi_16* sender_abi = (z_abi_16*)fp;120intptr_t* sender_sp = (intptr_t*) fp;121address sender_pc = (address) sender_abi->return_pc;122123// We must always be able to find a recognizable pc.124CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);125if (sender_blob == NULL) {126return false;127}128129// Could be a zombie method130if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {131return false;132}133134// It should be safe to construct the sender though it might not be valid.135136frame sender(sender_sp, sender_pc);137138// Do we have a valid fp?139address sender_fp = (address) sender.fp();140141// sender_fp must be within the stack and above (but not142// equal) current frame's fp.143if (!thread->is_in_stack_range_excl(sender_fp, fp)) {144return false;145}146147// If the potential sender is the interpreter then we can do some more checking.148if (Interpreter::contains(sender_pc)) {149return sender.is_interpreted_frame_valid(thread);150}151152// Could just be some random pointer within the codeBlob.153if (!sender.cb()->code_contains(sender_pc)) {154return false;155}156157// We should never be able to see an adapter if the current frame is something from code cache.158if (sender_blob->is_adapter_blob()) {159return false;160}161162if (sender.is_entry_frame()) {163return sender.is_entry_frame_valid(thread);164}165166// Frame size is always greater than zero. If the sender frame size is zero or less,167// something is really weird and we better give up.168if (sender_blob->frame_size() <= 0) {169return false;170}171172return true;173}174175// Must be native-compiled frame. Since sender will try and use fp to find176// linkages it must be safe177178if (!fp_safe) {179return false;180}181182return true;183}184185bool frame::is_interpreted_frame() const {186return Interpreter::contains(pc());187}188189// sender_sp190191intptr_t* frame::interpreter_frame_sender_sp() const {192return sender_sp();193}194195frame frame::sender_for_entry_frame(RegisterMap *map) const {196assert(map != NULL, "map must be set");197// Java frame called from C. Skip all C frames and return top C198// frame of that chunk as the sender.199JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();200201assert(!entry_frame_is_first(), "next Java sp must be non zero");202assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");203204map->clear();205206assert(map->include_argument_oops(), "should be set by clear");207208if (jfa->last_Java_pc() != NULL) {209frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());210return fr;211}212// Last_java_pc is not set if we come here from compiled code.213frame fr(jfa->last_Java_sp());214return fr;215}216217OptimizedEntryBlob::FrameData* OptimizedEntryBlob::frame_data_for_frame(const frame& frame) const {218ShouldNotCallThis();219return nullptr;220}221222bool frame::optimized_entry_frame_is_first() const {223ShouldNotCallThis();224return false;225}226227frame frame::sender_for_interpreter_frame(RegisterMap *map) const {228// Pass callers sender_sp as unextended_sp.229return frame(sender_sp(), sender_pc(), (intptr_t*)(ijava_state()->sender_sp));230}231232frame frame::sender_for_compiled_frame(RegisterMap *map) const {233assert(map != NULL, "map must be set");234// Frame owned by compiler.235236address pc = *compiled_sender_pc_addr(_cb);237frame caller(compiled_sender_sp(_cb), pc);238239// Now adjust the map.240241// Get the rest.242if (map->update_map()) {243// Tell GC to use argument oopmaps for some runtime stubs that need it.244map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));245if (_cb->oop_maps() != NULL) {246OopMapSet::update_register_map(this, map);247}248}249250return caller;251}252253intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const {254return sender_sp();255}256257address* frame::compiled_sender_pc_addr(CodeBlob* cb) const {258return sender_pc_addr();259}260261frame frame::sender(RegisterMap* map) const {262// Default is we don't have to follow them. The sender_for_xxx will263// update it accordingly.264map->set_include_argument_oops(false);265266if (is_entry_frame()) {267return sender_for_entry_frame(map);268}269if (is_interpreted_frame()) {270return sender_for_interpreter_frame(map);271}272assert(_cb == CodeCache::find_blob(pc()),"Must be the same");273if (_cb != NULL) {274return sender_for_compiled_frame(map);275}276// Must be native-compiled frame, i.e. the marshaling code for native277// methods that exists in the core system.278return frame(sender_sp(), sender_pc());279}280281void frame::patch_pc(Thread* thread, address pc) {282assert(_cb == CodeCache::find_blob(pc), "unexpected pc");283if (TracePcPatching) {284tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "] ",285p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));286}287own_abi()->return_pc = (uint64_t)pc;288address original_pc = CompiledMethod::get_deopt_original_pc(this);289if (original_pc != NULL) {290assert(original_pc == _pc, "expected original to be stored before patching");291_deopt_state = is_deoptimized;292// Leave _pc as is.293} else {294_deopt_state = not_deoptimized;295_pc = pc;296}297}298299bool frame::is_interpreted_frame_valid(JavaThread* thread) const {300assert(is_interpreted_frame(), "Not an interpreted frame");301// These are reasonable sanity checks302if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {303return false;304}305if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {306return false;307}308int min_frame_slots = (z_abi_16_size + z_ijava_state_size) / sizeof(intptr_t);309if (fp() - min_frame_slots < sp()) {310return false;311}312// These are hacks to keep us out of trouble.313// The problem with these is that they mask other problems314if (fp() <= sp()) { // this attempts to deal with unsigned comparison above315return false;316}317318// do some validation of frame elements319320// first the method321// Need to use "unchecked" versions to avoid "z_istate_magic_number" assertion.322Method* m = (Method*)(ijava_state_unchecked()->method);323324// validate the method we'd find in this potential sender325if (!Method::is_valid_method(m)) return false;326327// stack frames shouldn't be much larger than max_stack elements328// this test requires the use of unextended_sp which is the sp as seen by329// the current frame, and not sp which is the "raw" pc which could point330// further because of local variables of the callee method inserted after331// method arguments332if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {333return false;334}335336// validate bci/bcx337address bcp = (address)(ijava_state_unchecked()->bcp);338if (m->validate_bci_from_bcp(bcp) < 0) {339return false;340}341342// validate constantPoolCache*343ConstantPoolCache* cp = (ConstantPoolCache*)(ijava_state_unchecked()->cpoolCache);344if (MetaspaceObj::is_valid(cp) == false) return false;345346// validate locals347address locals = (address)(ijava_state_unchecked()->locals);348return thread->is_in_stack_range_incl(locals, (address)fp());349}350351BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {352assert(is_interpreted_frame(), "interpreted frame expected");353Method* method = interpreter_frame_method();354BasicType type = method->result_type();355356if (method->is_native()) {357address lresult = (address)&(ijava_state()->lresult);358address fresult = (address)&(ijava_state()->fresult);359360switch (type) {361case T_OBJECT:362case T_ARRAY: {363*oop_result = cast_to_oop((void*) ijava_state()->oop_tmp);364break;365}366// We use std/stfd to store the values.367case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;368case T_INT : value_result->i = (jint) *(long*)lresult; break;369case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;370case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;371case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;372case T_LONG : value_result->j = (jlong) *(long*)lresult; break;373case T_FLOAT : value_result->f = (jfloat) *(float*)fresult; break;374case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;375case T_VOID : break; // Nothing to do.376default : ShouldNotReachHere();377}378} else {379intptr_t* tos_addr = interpreter_frame_tos_address();380switch (type) {381case T_OBJECT:382case T_ARRAY: {383oop obj = *(oop*)tos_addr;384assert(Universe::is_in_heap_or_null(obj), "sanity check");385*oop_result = obj;386break;387}388case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;389case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;390case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;391case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;392case T_INT : value_result->i = *(jint*)tos_addr; break;393case T_LONG : value_result->j = *(jlong*)tos_addr; break;394case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;395case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;396case T_VOID : break; // Nothing to do.397default : ShouldNotReachHere();398}399}400401return type;402}403404405// Dump all frames starting a given C stack-pointer.406// Use max_frames to limit the number of traced frames.407void frame::back_trace(outputStream* st, intptr_t* start_sp, intptr_t* top_pc, unsigned long flags, int max_frames) {408409static char buf[ 150 ];410411bool print_outgoing_arguments = flags & 0x1;412bool print_istate_pointers = flags & 0x2;413int num = 0;414415intptr_t* current_sp = (intptr_t*) start_sp;416int last_num_jargs = 0;417int frame_type = 0;418int last_frame_type = 0;419420while (current_sp) {421intptr_t* current_fp = (intptr_t*) *current_sp;422address current_pc = (num == 0)423? (address) top_pc424: (address) *((intptr_t*)(((address) current_sp) + _z_abi(return_pc)));425426if ((intptr_t*) current_fp != 0 && (intptr_t*) current_fp <= current_sp) {427st->print_cr("ERROR: corrupt stack");428return;429}430431st->print("#%-3d ", num);432const char* type_name = " ";433const char* function_name = NULL;434435// Detect current frame's frame_type, default to 'C frame'.436frame_type = 0;437438CodeBlob* blob = NULL;439440if (Interpreter::contains(current_pc)) {441frame_type = 1;442} else if (StubRoutines::contains(current_pc)) {443if (StubRoutines::returns_to_call_stub(current_pc)) {444frame_type = 2;445} else {446frame_type = 4;447type_name = "stu";448StubCodeDesc* desc = StubCodeDesc::desc_for (current_pc);449if (desc) {450function_name = desc->name();451} else {452function_name = "unknown stub";453}454}455} else if (CodeCache::contains(current_pc)) {456blob = CodeCache::find_blob_unsafe(current_pc);457if (blob) {458if (blob->is_nmethod()) {459frame_type = 3;460} else if (blob->is_deoptimization_stub()) {461frame_type = 4;462type_name = "deo";463function_name = "deoptimization blob";464} else if (blob->is_uncommon_trap_stub()) {465frame_type = 4;466type_name = "uct";467function_name = "uncommon trap blob";468} else if (blob->is_exception_stub()) {469frame_type = 4;470type_name = "exc";471function_name = "exception blob";472} else if (blob->is_safepoint_stub()) {473frame_type = 4;474type_name = "saf";475function_name = "safepoint blob";476} else if (blob->is_runtime_stub()) {477frame_type = 4;478type_name = "run";479function_name = ((RuntimeStub *)blob)->name();480} else if (blob->is_method_handles_adapter_blob()) {481frame_type = 4;482type_name = "mha";483function_name = "method handles adapter blob";484} else {485frame_type = 4;486type_name = "blo";487function_name = "unknown code blob";488}489} else {490frame_type = 4;491type_name = "blo";492function_name = "unknown code blob";493}494}495496st->print("sp=" PTR_FORMAT " ", p2i(current_sp));497498if (frame_type == 0) {499current_pc = (address) *((intptr_t*)(((address) current_sp) + _z_abi(gpr14)));500}501502st->print("pc=" PTR_FORMAT " ", p2i(current_pc));503st->print(" ");504505switch (frame_type) {506case 0: // C frame:507{508st->print(" ");509if (current_pc == 0) {510st->print("? ");511} else {512// name513int func_offset;514char demangled_name[256];515int demangled_name_len = 256;516if (os::dll_address_to_function_name(current_pc, demangled_name, demangled_name_len, &func_offset)) {517demangled_name[demangled_name_len-1] = '\0';518st->print(func_offset == -1 ? "%s " : "%s+0x%x", demangled_name, func_offset);519} else {520st->print("? ");521}522}523}524break;525526case 1: // interpreter frame:527{528st->print(" i ");529530if (last_frame_type != 1) last_num_jargs = 8;531532// name533Method* method = *(Method**)((address)current_fp + _z_ijava_state_neg(method));534if (method) {535ResourceMark rm;536if (method->is_synchronized()) st->print("synchronized ");537if (method->is_static()) st->print("static ");538if (method->is_native()) st->print("native ");539method->name_and_sig_as_C_string(buf, sizeof(buf));540st->print("%s ", buf);541}542else543st->print("? ");544545intptr_t* tos = (intptr_t*) *(intptr_t*)((address)current_fp + _z_ijava_state_neg(esp));546if (print_istate_pointers) {547st->cr();548st->print(" ");549st->print("ts=" PTR_FORMAT " ", p2i(tos));550}551552// Dump some Java stack slots.553if (print_outgoing_arguments) {554if (method->is_native()) {555#ifdef ASSERT556intptr_t* cargs = (intptr_t*) (((address)current_sp) + _z_abi(carg_1));557for (int i = 0; i < last_num_jargs; i++) {558// Cargs is not prepushed.559st->cr();560st->print(" ");561st->print(PTR_FORMAT, *(cargs));562cargs++;563}564#endif /* ASSERT */565}566else {567if (tos) {568for (int i = 0; i < last_num_jargs; i++) {569// tos+0 is prepushed, ignore.570tos++;571if (tos >= (intptr_t *)((address)current_fp + _z_ijava_state_neg(monitors)))572break;573st->cr();574st->print(" ");575st->print(PTR_FORMAT " %+.3e %+.3le", *(tos), *(float*)(tos), *(double*)(tos));576}577}578}579last_num_jargs = method->size_of_parameters();580}581}582break;583584case 2: // entry frame:585{586st->print("v2i ");587588// name589st->print("call stub");590}591break;592593case 3: // compiled frame:594{595st->print(" c ");596597// name598Method* method = ((nmethod *)blob)->method();599if (method) {600ResourceMark rm;601method->name_and_sig_as_C_string(buf, sizeof(buf));602st->print("%s ", buf);603}604else605st->print("? ");606}607break;608609case 4: // named frames610{611st->print("%s ", type_name);612613// name614if (function_name)615st->print("%s", function_name);616}617break;618619default:620break;621}622623st->cr();624st->flush();625626current_sp = current_fp;627last_frame_type = frame_type;628num++;629// Check for maximum # of frames, and stop when reached.630if (max_frames > 0 && --max_frames == 0)631break;632}633634}635636// Convenience function for calls from the debugger.637638extern "C" void bt(intptr_t* start_sp,intptr_t* top_pc) {639frame::back_trace(tty,start_sp, top_pc, 0);640}641642extern "C" void bt_full(intptr_t* start_sp,intptr_t* top_pc) {643frame::back_trace(tty,start_sp, top_pc, (unsigned long)(long)-1);644}645646647// Function for tracing a limited number of frames.648// Use this one if you only need to see the "top of stack" frames.649extern "C" void bt_max(intptr_t *start_sp, intptr_t *top_pc, int max_frames) {650frame::back_trace(tty, start_sp, top_pc, 0, max_frames);651}652653#if !defined(PRODUCT)654655#define DESCRIBE_ADDRESS(name) \656values.describe(frame_no, (intptr_t*)&ijava_state()->name, #name);657658void frame::describe_pd(FrameValues& values, int frame_no) {659if (is_interpreted_frame()) {660// Describe z_ijava_state elements.661DESCRIBE_ADDRESS(method);662DESCRIBE_ADDRESS(locals);663DESCRIBE_ADDRESS(monitors);664DESCRIBE_ADDRESS(cpoolCache);665DESCRIBE_ADDRESS(bcp);666DESCRIBE_ADDRESS(mdx);667DESCRIBE_ADDRESS(esp);668DESCRIBE_ADDRESS(sender_sp);669DESCRIBE_ADDRESS(top_frame_sp);670DESCRIBE_ADDRESS(oop_tmp);671DESCRIBE_ADDRESS(lresult);672DESCRIBE_ADDRESS(fresult);673}674}675676677void frame::pd_ps() {}678#endif // !PRODUCT679680intptr_t *frame::initial_deoptimization_info() {681// Used to reset the saved FP.682return fp();683}684685686