- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathdebugInfo.cpp
420 lines (359 loc) · 13.2 KB
/
debugInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/*
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include"code/debugInfo.hpp"
#include"code/debugInfoRec.hpp"
#include"code/nmethod.hpp"
#include"gc/shared/collectedHeap.hpp"
#include"memory/universe.hpp"
#include"oops/oop.inline.hpp"
#include"runtime/stackValue.hpp"
#include"runtime/handles.inline.hpp"
#include"runtime/interfaceSupport.inline.hpp"
#include"runtime/javaThread.hpp"
#include"runtime/jniHandles.inline.hpp"
// Constructors
DebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size)
: CompressedWriteStream(initial_size) {
_recorder = recorder;
}
// Serializing oops
voidDebugInfoWriteStream::write_handle(jobject h) {
write_int(recorder()->oop_recorder()->find_index(h));
}
voidDebugInfoWriteStream::write_metadata(Metadata* h) {
write_int(recorder()->oop_recorder()->find_index(h));
}
oop DebugInfoReadStream::read_oop() {
// Despite these oops being found inside nmethods that are on-stack,
// they are not kept alive by all GCs (e.g. G1 and Shenandoah).
oop o = code()->oop_at_phantom(read_int());
assert(oopDesc::is_oop_or_null(o), "oop only");
return o;
}
ScopeValue* DebugInfoReadStream::read_object_value(bool is_auto_box) {
int id = read_int();
#ifdef ASSERT
assert(_obj_pool != nullptr, "object pool does not exist");
for (int i = _obj_pool->length() - 1; i >= 0; i--) {
assert(_obj_pool->at(i)->as_ObjectValue()->id() != id, "should not be read twice");
}
#endif
ObjectValue* result = is_auto_box ? newAutoBoxObjectValue(id) : newObjectValue(id);
// Cache the object since an object field could reference it.
_obj_pool->push(result);
result->read_object(this);
return result;
}
ScopeValue* DebugInfoReadStream::read_object_merge_value() {
int id = read_int();
#ifdef ASSERT
assert(_obj_pool != nullptr, "object pool does not exist");
for (int i = _obj_pool->length() - 1; i >= 0; i--) {
assert(_obj_pool->at(i)->as_ObjectValue()->id() != id, "should not be read twice");
}
#endif
ObjectMergeValue* result = newObjectMergeValue(id);
_obj_pool->push(result);
result->read_object(this);
return result;
}
ScopeValue* DebugInfoReadStream::get_cached_object() {
int id = read_int();
assert(_obj_pool != nullptr, "object pool does not exist");
for (int i = _obj_pool->length() - 1; i >= 0; i--) {
ObjectValue* ov = _obj_pool->at(i)->as_ObjectValue();
if (ov->id() == id) {
return ov;
}
}
ShouldNotReachHere();
returnnullptr;
}
// Serializing scope values
enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,
CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
OBJECT_CODE = 5, OBJECT_ID_CODE = 6,
AUTO_BOX_OBJECT_CODE = 7, MARKER_CODE = 8,
OBJECT_MERGE_CODE = 9 };
ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
ScopeValue* result = nullptr;
switch(stream->read_int()) {
case LOCATION_CODE: result = newLocationValue(stream); break;
case CONSTANT_INT_CODE: result = newConstantIntValue(stream); break;
case CONSTANT_OOP_CODE: result = newConstantOopReadValue(stream); break;
case CONSTANT_LONG_CODE: result = newConstantLongValue(stream); break;
case CONSTANT_DOUBLE_CODE: result = newConstantDoubleValue(stream); break;
case OBJECT_CODE: result = stream->read_object_value(false/*is_auto_box*/); break;
case AUTO_BOX_OBJECT_CODE: result = stream->read_object_value(true/*is_auto_box*/); break;
case OBJECT_MERGE_CODE: result = stream->read_object_merge_value(); break;
case OBJECT_ID_CODE: result = stream->get_cached_object(); break;
case MARKER_CODE: result = newMarkerValue(); break;
default: ShouldNotReachHere();
}
return result;
}
// LocationValue
LocationValue::LocationValue(DebugInfoReadStream* stream) {
_location = Location(stream);
}
voidLocationValue::write_on(DebugInfoWriteStream* stream) {
stream->write_int(LOCATION_CODE);
location().write_on(stream);
}
voidLocationValue::print_on(outputStream* st) const {
location().print_on(st);
}
// MarkerValue
voidMarkerValue::write_on(DebugInfoWriteStream* stream) {
stream->write_int(MARKER_CODE);
}
voidMarkerValue::print_on(outputStream* st) const {
st->print("marker");
}
// ObjectValue
voidObjectValue::set_value(oop value) {
_value = Handle(Thread::current(), value);
}
voidObjectValue::read_object(DebugInfoReadStream* stream) {
_is_root = stream->read_bool();
_klass = read_from(stream);
assert(_klass->is_constant_oop(), "should be constant java mirror oop");
int length = stream->read_int();
for (int i = 0; i < length; i++) {
ScopeValue* val = read_from(stream);
_field_values.append(val);
}
}
voidObjectValue::write_on(DebugInfoWriteStream* stream) {
if (is_visited()) {
stream->write_int(OBJECT_ID_CODE);
stream->write_int(_id);
} else {
set_visited(true);
stream->write_int(is_auto_box() ? AUTO_BOX_OBJECT_CODE : OBJECT_CODE);
stream->write_int(_id);
stream->write_bool(_is_root);
_klass->write_on(stream);
int length = _field_values.length();
stream->write_int(length);
for (int i = 0; i < length; i++) {
_field_values.at(i)->write_on(stream);
}
}
}
voidObjectValue::print_on(outputStream* st) const {
st->print("%s[%d]", is_auto_box() ? "box_obj" : is_object_merge() ? "merge_obj" : "obj", _id);
}
voidObjectValue::print_fields_on(outputStream* st) const {
#ifndef PRODUCT
if (is_object_merge()) {
ObjectMergeValue* omv = (ObjectMergeValue*)this;
st->print("selector=\"");
omv->selector()->print_on(st);
st->print("\"");
ScopeValue* merge_pointer = omv->merge_pointer();
if (!(merge_pointer->is_object() && merge_pointer->as_ObjectValue()->value()() == nullptr) &&
!(merge_pointer->is_constant_oop() && merge_pointer->as_ConstantOopReadValue()->value()() == nullptr)) {
st->print(", merge_pointer=\"");
merge_pointer->print_on(st);
st->print("\"");
}
GrowableArray<ScopeValue*>* possible_objects = omv->possible_objects();
st->print(", candidate_objs=[%d", possible_objects->at(0)->as_ObjectValue()->id());
int ncandidates = possible_objects->length();
for (int i = 1; i < ncandidates; i++) {
st->print(", %d", possible_objects->at(i)->as_ObjectValue()->id());
}
st->print("]");
} else {
st->print("\n Fields: ");
if (_field_values.length() > 0) {
_field_values.at(0)->print_on(st);
}
for (int i = 1; i < _field_values.length(); i++) {
st->print(", ");
_field_values.at(i)->print_on(st);
}
}
#endif
}
// ObjectMergeValue
// Returns the ObjectValue that should be used for the local that this
// ObjectMergeValue represents. ObjectMergeValue represents allocation
// merges in C2. This method will select which path the allocation merge
// took during execution of the Trap that triggered the rematerialization
// of the object.
ObjectValue* ObjectMergeValue::select(frame& fr, RegisterMap& reg_map) {
StackValue* sv_selector = StackValue::create_stack_value(&fr, ®_map, _selector);
jint selector = sv_selector->get_jint();
// If the selector is '-1' it means that execution followed the path
// where no scalar replacement happened.
// Otherwise, it is the index in _possible_objects array that holds
// the description of the scalar replaced object.
if (selector == -1) {
StackValue* sv_merge_pointer = StackValue::create_stack_value(&fr, ®_map, _merge_pointer);
_selected = newObjectValue(id(), nullptr, false);
// Retrieve the pointer to the real object and use it as if we had
// allocated it during the deoptimization
_selected->set_value(sv_merge_pointer->get_obj()());
return _selected;
} else {
assert(selector < _possible_objects.length(), "sanity");
_selected = (ObjectValue*) _possible_objects.at(selector);
return _selected;
}
}
HandleObjectMergeValue::value() const {
if (_selected != nullptr) {
return _selected->value();
} else {
returnHandle();
}
}
voidObjectMergeValue::read_object(DebugInfoReadStream* stream) {
_selector = read_from(stream);
_merge_pointer = read_from(stream);
int ncandidates = stream->read_int();
for (int i = 0; i < ncandidates; i++) {
ScopeValue* result = read_from(stream);
assert(result->is_object(), "Candidate is not an object!");
ObjectValue* obj = result->as_ObjectValue();
_possible_objects.append(obj);
}
}
voidObjectMergeValue::write_on(DebugInfoWriteStream* stream) {
if (is_visited()) {
stream->write_int(OBJECT_ID_CODE);
stream->write_int(_id);
} else {
set_visited(true);
stream->write_int(OBJECT_MERGE_CODE);
stream->write_int(_id);
_selector->write_on(stream);
_merge_pointer->write_on(stream);
int ncandidates = _possible_objects.length();
stream->write_int(ncandidates);
for (int i = 0; i < ncandidates; i++) {
_possible_objects.at(i)->as_ObjectValue()->write_on(stream);
}
}
}
// ConstantIntValue
ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
_value = stream->read_signed_int();
}
voidConstantIntValue::write_on(DebugInfoWriteStream* stream) {
stream->write_int(CONSTANT_INT_CODE);
stream->write_signed_int(value());
}
voidConstantIntValue::print_on(outputStream* st) const {
st->print("%d", value());
}
// ConstantLongValue
ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {
_value = stream->read_long();
}
voidConstantLongValue::write_on(DebugInfoWriteStream* stream) {
stream->write_int(CONSTANT_LONG_CODE);
stream->write_long(value());
}
voidConstantLongValue::print_on(outputStream* st) const {
st->print(JLONG_FORMAT, value());
}
// ConstantDoubleValue
ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) {
_value = stream->read_double();
}
voidConstantDoubleValue::write_on(DebugInfoWriteStream* stream) {
stream->write_int(CONSTANT_DOUBLE_CODE);
stream->write_double(value());
}
voidConstantDoubleValue::print_on(outputStream* st) const {
st->print("%f", value());
}
// ConstantOopWriteValue
voidConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) {
#ifdef ASSERT
{
// cannot use ThreadInVMfromNative here since in case of JVMCI compiler,
// thread is already in VM state.
ThreadInVMfromUnknown tiv;
assert(JNIHandles::resolve(value()) == nullptr ||
Universe::heap()->is_in(JNIHandles::resolve(value())),
"Should be in heap");
}
#endif
stream->write_int(CONSTANT_OOP_CODE);
stream->write_handle(value());
}
voidConstantOopWriteValue::print_on(outputStream* st) const {
// using ThreadInVMfromUnknown here since in case of JVMCI compiler,
// thread is already in VM state.
ThreadInVMfromUnknown tiv;
JNIHandles::resolve(value())->print_value_on(st);
}
// ConstantOopReadValue
ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {
_value = Handle(Thread::current(), stream->read_oop());
assert(_value() == nullptr ||
Universe::heap()->is_in(_value()), "Should be in heap");
}
voidConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {
ShouldNotReachHere();
}
voidConstantOopReadValue::print_on(outputStream* st) const {
if (value()() != nullptr) {
value()()->print_value_on(st);
} else {
st->print("null");
}
}
// MonitorValue
MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) {
_owner = owner;
_basic_lock = basic_lock;
_eliminated = eliminated;
}
MonitorValue::MonitorValue(DebugInfoReadStream* stream) {
_basic_lock = Location(stream);
_owner = ScopeValue::read_from(stream);
_eliminated = (stream->read_bool() != 0);
}
voidMonitorValue::write_on(DebugInfoWriteStream* stream) {
_basic_lock.write_on(stream);
_owner->write_on(stream);
stream->write_bool(_eliminated);
}
#ifndef PRODUCT
voidMonitorValue::print_on(outputStream* st) const {
st->print("monitor{");
owner()->print_on(st);
st->print(",");
basic_lock().print_on(st);
st->print("}");
if (_eliminated) {
st->print(" (eliminated)");
}
}
#endif