1 /* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_CODE_DEBUGINFO_HPP 26 #define SHARE_VM_CODE_DEBUGINFO_HPP 27 28 #include "code/compressedStream.hpp" 29 #include "code/location.hpp" 30 #include "code/nmethod.hpp" 31 #include "code/oopRecorder.hpp" 32 #include "runtime/stackValue.hpp" 33 #include "utilities/growableArray.hpp" 34 35 // Classes used for serializing debugging information. 36 // These abstractions are introducted to provide symmetric 37 // read and write operations. 38 39 // ScopeValue describes the value of a variable/expression in a scope 40 // - LocationValue describes a value in a given location (in frame or register) 41 // - ConstantValue describes a constant 42 43 class ConstantOopReadValue; 44 class ObjectValue; 45 46 class ScopeValue: public ResourceObj { 47 public: 48 // Testers 49 virtual bool is_location() const { return false; } 50 virtual bool is_object() const { return false; } 51 virtual bool is_constant_int() const { return false; } 52 virtual bool is_constant_double() const { return false; } 53 virtual bool is_constant_long() const { return false; } 54 virtual bool is_constant_oop() const { return false; } 55 virtual bool equals(ScopeValue* other) const { return false; } 56 57 ConstantOopReadValue* as_ConstantOopReadValue() { 58 assert(is_constant_oop(), "must be"); 59 return (ConstantOopReadValue*) this; 60 } 61 62 ObjectValue* as_ObjectValue() { 63 assert(is_object(), "must be"); 64 return (ObjectValue*)this; 65 } 66 67 // Serialization of debugging information 68 virtual void write_on(DebugInfoWriteStream* stream) = 0; 69 static ScopeValue* read_from(DebugInfoReadStream* stream); 70 }; 71 72 73 // A Location value describes a value in a given location; i.e. the corresponding 74 // logical entity (e.g., a method temporary) lives in this location. 75 76 class LocationValue: public ScopeValue { 77 private: 78 Location _location; 79 public: 80 LocationValue(Location location) { _location = location; } 81 bool is_location() const { return true; } 82 Location location() const { return _location; } 83 84 // Serialization of debugging information 85 LocationValue(DebugInfoReadStream* stream); 86 void write_on(DebugInfoWriteStream* stream); 87 88 // Printing 89 void print_on(outputStream* st) const; 90 }; 91 92 93 // An ObjectValue describes an object eliminated by escape analysis. 94 95 class ObjectValue: public ScopeValue { 96 private: 97 int _id; 98 ScopeValue* _klass; 99 GrowableArray<ScopeValue*> _field_values; 100 Handle _value; 101 bool _visited; 102 103 public: 104 ObjectValue(int id, ScopeValue* klass) 105 : _id(id) 106 , _klass(klass) 107 , _field_values() 108 , _value() 109 , _visited(false) { 110 assert(klass->is_constant_oop(), "should be constant java mirror oop"); 111 } 112 113 ObjectValue(int id) 114 : _id(id) 115 , _klass(NULL) 116 , _field_values() 117 , _value() 118 , _visited(false) {} 119 120 // Accessors 121 bool is_object() const { return true; } 122 int id() const { return _id; } 123 ScopeValue* klass() const { return _klass; } 124 GrowableArray<ScopeValue*>* field_values() { return &_field_values; } 125 ScopeValue* field_at(int i) const { return _field_values.at(i); } 126 int field_size() { return _field_values.length(); } 127 Handle value() const { return _value; } 128 bool is_visited() const { return _visited; } 129 130 void set_value(oop value) { _value = Handle(value); } 131 void set_visited(bool visited) { _visited = false; } 132 133 // Serialization of debugging information 134 void read_object(DebugInfoReadStream* stream); 135 void write_on(DebugInfoWriteStream* stream); 136 137 // Printing 138 void print_on(outputStream* st) const; 139 void print_fields_on(outputStream* st) const; 140 }; 141 142 143 // A ConstantIntValue describes a constant int; i.e., the corresponding logical entity 144 // is either a source constant or its computation has been constant-folded. 145 146 class ConstantIntValue: public ScopeValue { 147 private: 148 jint _value; 149 public: 150 ConstantIntValue(jint value) { _value = value; } 151 jint value() const { return _value; } 152 bool is_constant_int() const { return true; } 153 bool equals(ScopeValue* other) const { return false; } 154 155 // Serialization of debugging information 156 ConstantIntValue(DebugInfoReadStream* stream); 157 void write_on(DebugInfoWriteStream* stream); 158 159 // Printing 160 void print_on(outputStream* st) const; 161 }; 162 163 class ConstantLongValue: public ScopeValue { 164 private: 165 jlong _value; 166 public: 167 ConstantLongValue(jlong value) { _value = value; } 168 jlong value() const { return _value; } 169 bool is_constant_long() const { return true; } 170 bool equals(ScopeValue* other) const { return false; } 171 172 // Serialization of debugging information 173 ConstantLongValue(DebugInfoReadStream* stream); 174 void write_on(DebugInfoWriteStream* stream); 175 176 // Printing 177 void print_on(outputStream* st) const; 178 }; 179 180 class ConstantDoubleValue: public ScopeValue { 181 private: 182 jdouble _value; 183 public: 184 ConstantDoubleValue(jdouble value) { _value = value; } 185 jdouble value() const { return _value; } 186 bool is_constant_double() const { return true; } 187 bool equals(ScopeValue* other) const { return false; } 188 189 // Serialization of debugging information 190 ConstantDoubleValue(DebugInfoReadStream* stream); 191 void write_on(DebugInfoWriteStream* stream); 192 193 // Printing 194 void print_on(outputStream* st) const; 195 }; 196 197 // A ConstantOopWriteValue is created by the compiler to 198 // be written as debugging information. 199 200 class ConstantOopWriteValue: public ScopeValue { 201 private: 202 jobject _value; 203 public: 204 ConstantOopWriteValue(jobject value) { _value = value; } 205 jobject value() const { return _value; } 206 bool is_constant_oop() const { return true; } 207 bool equals(ScopeValue* other) const { return false; } 208 209 // Serialization of debugging information 210 void write_on(DebugInfoWriteStream* stream); 211 212 // Printing 213 void print_on(outputStream* st) const; 214 }; 215 216 // A ConstantOopReadValue is created by the VM when reading 217 // debug information 218 219 class ConstantOopReadValue: public ScopeValue { 220 private: 221 Handle _value; 222 public: 223 Handle value() const { return _value; } 224 bool is_constant_oop() const { return true; } 225 bool equals(ScopeValue* other) const { return false; } 226 227 // Serialization of debugging information 228 ConstantOopReadValue(DebugInfoReadStream* stream); 229 void write_on(DebugInfoWriteStream* stream); 230 231 // Printing 232 void print_on(outputStream* st) const; 233 }; 234 235 // MonitorValue describes the pair used for monitor_enter and monitor_exit. 236 237 class MonitorValue: public ResourceObj { 238 private: 239 ScopeValue* _owner; 240 Location _basic_lock; 241 bool _eliminated; 242 public: 243 // Constructor 244 MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated = false); 245 246 // Accessors 247 ScopeValue* owner() const { return _owner; } 248 Location basic_lock() const { return _basic_lock; } 249 bool eliminated() const { return _eliminated; } 250 251 // Serialization of debugging information 252 MonitorValue(DebugInfoReadStream* stream); 253 void write_on(DebugInfoWriteStream* stream); 254 255 // Printing 256 void print_on(outputStream* st) const; 257 }; 258 259 // DebugInfoReadStream specializes CompressedReadStream for reading 260 // debugging information. Used by ScopeDesc. 261 262 class DebugInfoReadStream : public CompressedReadStream { 263 private: 264 const nmethod* _code; 265 const nmethod* code() const { return _code; } 266 GrowableArray<ScopeValue*>* _obj_pool; 267 public: 268 DebugInfoReadStream(const nmethod* code, int offset, GrowableArray<ScopeValue*>* obj_pool = NULL) : 269 CompressedReadStream(code->scopes_data_begin(), offset) { 270 _code = code; 271 _obj_pool = obj_pool; 272 273 } ; 274 275 oop read_oop(); 276 Method* read_method() { 277 Method* o = (Method*)(code()->metadata_at(read_int())); 278 // is_metadata() is a faster check than is_metaspace_object() 279 assert(o == NULL || o->is_metadata(), "meta data only"); 280 return o; 281 } 282 ScopeValue* read_object_value(); 283 ScopeValue* get_cached_object(); 284 // BCI encoding is mostly unsigned, but -1 is a distinguished value 285 int read_bci() { return read_int() + InvocationEntryBci; } 286 }; 287 288 // DebugInfoWriteStream specializes CompressedWriteStream for 289 // writing debugging information. Used by ScopeDescRecorder. 290 291 class DebugInfoWriteStream : public CompressedWriteStream { 292 private: 293 DebugInformationRecorder* _recorder; 294 DebugInformationRecorder* recorder() const { return _recorder; } 295 public: 296 DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size); 297 void write_handle(jobject h); 298 void write_bci(int bci) { write_int(bci - InvocationEntryBci); } 299 300 void write_metadata(Metadata* m); 301 }; 302 303 #endif // SHARE_VM_CODE_DEBUGINFO_HPP