Path: blob/master/src/hotspot/share/code/scopeDesc.cpp
40931 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/javaClasses.inline.hpp"26#include "code/debugInfoRec.hpp"27#include "code/pcDesc.hpp"28#include "code/scopeDesc.hpp"29#include "compiler/compiler_globals.hpp"30#include "memory/resourceArea.hpp"31#include "oops/oop.inline.hpp"32#include "runtime/handles.inline.hpp"3334ScopeDesc::ScopeDesc(const CompiledMethod* code, PcDesc* pd, bool ignore_objects) {35int obj_decode_offset = ignore_objects ? DebugInformationRecorder::serialized_null : pd->obj_decode_offset();36_code = code;37_decode_offset = pd->scope_decode_offset();38_objects = decode_object_values(obj_decode_offset);39_reexecute = pd->should_reexecute();40_rethrow_exception = pd->rethrow_exception();41_return_oop = pd->return_oop();42_has_ea_local_in_scope = ignore_objects ? false : pd->has_ea_local_in_scope();43_arg_escape = ignore_objects ? false : pd->arg_escape();44decode_body();45}464748void ScopeDesc::initialize(const ScopeDesc* parent, int decode_offset) {49_code = parent->_code;50_decode_offset = decode_offset;51_objects = parent->_objects;52_reexecute = false; //reexecute only applies to the first scope53_rethrow_exception = false;54_return_oop = false;55_has_ea_local_in_scope = parent->has_ea_local_in_scope();56_arg_escape = false;57decode_body();58}5960ScopeDesc::ScopeDesc(const ScopeDesc* parent) {61initialize(parent, parent->_sender_decode_offset);62}6364ScopeDesc::ScopeDesc(const ScopeDesc* parent, int decode_offset) {65initialize(parent, decode_offset);66}676869void ScopeDesc::decode_body() {70if (decode_offset() == DebugInformationRecorder::serialized_null) {71// This is a sentinel record, which is only relevant to72// approximate queries. Decode a reasonable frame.73_sender_decode_offset = DebugInformationRecorder::serialized_null;74_method = _code->method();75_bci = InvocationEntryBci;76_locals_decode_offset = DebugInformationRecorder::serialized_null;77_expressions_decode_offset = DebugInformationRecorder::serialized_null;78_monitors_decode_offset = DebugInformationRecorder::serialized_null;79} else {80// decode header81DebugInfoReadStream* stream = stream_at(decode_offset());8283_sender_decode_offset = stream->read_int();84_method = stream->read_method();85_bci = stream->read_bci();8687// decode offsets for body and sender88_locals_decode_offset = stream->read_int();89_expressions_decode_offset = stream->read_int();90_monitors_decode_offset = stream->read_int();91}92}939495GrowableArray<ScopeValue*>* ScopeDesc::decode_scope_values(int decode_offset) {96if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;97DebugInfoReadStream* stream = stream_at(decode_offset);98int length = stream->read_int();99GrowableArray<ScopeValue*>* result = new GrowableArray<ScopeValue*> (length);100for (int index = 0; index < length; index++) {101result->push(ScopeValue::read_from(stream));102}103return result;104}105106GrowableArray<ScopeValue*>* ScopeDesc::decode_object_values(int decode_offset) {107if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;108GrowableArray<ScopeValue*>* result = new GrowableArray<ScopeValue*>();109DebugInfoReadStream* stream = new DebugInfoReadStream(_code, decode_offset, result);110int length = stream->read_int();111for (int index = 0; index < length; index++) {112// Objects values are pushed to 'result' array during read so that113// object's fields could reference it (OBJECT_ID_CODE).114(void)ScopeValue::read_from(stream);115}116assert(result->length() == length, "inconsistent debug information");117return result;118}119120121GrowableArray<MonitorValue*>* ScopeDesc::decode_monitor_values(int decode_offset) {122if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;123DebugInfoReadStream* stream = stream_at(decode_offset);124int length = stream->read_int();125GrowableArray<MonitorValue*>* result = new GrowableArray<MonitorValue*> (length);126for (int index = 0; index < length; index++) {127result->push(new MonitorValue(stream));128}129return result;130}131132DebugInfoReadStream* ScopeDesc::stream_at(int decode_offset) const {133return new DebugInfoReadStream(_code, decode_offset, _objects);134}135136GrowableArray<ScopeValue*>* ScopeDesc::locals() {137return decode_scope_values(_locals_decode_offset);138}139140GrowableArray<ScopeValue*>* ScopeDesc::expressions() {141return decode_scope_values(_expressions_decode_offset);142}143144GrowableArray<MonitorValue*>* ScopeDesc::monitors() {145return decode_monitor_values(_monitors_decode_offset);146}147148GrowableArray<ScopeValue*>* ScopeDesc::objects() {149return _objects;150}151152bool ScopeDesc::is_top() const {153return _sender_decode_offset == DebugInformationRecorder::serialized_null;154}155156ScopeDesc* ScopeDesc::sender() const {157if (is_top()) return NULL;158return new ScopeDesc(this);159}160161162#ifndef PRODUCT163164void ScopeDesc::print_value_on(outputStream* st) const {165st->print(" ");166method()->print_short_name(st);167int lineno = method()->line_number_from_bci(bci());168if (lineno != -1) {169st->print("@%d (line %d)", bci(), lineno);170} else {171st->print("@%d", bci());172}173if (should_reexecute()) {174st->print(" reexecute=true");175}176st->cr();177}178179void ScopeDesc::print_on(outputStream* st) const {180print_on(st, NULL);181}182183void ScopeDesc::print_on(outputStream* st, PcDesc* pd) const {184// header185if (pd != NULL) {186st->print_cr("ScopeDesc(pc=" PTR_FORMAT " offset=%x):", p2i(pd->real_pc(_code)), pd->pc_offset());187}188189print_value_on(st);190// decode offsets191if (WizardMode) {192st->print("ScopeDesc[%d]@" PTR_FORMAT " ", _decode_offset, p2i(_code->content_begin()));193st->print_cr(" offset: %d", _decode_offset);194st->print_cr(" bci: %d", bci());195st->print_cr(" reexecute: %s", should_reexecute() ? "true" : "false");196st->print_cr(" locals: %d", _locals_decode_offset);197st->print_cr(" stack: %d", _expressions_decode_offset);198st->print_cr(" monitor: %d", _monitors_decode_offset);199st->print_cr(" sender: %d", _sender_decode_offset);200}201// locals202{ GrowableArray<ScopeValue*>* l = ((ScopeDesc*) this)->locals();203if (l != NULL) {204st->print_cr(" Locals");205for (int index = 0; index < l->length(); index++) {206st->print(" - l%d: ", index);207l->at(index)->print_on(st);208st->cr();209}210}211}212// expressions213{ GrowableArray<ScopeValue*>* l = ((ScopeDesc*) this)->expressions();214if (l != NULL) {215st->print_cr(" Expression stack");216for (int index = 0; index < l->length(); index++) {217st->print(" - @%d: ", index);218l->at(index)->print_on(st);219st->cr();220}221}222}223// monitors224{ GrowableArray<MonitorValue*>* l = ((ScopeDesc*) this)->monitors();225if (l != NULL) {226st->print_cr(" Monitor stack");227for (int index = 0; index < l->length(); index++) {228st->print(" - @%d: ", index);229l->at(index)->print_on(st);230st->cr();231}232}233}234235#if COMPILER2_OR_JVMCI236if (NOT_JVMCI(DoEscapeAnalysis &&) is_top() && _objects != NULL) {237st->print_cr(" Objects");238for (int i = 0; i < _objects->length(); i++) {239ObjectValue* sv = (ObjectValue*) _objects->at(i);240st->print(" - %d: ", sv->id());241st->print("%s ", java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()())->external_name());242sv->print_fields_on(st);243st->cr();244}245}246#endif // COMPILER2_OR_JVMCI247}248249#endif250251void ScopeDesc::verify() {252Thread* current_thread = Thread::current();253ResourceMark rm(current_thread);254HandleMark hm(current_thread);255guarantee(method()->is_method(), "type check");256257// check if we have any illegal elements on the expression stack258{ GrowableArray<ScopeValue*>* l = expressions();259if (l != NULL) {260for (int index = 0; index < l->length(); index++) {261//guarantee(!l->at(index)->is_illegal(), "expression element cannot be illegal");262}263}264}265}266267268