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