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