Path: blob/master/src/hotspot/share/code/debugInfo.hpp
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#ifndef SHARE_CODE_DEBUGINFO_HPP25#define SHARE_CODE_DEBUGINFO_HPP2627#include "code/compressedStream.hpp"28#include "code/location.hpp"29#include "code/nmethod.hpp"30#include "code/oopRecorder.hpp"31#include "runtime/stackValue.hpp"32#include "runtime/thread.hpp"33#include "utilities/growableArray.hpp"3435// Classes used for serializing debugging information.36// These abstractions are introducted to provide symmetric37// read and write operations.3839// ScopeValue describes the value of a variable/expression in a scope40// - LocationValue describes a value in a given location (in frame or register)41// - ConstantValue describes a constant4243class ConstantOopReadValue;44class LocationValue;45class ObjectValue;4647class ScopeValue: public ResourceObj {48public:49// Testers50virtual bool is_location() const { return false; }51virtual bool is_object() const { return false; }52virtual bool is_auto_box() const { return false; }53virtual bool is_marker() const { return false; }54virtual bool is_constant_int() const { return false; }55virtual bool is_constant_double() const { return false; }56virtual bool is_constant_long() const { return false; }57virtual bool is_constant_oop() const { return false; }58virtual bool equals(ScopeValue* other) const { return false; }5960ConstantOopReadValue* as_ConstantOopReadValue() {61assert(is_constant_oop(), "must be");62return (ConstantOopReadValue*) this;63}6465ObjectValue* as_ObjectValue() {66assert(is_object(), "must be");67return (ObjectValue*)this;68}6970LocationValue* as_LocationValue() {71assert(is_location(), "must be");72return (LocationValue*)this;73}7475// Serialization of debugging information76virtual void write_on(DebugInfoWriteStream* stream) = 0;77static ScopeValue* read_from(DebugInfoReadStream* stream);78};798081// A Location value describes a value in a given location; i.e. the corresponding82// logical entity (e.g., a method temporary) lives in this location.8384class LocationValue: public ScopeValue {85private:86Location _location;87public:88LocationValue(Location location) { _location = location; }89bool is_location() const { return true; }90Location location() const { return _location; }9192// Serialization of debugging information93LocationValue(DebugInfoReadStream* stream);94void write_on(DebugInfoWriteStream* stream);9596// Printing97void print_on(outputStream* st) const;98};99100// A placeholder value that has no concrete meaning other than helping constructing101// other values.102103class MarkerValue: public ScopeValue {104public:105bool is_marker() const { return true; }106107// Serialization of debugging information108void write_on(DebugInfoWriteStream* stream);109110// Printing111void print_on(outputStream* st) const;112};113114// An ObjectValue describes an object eliminated by escape analysis.115116class ObjectValue: public ScopeValue {117protected:118int _id;119ScopeValue* _klass;120GrowableArray<ScopeValue*> _field_values;121Handle _value;122bool _visited;123public:124ObjectValue(int id, ScopeValue* klass)125: _id(id)126, _klass(klass)127, _field_values()128, _value()129, _visited(false) {130assert(klass->is_constant_oop(), "should be constant java mirror oop");131}132133ObjectValue(int id)134: _id(id)135, _klass(NULL)136, _field_values()137, _value()138, _visited(false) {}139140// Accessors141bool is_object() const { return true; }142int id() const { return _id; }143ScopeValue* klass() const { return _klass; }144GrowableArray<ScopeValue*>* field_values() { return &_field_values; }145ScopeValue* field_at(int i) const { return _field_values.at(i); }146int field_size() { return _field_values.length(); }147Handle value() const { return _value; }148bool is_visited() const { return _visited; }149150void set_value(oop value);151void set_visited(bool visited) { _visited = visited; }152153// Serialization of debugging information154void read_object(DebugInfoReadStream* stream);155void write_on(DebugInfoWriteStream* stream);156157// Printing158void print_on(outputStream* st) const;159void print_fields_on(outputStream* st) const;160};161162class AutoBoxObjectValue : public ObjectValue {163bool _cached;164public:165bool is_auto_box() const { return true; }166bool is_cached() const { return _cached; }167void set_cached(bool cached) { _cached = cached; }168AutoBoxObjectValue(int id, ScopeValue* klass) : ObjectValue(id, klass), _cached(false) { }169AutoBoxObjectValue(int id) : ObjectValue(id), _cached(false) { }170};171172173// A ConstantIntValue describes a constant int; i.e., the corresponding logical entity174// is either a source constant or its computation has been constant-folded.175176class ConstantIntValue: public ScopeValue {177private:178jint _value;179public:180ConstantIntValue(jint value) { _value = value; }181jint value() const { return _value; }182bool is_constant_int() const { return true; }183bool equals(ScopeValue* other) const { return false; }184185// Serialization of debugging information186ConstantIntValue(DebugInfoReadStream* stream);187void write_on(DebugInfoWriteStream* stream);188189// Printing190void print_on(outputStream* st) const;191};192193class ConstantLongValue: public ScopeValue {194private:195jlong _value;196public:197ConstantLongValue(jlong value) { _value = value; }198jlong value() const { return _value; }199bool is_constant_long() const { return true; }200bool equals(ScopeValue* other) const { return false; }201202// Serialization of debugging information203ConstantLongValue(DebugInfoReadStream* stream);204void write_on(DebugInfoWriteStream* stream);205206// Printing207void print_on(outputStream* st) const;208};209210class ConstantDoubleValue: public ScopeValue {211private:212jdouble _value;213public:214ConstantDoubleValue(jdouble value) { _value = value; }215jdouble value() const { return _value; }216bool is_constant_double() const { return true; }217bool equals(ScopeValue* other) const { return false; }218219// Serialization of debugging information220ConstantDoubleValue(DebugInfoReadStream* stream);221void write_on(DebugInfoWriteStream* stream);222223// Printing224void print_on(outputStream* st) const;225};226227// A ConstantOopWriteValue is created by the compiler to228// be written as debugging information.229230class ConstantOopWriteValue: public ScopeValue {231private:232jobject _value;233public:234ConstantOopWriteValue(jobject value) { _value = value; }235jobject value() const { return _value; }236bool is_constant_oop() const { return true; }237bool equals(ScopeValue* other) const { return false; }238239// Serialization of debugging information240void write_on(DebugInfoWriteStream* stream);241242// Printing243void print_on(outputStream* st) const;244};245246// A ConstantOopReadValue is created by the VM when reading247// debug information248249class ConstantOopReadValue: public ScopeValue {250private:251Handle _value;252public:253Handle value() const { return _value; }254bool is_constant_oop() const { return true; }255bool equals(ScopeValue* other) const { return false; }256257// Serialization of debugging information258ConstantOopReadValue(DebugInfoReadStream* stream);259void write_on(DebugInfoWriteStream* stream);260261// Printing262void print_on(outputStream* st) const;263};264265// MonitorValue describes the pair used for monitor_enter and monitor_exit.266267class MonitorValue: public ResourceObj {268private:269ScopeValue* _owner;270Location _basic_lock;271bool _eliminated;272public:273// Constructor274MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated = false);275276// Accessors277ScopeValue* owner() const { return _owner; }278Location basic_lock() const { return _basic_lock; }279bool eliminated() const { return _eliminated; }280281// Serialization of debugging information282MonitorValue(DebugInfoReadStream* stream);283void write_on(DebugInfoWriteStream* stream);284285// Printing286void print_on(outputStream* st) const;287};288289// DebugInfoReadStream specializes CompressedReadStream for reading290// debugging information. Used by ScopeDesc.291292class DebugInfoReadStream : public CompressedReadStream {293private:294const CompiledMethod* _code;295const CompiledMethod* code() const { return _code; }296GrowableArray<ScopeValue*>* _obj_pool;297public:298DebugInfoReadStream(const CompiledMethod* code, int offset, GrowableArray<ScopeValue*>* obj_pool = NULL) :299CompressedReadStream(code->scopes_data_begin(), offset) {300_code = code;301_obj_pool = obj_pool;302303} ;304305oop read_oop();306Method* read_method() {307Method* o = (Method*)(code()->metadata_at(read_int()));308// is_metadata() is a faster check than is_metaspace_object()309assert(o == NULL || o->is_metadata(), "meta data only");310return o;311}312ScopeValue* read_object_value(bool is_auto_box);313ScopeValue* get_cached_object();314// BCI encoding is mostly unsigned, but -1 is a distinguished value315int read_bci() { return read_int() + InvocationEntryBci; }316};317318// DebugInfoWriteStream specializes CompressedWriteStream for319// writing debugging information. Used by ScopeDescRecorder.320321class DebugInfoWriteStream : public CompressedWriteStream {322private:323DebugInformationRecorder* _recorder;324DebugInformationRecorder* recorder() const { return _recorder; }325public:326DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size);327void write_handle(jobject h);328void write_bci(int bci) { write_int(bci - InvocationEntryBci); }329330void write_metadata(Metadata* m);331};332333#endif // SHARE_CODE_DEBUGINFO_HPP334335336