Path: blob/master/src/hotspot/share/code/debugInfo.cpp
40931 views
/*1* Copyright (c) 1997, 2021, 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 "gc/shared/collectedHeap.hpp"29#include "memory/universe.hpp"30#include "oops/oop.inline.hpp"31#include "runtime/handles.inline.hpp"32#include "runtime/interfaceSupport.inline.hpp"33#include "runtime/jniHandles.inline.hpp"34#include "runtime/thread.hpp"3536// Constructors3738DebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size)39: CompressedWriteStream(initial_size) {40_recorder = recorder;41}4243// Serializing oops4445void DebugInfoWriteStream::write_handle(jobject h) {46write_int(recorder()->oop_recorder()->find_index(h));47}4849void DebugInfoWriteStream::write_metadata(Metadata* h) {50write_int(recorder()->oop_recorder()->find_index(h));51}5253oop DebugInfoReadStream::read_oop() {54nmethod* nm = const_cast<CompiledMethod*>(code())->as_nmethod_or_null();55oop o;56if (nm != NULL) {57// Despite these oops being found inside nmethods that are on-stack,58// they are not kept alive by all GCs (e.g. G1 and Shenandoah).59o = nm->oop_at_phantom(read_int());60} else {61o = code()->oop_at(read_int());62}63assert(oopDesc::is_oop_or_null(o), "oop only");64return o;65}6667ScopeValue* DebugInfoReadStream::read_object_value(bool is_auto_box) {68int id = read_int();69#ifdef ASSERT70assert(_obj_pool != NULL, "object pool does not exist");71for (int i = _obj_pool->length() - 1; i >= 0; i--) {72assert(_obj_pool->at(i)->as_ObjectValue()->id() != id, "should not be read twice");73}74#endif75ObjectValue* result = is_auto_box ? new AutoBoxObjectValue(id) : new ObjectValue(id);76// Cache the object since an object field could reference it.77_obj_pool->push(result);78result->read_object(this);79return result;80}8182ScopeValue* DebugInfoReadStream::get_cached_object() {83int id = read_int();84assert(_obj_pool != NULL, "object pool does not exist");85for (int i = _obj_pool->length() - 1; i >= 0; i--) {86ObjectValue* ov = _obj_pool->at(i)->as_ObjectValue();87if (ov->id() == id) {88return ov;89}90}91ShouldNotReachHere();92return NULL;93}9495// Serializing scope values9697enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,98CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,99OBJECT_CODE = 5, OBJECT_ID_CODE = 6,100AUTO_BOX_OBJECT_CODE = 7, MARKER_CODE = 8 };101102ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {103ScopeValue* result = NULL;104switch(stream->read_int()) {105case LOCATION_CODE: result = new LocationValue(stream); break;106case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break;107case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break;108case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break;109case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break;110case OBJECT_CODE: result = stream->read_object_value(false /*is_auto_box*/); break;111case AUTO_BOX_OBJECT_CODE: result = stream->read_object_value(true /*is_auto_box*/); break;112case OBJECT_ID_CODE: result = stream->get_cached_object(); break;113case MARKER_CODE: result = new MarkerValue(); break;114default: ShouldNotReachHere();115}116return result;117}118119// LocationValue120121LocationValue::LocationValue(DebugInfoReadStream* stream) {122_location = Location(stream);123}124125void LocationValue::write_on(DebugInfoWriteStream* stream) {126stream->write_int(LOCATION_CODE);127location().write_on(stream);128}129130void LocationValue::print_on(outputStream* st) const {131location().print_on(st);132}133134// MarkerValue135136void MarkerValue::write_on(DebugInfoWriteStream* stream) {137stream->write_int(MARKER_CODE);138}139140void MarkerValue::print_on(outputStream* st) const {141st->print("marker");142}143144// ObjectValue145146void ObjectValue::set_value(oop value) {147_value = Handle(Thread::current(), value);148}149150void ObjectValue::read_object(DebugInfoReadStream* stream) {151_klass = read_from(stream);152assert(_klass->is_constant_oop(), "should be constant java mirror oop");153int length = stream->read_int();154for (int i = 0; i < length; i++) {155ScopeValue* val = read_from(stream);156_field_values.append(val);157}158}159160void ObjectValue::write_on(DebugInfoWriteStream* stream) {161if (is_visited()) {162stream->write_int(OBJECT_ID_CODE);163stream->write_int(_id);164} else {165set_visited(true);166stream->write_int(is_auto_box() ? AUTO_BOX_OBJECT_CODE : OBJECT_CODE);167stream->write_int(_id);168_klass->write_on(stream);169int length = _field_values.length();170stream->write_int(length);171for (int i = 0; i < length; i++) {172_field_values.at(i)->write_on(stream);173}174}175}176177void ObjectValue::print_on(outputStream* st) const {178st->print("%s[%d]", is_auto_box() ? "box_obj" : "obj", _id);179}180181void ObjectValue::print_fields_on(outputStream* st) const {182#ifndef PRODUCT183if (_field_values.length() > 0) {184_field_values.at(0)->print_on(st);185}186for (int i = 1; i < _field_values.length(); i++) {187st->print(", ");188_field_values.at(i)->print_on(st);189}190#endif191}192193// ConstantIntValue194195ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {196_value = stream->read_signed_int();197}198199void ConstantIntValue::write_on(DebugInfoWriteStream* stream) {200stream->write_int(CONSTANT_INT_CODE);201stream->write_signed_int(value());202}203204void ConstantIntValue::print_on(outputStream* st) const {205st->print("%d", value());206}207208// ConstantLongValue209210ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {211_value = stream->read_long();212}213214void ConstantLongValue::write_on(DebugInfoWriteStream* stream) {215stream->write_int(CONSTANT_LONG_CODE);216stream->write_long(value());217}218219void ConstantLongValue::print_on(outputStream* st) const {220st->print(JLONG_FORMAT, value());221}222223// ConstantDoubleValue224225ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) {226_value = stream->read_double();227}228229void ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) {230stream->write_int(CONSTANT_DOUBLE_CODE);231stream->write_double(value());232}233234void ConstantDoubleValue::print_on(outputStream* st) const {235st->print("%f", value());236}237238// ConstantOopWriteValue239240void ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) {241#ifdef ASSERT242{243// cannot use ThreadInVMfromNative here since in case of JVMCI compiler,244// thread is already in VM state.245ThreadInVMfromUnknown tiv;246assert(JNIHandles::resolve(value()) == NULL ||247Universe::heap()->is_in(JNIHandles::resolve(value())),248"Should be in heap");249}250#endif251stream->write_int(CONSTANT_OOP_CODE);252stream->write_handle(value());253}254255void ConstantOopWriteValue::print_on(outputStream* st) const {256// using ThreadInVMfromUnknown here since in case of JVMCI compiler,257// thread is already in VM state.258ThreadInVMfromUnknown tiv;259JNIHandles::resolve(value())->print_value_on(st);260}261262263// ConstantOopReadValue264265ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {266_value = Handle(Thread::current(), stream->read_oop());267assert(_value() == NULL ||268Universe::heap()->is_in(_value()), "Should be in heap");269}270271void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {272ShouldNotReachHere();273}274275void ConstantOopReadValue::print_on(outputStream* st) const {276if (value()() != NULL) {277value()()->print_value_on(st);278} else {279st->print("NULL");280}281}282283284// MonitorValue285286MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) {287_owner = owner;288_basic_lock = basic_lock;289_eliminated = eliminated;290}291292MonitorValue::MonitorValue(DebugInfoReadStream* stream) {293_basic_lock = Location(stream);294_owner = ScopeValue::read_from(stream);295_eliminated = (stream->read_bool() != 0);296}297298void MonitorValue::write_on(DebugInfoWriteStream* stream) {299_basic_lock.write_on(stream);300_owner->write_on(stream);301stream->write_bool(_eliminated);302}303304#ifndef PRODUCT305void MonitorValue::print_on(outputStream* st) const {306st->print("monitor{");307owner()->print_on(st);308st->print(",");309basic_lock().print_on(st);310st->print("}");311if (_eliminated) {312st->print(" (eliminated)");313}314}315#endif316317318