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