1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/code/debugInfo.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,301 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_CODE_DEBUGINFO_HPP 1.29 +#define SHARE_VM_CODE_DEBUGINFO_HPP 1.30 + 1.31 +#include "code/compressedStream.hpp" 1.32 +#include "code/location.hpp" 1.33 +#include "code/nmethod.hpp" 1.34 +#include "code/oopRecorder.hpp" 1.35 +#include "runtime/stackValue.hpp" 1.36 +#include "utilities/growableArray.hpp" 1.37 + 1.38 +// Classes used for serializing debugging information. 1.39 +// These abstractions are introducted to provide symmetric 1.40 +// read and write operations. 1.41 + 1.42 +// ScopeValue describes the value of a variable/expression in a scope 1.43 +// - LocationValue describes a value in a given location (in frame or register) 1.44 +// - ConstantValue describes a constant 1.45 + 1.46 +class ConstantOopReadValue; 1.47 + 1.48 +class ScopeValue: public ResourceObj { 1.49 + public: 1.50 + // Testers 1.51 + virtual bool is_location() const { return false; } 1.52 + virtual bool is_object() const { return false; } 1.53 + virtual bool is_constant_int() const { return false; } 1.54 + virtual bool is_constant_double() const { return false; } 1.55 + virtual bool is_constant_long() const { return false; } 1.56 + virtual bool is_constant_oop() const { return false; } 1.57 + virtual bool equals(ScopeValue* other) const { return false; } 1.58 + 1.59 + ConstantOopReadValue* as_ConstantOopReadValue() { 1.60 + assert(is_constant_oop(), "must be"); 1.61 + return (ConstantOopReadValue*) this; 1.62 + } 1.63 + 1.64 + // Serialization of debugging information 1.65 + virtual void write_on(DebugInfoWriteStream* stream) = 0; 1.66 + static ScopeValue* read_from(DebugInfoReadStream* stream); 1.67 +}; 1.68 + 1.69 + 1.70 +// A Location value describes a value in a given location; i.e. the corresponding 1.71 +// logical entity (e.g., a method temporary) lives in this location. 1.72 + 1.73 +class LocationValue: public ScopeValue { 1.74 + private: 1.75 + Location _location; 1.76 + public: 1.77 + LocationValue(Location location) { _location = location; } 1.78 + bool is_location() const { return true; } 1.79 + Location location() const { return _location; } 1.80 + 1.81 + // Serialization of debugging information 1.82 + LocationValue(DebugInfoReadStream* stream); 1.83 + void write_on(DebugInfoWriteStream* stream); 1.84 + 1.85 + // Printing 1.86 + void print_on(outputStream* st) const; 1.87 +}; 1.88 + 1.89 + 1.90 +// An ObjectValue describes an object eliminated by escape analysis. 1.91 + 1.92 +class ObjectValue: public ScopeValue { 1.93 + private: 1.94 + int _id; 1.95 + ScopeValue* _klass; 1.96 + GrowableArray<ScopeValue*> _field_values; 1.97 + Handle _value; 1.98 + bool _visited; 1.99 + 1.100 + public: 1.101 + ObjectValue(int id, ScopeValue* klass) 1.102 + : _id(id) 1.103 + , _klass(klass) 1.104 + , _field_values() 1.105 + , _value() 1.106 + , _visited(false) { 1.107 + assert(klass->is_constant_oop(), "should be constant java mirror oop"); 1.108 + } 1.109 + 1.110 + ObjectValue(int id) 1.111 + : _id(id) 1.112 + , _klass(NULL) 1.113 + , _field_values() 1.114 + , _value() 1.115 + , _visited(false) {} 1.116 + 1.117 + // Accessors 1.118 + bool is_object() const { return true; } 1.119 + int id() const { return _id; } 1.120 + ScopeValue* klass() const { return _klass; } 1.121 + GrowableArray<ScopeValue*>* field_values() { return &_field_values; } 1.122 + ScopeValue* field_at(int i) const { return _field_values.at(i); } 1.123 + int field_size() { return _field_values.length(); } 1.124 + Handle value() const { return _value; } 1.125 + bool is_visited() const { return _visited; } 1.126 + 1.127 + void set_value(oop value) { _value = Handle(value); } 1.128 + void set_visited(bool visited) { _visited = false; } 1.129 + 1.130 + // Serialization of debugging information 1.131 + void read_object(DebugInfoReadStream* stream); 1.132 + void write_on(DebugInfoWriteStream* stream); 1.133 + 1.134 + // Printing 1.135 + void print_on(outputStream* st) const; 1.136 + void print_fields_on(outputStream* st) const; 1.137 +}; 1.138 + 1.139 + 1.140 +// A ConstantIntValue describes a constant int; i.e., the corresponding logical entity 1.141 +// is either a source constant or its computation has been constant-folded. 1.142 + 1.143 +class ConstantIntValue: public ScopeValue { 1.144 + private: 1.145 + jint _value; 1.146 + public: 1.147 + ConstantIntValue(jint value) { _value = value; } 1.148 + jint value() const { return _value; } 1.149 + bool is_constant_int() const { return true; } 1.150 + bool equals(ScopeValue* other) const { return false; } 1.151 + 1.152 + // Serialization of debugging information 1.153 + ConstantIntValue(DebugInfoReadStream* stream); 1.154 + void write_on(DebugInfoWriteStream* stream); 1.155 + 1.156 + // Printing 1.157 + void print_on(outputStream* st) const; 1.158 +}; 1.159 + 1.160 +class ConstantLongValue: public ScopeValue { 1.161 + private: 1.162 + jlong _value; 1.163 + public: 1.164 + ConstantLongValue(jlong value) { _value = value; } 1.165 + jlong value() const { return _value; } 1.166 + bool is_constant_long() const { return true; } 1.167 + bool equals(ScopeValue* other) const { return false; } 1.168 + 1.169 + // Serialization of debugging information 1.170 + ConstantLongValue(DebugInfoReadStream* stream); 1.171 + void write_on(DebugInfoWriteStream* stream); 1.172 + 1.173 + // Printing 1.174 + void print_on(outputStream* st) const; 1.175 +}; 1.176 + 1.177 +class ConstantDoubleValue: public ScopeValue { 1.178 + private: 1.179 + jdouble _value; 1.180 + public: 1.181 + ConstantDoubleValue(jdouble value) { _value = value; } 1.182 + jdouble value() const { return _value; } 1.183 + bool is_constant_double() const { return true; } 1.184 + bool equals(ScopeValue* other) const { return false; } 1.185 + 1.186 + // Serialization of debugging information 1.187 + ConstantDoubleValue(DebugInfoReadStream* stream); 1.188 + void write_on(DebugInfoWriteStream* stream); 1.189 + 1.190 + // Printing 1.191 + void print_on(outputStream* st) const; 1.192 +}; 1.193 + 1.194 +// A ConstantOopWriteValue is created by the compiler to 1.195 +// be written as debugging information. 1.196 + 1.197 +class ConstantOopWriteValue: public ScopeValue { 1.198 + private: 1.199 + jobject _value; 1.200 + public: 1.201 + ConstantOopWriteValue(jobject value) { _value = value; } 1.202 + jobject value() const { return _value; } 1.203 + bool is_constant_oop() const { return true; } 1.204 + bool equals(ScopeValue* other) const { return false; } 1.205 + 1.206 + // Serialization of debugging information 1.207 + void write_on(DebugInfoWriteStream* stream); 1.208 + 1.209 + // Printing 1.210 + void print_on(outputStream* st) const; 1.211 +}; 1.212 + 1.213 +// A ConstantOopReadValue is created by the VM when reading 1.214 +// debug information 1.215 + 1.216 +class ConstantOopReadValue: public ScopeValue { 1.217 + private: 1.218 + Handle _value; 1.219 + public: 1.220 + Handle value() const { return _value; } 1.221 + bool is_constant_oop() const { return true; } 1.222 + bool equals(ScopeValue* other) const { return false; } 1.223 + 1.224 + // Serialization of debugging information 1.225 + ConstantOopReadValue(DebugInfoReadStream* stream); 1.226 + void write_on(DebugInfoWriteStream* stream); 1.227 + 1.228 + // Printing 1.229 + void print_on(outputStream* st) const; 1.230 +}; 1.231 + 1.232 +// MonitorValue describes the pair used for monitor_enter and monitor_exit. 1.233 + 1.234 +class MonitorValue: public ResourceObj { 1.235 + private: 1.236 + ScopeValue* _owner; 1.237 + Location _basic_lock; 1.238 + bool _eliminated; 1.239 + public: 1.240 + // Constructor 1.241 + MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated = false); 1.242 + 1.243 + // Accessors 1.244 + ScopeValue* owner() const { return _owner; } 1.245 + Location basic_lock() const { return _basic_lock; } 1.246 + bool eliminated() const { return _eliminated; } 1.247 + 1.248 + // Serialization of debugging information 1.249 + MonitorValue(DebugInfoReadStream* stream); 1.250 + void write_on(DebugInfoWriteStream* stream); 1.251 + 1.252 + // Printing 1.253 + void print_on(outputStream* st) const; 1.254 +}; 1.255 + 1.256 +// DebugInfoReadStream specializes CompressedReadStream for reading 1.257 +// debugging information. Used by ScopeDesc. 1.258 + 1.259 +class DebugInfoReadStream : public CompressedReadStream { 1.260 + private: 1.261 + const nmethod* _code; 1.262 + const nmethod* code() const { return _code; } 1.263 + GrowableArray<ScopeValue*>* _obj_pool; 1.264 + public: 1.265 + DebugInfoReadStream(const nmethod* code, int offset, GrowableArray<ScopeValue*>* obj_pool = NULL) : 1.266 + CompressedReadStream(code->scopes_data_begin(), offset) { 1.267 + _code = code; 1.268 + _obj_pool = obj_pool; 1.269 + 1.270 + } ; 1.271 + 1.272 + oop read_oop() { 1.273 + oop o = code()->oop_at(read_int()); 1.274 + assert(o == NULL || o->is_oop(), "oop only"); 1.275 + return o; 1.276 + } 1.277 + Method* read_method() { 1.278 + Method* o = (Method*)(code()->metadata_at(read_int())); 1.279 + // is_metadata() is a faster check than is_metaspace_object() 1.280 + assert(o == NULL || o->is_metadata(), "meta data only"); 1.281 + return o; 1.282 + } 1.283 + ScopeValue* read_object_value(); 1.284 + ScopeValue* get_cached_object(); 1.285 + // BCI encoding is mostly unsigned, but -1 is a distinguished value 1.286 + int read_bci() { return read_int() + InvocationEntryBci; } 1.287 +}; 1.288 + 1.289 +// DebugInfoWriteStream specializes CompressedWriteStream for 1.290 +// writing debugging information. Used by ScopeDescRecorder. 1.291 + 1.292 +class DebugInfoWriteStream : public CompressedWriteStream { 1.293 + private: 1.294 + DebugInformationRecorder* _recorder; 1.295 + DebugInformationRecorder* recorder() const { return _recorder; } 1.296 + public: 1.297 + DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size); 1.298 + void write_handle(jobject h); 1.299 + void write_bci(int bci) { write_int(bci - InvocationEntryBci); } 1.300 + 1.301 + void write_metadata(Metadata* m); 1.302 +}; 1.303 + 1.304 +#endif // SHARE_VM_CODE_DEBUGINFO_HPP