Path: blob/master/src/hotspot/cpu/zero/frame_zero.cpp
40931 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 "vmreg_zero.inline.hpp"3738#ifdef ASSERT39void RegisterMap::check_location_valid() {40ShouldNotCallThis();41}42#endif4344bool frame::is_interpreted_frame() const {45return zeroframe()->is_interpreter_frame();46}4748bool frame::is_fake_stub_frame() const {49return zeroframe()->is_fake_stub_frame();50}5152frame frame::sender_for_entry_frame(RegisterMap *map) const {53assert(zeroframe()->is_entry_frame(), "wrong type of frame");54assert(map != NULL, "map must be set");55assert(!entry_frame_is_first(), "next Java fp must be non zero");56assert(entry_frame_call_wrapper()->anchor()->last_Java_sp() == sender_sp(),57"sender should be next Java frame");58map->clear();59assert(map->include_argument_oops(), "should be set by clear");60return frame(zeroframe()->next(), sender_sp());61}6263frame frame::sender_for_nonentry_frame(RegisterMap *map) const {64assert(zeroframe()->is_interpreter_frame() ||65zeroframe()->is_fake_stub_frame(), "wrong type of frame");66return frame(zeroframe()->next(), sender_sp());67}6869frame frame::sender(RegisterMap* map) const {70// Default is not to follow arguments; the various71// sender_for_xxx methods update this accordingly.72map->set_include_argument_oops(false);7374if (is_entry_frame())75return sender_for_entry_frame(map);76else77return sender_for_nonentry_frame(map);78}7980BasicObjectLock* frame::interpreter_frame_monitor_begin() const {81return get_interpreterState()->monitor_base();82}8384BasicObjectLock* frame::interpreter_frame_monitor_end() const {85return (BasicObjectLock*) get_interpreterState()->stack_base();86}8788void frame::patch_pc(Thread* thread, address pc) {89if (pc != NULL) {90assert(_cb == CodeCache::find_blob(pc), "unexpected pc");91_pc = pc;92_deopt_state = is_deoptimized;93} else {94// We borrow this call to set the thread pointer in the interpreter95// state; the hook to set up deoptimized frames isn't supplied it.96assert(pc == NULL, "should be");97get_interpreterState()->set_thread(thread->as_Java_thread());98}99}100101bool frame::safe_for_sender(JavaThread *thread) {102ShouldNotCallThis();103return false;104}105106bool frame::is_interpreted_frame_valid(JavaThread *thread) const {107ShouldNotCallThis();108return false;109}110111BasicType frame::interpreter_frame_result(oop* oop_result,112jvalue* value_result) {113assert(is_interpreted_frame(), "interpreted frame expected");114Method* method = interpreter_frame_method();115BasicType type = method->result_type();116intptr_t* tos_addr = (intptr_t *) interpreter_frame_tos_address();117oop obj;118119switch (type) {120case T_VOID:121break;122case T_BOOLEAN:123value_result->z = *(jboolean *) tos_addr;124break;125case T_BYTE:126value_result->b = *(jbyte *) tos_addr;127break;128case T_CHAR:129value_result->c = *(jchar *) tos_addr;130break;131case T_SHORT:132value_result->s = *(jshort *) tos_addr;133break;134case T_INT:135value_result->i = *(jint *) tos_addr;136break;137case T_LONG:138value_result->j = *(jlong *) tos_addr;139break;140case T_FLOAT:141value_result->f = *(jfloat *) tos_addr;142break;143case T_DOUBLE:144value_result->d = *(jdouble *) tos_addr;145break;146147case T_OBJECT:148case T_ARRAY:149if (method->is_native()) {150obj = get_interpreterState()->oop_temp();151}152else {153oop* obj_p = (oop *) tos_addr;154obj = (obj_p == NULL) ? (oop) NULL : *obj_p;155}156assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");157*oop_result = obj;158break;159160default:161ShouldNotReachHere();162}163164return type;165}166167int frame::frame_size(RegisterMap* map) const {168#ifdef PRODUCT169ShouldNotCallThis();170#endif // PRODUCT171return 0; // make javaVFrame::print_value work172}173174intptr_t* frame::interpreter_frame_tos_at(jint offset) const {175int index = (Interpreter::expr_offset_in_bytes(offset) / wordSize);176return &interpreter_frame_tos_address()[index];177}178179void frame::zero_print_on_error(int frame_index,180outputStream* st,181char* buf,182int buflen) const {183// Divide the buffer between the field and the value184buflen >>= 1;185char *fieldbuf = buf;186char *valuebuf = buf + buflen;187188// Print each word of the frame189for (intptr_t *addr = sp(); addr <= fp(); addr++) {190int offset = fp() - addr;191192// Fill in default values, then try and improve them193snprintf(fieldbuf, buflen, "word[%d]", offset);194snprintf(valuebuf, buflen, PTR_FORMAT, *addr);195zeroframe()->identify_word(frame_index, offset, fieldbuf, valuebuf, buflen);196fieldbuf[buflen - 1] = '\0';197valuebuf[buflen - 1] = '\0';198199// Print the result200st->print_cr(" " PTR_FORMAT ": %-21s = %s", p2i(addr), fieldbuf, valuebuf);201}202}203204void ZeroFrame::identify_word(int frame_index,205int offset,206char* fieldbuf,207char* valuebuf,208int buflen) const {209switch (offset) {210case next_frame_off:211strncpy(fieldbuf, "next_frame", buflen);212break;213214case frame_type_off:215strncpy(fieldbuf, "frame_type", buflen);216if (is_entry_frame())217strncpy(valuebuf, "ENTRY_FRAME", buflen);218else if (is_interpreter_frame())219strncpy(valuebuf, "INTERPRETER_FRAME", buflen);220else if (is_fake_stub_frame())221strncpy(valuebuf, "FAKE_STUB_FRAME", buflen);222break;223224default:225if (is_entry_frame()) {226as_entry_frame()->identify_word(227frame_index, offset, fieldbuf, valuebuf, buflen);228}229else if (is_interpreter_frame()) {230as_interpreter_frame()->identify_word(231frame_index, offset, fieldbuf, valuebuf, buflen);232}233else if (is_fake_stub_frame()) {234as_fake_stub_frame()->identify_word(235frame_index, offset, fieldbuf, valuebuf, buflen);236}237}238}239240void EntryFrame::identify_word(int frame_index,241int offset,242char* fieldbuf,243char* valuebuf,244int buflen) const {245switch (offset) {246case call_wrapper_off:247strncpy(fieldbuf, "call_wrapper", buflen);248break;249250default:251snprintf(fieldbuf, buflen, "local[%d]", offset - 3);252}253}254255void InterpreterFrame::identify_word(int frame_index,256int offset,257char* fieldbuf,258char* valuebuf,259int buflen) const {260interpreterState istate = interpreter_state();261bool is_valid = istate->self_link() == istate;262intptr_t *addr = addr_of_word(offset);263264// Fixed part265if (addr >= (intptr_t *) istate) {266const char *field = istate->name_of_field_at_address((address) addr);267if (field) {268if (is_valid && !strcmp(field, "_method")) {269istate->method()->name_and_sig_as_C_string(valuebuf, buflen);270}271else if (is_valid && !strcmp(field, "_bcp") && istate->bcp()) {272snprintf(valuebuf, buflen, PTR_FORMAT " (bci %d)",273(intptr_t) istate->bcp(),274istate->method()->bci_from(istate->bcp()));275}276snprintf(fieldbuf, buflen, "%sistate->%s",277field[strlen(field) - 1] == ')' ? "(": "", field);278}279else if (addr == (intptr_t *) istate) {280strncpy(fieldbuf, "(vtable for istate)", buflen);281}282return;283}284285// Variable part286if (!is_valid)287return;288289// JNI stuff290if (istate->method()->is_native() && addr < istate->stack_base()) {291address hA = istate->method()->signature_handler();292if (hA != NULL) {293if (hA != (address) InterpreterRuntime::slow_signature_handler) {294InterpreterRuntime::SignatureHandler *handler =295InterpreterRuntime::SignatureHandler::from_handlerAddr(hA);296297intptr_t *params = istate->stack_base() - handler->argument_count();298if (addr >= params) {299int param = addr - params;300const char *desc = "";301if (param == 0)302desc = " (JNIEnv)";303else if (param == 1) {304if (istate->method()->is_static())305desc = " (mirror)";306else307desc = " (this)";308}309snprintf(fieldbuf, buflen, "parameter[%d]%s", param, desc);310return;311}312313for (int i = 0; i < handler->argument_count(); i++) {314if (params[i] == (intptr_t) addr) {315snprintf(fieldbuf, buflen, "unboxed parameter[%d]", i);316return;317}318}319}320}321return;322}323324// Monitors and stack325identify_vp_word(frame_index, addr,326(intptr_t *) istate->monitor_base(),327istate->stack_base(),328fieldbuf, buflen);329}330331void ZeroFrame::identify_vp_word(int frame_index,332intptr_t* addr,333intptr_t* monitor_base,334intptr_t* stack_base,335char* fieldbuf,336int buflen) const {337// Monitors338if (addr >= stack_base && addr < monitor_base) {339int monitor_size = frame::interpreter_frame_monitor_size();340int last_index = (monitor_base - stack_base) / monitor_size - 1;341int index = last_index - (addr - stack_base) / monitor_size;342intptr_t monitor = (intptr_t) (343(BasicObjectLock *) monitor_base - 1 - index);344intptr_t offset = (intptr_t) addr - monitor;345346if (offset == BasicObjectLock::obj_offset_in_bytes())347snprintf(fieldbuf, buflen, "monitor[%d]->_obj", index);348else if (offset == BasicObjectLock::lock_offset_in_bytes())349snprintf(fieldbuf, buflen, "monitor[%d]->_lock", index);350351return;352}353354// Expression stack355if (addr < stack_base) {356snprintf(fieldbuf, buflen, "%s[%d]",357frame_index == 0 ? "stack_word" : "local",358(int) (stack_base - addr - 1));359return;360}361}362363#ifndef PRODUCT364365void frame::describe_pd(FrameValues& values, int frame_no) {366367}368369#endif370371intptr_t *frame::initial_deoptimization_info() {372// unused... but returns fp() to minimize changes introduced by 7087445373return fp();374}375376#ifndef PRODUCT377// This is a generic constructor which is only used by pns() in debug.cpp.378frame::frame(void* sp, void* fp, void* pc) {379Unimplemented();380}381382void frame::pd_ps() {}383#endif384385386