src/share/vm/code/debugInfo.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "code/debugInfo.hpp"
aoqi@0 27 #include "code/debugInfoRec.hpp"
aoqi@0 28 #include "code/nmethod.hpp"
aoqi@0 29 #include "runtime/handles.inline.hpp"
aoqi@0 30
aoqi@0 31 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 32
aoqi@0 33 // Constructors
aoqi@0 34
aoqi@0 35 DebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size)
aoqi@0 36 : CompressedWriteStream(initial_size) {
aoqi@0 37 _recorder = recorder;
aoqi@0 38 }
aoqi@0 39
aoqi@0 40 // Serializing oops
aoqi@0 41
aoqi@0 42 void DebugInfoWriteStream::write_handle(jobject h) {
aoqi@0 43 write_int(recorder()->oop_recorder()->find_index(h));
aoqi@0 44 }
aoqi@0 45
aoqi@0 46 void DebugInfoWriteStream::write_metadata(Metadata* h) {
aoqi@0 47 write_int(recorder()->oop_recorder()->find_index(h));
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 ScopeValue* DebugInfoReadStream::read_object_value() {
aoqi@0 51 int id = read_int();
aoqi@0 52 #ifdef ASSERT
aoqi@0 53 assert(_obj_pool != NULL, "object pool does not exist");
aoqi@0 54 for (int i = _obj_pool->length() - 1; i >= 0; i--) {
aoqi@0 55 assert(((ObjectValue*) _obj_pool->at(i))->id() != id, "should not be read twice");
aoqi@0 56 }
aoqi@0 57 #endif
aoqi@0 58 ObjectValue* result = new ObjectValue(id);
aoqi@0 59 // Cache the object since an object field could reference it.
aoqi@0 60 _obj_pool->push(result);
aoqi@0 61 result->read_object(this);
aoqi@0 62 return result;
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 ScopeValue* DebugInfoReadStream::get_cached_object() {
aoqi@0 66 int id = read_int();
aoqi@0 67 assert(_obj_pool != NULL, "object pool does not exist");
aoqi@0 68 for (int i = _obj_pool->length() - 1; i >= 0; i--) {
aoqi@0 69 ObjectValue* ov = (ObjectValue*) _obj_pool->at(i);
aoqi@0 70 if (ov->id() == id) {
aoqi@0 71 return ov;
aoqi@0 72 }
aoqi@0 73 }
aoqi@0 74 ShouldNotReachHere();
aoqi@0 75 return NULL;
aoqi@0 76 }
aoqi@0 77
aoqi@0 78 // Serializing scope values
aoqi@0 79
aoqi@0 80 enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,
aoqi@0 81 CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
aoqi@0 82 OBJECT_CODE = 5, OBJECT_ID_CODE = 6 };
aoqi@0 83
aoqi@0 84 ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
aoqi@0 85 ScopeValue* result = NULL;
aoqi@0 86 switch(stream->read_int()) {
aoqi@0 87 case LOCATION_CODE: result = new LocationValue(stream); break;
aoqi@0 88 case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break;
aoqi@0 89 case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break;
aoqi@0 90 case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break;
aoqi@0 91 case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break;
aoqi@0 92 case OBJECT_CODE: result = stream->read_object_value(); break;
aoqi@0 93 case OBJECT_ID_CODE: result = stream->get_cached_object(); break;
aoqi@0 94 default: ShouldNotReachHere();
aoqi@0 95 }
aoqi@0 96 return result;
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 // LocationValue
aoqi@0 100
aoqi@0 101 LocationValue::LocationValue(DebugInfoReadStream* stream) {
aoqi@0 102 _location = Location(stream);
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 void LocationValue::write_on(DebugInfoWriteStream* stream) {
aoqi@0 106 stream->write_int(LOCATION_CODE);
aoqi@0 107 location().write_on(stream);
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 void LocationValue::print_on(outputStream* st) const {
aoqi@0 111 location().print_on(st);
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 // ObjectValue
aoqi@0 115
aoqi@0 116 void ObjectValue::read_object(DebugInfoReadStream* stream) {
aoqi@0 117 _klass = read_from(stream);
aoqi@0 118 assert(_klass->is_constant_oop(), "should be constant java mirror oop");
aoqi@0 119 int length = stream->read_int();
aoqi@0 120 for (int i = 0; i < length; i++) {
aoqi@0 121 ScopeValue* val = read_from(stream);
aoqi@0 122 _field_values.append(val);
aoqi@0 123 }
aoqi@0 124 }
aoqi@0 125
aoqi@0 126 void ObjectValue::write_on(DebugInfoWriteStream* stream) {
aoqi@0 127 if (_visited) {
aoqi@0 128 stream->write_int(OBJECT_ID_CODE);
aoqi@0 129 stream->write_int(_id);
aoqi@0 130 } else {
aoqi@0 131 _visited = true;
aoqi@0 132 stream->write_int(OBJECT_CODE);
aoqi@0 133 stream->write_int(_id);
aoqi@0 134 _klass->write_on(stream);
aoqi@0 135 int length = _field_values.length();
aoqi@0 136 stream->write_int(length);
aoqi@0 137 for (int i = 0; i < length; i++) {
aoqi@0 138 _field_values.at(i)->write_on(stream);
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 }
aoqi@0 142
aoqi@0 143 void ObjectValue::print_on(outputStream* st) const {
aoqi@0 144 st->print("obj[%d]", _id);
aoqi@0 145 }
aoqi@0 146
aoqi@0 147 void ObjectValue::print_fields_on(outputStream* st) const {
aoqi@0 148 #ifndef PRODUCT
aoqi@0 149 if (_field_values.length() > 0) {
aoqi@0 150 _field_values.at(0)->print_on(st);
aoqi@0 151 }
aoqi@0 152 for (int i = 1; i < _field_values.length(); i++) {
aoqi@0 153 st->print(", ");
aoqi@0 154 _field_values.at(i)->print_on(st);
aoqi@0 155 }
aoqi@0 156 #endif
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 // ConstantIntValue
aoqi@0 160
aoqi@0 161 ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
aoqi@0 162 _value = stream->read_signed_int();
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 void ConstantIntValue::write_on(DebugInfoWriteStream* stream) {
aoqi@0 166 stream->write_int(CONSTANT_INT_CODE);
aoqi@0 167 stream->write_signed_int(value());
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 void ConstantIntValue::print_on(outputStream* st) const {
aoqi@0 171 st->print("%d", value());
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 // ConstantLongValue
aoqi@0 175
aoqi@0 176 ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {
aoqi@0 177 _value = stream->read_long();
aoqi@0 178 }
aoqi@0 179
aoqi@0 180 void ConstantLongValue::write_on(DebugInfoWriteStream* stream) {
aoqi@0 181 stream->write_int(CONSTANT_LONG_CODE);
aoqi@0 182 stream->write_long(value());
aoqi@0 183 }
aoqi@0 184
aoqi@0 185 void ConstantLongValue::print_on(outputStream* st) const {
aoqi@0 186 st->print(INT64_FORMAT, value());
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 // ConstantDoubleValue
aoqi@0 190
aoqi@0 191 ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) {
aoqi@0 192 _value = stream->read_double();
aoqi@0 193 }
aoqi@0 194
aoqi@0 195 void ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) {
aoqi@0 196 stream->write_int(CONSTANT_DOUBLE_CODE);
aoqi@0 197 stream->write_double(value());
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 void ConstantDoubleValue::print_on(outputStream* st) const {
aoqi@0 201 st->print("%f", value());
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 // ConstantOopWriteValue
aoqi@0 205
aoqi@0 206 void ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) {
aoqi@0 207 assert(JNIHandles::resolve(value()) == NULL ||
aoqi@0 208 Universe::heap()->is_in_reserved(JNIHandles::resolve(value())),
aoqi@0 209 "Should be in heap");
aoqi@0 210 stream->write_int(CONSTANT_OOP_CODE);
aoqi@0 211 stream->write_handle(value());
aoqi@0 212 }
aoqi@0 213
aoqi@0 214 void ConstantOopWriteValue::print_on(outputStream* st) const {
aoqi@0 215 JNIHandles::resolve(value())->print_value_on(st);
aoqi@0 216 }
aoqi@0 217
aoqi@0 218
aoqi@0 219 // ConstantOopReadValue
aoqi@0 220
aoqi@0 221 ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {
aoqi@0 222 _value = Handle(stream->read_oop());
aoqi@0 223 assert(_value() == NULL ||
aoqi@0 224 Universe::heap()->is_in_reserved(_value()), "Should be in heap");
aoqi@0 225 }
aoqi@0 226
aoqi@0 227 void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {
aoqi@0 228 ShouldNotReachHere();
aoqi@0 229 }
aoqi@0 230
aoqi@0 231 void ConstantOopReadValue::print_on(outputStream* st) const {
aoqi@0 232 value()()->print_value_on(st);
aoqi@0 233 }
aoqi@0 234
aoqi@0 235
aoqi@0 236 // MonitorValue
aoqi@0 237
aoqi@0 238 MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) {
aoqi@0 239 _owner = owner;
aoqi@0 240 _basic_lock = basic_lock;
aoqi@0 241 _eliminated = eliminated;
aoqi@0 242 }
aoqi@0 243
aoqi@0 244 MonitorValue::MonitorValue(DebugInfoReadStream* stream) {
aoqi@0 245 _basic_lock = Location(stream);
aoqi@0 246 _owner = ScopeValue::read_from(stream);
aoqi@0 247 _eliminated = (stream->read_bool() != 0);
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 void MonitorValue::write_on(DebugInfoWriteStream* stream) {
aoqi@0 251 _basic_lock.write_on(stream);
aoqi@0 252 _owner->write_on(stream);
aoqi@0 253 stream->write_bool(_eliminated);
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 #ifndef PRODUCT
aoqi@0 257 void MonitorValue::print_on(outputStream* st) const {
aoqi@0 258 st->print("monitor{");
aoqi@0 259 owner()->print_on(st);
aoqi@0 260 st->print(",");
aoqi@0 261 basic_lock().print_on(st);
aoqi@0 262 st->print("}");
aoqi@0 263 if (_eliminated) {
aoqi@0 264 st->print(" (eliminated)");
aoqi@0 265 }
aoqi@0 266 }
aoqi@0 267 #endif

mercurial