src/share/vm/code/scopeDesc.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 479
52fed2ec0afb
permissions
-rw-r--r--

Initial load

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

mercurial