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