1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/code/debugInfo.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,267 @@ 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 +#include "precompiled.hpp" 1.29 +#include "code/debugInfo.hpp" 1.30 +#include "code/debugInfoRec.hpp" 1.31 +#include "code/nmethod.hpp" 1.32 +#include "runtime/handles.inline.hpp" 1.33 + 1.34 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 1.35 + 1.36 +// Constructors 1.37 + 1.38 +DebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size) 1.39 +: CompressedWriteStream(initial_size) { 1.40 + _recorder = recorder; 1.41 +} 1.42 + 1.43 +// Serializing oops 1.44 + 1.45 +void DebugInfoWriteStream::write_handle(jobject h) { 1.46 + write_int(recorder()->oop_recorder()->find_index(h)); 1.47 +} 1.48 + 1.49 +void DebugInfoWriteStream::write_metadata(Metadata* h) { 1.50 + write_int(recorder()->oop_recorder()->find_index(h)); 1.51 +} 1.52 + 1.53 +ScopeValue* DebugInfoReadStream::read_object_value() { 1.54 + int id = read_int(); 1.55 +#ifdef ASSERT 1.56 + assert(_obj_pool != NULL, "object pool does not exist"); 1.57 + for (int i = _obj_pool->length() - 1; i >= 0; i--) { 1.58 + assert(((ObjectValue*) _obj_pool->at(i))->id() != id, "should not be read twice"); 1.59 + } 1.60 +#endif 1.61 + ObjectValue* result = new ObjectValue(id); 1.62 + // Cache the object since an object field could reference it. 1.63 + _obj_pool->push(result); 1.64 + result->read_object(this); 1.65 + return result; 1.66 +} 1.67 + 1.68 +ScopeValue* DebugInfoReadStream::get_cached_object() { 1.69 + int id = read_int(); 1.70 + assert(_obj_pool != NULL, "object pool does not exist"); 1.71 + for (int i = _obj_pool->length() - 1; i >= 0; i--) { 1.72 + ObjectValue* ov = (ObjectValue*) _obj_pool->at(i); 1.73 + if (ov->id() == id) { 1.74 + return ov; 1.75 + } 1.76 + } 1.77 + ShouldNotReachHere(); 1.78 + return NULL; 1.79 +} 1.80 + 1.81 +// Serializing scope values 1.82 + 1.83 +enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2, 1.84 + CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4, 1.85 + OBJECT_CODE = 5, OBJECT_ID_CODE = 6 }; 1.86 + 1.87 +ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) { 1.88 + ScopeValue* result = NULL; 1.89 + switch(stream->read_int()) { 1.90 + case LOCATION_CODE: result = new LocationValue(stream); break; 1.91 + case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break; 1.92 + case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break; 1.93 + case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break; 1.94 + case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break; 1.95 + case OBJECT_CODE: result = stream->read_object_value(); break; 1.96 + case OBJECT_ID_CODE: result = stream->get_cached_object(); break; 1.97 + default: ShouldNotReachHere(); 1.98 + } 1.99 + return result; 1.100 +} 1.101 + 1.102 +// LocationValue 1.103 + 1.104 +LocationValue::LocationValue(DebugInfoReadStream* stream) { 1.105 + _location = Location(stream); 1.106 +} 1.107 + 1.108 +void LocationValue::write_on(DebugInfoWriteStream* stream) { 1.109 + stream->write_int(LOCATION_CODE); 1.110 + location().write_on(stream); 1.111 +} 1.112 + 1.113 +void LocationValue::print_on(outputStream* st) const { 1.114 + location().print_on(st); 1.115 +} 1.116 + 1.117 +// ObjectValue 1.118 + 1.119 +void ObjectValue::read_object(DebugInfoReadStream* stream) { 1.120 + _klass = read_from(stream); 1.121 + assert(_klass->is_constant_oop(), "should be constant java mirror oop"); 1.122 + int length = stream->read_int(); 1.123 + for (int i = 0; i < length; i++) { 1.124 + ScopeValue* val = read_from(stream); 1.125 + _field_values.append(val); 1.126 + } 1.127 +} 1.128 + 1.129 +void ObjectValue::write_on(DebugInfoWriteStream* stream) { 1.130 + if (_visited) { 1.131 + stream->write_int(OBJECT_ID_CODE); 1.132 + stream->write_int(_id); 1.133 + } else { 1.134 + _visited = true; 1.135 + stream->write_int(OBJECT_CODE); 1.136 + stream->write_int(_id); 1.137 + _klass->write_on(stream); 1.138 + int length = _field_values.length(); 1.139 + stream->write_int(length); 1.140 + for (int i = 0; i < length; i++) { 1.141 + _field_values.at(i)->write_on(stream); 1.142 + } 1.143 + } 1.144 +} 1.145 + 1.146 +void ObjectValue::print_on(outputStream* st) const { 1.147 + st->print("obj[%d]", _id); 1.148 +} 1.149 + 1.150 +void ObjectValue::print_fields_on(outputStream* st) const { 1.151 +#ifndef PRODUCT 1.152 + if (_field_values.length() > 0) { 1.153 + _field_values.at(0)->print_on(st); 1.154 + } 1.155 + for (int i = 1; i < _field_values.length(); i++) { 1.156 + st->print(", "); 1.157 + _field_values.at(i)->print_on(st); 1.158 + } 1.159 +#endif 1.160 +} 1.161 + 1.162 +// ConstantIntValue 1.163 + 1.164 +ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) { 1.165 + _value = stream->read_signed_int(); 1.166 +} 1.167 + 1.168 +void ConstantIntValue::write_on(DebugInfoWriteStream* stream) { 1.169 + stream->write_int(CONSTANT_INT_CODE); 1.170 + stream->write_signed_int(value()); 1.171 +} 1.172 + 1.173 +void ConstantIntValue::print_on(outputStream* st) const { 1.174 + st->print("%d", value()); 1.175 +} 1.176 + 1.177 +// ConstantLongValue 1.178 + 1.179 +ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) { 1.180 + _value = stream->read_long(); 1.181 +} 1.182 + 1.183 +void ConstantLongValue::write_on(DebugInfoWriteStream* stream) { 1.184 + stream->write_int(CONSTANT_LONG_CODE); 1.185 + stream->write_long(value()); 1.186 +} 1.187 + 1.188 +void ConstantLongValue::print_on(outputStream* st) const { 1.189 + st->print(INT64_FORMAT, value()); 1.190 +} 1.191 + 1.192 +// ConstantDoubleValue 1.193 + 1.194 +ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) { 1.195 + _value = stream->read_double(); 1.196 +} 1.197 + 1.198 +void ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) { 1.199 + stream->write_int(CONSTANT_DOUBLE_CODE); 1.200 + stream->write_double(value()); 1.201 +} 1.202 + 1.203 +void ConstantDoubleValue::print_on(outputStream* st) const { 1.204 + st->print("%f", value()); 1.205 +} 1.206 + 1.207 +// ConstantOopWriteValue 1.208 + 1.209 +void ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) { 1.210 + assert(JNIHandles::resolve(value()) == NULL || 1.211 + Universe::heap()->is_in_reserved(JNIHandles::resolve(value())), 1.212 + "Should be in heap"); 1.213 + stream->write_int(CONSTANT_OOP_CODE); 1.214 + stream->write_handle(value()); 1.215 +} 1.216 + 1.217 +void ConstantOopWriteValue::print_on(outputStream* st) const { 1.218 + JNIHandles::resolve(value())->print_value_on(st); 1.219 +} 1.220 + 1.221 + 1.222 +// ConstantOopReadValue 1.223 + 1.224 +ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) { 1.225 + _value = Handle(stream->read_oop()); 1.226 + assert(_value() == NULL || 1.227 + Universe::heap()->is_in_reserved(_value()), "Should be in heap"); 1.228 +} 1.229 + 1.230 +void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) { 1.231 + ShouldNotReachHere(); 1.232 +} 1.233 + 1.234 +void ConstantOopReadValue::print_on(outputStream* st) const { 1.235 + value()()->print_value_on(st); 1.236 +} 1.237 + 1.238 + 1.239 +// MonitorValue 1.240 + 1.241 +MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) { 1.242 + _owner = owner; 1.243 + _basic_lock = basic_lock; 1.244 + _eliminated = eliminated; 1.245 +} 1.246 + 1.247 +MonitorValue::MonitorValue(DebugInfoReadStream* stream) { 1.248 + _basic_lock = Location(stream); 1.249 + _owner = ScopeValue::read_from(stream); 1.250 + _eliminated = (stream->read_bool() != 0); 1.251 +} 1.252 + 1.253 +void MonitorValue::write_on(DebugInfoWriteStream* stream) { 1.254 + _basic_lock.write_on(stream); 1.255 + _owner->write_on(stream); 1.256 + stream->write_bool(_eliminated); 1.257 +} 1.258 + 1.259 +#ifndef PRODUCT 1.260 +void MonitorValue::print_on(outputStream* st) const { 1.261 + st->print("monitor{"); 1.262 + owner()->print_on(st); 1.263 + st->print(","); 1.264 + basic_lock().print_on(st); 1.265 + st->print("}"); 1.266 + if (_eliminated) { 1.267 + st->print(" (eliminated)"); 1.268 + } 1.269 +} 1.270 +#endif