Fri, 28 Sep 2012 10:16:29 -0700
Merge
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/debugInfoRec.hpp" |
stefank@2314 | 27 | #include "code/pcDesc.hpp" |
stefank@2314 | 28 | #include "code/scopeDesc.hpp" |
stefank@2314 | 29 | #include "memory/resourceArea.hpp" |
stefank@2314 | 30 | #include "oops/oop.inline.hpp" |
stefank@2314 | 31 | #include "runtime/handles.inline.hpp" |
duke@435 | 32 | |
duke@435 | 33 | |
kvn@1688 | 34 | ScopeDesc::ScopeDesc(const nmethod* code, int decode_offset, int obj_decode_offset, bool reexecute, bool return_oop) { |
duke@435 | 35 | _code = code; |
duke@435 | 36 | _decode_offset = decode_offset; |
duke@435 | 37 | _objects = decode_object_values(obj_decode_offset); |
cfang@1366 | 38 | _reexecute = reexecute; |
kvn@1688 | 39 | _return_oop = return_oop; |
duke@435 | 40 | decode_body(); |
duke@435 | 41 | } |
duke@435 | 42 | |
kvn@1688 | 43 | ScopeDesc::ScopeDesc(const nmethod* code, int decode_offset, bool reexecute, bool return_oop) { |
duke@435 | 44 | _code = code; |
duke@435 | 45 | _decode_offset = decode_offset; |
duke@435 | 46 | _objects = decode_object_values(DebugInformationRecorder::serialized_null); |
cfang@1366 | 47 | _reexecute = reexecute; |
kvn@1688 | 48 | _return_oop = return_oop; |
duke@435 | 49 | decode_body(); |
duke@435 | 50 | } |
duke@435 | 51 | |
duke@435 | 52 | |
duke@435 | 53 | ScopeDesc::ScopeDesc(const ScopeDesc* parent) { |
duke@435 | 54 | _code = parent->_code; |
duke@435 | 55 | _decode_offset = parent->_sender_decode_offset; |
duke@435 | 56 | _objects = parent->_objects; |
cfang@1366 | 57 | _reexecute = false; //reexecute only applies to the first scope |
kvn@1688 | 58 | _return_oop = false; |
duke@435 | 59 | decode_body(); |
duke@435 | 60 | } |
duke@435 | 61 | |
duke@435 | 62 | |
duke@435 | 63 | void ScopeDesc::decode_body() { |
duke@435 | 64 | if (decode_offset() == DebugInformationRecorder::serialized_null) { |
duke@435 | 65 | // This is a sentinel record, which is only relevant to |
duke@435 | 66 | // approximate queries. Decode a reasonable frame. |
duke@435 | 67 | _sender_decode_offset = DebugInformationRecorder::serialized_null; |
coleenp@4037 | 68 | _method = _code->method(); |
duke@435 | 69 | _bci = InvocationEntryBci; |
duke@435 | 70 | _locals_decode_offset = DebugInformationRecorder::serialized_null; |
duke@435 | 71 | _expressions_decode_offset = DebugInformationRecorder::serialized_null; |
duke@435 | 72 | _monitors_decode_offset = DebugInformationRecorder::serialized_null; |
duke@435 | 73 | } else { |
duke@435 | 74 | // decode header |
duke@435 | 75 | DebugInfoReadStream* stream = stream_at(decode_offset()); |
duke@435 | 76 | |
duke@435 | 77 | _sender_decode_offset = stream->read_int(); |
coleenp@4037 | 78 | _method = stream->read_method(); |
cfang@1366 | 79 | _bci = stream->read_bci(); |
cfang@1335 | 80 | |
duke@435 | 81 | // decode offsets for body and sender |
duke@435 | 82 | _locals_decode_offset = stream->read_int(); |
duke@435 | 83 | _expressions_decode_offset = stream->read_int(); |
duke@435 | 84 | _monitors_decode_offset = stream->read_int(); |
duke@435 | 85 | } |
duke@435 | 86 | } |
duke@435 | 87 | |
duke@435 | 88 | |
duke@435 | 89 | GrowableArray<ScopeValue*>* ScopeDesc::decode_scope_values(int decode_offset) { |
duke@435 | 90 | if (decode_offset == DebugInformationRecorder::serialized_null) return NULL; |
duke@435 | 91 | DebugInfoReadStream* stream = stream_at(decode_offset); |
duke@435 | 92 | int length = stream->read_int(); |
duke@435 | 93 | GrowableArray<ScopeValue*>* result = new GrowableArray<ScopeValue*> (length); |
duke@435 | 94 | for (int index = 0; index < length; index++) { |
duke@435 | 95 | result->push(ScopeValue::read_from(stream)); |
duke@435 | 96 | } |
duke@435 | 97 | return result; |
duke@435 | 98 | } |
duke@435 | 99 | |
duke@435 | 100 | GrowableArray<ScopeValue*>* ScopeDesc::decode_object_values(int decode_offset) { |
duke@435 | 101 | if (decode_offset == DebugInformationRecorder::serialized_null) return NULL; |
duke@435 | 102 | GrowableArray<ScopeValue*>* result = new GrowableArray<ScopeValue*>(); |
duke@435 | 103 | DebugInfoReadStream* stream = new DebugInfoReadStream(_code, decode_offset, result); |
duke@435 | 104 | int length = stream->read_int(); |
duke@435 | 105 | for (int index = 0; index < length; index++) { |
kvn@479 | 106 | // Objects values are pushed to 'result' array during read so that |
kvn@479 | 107 | // object's fields could reference it (OBJECT_ID_CODE). |
kvn@479 | 108 | (void)ScopeValue::read_from(stream); |
duke@435 | 109 | } |
duke@435 | 110 | assert(result->length() == length, "inconsistent debug information"); |
duke@435 | 111 | return result; |
duke@435 | 112 | } |
duke@435 | 113 | |
duke@435 | 114 | |
duke@435 | 115 | GrowableArray<MonitorValue*>* ScopeDesc::decode_monitor_values(int decode_offset) { |
duke@435 | 116 | if (decode_offset == DebugInformationRecorder::serialized_null) return NULL; |
duke@435 | 117 | DebugInfoReadStream* stream = stream_at(decode_offset); |
duke@435 | 118 | int length = stream->read_int(); |
duke@435 | 119 | GrowableArray<MonitorValue*>* result = new GrowableArray<MonitorValue*> (length); |
duke@435 | 120 | for (int index = 0; index < length; index++) { |
duke@435 | 121 | result->push(new MonitorValue(stream)); |
duke@435 | 122 | } |
duke@435 | 123 | return result; |
duke@435 | 124 | } |
duke@435 | 125 | |
duke@435 | 126 | DebugInfoReadStream* ScopeDesc::stream_at(int decode_offset) const { |
duke@435 | 127 | return new DebugInfoReadStream(_code, decode_offset, _objects); |
duke@435 | 128 | } |
duke@435 | 129 | |
duke@435 | 130 | GrowableArray<ScopeValue*>* ScopeDesc::locals() { |
duke@435 | 131 | return decode_scope_values(_locals_decode_offset); |
duke@435 | 132 | } |
duke@435 | 133 | |
duke@435 | 134 | GrowableArray<ScopeValue*>* ScopeDesc::expressions() { |
duke@435 | 135 | return decode_scope_values(_expressions_decode_offset); |
duke@435 | 136 | } |
duke@435 | 137 | |
duke@435 | 138 | GrowableArray<MonitorValue*>* ScopeDesc::monitors() { |
duke@435 | 139 | return decode_monitor_values(_monitors_decode_offset); |
duke@435 | 140 | } |
duke@435 | 141 | |
duke@435 | 142 | GrowableArray<ScopeValue*>* ScopeDesc::objects() { |
duke@435 | 143 | return _objects; |
duke@435 | 144 | } |
duke@435 | 145 | |
duke@435 | 146 | bool ScopeDesc::is_top() const { |
duke@435 | 147 | return _sender_decode_offset == DebugInformationRecorder::serialized_null; |
duke@435 | 148 | } |
duke@435 | 149 | |
duke@435 | 150 | ScopeDesc* ScopeDesc::sender() const { |
duke@435 | 151 | if (is_top()) return NULL; |
duke@435 | 152 | return new ScopeDesc(this); |
duke@435 | 153 | } |
duke@435 | 154 | |
duke@435 | 155 | |
duke@435 | 156 | #ifndef PRODUCT |
duke@435 | 157 | |
duke@435 | 158 | void ScopeDesc::print_value_on(outputStream* st) const { |
duke@435 | 159 | tty->print(" "); |
coleenp@4037 | 160 | method()->print_short_name(st); |
duke@435 | 161 | int lineno = method()->line_number_from_bci(bci()); |
duke@435 | 162 | if (lineno != -1) { |
duke@435 | 163 | st->print_cr("@%d (line %d)", bci(), lineno); |
duke@435 | 164 | } else { |
duke@435 | 165 | st->print_cr("@%d", bci()); |
duke@435 | 166 | } |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | void ScopeDesc::print_on(outputStream* st) const { |
duke@435 | 170 | print_on(st, NULL); |
duke@435 | 171 | } |
duke@435 | 172 | |
duke@435 | 173 | void ScopeDesc::print_on(outputStream* st, PcDesc* pd) const { |
duke@435 | 174 | // header |
duke@435 | 175 | if (pd != NULL) { |
duke@435 | 176 | tty->print_cr("ScopeDesc(pc=" PTR_FORMAT " offset=%x):", pd->real_pc(_code), pd->pc_offset()); |
duke@435 | 177 | } |
duke@435 | 178 | |
duke@435 | 179 | print_value_on(st); |
duke@435 | 180 | // decode offsets |
duke@435 | 181 | if (WizardMode) { |
twisti@2103 | 182 | st->print("ScopeDesc[%d]@" PTR_FORMAT " ", _decode_offset, _code->content_begin()); |
duke@435 | 183 | st->print_cr(" offset: %d", _decode_offset); |
duke@435 | 184 | st->print_cr(" bci: %d", bci()); |
cfang@1335 | 185 | st->print_cr(" reexecute: %s", should_reexecute() ? "true" : "false"); |
duke@435 | 186 | st->print_cr(" locals: %d", _locals_decode_offset); |
duke@435 | 187 | st->print_cr(" stack: %d", _expressions_decode_offset); |
duke@435 | 188 | st->print_cr(" monitor: %d", _monitors_decode_offset); |
duke@435 | 189 | st->print_cr(" sender: %d", _sender_decode_offset); |
duke@435 | 190 | } |
duke@435 | 191 | // locals |
duke@435 | 192 | { GrowableArray<ScopeValue*>* l = ((ScopeDesc*) this)->locals(); |
duke@435 | 193 | if (l != NULL) { |
duke@435 | 194 | tty->print_cr(" Locals"); |
duke@435 | 195 | for (int index = 0; index < l->length(); index++) { |
duke@435 | 196 | st->print(" - l%d: ", index); |
duke@435 | 197 | l->at(index)->print_on(st); |
duke@435 | 198 | st->cr(); |
duke@435 | 199 | } |
duke@435 | 200 | } |
duke@435 | 201 | } |
duke@435 | 202 | // expressions |
duke@435 | 203 | { GrowableArray<ScopeValue*>* l = ((ScopeDesc*) this)->expressions(); |
duke@435 | 204 | if (l != NULL) { |
duke@435 | 205 | st->print_cr(" Expression stack"); |
duke@435 | 206 | for (int index = 0; index < l->length(); index++) { |
duke@435 | 207 | st->print(" - @%d: ", index); |
duke@435 | 208 | l->at(index)->print_on(st); |
duke@435 | 209 | st->cr(); |
duke@435 | 210 | } |
duke@435 | 211 | } |
duke@435 | 212 | } |
duke@435 | 213 | // monitors |
duke@435 | 214 | { GrowableArray<MonitorValue*>* l = ((ScopeDesc*) this)->monitors(); |
duke@435 | 215 | if (l != NULL) { |
duke@435 | 216 | st->print_cr(" Monitor stack"); |
duke@435 | 217 | for (int index = 0; index < l->length(); index++) { |
duke@435 | 218 | st->print(" - @%d: ", index); |
duke@435 | 219 | l->at(index)->print_on(st); |
duke@435 | 220 | st->cr(); |
duke@435 | 221 | } |
duke@435 | 222 | } |
duke@435 | 223 | } |
duke@435 | 224 | |
duke@435 | 225 | #ifdef COMPILER2 |
duke@435 | 226 | if (DoEscapeAnalysis && is_top() && _objects != NULL) { |
duke@435 | 227 | tty->print_cr("Objects"); |
duke@435 | 228 | for (int i = 0; i < _objects->length(); i++) { |
duke@435 | 229 | ObjectValue* sv = (ObjectValue*) _objects->at(i); |
duke@435 | 230 | tty->print(" - %d: ", sv->id()); |
duke@435 | 231 | sv->print_fields_on(tty); |
duke@435 | 232 | tty->cr(); |
duke@435 | 233 | } |
duke@435 | 234 | } |
duke@435 | 235 | #endif // COMPILER2 |
duke@435 | 236 | } |
duke@435 | 237 | |
duke@435 | 238 | #endif |
duke@435 | 239 | |
duke@435 | 240 | void ScopeDesc::verify() { |
duke@435 | 241 | ResourceMark rm; |
duke@435 | 242 | guarantee(method()->is_method(), "type check"); |
duke@435 | 243 | |
duke@435 | 244 | // check if we have any illegal elements on the expression stack |
duke@435 | 245 | { GrowableArray<ScopeValue*>* l = expressions(); |
duke@435 | 246 | if (l != NULL) { |
duke@435 | 247 | for (int index = 0; index < l->length(); index++) { |
duke@435 | 248 | //guarantee(!l->at(index)->is_illegal(), "expression element cannot be illegal"); |
duke@435 | 249 | } |
duke@435 | 250 | } |
duke@435 | 251 | } |
duke@435 | 252 | } |