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