src/share/vm/code/scopeDesc.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

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

mercurial