Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/code/scopeDesc.cpp
32285 views
/*1* Copyright (c) 1997, 2014, 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 "code/debugInfoRec.hpp"26#include "code/pcDesc.hpp"27#include "code/scopeDesc.hpp"28#include "memory/resourceArea.hpp"29#include "oops/oop.inline.hpp"30#include "runtime/handles.inline.hpp"3132PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC3334ScopeDesc::ScopeDesc(const nmethod* code, int decode_offset, int obj_decode_offset, bool reexecute, bool return_oop) {35_code = code;36_decode_offset = decode_offset;37_objects = decode_object_values(obj_decode_offset);38_reexecute = reexecute;39_return_oop = return_oop;40decode_body();41}4243ScopeDesc::ScopeDesc(const nmethod* code, int decode_offset, bool reexecute, bool return_oop) {44_code = code;45_decode_offset = decode_offset;46_objects = decode_object_values(DebugInformationRecorder::serialized_null);47_reexecute = reexecute;48_return_oop = return_oop;49decode_body();50}515253ScopeDesc::ScopeDesc(const ScopeDesc* parent) {54_code = parent->_code;55_decode_offset = parent->_sender_decode_offset;56_objects = parent->_objects;57_reexecute = false; //reexecute only applies to the first scope58_return_oop = false;59decode_body();60}616263void ScopeDesc::decode_body() {64if (decode_offset() == DebugInformationRecorder::serialized_null) {65// This is a sentinel record, which is only relevant to66// approximate queries. Decode a reasonable frame.67_sender_decode_offset = DebugInformationRecorder::serialized_null;68_method = _code->method();69_bci = InvocationEntryBci;70_locals_decode_offset = DebugInformationRecorder::serialized_null;71_expressions_decode_offset = DebugInformationRecorder::serialized_null;72_monitors_decode_offset = DebugInformationRecorder::serialized_null;73} else {74// decode header75DebugInfoReadStream* stream = stream_at(decode_offset());7677_sender_decode_offset = stream->read_int();78_method = stream->read_method();79_bci = stream->read_bci();8081// decode offsets for body and sender82_locals_decode_offset = stream->read_int();83_expressions_decode_offset = stream->read_int();84_monitors_decode_offset = stream->read_int();85}86}878889GrowableArray<ScopeValue*>* ScopeDesc::decode_scope_values(int decode_offset) {90if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;91DebugInfoReadStream* stream = stream_at(decode_offset);92int length = stream->read_int();93GrowableArray<ScopeValue*>* result = new GrowableArray<ScopeValue*> (length);94for (int index = 0; index < length; index++) {95result->push(ScopeValue::read_from(stream));96}97return result;98}99100GrowableArray<ScopeValue*>* ScopeDesc::decode_object_values(int decode_offset) {101if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;102GrowableArray<ScopeValue*>* result = new GrowableArray<ScopeValue*>();103DebugInfoReadStream* stream = new DebugInfoReadStream(_code, decode_offset, result);104int length = stream->read_int();105for (int index = 0; index < length; index++) {106// Objects values are pushed to 'result' array during read so that107// object's fields could reference it (OBJECT_ID_CODE).108(void)ScopeValue::read_from(stream);109}110assert(result->length() == length, "inconsistent debug information");111return result;112}113114115GrowableArray<MonitorValue*>* ScopeDesc::decode_monitor_values(int decode_offset) {116if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;117DebugInfoReadStream* stream = stream_at(decode_offset);118int length = stream->read_int();119GrowableArray<MonitorValue*>* result = new GrowableArray<MonitorValue*> (length);120for (int index = 0; index < length; index++) {121result->push(new MonitorValue(stream));122}123return result;124}125126DebugInfoReadStream* ScopeDesc::stream_at(int decode_offset) const {127return new DebugInfoReadStream(_code, decode_offset, _objects);128}129130GrowableArray<ScopeValue*>* ScopeDesc::locals() {131return decode_scope_values(_locals_decode_offset);132}133134GrowableArray<ScopeValue*>* ScopeDesc::expressions() {135return decode_scope_values(_expressions_decode_offset);136}137138GrowableArray<MonitorValue*>* ScopeDesc::monitors() {139return decode_monitor_values(_monitors_decode_offset);140}141142GrowableArray<ScopeValue*>* ScopeDesc::objects() {143return _objects;144}145146bool ScopeDesc::is_top() const {147return _sender_decode_offset == DebugInformationRecorder::serialized_null;148}149150ScopeDesc* ScopeDesc::sender() const {151if (is_top()) return NULL;152return new ScopeDesc(this);153}154155156#ifndef PRODUCT157158void ScopeDesc::print_value_on(outputStream* st) const {159tty->print(" ");160method()->print_short_name(st);161int lineno = method()->line_number_from_bci(bci());162if (lineno != -1) {163st->print_cr("@%d (line %d)", bci(), lineno);164} else {165st->print_cr("@%d", bci());166}167}168169void ScopeDesc::print_on(outputStream* st) const {170print_on(st, NULL);171}172173void ScopeDesc::print_on(outputStream* st, PcDesc* pd) const {174// header175if (pd != NULL) {176tty->print_cr("ScopeDesc(pc=" PTR_FORMAT " offset=%x):", pd->real_pc(_code), pd->pc_offset());177}178179print_value_on(st);180// decode offsets181if (WizardMode) {182st->print("ScopeDesc[%d]@" PTR_FORMAT " ", _decode_offset, _code->content_begin());183st->print_cr(" offset: %d", _decode_offset);184st->print_cr(" bci: %d", bci());185st->print_cr(" reexecute: %s", should_reexecute() ? "true" : "false");186st->print_cr(" locals: %d", _locals_decode_offset);187st->print_cr(" stack: %d", _expressions_decode_offset);188st->print_cr(" monitor: %d", _monitors_decode_offset);189st->print_cr(" sender: %d", _sender_decode_offset);190}191// locals192{ GrowableArray<ScopeValue*>* l = ((ScopeDesc*) this)->locals();193if (l != NULL) {194tty->print_cr(" Locals");195for (int index = 0; index < l->length(); index++) {196st->print(" - l%d: ", index);197l->at(index)->print_on(st);198st->cr();199}200}201}202// expressions203{ GrowableArray<ScopeValue*>* l = ((ScopeDesc*) this)->expressions();204if (l != NULL) {205st->print_cr(" Expression stack");206for (int index = 0; index < l->length(); index++) {207st->print(" - @%d: ", index);208l->at(index)->print_on(st);209st->cr();210}211}212}213// monitors214{ GrowableArray<MonitorValue*>* l = ((ScopeDesc*) this)->monitors();215if (l != NULL) {216st->print_cr(" Monitor stack");217for (int index = 0; index < l->length(); index++) {218st->print(" - @%d: ", index);219l->at(index)->print_on(st);220st->cr();221}222}223}224225#ifdef COMPILER2226if (DoEscapeAnalysis && is_top() && _objects != NULL) {227tty->print_cr("Objects");228for (int i = 0; i < _objects->length(); i++) {229ObjectValue* sv = (ObjectValue*) _objects->at(i);230tty->print(" - %d: ", sv->id());231sv->print_fields_on(tty);232tty->cr();233}234}235#endif // COMPILER2236}237238#endif239240void ScopeDesc::verify() {241ResourceMark rm;242guarantee(method()->is_method(), "type check");243244// check if we have any illegal elements on the expression stack245{ GrowableArray<ScopeValue*>* l = expressions();246if (l != NULL) {247for (int index = 0; index < l->length(); index++) {248//guarantee(!l->at(index)->is_illegal(), "expression element cannot be illegal");249}250}251}252}253254255