debugInfo.cpp revision 3602:da91efe96a93
12786Ssos/* 22786Ssos * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 32786Ssos * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42786Ssos * 52786Ssos * This code is free software; you can redistribute it and/or modify it 62786Ssos * under the terms of the GNU General Public License version 2 only, as 72786Ssos * published by the Free Software Foundation. 86851Ssos * 92786Ssos * This code is distributed in the hope that it will be useful, but WITHOUT 102786Ssos * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 112786Ssos * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 122786Ssos * version 2 for more details (a copy is included in the LICENSE file that 132786Ssos * accompanied this code). 142786Ssos * 152786Ssos * You should have received a copy of the GNU General Public License version 162786Ssos * 2 along with this work; if not, write to the Free Software Foundation, 172786Ssos * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 182786Ssos * 197420Ssos * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 204686Sache * or visit www.oracle.com if you need additional information or have any 212786Ssos * questions. 222786Ssos * 232786Ssos */ 242786Ssos 252786Ssos#include "precompiled.hpp" 262786Ssos#include "code/debugInfo.hpp" 272786Ssos#include "code/debugInfoRec.hpp" 282786Ssos#include "code/nmethod.hpp" 292786Ssos#include "runtime/handles.inline.hpp" 302786Ssos 312786Ssos// Comstructors 322786Ssos 332786SsosDebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size) 342786Ssos: CompressedWriteStream(initial_size) { 352786Ssos _recorder = recorder; 362786Ssos} 372786Ssos 382786Ssos// Serializing oops 392786Ssos 402786Ssosvoid DebugInfoWriteStream::write_handle(jobject h) { 412786Ssos write_int(recorder()->oop_recorder()->find_index(h)); 422786Ssos} 432786Ssos 442786Ssosvoid DebugInfoWriteStream::write_metadata(Metadata* h) { 452786Ssos write_int(recorder()->oop_recorder()->find_index(h)); 462786Ssos} 472786Ssos 482786SsosScopeValue* DebugInfoReadStream::read_object_value() { 492786Ssos int id = read_int(); 502786Ssos#ifdef ASSERT 512786Ssos assert(_obj_pool != NULL, "object pool does not exist"); 522786Ssos for (int i = _obj_pool->length() - 1; i >= 0; i--) { 532786Ssos assert(((ObjectValue*) _obj_pool->at(i))->id() != id, "should not be read twice"); 542786Ssos } 552786Ssos#endif 562786Ssos ObjectValue* result = new ObjectValue(id); 572786Ssos // Cache the object since an object field could reference it. 582786Ssos _obj_pool->push(result); 592786Ssos result->read_object(this); 602786Ssos return result; 612786Ssos} 626851Ssos 632786SsosScopeValue* DebugInfoReadStream::get_cached_object() { 642786Ssos int id = read_int(); 652786Ssos assert(_obj_pool != NULL, "object pool does not exist"); 662786Ssos for (int i = _obj_pool->length() - 1; i >= 0; i--) { 672786Ssos ObjectValue* ov = (ObjectValue*) _obj_pool->at(i); 682786Ssos if (ov->id() == id) { 692786Ssos return ov; 702786Ssos } 712786Ssos } 722786Ssos ShouldNotReachHere(); 732786Ssos return NULL; 742786Ssos} 752786Ssos 762786Ssos// Serializing scope values 772786Ssos 782786Ssosenum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2, 792786Ssos CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4, 802786Ssos OBJECT_CODE = 5, OBJECT_ID_CODE = 6 }; 815994Ssos 822786SsosScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) { 832786Ssos ScopeValue* result = NULL; 842786Ssos switch(stream->read_int()) { 852786Ssos case LOCATION_CODE: result = new LocationValue(stream); break; 862786Ssos case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break; 872786Ssos case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break; 886045Ssos case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break; 892786Ssos case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break; 902786Ssos case OBJECT_CODE: result = stream->read_object_value(); break; 912786Ssos case OBJECT_ID_CODE: result = stream->get_cached_object(); break; 922786Ssos default: ShouldNotReachHere(); 932786Ssos } 9418194Ssos return result; 952786Ssos} 962786Ssos 972786Ssos// LocationValue 982786Ssos 992786SsosLocationValue::LocationValue(DebugInfoReadStream* stream) { 1002786Ssos _location = Location(stream); 1012786Ssos} 1022786Ssos 1032786Ssosvoid LocationValue::write_on(DebugInfoWriteStream* stream) { 1042786Ssos stream->write_int(LOCATION_CODE); 1052786Ssos location().write_on(stream); 1062786Ssos} 1072786Ssos 1086851Ssosvoid LocationValue::print_on(outputStream* st) const { 1092786Ssos location().print_on(st); 1106851Ssos} 1116851Ssos 1126851Ssos// ObjectValue 113 114void ObjectValue::read_object(DebugInfoReadStream* stream) { 115 _klass = read_from(stream); 116 assert(_klass->is_constant_oop(), "should be constant java mirror oop"); 117 int length = stream->read_int(); 118 for (int i = 0; i < length; i++) { 119 ScopeValue* val = read_from(stream); 120 _field_values.append(val); 121 } 122} 123 124void ObjectValue::write_on(DebugInfoWriteStream* stream) { 125 if (_visited) { 126 stream->write_int(OBJECT_ID_CODE); 127 stream->write_int(_id); 128 } else { 129 _visited = true; 130 stream->write_int(OBJECT_CODE); 131 stream->write_int(_id); 132 _klass->write_on(stream); 133 int length = _field_values.length(); 134 stream->write_int(length); 135 for (int i = 0; i < length; i++) { 136 _field_values.at(i)->write_on(stream); 137 } 138 } 139} 140 141void ObjectValue::print_on(outputStream* st) const { 142 st->print("obj[%d]", _id); 143} 144 145void ObjectValue::print_fields_on(outputStream* st) const { 146#ifndef PRODUCT 147 if (_field_values.length() > 0) { 148 _field_values.at(0)->print_on(st); 149 } 150 for (int i = 1; i < _field_values.length(); i++) { 151 st->print(", "); 152 _field_values.at(i)->print_on(st); 153 } 154#endif 155} 156 157// ConstantIntValue 158 159ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) { 160 _value = stream->read_signed_int(); 161} 162 163void ConstantIntValue::write_on(DebugInfoWriteStream* stream) { 164 stream->write_int(CONSTANT_INT_CODE); 165 stream->write_signed_int(value()); 166} 167 168void ConstantIntValue::print_on(outputStream* st) const { 169 st->print("%d", value()); 170} 171 172// ConstantLongValue 173 174ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) { 175 _value = stream->read_long(); 176} 177 178void ConstantLongValue::write_on(DebugInfoWriteStream* stream) { 179 stream->write_int(CONSTANT_LONG_CODE); 180 stream->write_long(value()); 181} 182 183void ConstantLongValue::print_on(outputStream* st) const { 184 st->print(INT64_FORMAT, value()); 185} 186 187// ConstantDoubleValue 188 189ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) { 190 _value = stream->read_double(); 191} 192 193void ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) { 194 stream->write_int(CONSTANT_DOUBLE_CODE); 195 stream->write_double(value()); 196} 197 198void ConstantDoubleValue::print_on(outputStream* st) const { 199 st->print("%f", value()); 200} 201 202// ConstantOopWriteValue 203 204void ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) { 205 assert(JNIHandles::resolve(value()) == NULL || 206 Universe::heap()->is_in_reserved(JNIHandles::resolve(value())), 207 "Should be in heap"); 208 stream->write_int(CONSTANT_OOP_CODE); 209 stream->write_handle(value()); 210} 211 212void ConstantOopWriteValue::print_on(outputStream* st) const { 213 JNIHandles::resolve(value())->print_value_on(st); 214} 215 216 217// ConstantOopReadValue 218 219ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) { 220 _value = Handle(stream->read_oop()); 221 assert(_value() == NULL || 222 Universe::heap()->is_in_reserved(_value()), "Should be in heap"); 223} 224 225void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) { 226 ShouldNotReachHere(); 227} 228 229void ConstantOopReadValue::print_on(outputStream* st) const { 230 value()()->print_value_on(st); 231} 232 233 234// MonitorValue 235 236MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) { 237 _owner = owner; 238 _basic_lock = basic_lock; 239 _eliminated = eliminated; 240} 241 242MonitorValue::MonitorValue(DebugInfoReadStream* stream) { 243 _basic_lock = Location(stream); 244 _owner = ScopeValue::read_from(stream); 245 _eliminated = (stream->read_bool() != 0); 246} 247 248void MonitorValue::write_on(DebugInfoWriteStream* stream) { 249 _basic_lock.write_on(stream); 250 _owner->write_on(stream); 251 stream->write_bool(_eliminated); 252} 253 254#ifndef PRODUCT 255void MonitorValue::print_on(outputStream* st) const { 256 st->print("monitor{"); 257 owner()->print_on(st); 258 st->print(","); 259 basic_lock().print_on(st); 260 st->print("}"); 261 if (_eliminated) { 262 st->print(" (eliminated)"); 263 } 264} 265#endif 266