aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "code/debugInfoRec.hpp" aoqi@0: #include "code/pcDesc.hpp" aoqi@0: #include "code/scopeDesc.hpp" aoqi@0: #include "memory/resourceArea.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "runtime/handles.inline.hpp" aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: ScopeDesc::ScopeDesc(const nmethod* code, int decode_offset, int obj_decode_offset, bool reexecute, bool return_oop) { aoqi@0: _code = code; aoqi@0: _decode_offset = decode_offset; aoqi@0: _objects = decode_object_values(obj_decode_offset); aoqi@0: _reexecute = reexecute; aoqi@0: _return_oop = return_oop; aoqi@0: decode_body(); aoqi@0: } aoqi@0: aoqi@0: ScopeDesc::ScopeDesc(const nmethod* code, int decode_offset, bool reexecute, bool return_oop) { aoqi@0: _code = code; aoqi@0: _decode_offset = decode_offset; aoqi@0: _objects = decode_object_values(DebugInformationRecorder::serialized_null); aoqi@0: _reexecute = reexecute; aoqi@0: _return_oop = return_oop; aoqi@0: decode_body(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: ScopeDesc::ScopeDesc(const ScopeDesc* parent) { aoqi@0: _code = parent->_code; aoqi@0: _decode_offset = parent->_sender_decode_offset; aoqi@0: _objects = parent->_objects; aoqi@0: _reexecute = false; //reexecute only applies to the first scope aoqi@0: _return_oop = false; aoqi@0: decode_body(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void ScopeDesc::decode_body() { aoqi@0: if (decode_offset() == DebugInformationRecorder::serialized_null) { aoqi@0: // This is a sentinel record, which is only relevant to aoqi@0: // approximate queries. Decode a reasonable frame. aoqi@0: _sender_decode_offset = DebugInformationRecorder::serialized_null; aoqi@0: _method = _code->method(); aoqi@0: _bci = InvocationEntryBci; aoqi@0: _locals_decode_offset = DebugInformationRecorder::serialized_null; aoqi@0: _expressions_decode_offset = DebugInformationRecorder::serialized_null; aoqi@0: _monitors_decode_offset = DebugInformationRecorder::serialized_null; aoqi@0: } else { aoqi@0: // decode header aoqi@0: DebugInfoReadStream* stream = stream_at(decode_offset()); aoqi@0: aoqi@0: _sender_decode_offset = stream->read_int(); aoqi@0: _method = stream->read_method(); aoqi@0: _bci = stream->read_bci(); aoqi@0: aoqi@0: // decode offsets for body and sender aoqi@0: _locals_decode_offset = stream->read_int(); aoqi@0: _expressions_decode_offset = stream->read_int(); aoqi@0: _monitors_decode_offset = stream->read_int(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: GrowableArray* ScopeDesc::decode_scope_values(int decode_offset) { aoqi@0: if (decode_offset == DebugInformationRecorder::serialized_null) return NULL; aoqi@0: DebugInfoReadStream* stream = stream_at(decode_offset); aoqi@0: int length = stream->read_int(); aoqi@0: GrowableArray* result = new GrowableArray (length); aoqi@0: for (int index = 0; index < length; index++) { aoqi@0: result->push(ScopeValue::read_from(stream)); aoqi@0: } aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: GrowableArray* ScopeDesc::decode_object_values(int decode_offset) { aoqi@0: if (decode_offset == DebugInformationRecorder::serialized_null) return NULL; aoqi@0: GrowableArray* result = new GrowableArray(); aoqi@0: DebugInfoReadStream* stream = new DebugInfoReadStream(_code, decode_offset, result); aoqi@0: int length = stream->read_int(); aoqi@0: for (int index = 0; index < length; index++) { aoqi@0: // Objects values are pushed to 'result' array during read so that aoqi@0: // object's fields could reference it (OBJECT_ID_CODE). aoqi@0: (void)ScopeValue::read_from(stream); aoqi@0: } aoqi@0: assert(result->length() == length, "inconsistent debug information"); aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: GrowableArray* ScopeDesc::decode_monitor_values(int decode_offset) { aoqi@0: if (decode_offset == DebugInformationRecorder::serialized_null) return NULL; aoqi@0: DebugInfoReadStream* stream = stream_at(decode_offset); aoqi@0: int length = stream->read_int(); aoqi@0: GrowableArray* result = new GrowableArray (length); aoqi@0: for (int index = 0; index < length; index++) { aoqi@0: result->push(new MonitorValue(stream)); aoqi@0: } aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: DebugInfoReadStream* ScopeDesc::stream_at(int decode_offset) const { aoqi@0: return new DebugInfoReadStream(_code, decode_offset, _objects); aoqi@0: } aoqi@0: aoqi@0: GrowableArray* ScopeDesc::locals() { aoqi@0: return decode_scope_values(_locals_decode_offset); aoqi@0: } aoqi@0: aoqi@0: GrowableArray* ScopeDesc::expressions() { aoqi@0: return decode_scope_values(_expressions_decode_offset); aoqi@0: } aoqi@0: aoqi@0: GrowableArray* ScopeDesc::monitors() { aoqi@0: return decode_monitor_values(_monitors_decode_offset); aoqi@0: } aoqi@0: aoqi@0: GrowableArray* ScopeDesc::objects() { aoqi@0: return _objects; aoqi@0: } aoqi@0: aoqi@0: bool ScopeDesc::is_top() const { aoqi@0: return _sender_decode_offset == DebugInformationRecorder::serialized_null; aoqi@0: } aoqi@0: aoqi@0: ScopeDesc* ScopeDesc::sender() const { aoqi@0: if (is_top()) return NULL; aoqi@0: return new ScopeDesc(this); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: aoqi@0: void ScopeDesc::print_value_on(outputStream* st) const { aoqi@0: tty->print(" "); aoqi@0: method()->print_short_name(st); aoqi@0: int lineno = method()->line_number_from_bci(bci()); aoqi@0: if (lineno != -1) { aoqi@0: st->print_cr("@%d (line %d)", bci(), lineno); aoqi@0: } else { aoqi@0: st->print_cr("@%d", bci()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ScopeDesc::print_on(outputStream* st) const { aoqi@0: print_on(st, NULL); aoqi@0: } aoqi@0: aoqi@0: void ScopeDesc::print_on(outputStream* st, PcDesc* pd) const { aoqi@0: // header aoqi@0: if (pd != NULL) { aoqi@0: tty->print_cr("ScopeDesc(pc=" PTR_FORMAT " offset=%x):", pd->real_pc(_code), pd->pc_offset()); aoqi@0: } aoqi@0: aoqi@0: print_value_on(st); aoqi@0: // decode offsets aoqi@0: if (WizardMode) { aoqi@0: st->print("ScopeDesc[%d]@" PTR_FORMAT " ", _decode_offset, _code->content_begin()); aoqi@0: st->print_cr(" offset: %d", _decode_offset); aoqi@0: st->print_cr(" bci: %d", bci()); aoqi@0: st->print_cr(" reexecute: %s", should_reexecute() ? "true" : "false"); aoqi@0: st->print_cr(" locals: %d", _locals_decode_offset); aoqi@0: st->print_cr(" stack: %d", _expressions_decode_offset); aoqi@0: st->print_cr(" monitor: %d", _monitors_decode_offset); aoqi@0: st->print_cr(" sender: %d", _sender_decode_offset); aoqi@0: } aoqi@0: // locals aoqi@0: { GrowableArray* l = ((ScopeDesc*) this)->locals(); aoqi@0: if (l != NULL) { aoqi@0: tty->print_cr(" Locals"); aoqi@0: for (int index = 0; index < l->length(); index++) { aoqi@0: st->print(" - l%d: ", index); aoqi@0: l->at(index)->print_on(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: // expressions aoqi@0: { GrowableArray* l = ((ScopeDesc*) this)->expressions(); aoqi@0: if (l != NULL) { aoqi@0: st->print_cr(" Expression stack"); aoqi@0: for (int index = 0; index < l->length(); index++) { aoqi@0: st->print(" - @%d: ", index); aoqi@0: l->at(index)->print_on(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: // monitors aoqi@0: { GrowableArray* l = ((ScopeDesc*) this)->monitors(); aoqi@0: if (l != NULL) { aoqi@0: st->print_cr(" Monitor stack"); aoqi@0: for (int index = 0; index < l->length(); index++) { aoqi@0: st->print(" - @%d: ", index); aoqi@0: l->at(index)->print_on(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifdef COMPILER2 aoqi@0: if (DoEscapeAnalysis && is_top() && _objects != NULL) { aoqi@0: tty->print_cr("Objects"); aoqi@0: for (int i = 0; i < _objects->length(); i++) { aoqi@0: ObjectValue* sv = (ObjectValue*) _objects->at(i); aoqi@0: tty->print(" - %d: ", sv->id()); aoqi@0: sv->print_fields_on(tty); aoqi@0: tty->cr(); aoqi@0: } aoqi@0: } aoqi@0: #endif // COMPILER2 aoqi@0: } aoqi@0: aoqi@0: #endif aoqi@0: aoqi@0: void ScopeDesc::verify() { aoqi@0: ResourceMark rm; aoqi@0: guarantee(method()->is_method(), "type check"); aoqi@0: aoqi@0: // check if we have any illegal elements on the expression stack aoqi@0: { GrowableArray* l = expressions(); aoqi@0: if (l != NULL) { aoqi@0: for (int index = 0; index < l->length(); index++) { aoqi@0: //guarantee(!l->at(index)->is_illegal(), "expression element cannot be illegal"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: }