Path: blob/master/src/hotspot/cpu/zero/frame_zero.cpp
64440 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.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 "gc/shared/collectedHeap.hpp"27#include "interpreter/interpreter.hpp"28#include "interpreter/interpreterRuntime.hpp"29#include "memory/resourceArea.hpp"30#include "memory/universe.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/signature.hpp"36#include "runtime/stackWatermarkSet.hpp"37#include "vmreg_zero.inline.hpp"3839#ifdef ASSERT40void RegisterMap::check_location_valid() {41ShouldNotCallThis();42}43#endif4445bool frame::is_interpreted_frame() const {46return zeroframe()->is_interpreter_frame();47}4849bool frame::is_fake_stub_frame() const {50return zeroframe()->is_fake_stub_frame();51}5253frame frame::sender_for_entry_frame(RegisterMap *map) const {54assert(zeroframe()->is_entry_frame(), "wrong type of frame");55assert(map != NULL, "map must be set");56assert(!entry_frame_is_first(), "next Java fp must be non zero");57assert(entry_frame_call_wrapper()->anchor()->last_Java_sp() == sender_sp(),58"sender should be next Java frame");59map->clear();60assert(map->include_argument_oops(), "should be set by clear");61return frame(zeroframe()->next(), sender_sp());62}6364OptimizedEntryBlob::FrameData* OptimizedEntryBlob::frame_data_for_frame(const frame& frame) const {65ShouldNotCallThis();66return nullptr;67}6869bool frame::optimized_entry_frame_is_first() const {70ShouldNotCallThis();71return false;72}7374frame frame::sender_for_nonentry_frame(RegisterMap *map) const {75assert(zeroframe()->is_interpreter_frame() ||76zeroframe()->is_fake_stub_frame(), "wrong type of frame");77return frame(zeroframe()->next(), sender_sp());78}7980frame frame::sender(RegisterMap* map) const {81// Default is not to follow arguments; the various82// sender_for_xxx methods update this accordingly.83map->set_include_argument_oops(false);8485frame result = zeroframe()->is_entry_frame() ?86sender_for_entry_frame(map) :87sender_for_nonentry_frame(map);8889if (map->process_frames()) {90StackWatermarkSet::on_iteration(map->thread(), result);91}9293return result;94}9596BasicObjectLock* frame::interpreter_frame_monitor_begin() const {97return get_interpreterState()->monitor_base();98}99100BasicObjectLock* frame::interpreter_frame_monitor_end() const {101return (BasicObjectLock*) get_interpreterState()->stack_base();102}103104void frame::patch_pc(Thread* thread, address pc) {105if (pc != NULL) {106assert(_cb == CodeCache::find_blob(pc), "unexpected pc");107_pc = pc;108_deopt_state = is_deoptimized;109} else {110// We borrow this call to set the thread pointer in the interpreter111// state; the hook to set up deoptimized frames isn't supplied it.112assert(pc == NULL, "should be");113get_interpreterState()->set_thread(thread->as_Java_thread());114}115}116117bool frame::safe_for_sender(JavaThread *thread) {118ShouldNotCallThis();119return false;120}121122bool frame::is_interpreted_frame_valid(JavaThread *thread) const {123ShouldNotCallThis();124return false;125}126127BasicType frame::interpreter_frame_result(oop* oop_result,128jvalue* value_result) {129assert(is_interpreted_frame(), "interpreted frame expected");130Method* method = interpreter_frame_method();131BasicType type = method->result_type();132intptr_t* tos_addr = (intptr_t *) interpreter_frame_tos_address();133oop obj;134135switch (type) {136case T_VOID:137break;138case T_BOOLEAN:139value_result->z = *(jboolean *) tos_addr;140break;141case T_BYTE:142value_result->b = *(jbyte *) tos_addr;143break;144case T_CHAR:145value_result->c = *(jchar *) tos_addr;146break;147case T_SHORT:148value_result->s = *(jshort *) tos_addr;149break;150case T_INT:151value_result->i = *(jint *) tos_addr;152break;153case T_LONG:154value_result->j = *(jlong *) tos_addr;155break;156case T_FLOAT:157value_result->f = *(jfloat *) tos_addr;158break;159case T_DOUBLE:160value_result->d = *(jdouble *) tos_addr;161break;162163case T_OBJECT:164case T_ARRAY:165if (method->is_native()) {166obj = get_interpreterState()->oop_temp();167}168else {169oop* obj_p = (oop *) tos_addr;170obj = (obj_p == NULL) ? (oop) NULL : *obj_p;171}172assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");173*oop_result = obj;174break;175176default:177ShouldNotReachHere();178}179180return type;181}182183int frame::frame_size(RegisterMap* map) const {184#ifdef PRODUCT185ShouldNotCallThis();186#endif // PRODUCT187return 0; // make javaVFrame::print_value work188}189190intptr_t* frame::interpreter_frame_tos_at(jint offset) const {191int index = (Interpreter::expr_offset_in_bytes(offset) / wordSize);192return &interpreter_frame_tos_address()[index];193}194195void frame::zero_print_on_error(int frame_index,196outputStream* st,197char* buf,198int buflen) const {199// Divide the buffer between the field and the value200buflen >>= 1;201char *fieldbuf = buf;202char *valuebuf = buf + buflen;203204// Print each word of the frame205for (intptr_t *addr = sp(); addr <= fp(); addr++) {206int offset = fp() - addr;207208// Fill in default values, then try and improve them209snprintf(fieldbuf, buflen, "word[%d]", offset);210snprintf(valuebuf, buflen, PTR_FORMAT, *addr);211zeroframe()->identify_word(frame_index, offset, fieldbuf, valuebuf, buflen);212fieldbuf[buflen - 1] = '\0';213valuebuf[buflen - 1] = '\0';214215// Print the result216st->print_cr(" " PTR_FORMAT ": %-21s = %s", p2i(addr), fieldbuf, valuebuf);217}218}219220void ZeroFrame::identify_word(int frame_index,221int offset,222char* fieldbuf,223char* valuebuf,224int buflen) const {225switch (offset) {226case next_frame_off:227strncpy(fieldbuf, "next_frame", buflen);228break;229230case frame_type_off:231strncpy(fieldbuf, "frame_type", buflen);232if (is_entry_frame())233strncpy(valuebuf, "ENTRY_FRAME", buflen);234else if (is_interpreter_frame())235strncpy(valuebuf, "INTERPRETER_FRAME", buflen);236else if (is_fake_stub_frame())237strncpy(valuebuf, "FAKE_STUB_FRAME", buflen);238break;239240default:241if (is_entry_frame()) {242as_entry_frame()->identify_word(243frame_index, offset, fieldbuf, valuebuf, buflen);244}245else if (is_interpreter_frame()) {246as_interpreter_frame()->identify_word(247frame_index, offset, fieldbuf, valuebuf, buflen);248}249else if (is_fake_stub_frame()) {250as_fake_stub_frame()->identify_word(251frame_index, offset, fieldbuf, valuebuf, buflen);252}253}254}255256void EntryFrame::identify_word(int frame_index,257int offset,258char* fieldbuf,259char* valuebuf,260int buflen) const {261switch (offset) {262case call_wrapper_off:263strncpy(fieldbuf, "call_wrapper", buflen);264break;265266default:267snprintf(fieldbuf, buflen, "local[%d]", offset - 3);268}269}270271void InterpreterFrame::identify_word(int frame_index,272int offset,273char* fieldbuf,274char* valuebuf,275int buflen) const {276interpreterState istate = interpreter_state();277bool is_valid = istate->self_link() == istate;278intptr_t *addr = addr_of_word(offset);279280// Fixed part281if (addr >= (intptr_t *) istate) {282const char *field = istate->name_of_field_at_address((address) addr);283if (field) {284if (is_valid && !strcmp(field, "_method")) {285istate->method()->name_and_sig_as_C_string(valuebuf, buflen);286}287else if (is_valid && !strcmp(field, "_bcp") && istate->bcp()) {288snprintf(valuebuf, buflen, PTR_FORMAT " (bci %d)",289(intptr_t) istate->bcp(),290istate->method()->bci_from(istate->bcp()));291}292snprintf(fieldbuf, buflen, "%sistate->%s",293field[strlen(field) - 1] == ')' ? "(": "", field);294}295else if (addr == (intptr_t *) istate) {296strncpy(fieldbuf, "(vtable for istate)", buflen);297}298return;299}300301// Variable part302if (!is_valid)303return;304305// JNI stuff306if (istate->method()->is_native() && addr < istate->stack_base()) {307address hA = istate->method()->signature_handler();308if (hA != NULL) {309if (hA != (address) InterpreterRuntime::slow_signature_handler) {310InterpreterRuntime::SignatureHandler *handler =311InterpreterRuntime::SignatureHandler::from_handlerAddr(hA);312313intptr_t *params = istate->stack_base() - handler->argument_count();314if (addr >= params) {315int param = addr - params;316const char *desc = "";317if (param == 0)318desc = " (JNIEnv)";319else if (param == 1) {320if (istate->method()->is_static())321desc = " (mirror)";322else323desc = " (this)";324}325snprintf(fieldbuf, buflen, "parameter[%d]%s", param, desc);326return;327}328329for (int i = 0; i < handler->argument_count(); i++) {330if (params[i] == (intptr_t) addr) {331snprintf(fieldbuf, buflen, "unboxed parameter[%d]", i);332return;333}334}335}336}337return;338}339340// Monitors and stack341identify_vp_word(frame_index, addr,342(intptr_t *) istate->monitor_base(),343istate->stack_base(),344fieldbuf, buflen);345}346347void ZeroFrame::identify_vp_word(int frame_index,348intptr_t* addr,349intptr_t* monitor_base,350intptr_t* stack_base,351char* fieldbuf,352int buflen) const {353// Monitors354if (addr >= stack_base && addr < monitor_base) {355int monitor_size = frame::interpreter_frame_monitor_size();356int last_index = (monitor_base - stack_base) / monitor_size - 1;357int index = last_index - (addr - stack_base) / monitor_size;358intptr_t monitor = (intptr_t) (359(BasicObjectLock *) monitor_base - 1 - index);360intptr_t offset = (intptr_t) addr - monitor;361362if (offset == BasicObjectLock::obj_offset_in_bytes())363snprintf(fieldbuf, buflen, "monitor[%d]->_obj", index);364else if (offset == BasicObjectLock::lock_offset_in_bytes())365snprintf(fieldbuf, buflen, "monitor[%d]->_lock", index);366367return;368}369370// Expression stack371if (addr < stack_base) {372snprintf(fieldbuf, buflen, "%s[%d]",373frame_index == 0 ? "stack_word" : "local",374(int) (stack_base - addr - 1));375return;376}377}378379#ifndef PRODUCT380381void frame::describe_pd(FrameValues& values, int frame_no) {382383}384385#endif386387intptr_t *frame::initial_deoptimization_info() {388// unused... but returns fp() to minimize changes introduced by 7087445389return fp();390}391392#ifndef PRODUCT393// This is a generic constructor which is only used by pns() in debug.cpp.394frame::frame(void* sp, void* fp, void* pc) {395Unimplemented();396}397398void frame::pd_ps() {}399#endif400401402