src/share/vm/code/scopeDesc.cpp

Wed, 02 Jun 2010 22:45:42 -0700

author
jrose
date
Wed, 02 Jun 2010 22:45:42 -0700
changeset 1934
e9ff18c4ace7
parent 1907
c18cbe5936b8
child 2103
3e8fbc61cee8
permissions
-rw-r--r--

Merge

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

mercurial