Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/code/debugInfo.cpp
32285 views
/*1* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "code/debugInfo.hpp"26#include "code/debugInfoRec.hpp"27#include "code/nmethod.hpp"28#include "runtime/handles.inline.hpp"29#include "runtime/interfaceSupport.hpp"30#include "runtime/thread.hpp"3132PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC3334// Constructors3536DebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size)37: CompressedWriteStream(initial_size) {38_recorder = recorder;39}4041// Serializing oops4243void DebugInfoWriteStream::write_handle(jobject h) {44write_int(recorder()->oop_recorder()->find_index(h));45}4647void DebugInfoWriteStream::write_metadata(Metadata* h) {48write_int(recorder()->oop_recorder()->find_index(h));49}5051ScopeValue* DebugInfoReadStream::read_object_value() {52int id = read_int();53#ifdef ASSERT54assert(_obj_pool != NULL, "object pool does not exist");55for (int i = _obj_pool->length() - 1; i >= 0; i--) {56assert(((ObjectValue*) _obj_pool->at(i))->id() != id, "should not be read twice");57}58#endif59ObjectValue* result = new ObjectValue(id);60// Cache the object since an object field could reference it.61_obj_pool->push(result);62result->read_object(this);63return result;64}6566ScopeValue* DebugInfoReadStream::get_cached_object() {67int id = read_int();68assert(_obj_pool != NULL, "object pool does not exist");69for (int i = _obj_pool->length() - 1; i >= 0; i--) {70ObjectValue* ov = (ObjectValue*) _obj_pool->at(i);71if (ov->id() == id) {72return ov;73}74}75ShouldNotReachHere();76return NULL;77}7879// Serializing scope values8081enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,82CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,83OBJECT_CODE = 5, OBJECT_ID_CODE = 6 };8485ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {86ScopeValue* result = NULL;87switch(stream->read_int()) {88case LOCATION_CODE: result = new LocationValue(stream); break;89case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break;90case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break;91case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break;92case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break;93case OBJECT_CODE: result = stream->read_object_value(); break;94case OBJECT_ID_CODE: result = stream->get_cached_object(); break;95default: ShouldNotReachHere();96}97return result;98}99100// LocationValue101102LocationValue::LocationValue(DebugInfoReadStream* stream) {103_location = Location(stream);104}105106void LocationValue::write_on(DebugInfoWriteStream* stream) {107stream->write_int(LOCATION_CODE);108location().write_on(stream);109}110111void LocationValue::print_on(outputStream* st) const {112location().print_on(st);113}114115// ObjectValue116117void ObjectValue::read_object(DebugInfoReadStream* stream) {118_klass = read_from(stream);119assert(_klass->is_constant_oop(), "should be constant java mirror oop");120int length = stream->read_int();121for (int i = 0; i < length; i++) {122ScopeValue* val = read_from(stream);123_field_values.append(val);124}125}126127void ObjectValue::write_on(DebugInfoWriteStream* stream) {128if (_visited) {129stream->write_int(OBJECT_ID_CODE);130stream->write_int(_id);131} else {132_visited = true;133stream->write_int(OBJECT_CODE);134stream->write_int(_id);135_klass->write_on(stream);136int length = _field_values.length();137stream->write_int(length);138for (int i = 0; i < length; i++) {139_field_values.at(i)->write_on(stream);140}141}142}143144void ObjectValue::print_on(outputStream* st) const {145st->print("obj[%d]", _id);146}147148void ObjectValue::print_fields_on(outputStream* st) const {149#ifndef PRODUCT150if (_field_values.length() > 0) {151_field_values.at(0)->print_on(st);152}153for (int i = 1; i < _field_values.length(); i++) {154st->print(", ");155_field_values.at(i)->print_on(st);156}157#endif158}159160// ConstantIntValue161162ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {163_value = stream->read_signed_int();164}165166void ConstantIntValue::write_on(DebugInfoWriteStream* stream) {167stream->write_int(CONSTANT_INT_CODE);168stream->write_signed_int(value());169}170171void ConstantIntValue::print_on(outputStream* st) const {172st->print("%d", value());173}174175// ConstantLongValue176177ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {178_value = stream->read_long();179}180181void ConstantLongValue::write_on(DebugInfoWriteStream* stream) {182stream->write_int(CONSTANT_LONG_CODE);183stream->write_long(value());184}185186void ConstantLongValue::print_on(outputStream* st) const {187st->print(INT64_FORMAT, value());188}189190// ConstantDoubleValue191192ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) {193_value = stream->read_double();194}195196void ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) {197stream->write_int(CONSTANT_DOUBLE_CODE);198stream->write_double(value());199}200201void ConstantDoubleValue::print_on(outputStream* st) const {202st->print("%f", value());203}204205// ConstantOopWriteValue206207void ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) {208#ifdef ASSERT209{210// cannot use ThreadInVMfromNative here since in case of JVMCI compiler,211// thread is already in VM state.212ThreadInVMfromUnknown tiv;213assert(JNIHandles::resolve(value()) == NULL ||214Universe::heap()->is_in_reserved(JNIHandles::resolve(value())),215"Should be in heap");216}217#endif218stream->write_int(CONSTANT_OOP_CODE);219stream->write_handle(value());220}221222void ConstantOopWriteValue::print_on(outputStream* st) const {223// using ThreadInVMfromUnknown here since in case of JVMCI compiler,224// thread is already in VM state.225ThreadInVMfromUnknown tiv;226JNIHandles::resolve(value())->print_value_on(st);227}228229230// ConstantOopReadValue231232ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {233_value = Handle(stream->read_oop());234assert(_value() == NULL ||235Universe::heap()->is_in_reserved(_value()), "Should be in heap");236}237238void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {239ShouldNotReachHere();240}241242void ConstantOopReadValue::print_on(outputStream* st) const {243value()()->print_value_on(st);244}245246247// MonitorValue248249MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) {250_owner = owner;251_basic_lock = basic_lock;252_eliminated = eliminated;253}254255MonitorValue::MonitorValue(DebugInfoReadStream* stream) {256_basic_lock = Location(stream);257_owner = ScopeValue::read_from(stream);258_eliminated = (stream->read_bool() != 0);259}260261void MonitorValue::write_on(DebugInfoWriteStream* stream) {262_basic_lock.write_on(stream);263_owner->write_on(stream);264stream->write_bool(_eliminated);265}266267#ifndef PRODUCT268void MonitorValue::print_on(outputStream* st) const {269st->print("monitor{");270owner()->print_on(st);271st->print(",");272basic_lock().print_on(st);273st->print("}");274if (_eliminated) {275st->print(" (eliminated)");276}277}278#endif279280281