0N/A/*
1879N/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/debugInfo.hpp"
1879N/A#include "code/debugInfoRec.hpp"
1879N/A#include "code/nmethod.hpp"
1879N/A#include "runtime/handles.inline.hpp"
0N/A
0N/A// Comstructors
0N/A
0N/ADebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size)
0N/A: CompressedWriteStream(initial_size) {
0N/A _recorder = recorder;
0N/A}
0N/A
0N/A// Serializing oops
0N/A
0N/Avoid DebugInfoWriteStream::write_handle(jobject h) {
0N/A write_int(recorder()->oop_recorder()->find_index(h));
0N/A}
0N/A
0N/AScopeValue* DebugInfoReadStream::read_object_value() {
0N/A int id = read_int();
0N/A#ifdef ASSERT
0N/A assert(_obj_pool != NULL, "object pool does not exist");
0N/A for (int i = _obj_pool->length() - 1; i >= 0; i--) {
0N/A assert(((ObjectValue*) _obj_pool->at(i))->id() != id, "should not be read twice");
0N/A }
0N/A#endif
0N/A ObjectValue* result = new ObjectValue(id);
44N/A // Cache the object since an object field could reference it.
44N/A _obj_pool->push(result);
0N/A result->read_object(this);
0N/A return result;
0N/A}
0N/A
0N/AScopeValue* DebugInfoReadStream::get_cached_object() {
0N/A int id = read_int();
0N/A assert(_obj_pool != NULL, "object pool does not exist");
0N/A for (int i = _obj_pool->length() - 1; i >= 0; i--) {
44N/A ObjectValue* ov = (ObjectValue*) _obj_pool->at(i);
44N/A if (ov->id() == id) {
44N/A return ov;
0N/A }
0N/A }
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A// Serializing scope values
0N/A
0N/Aenum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,
0N/A CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
0N/A OBJECT_CODE = 5, OBJECT_ID_CODE = 6 };
0N/A
0N/AScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
0N/A ScopeValue* result = NULL;
0N/A switch(stream->read_int()) {
0N/A case LOCATION_CODE: result = new LocationValue(stream); break;
0N/A case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break;
0N/A case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break;
0N/A case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break;
0N/A case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break;
0N/A case OBJECT_CODE: result = stream->read_object_value(); break;
0N/A case OBJECT_ID_CODE: result = stream->get_cached_object(); break;
0N/A default: ShouldNotReachHere();
0N/A }
0N/A return result;
0N/A}
0N/A
0N/A// LocationValue
0N/A
0N/ALocationValue::LocationValue(DebugInfoReadStream* stream) {
0N/A _location = Location(stream);
0N/A}
0N/A
0N/Avoid LocationValue::write_on(DebugInfoWriteStream* stream) {
0N/A stream->write_int(LOCATION_CODE);
0N/A location().write_on(stream);
0N/A}
0N/A
0N/Avoid LocationValue::print_on(outputStream* st) const {
0N/A location().print_on(st);
0N/A}
0N/A
0N/A// ObjectValue
0N/A
0N/Avoid ObjectValue::read_object(DebugInfoReadStream* stream) {
0N/A _klass = read_from(stream);
0N/A assert(_klass->is_constant_oop(), "should be constant klass oop");
0N/A int length = stream->read_int();
0N/A for (int i = 0; i < length; i++) {
0N/A ScopeValue* val = read_from(stream);
0N/A _field_values.append(val);
0N/A }
0N/A}
0N/A
0N/Avoid ObjectValue::write_on(DebugInfoWriteStream* stream) {
0N/A if (_visited) {
0N/A stream->write_int(OBJECT_ID_CODE);
0N/A stream->write_int(_id);
0N/A } else {
0N/A _visited = true;
0N/A stream->write_int(OBJECT_CODE);
0N/A stream->write_int(_id);
0N/A _klass->write_on(stream);
0N/A int length = _field_values.length();
0N/A stream->write_int(length);
0N/A for (int i = 0; i < length; i++) {
0N/A _field_values.at(i)->write_on(stream);
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ObjectValue::print_on(outputStream* st) const {
0N/A st->print("obj[%d]", _id);
0N/A}
0N/A
0N/Avoid ObjectValue::print_fields_on(outputStream* st) const {
0N/A#ifndef PRODUCT
0N/A if (_field_values.length() > 0) {
0N/A _field_values.at(0)->print_on(st);
0N/A }
0N/A for (int i = 1; i < _field_values.length(); i++) {
0N/A st->print(", ");
0N/A _field_values.at(i)->print_on(st);
0N/A }
0N/A#endif
0N/A}
0N/A
0N/A// ConstantIntValue
0N/A
0N/AConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
0N/A _value = stream->read_signed_int();
0N/A}
0N/A
0N/Avoid ConstantIntValue::write_on(DebugInfoWriteStream* stream) {
0N/A stream->write_int(CONSTANT_INT_CODE);
0N/A stream->write_signed_int(value());
0N/A}
0N/A
0N/Avoid ConstantIntValue::print_on(outputStream* st) const {
0N/A st->print("%d", value());
0N/A}
0N/A
0N/A// ConstantLongValue
0N/A
0N/AConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {
0N/A _value = stream->read_long();
0N/A}
0N/A
0N/Avoid ConstantLongValue::write_on(DebugInfoWriteStream* stream) {
0N/A stream->write_int(CONSTANT_LONG_CODE);
0N/A stream->write_long(value());
0N/A}
0N/A
0N/Avoid ConstantLongValue::print_on(outputStream* st) const {
0N/A st->print(INT64_FORMAT, value());
0N/A}
0N/A
0N/A// ConstantDoubleValue
0N/A
0N/AConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) {
0N/A _value = stream->read_double();
0N/A}
0N/A
0N/Avoid ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) {
0N/A stream->write_int(CONSTANT_DOUBLE_CODE);
0N/A stream->write_double(value());
0N/A}
0N/A
0N/Avoid ConstantDoubleValue::print_on(outputStream* st) const {
0N/A st->print("%f", value());
0N/A}
0N/A
0N/A// ConstantOopWriteValue
0N/A
0N/Avoid ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) {
0N/A stream->write_int(CONSTANT_OOP_CODE);
0N/A stream->write_handle(value());
0N/A}
0N/A
0N/Avoid ConstantOopWriteValue::print_on(outputStream* st) const {
0N/A JNIHandles::resolve(value())->print_value_on(st);
0N/A}
0N/A
0N/A
0N/A// ConstantOopReadValue
0N/A
0N/AConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {
0N/A _value = Handle(stream->read_oop());
0N/A}
0N/A
0N/Avoid ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {
0N/A ShouldNotReachHere();
0N/A}
0N/A
0N/Avoid ConstantOopReadValue::print_on(outputStream* st) const {
0N/A value()()->print_value_on(st);
0N/A}
0N/A
0N/A
0N/A// MonitorValue
0N/A
0N/AMonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) {
0N/A _owner = owner;
0N/A _basic_lock = basic_lock;
0N/A _eliminated = eliminated;
0N/A}
0N/A
0N/AMonitorValue::MonitorValue(DebugInfoReadStream* stream) {
0N/A _basic_lock = Location(stream);
0N/A _owner = ScopeValue::read_from(stream);
0N/A _eliminated = (stream->read_bool() != 0);
0N/A}
0N/A
0N/Avoid MonitorValue::write_on(DebugInfoWriteStream* stream) {
0N/A _basic_lock.write_on(stream);
0N/A _owner->write_on(stream);
0N/A stream->write_bool(_eliminated);
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid MonitorValue::print_on(outputStream* st) const {
0N/A st->print("monitor{");
0N/A owner()->print_on(st);
0N/A st->print(",");
0N/A basic_lock().print_on(st);
0N/A st->print("}");
0N/A if (_eliminated) {
0N/A st->print(" (eliminated)");
0N/A }
0N/A}
0N/A#endif