1
|
1 |
/*
|
|
2 |
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
# include "incls/_precompiled.incl"
|
|
26 |
# include "incls/_scopeDesc.cpp.incl"
|
|
27 |
|
|
28 |
|
|
29 |
ScopeDesc::ScopeDesc(const nmethod* code, int decode_offset, int obj_decode_offset) {
|
|
30 |
_code = code;
|
|
31 |
_decode_offset = decode_offset;
|
|
32 |
_objects = decode_object_values(obj_decode_offset);
|
|
33 |
decode_body();
|
|
34 |
}
|
|
35 |
|
|
36 |
ScopeDesc::ScopeDesc(const nmethod* code, int decode_offset) {
|
|
37 |
_code = code;
|
|
38 |
_decode_offset = decode_offset;
|
|
39 |
_objects = decode_object_values(DebugInformationRecorder::serialized_null);
|
|
40 |
decode_body();
|
|
41 |
}
|
|
42 |
|
|
43 |
|
|
44 |
ScopeDesc::ScopeDesc(const ScopeDesc* parent) {
|
|
45 |
_code = parent->_code;
|
|
46 |
_decode_offset = parent->_sender_decode_offset;
|
|
47 |
_objects = parent->_objects;
|
|
48 |
decode_body();
|
|
49 |
}
|
|
50 |
|
|
51 |
|
|
52 |
void ScopeDesc::decode_body() {
|
|
53 |
if (decode_offset() == DebugInformationRecorder::serialized_null) {
|
|
54 |
// This is a sentinel record, which is only relevant to
|
|
55 |
// approximate queries. Decode a reasonable frame.
|
|
56 |
_sender_decode_offset = DebugInformationRecorder::serialized_null;
|
|
57 |
_method = methodHandle(_code->method());
|
|
58 |
_bci = InvocationEntryBci;
|
|
59 |
_locals_decode_offset = DebugInformationRecorder::serialized_null;
|
|
60 |
_expressions_decode_offset = DebugInformationRecorder::serialized_null;
|
|
61 |
_monitors_decode_offset = DebugInformationRecorder::serialized_null;
|
|
62 |
} else {
|
|
63 |
// decode header
|
|
64 |
DebugInfoReadStream* stream = stream_at(decode_offset());
|
|
65 |
|
|
66 |
_sender_decode_offset = stream->read_int();
|
|
67 |
_method = methodHandle((methodOop) stream->read_oop());
|
|
68 |
_bci = stream->read_bci();
|
|
69 |
// decode offsets for body and sender
|
|
70 |
_locals_decode_offset = stream->read_int();
|
|
71 |
_expressions_decode_offset = stream->read_int();
|
|
72 |
_monitors_decode_offset = stream->read_int();
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
|
|
77 |
GrowableArray<ScopeValue*>* ScopeDesc::decode_scope_values(int decode_offset) {
|
|
78 |
if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;
|
|
79 |
DebugInfoReadStream* stream = stream_at(decode_offset);
|
|
80 |
int length = stream->read_int();
|
|
81 |
GrowableArray<ScopeValue*>* result = new GrowableArray<ScopeValue*> (length);
|
|
82 |
for (int index = 0; index < length; index++) {
|
|
83 |
result->push(ScopeValue::read_from(stream));
|
|
84 |
}
|
|
85 |
return result;
|
|
86 |
}
|
|
87 |
|
|
88 |
GrowableArray<ScopeValue*>* ScopeDesc::decode_object_values(int decode_offset) {
|
|
89 |
if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;
|
|
90 |
GrowableArray<ScopeValue*>* result = new GrowableArray<ScopeValue*>();
|
|
91 |
DebugInfoReadStream* stream = new DebugInfoReadStream(_code, decode_offset, result);
|
|
92 |
int length = stream->read_int();
|
|
93 |
for (int index = 0; index < length; index++) {
|
|
94 |
result->push(ScopeValue::read_from(stream));
|
|
95 |
}
|
|
96 |
assert(result->length() == length, "inconsistent debug information");
|
|
97 |
return result;
|
|
98 |
}
|
|
99 |
|
|
100 |
|
|
101 |
GrowableArray<MonitorValue*>* ScopeDesc::decode_monitor_values(int decode_offset) {
|
|
102 |
if (decode_offset == DebugInformationRecorder::serialized_null) return NULL;
|
|
103 |
DebugInfoReadStream* stream = stream_at(decode_offset);
|
|
104 |
int length = stream->read_int();
|
|
105 |
GrowableArray<MonitorValue*>* result = new GrowableArray<MonitorValue*> (length);
|
|
106 |
for (int index = 0; index < length; index++) {
|
|
107 |
result->push(new MonitorValue(stream));
|
|
108 |
}
|
|
109 |
return result;
|
|
110 |
}
|
|
111 |
|
|
112 |
DebugInfoReadStream* ScopeDesc::stream_at(int decode_offset) const {
|
|
113 |
return new DebugInfoReadStream(_code, decode_offset, _objects);
|
|
114 |
}
|
|
115 |
|
|
116 |
GrowableArray<ScopeValue*>* ScopeDesc::locals() {
|
|
117 |
return decode_scope_values(_locals_decode_offset);
|
|
118 |
}
|
|
119 |
|
|
120 |
GrowableArray<ScopeValue*>* ScopeDesc::expressions() {
|
|
121 |
return decode_scope_values(_expressions_decode_offset);
|
|
122 |
}
|
|
123 |
|
|
124 |
GrowableArray<MonitorValue*>* ScopeDesc::monitors() {
|
|
125 |
return decode_monitor_values(_monitors_decode_offset);
|
|
126 |
}
|
|
127 |
|
|
128 |
GrowableArray<ScopeValue*>* ScopeDesc::objects() {
|
|
129 |
return _objects;
|
|
130 |
}
|
|
131 |
|
|
132 |
bool ScopeDesc::is_top() const {
|
|
133 |
return _sender_decode_offset == DebugInformationRecorder::serialized_null;
|
|
134 |
}
|
|
135 |
|
|
136 |
ScopeDesc* ScopeDesc::sender() const {
|
|
137 |
if (is_top()) return NULL;
|
|
138 |
return new ScopeDesc(this);
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
#ifndef PRODUCT
|
|
143 |
|
|
144 |
void ScopeDesc::print_value_on(outputStream* st) const {
|
|
145 |
tty->print(" ");
|
|
146 |
method()()->print_short_name(st);
|
|
147 |
int lineno = method()->line_number_from_bci(bci());
|
|
148 |
if (lineno != -1) {
|
|
149 |
st->print_cr("@%d (line %d)", bci(), lineno);
|
|
150 |
} else {
|
|
151 |
st->print_cr("@%d", bci());
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
void ScopeDesc::print_on(outputStream* st) const {
|
|
156 |
print_on(st, NULL);
|
|
157 |
}
|
|
158 |
|
|
159 |
void ScopeDesc::print_on(outputStream* st, PcDesc* pd) const {
|
|
160 |
// header
|
|
161 |
if (pd != NULL) {
|
|
162 |
tty->print_cr("ScopeDesc(pc=" PTR_FORMAT " offset=%x):", pd->real_pc(_code), pd->pc_offset());
|
|
163 |
}
|
|
164 |
|
|
165 |
print_value_on(st);
|
|
166 |
// decode offsets
|
|
167 |
if (WizardMode) {
|
|
168 |
st->print("ScopeDesc[%d]@" PTR_FORMAT " ", _decode_offset, _code->instructions_begin());
|
|
169 |
st->print_cr(" offset: %d", _decode_offset);
|
|
170 |
st->print_cr(" bci: %d", bci());
|
|
171 |
st->print_cr(" locals: %d", _locals_decode_offset);
|
|
172 |
st->print_cr(" stack: %d", _expressions_decode_offset);
|
|
173 |
st->print_cr(" monitor: %d", _monitors_decode_offset);
|
|
174 |
st->print_cr(" sender: %d", _sender_decode_offset);
|
|
175 |
}
|
|
176 |
// locals
|
|
177 |
{ GrowableArray<ScopeValue*>* l = ((ScopeDesc*) this)->locals();
|
|
178 |
if (l != NULL) {
|
|
179 |
tty->print_cr(" Locals");
|
|
180 |
for (int index = 0; index < l->length(); index++) {
|
|
181 |
st->print(" - l%d: ", index);
|
|
182 |
l->at(index)->print_on(st);
|
|
183 |
st->cr();
|
|
184 |
}
|
|
185 |
}
|
|
186 |
}
|
|
187 |
// expressions
|
|
188 |
{ GrowableArray<ScopeValue*>* l = ((ScopeDesc*) this)->expressions();
|
|
189 |
if (l != NULL) {
|
|
190 |
st->print_cr(" Expression stack");
|
|
191 |
for (int index = 0; index < l->length(); index++) {
|
|
192 |
st->print(" - @%d: ", index);
|
|
193 |
l->at(index)->print_on(st);
|
|
194 |
st->cr();
|
|
195 |
}
|
|
196 |
}
|
|
197 |
}
|
|
198 |
// monitors
|
|
199 |
{ GrowableArray<MonitorValue*>* l = ((ScopeDesc*) this)->monitors();
|
|
200 |
if (l != NULL) {
|
|
201 |
st->print_cr(" Monitor stack");
|
|
202 |
for (int index = 0; index < l->length(); index++) {
|
|
203 |
st->print(" - @%d: ", index);
|
|
204 |
l->at(index)->print_on(st);
|
|
205 |
st->cr();
|
|
206 |
}
|
|
207 |
}
|
|
208 |
}
|
|
209 |
|
|
210 |
#ifdef COMPILER2
|
|
211 |
if (DoEscapeAnalysis && is_top() && _objects != NULL) {
|
|
212 |
tty->print_cr("Objects");
|
|
213 |
for (int i = 0; i < _objects->length(); i++) {
|
|
214 |
ObjectValue* sv = (ObjectValue*) _objects->at(i);
|
|
215 |
tty->print(" - %d: ", sv->id());
|
|
216 |
sv->print_fields_on(tty);
|
|
217 |
tty->cr();
|
|
218 |
}
|
|
219 |
}
|
|
220 |
#endif // COMPILER2
|
|
221 |
}
|
|
222 |
|
|
223 |
#endif
|
|
224 |
|
|
225 |
void ScopeDesc::verify() {
|
|
226 |
ResourceMark rm;
|
|
227 |
guarantee(method()->is_method(), "type check");
|
|
228 |
|
|
229 |
// check if we have any illegal elements on the expression stack
|
|
230 |
{ GrowableArray<ScopeValue*>* l = expressions();
|
|
231 |
if (l != NULL) {
|
|
232 |
for (int index = 0; index < l->length(); index++) {
|
|
233 |
//guarantee(!l->at(index)->is_illegal(), "expression element cannot be illegal");
|
|
234 |
}
|
|
235 |
}
|
|
236 |
}
|
|
237 |
}
|