Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/code/debugInfo.cpp
32285 views
1
/*
2
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "code/debugInfo.hpp"
27
#include "code/debugInfoRec.hpp"
28
#include "code/nmethod.hpp"
29
#include "runtime/handles.inline.hpp"
30
#include "runtime/interfaceSupport.hpp"
31
#include "runtime/thread.hpp"
32
33
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
34
35
// Constructors
36
37
DebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size)
38
: CompressedWriteStream(initial_size) {
39
_recorder = recorder;
40
}
41
42
// Serializing oops
43
44
void DebugInfoWriteStream::write_handle(jobject h) {
45
write_int(recorder()->oop_recorder()->find_index(h));
46
}
47
48
void DebugInfoWriteStream::write_metadata(Metadata* h) {
49
write_int(recorder()->oop_recorder()->find_index(h));
50
}
51
52
ScopeValue* DebugInfoReadStream::read_object_value() {
53
int id = read_int();
54
#ifdef ASSERT
55
assert(_obj_pool != NULL, "object pool does not exist");
56
for (int i = _obj_pool->length() - 1; i >= 0; i--) {
57
assert(((ObjectValue*) _obj_pool->at(i))->id() != id, "should not be read twice");
58
}
59
#endif
60
ObjectValue* result = new ObjectValue(id);
61
// Cache the object since an object field could reference it.
62
_obj_pool->push(result);
63
result->read_object(this);
64
return result;
65
}
66
67
ScopeValue* DebugInfoReadStream::get_cached_object() {
68
int id = read_int();
69
assert(_obj_pool != NULL, "object pool does not exist");
70
for (int i = _obj_pool->length() - 1; i >= 0; i--) {
71
ObjectValue* ov = (ObjectValue*) _obj_pool->at(i);
72
if (ov->id() == id) {
73
return ov;
74
}
75
}
76
ShouldNotReachHere();
77
return NULL;
78
}
79
80
// Serializing scope values
81
82
enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,
83
CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
84
OBJECT_CODE = 5, OBJECT_ID_CODE = 6 };
85
86
ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
87
ScopeValue* result = NULL;
88
switch(stream->read_int()) {
89
case LOCATION_CODE: result = new LocationValue(stream); break;
90
case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break;
91
case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break;
92
case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break;
93
case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break;
94
case OBJECT_CODE: result = stream->read_object_value(); break;
95
case OBJECT_ID_CODE: result = stream->get_cached_object(); break;
96
default: ShouldNotReachHere();
97
}
98
return result;
99
}
100
101
// LocationValue
102
103
LocationValue::LocationValue(DebugInfoReadStream* stream) {
104
_location = Location(stream);
105
}
106
107
void LocationValue::write_on(DebugInfoWriteStream* stream) {
108
stream->write_int(LOCATION_CODE);
109
location().write_on(stream);
110
}
111
112
void LocationValue::print_on(outputStream* st) const {
113
location().print_on(st);
114
}
115
116
// ObjectValue
117
118
void ObjectValue::read_object(DebugInfoReadStream* stream) {
119
_klass = read_from(stream);
120
assert(_klass->is_constant_oop(), "should be constant java mirror oop");
121
int length = stream->read_int();
122
for (int i = 0; i < length; i++) {
123
ScopeValue* val = read_from(stream);
124
_field_values.append(val);
125
}
126
}
127
128
void ObjectValue::write_on(DebugInfoWriteStream* stream) {
129
if (_visited) {
130
stream->write_int(OBJECT_ID_CODE);
131
stream->write_int(_id);
132
} else {
133
_visited = true;
134
stream->write_int(OBJECT_CODE);
135
stream->write_int(_id);
136
_klass->write_on(stream);
137
int length = _field_values.length();
138
stream->write_int(length);
139
for (int i = 0; i < length; i++) {
140
_field_values.at(i)->write_on(stream);
141
}
142
}
143
}
144
145
void ObjectValue::print_on(outputStream* st) const {
146
st->print("obj[%d]", _id);
147
}
148
149
void ObjectValue::print_fields_on(outputStream* st) const {
150
#ifndef PRODUCT
151
if (_field_values.length() > 0) {
152
_field_values.at(0)->print_on(st);
153
}
154
for (int i = 1; i < _field_values.length(); i++) {
155
st->print(", ");
156
_field_values.at(i)->print_on(st);
157
}
158
#endif
159
}
160
161
// ConstantIntValue
162
163
ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
164
_value = stream->read_signed_int();
165
}
166
167
void ConstantIntValue::write_on(DebugInfoWriteStream* stream) {
168
stream->write_int(CONSTANT_INT_CODE);
169
stream->write_signed_int(value());
170
}
171
172
void ConstantIntValue::print_on(outputStream* st) const {
173
st->print("%d", value());
174
}
175
176
// ConstantLongValue
177
178
ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {
179
_value = stream->read_long();
180
}
181
182
void ConstantLongValue::write_on(DebugInfoWriteStream* stream) {
183
stream->write_int(CONSTANT_LONG_CODE);
184
stream->write_long(value());
185
}
186
187
void ConstantLongValue::print_on(outputStream* st) const {
188
st->print(INT64_FORMAT, value());
189
}
190
191
// ConstantDoubleValue
192
193
ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) {
194
_value = stream->read_double();
195
}
196
197
void ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) {
198
stream->write_int(CONSTANT_DOUBLE_CODE);
199
stream->write_double(value());
200
}
201
202
void ConstantDoubleValue::print_on(outputStream* st) const {
203
st->print("%f", value());
204
}
205
206
// ConstantOopWriteValue
207
208
void ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) {
209
#ifdef ASSERT
210
{
211
// cannot use ThreadInVMfromNative here since in case of JVMCI compiler,
212
// thread is already in VM state.
213
ThreadInVMfromUnknown tiv;
214
assert(JNIHandles::resolve(value()) == NULL ||
215
Universe::heap()->is_in_reserved(JNIHandles::resolve(value())),
216
"Should be in heap");
217
}
218
#endif
219
stream->write_int(CONSTANT_OOP_CODE);
220
stream->write_handle(value());
221
}
222
223
void ConstantOopWriteValue::print_on(outputStream* st) const {
224
// using ThreadInVMfromUnknown here since in case of JVMCI compiler,
225
// thread is already in VM state.
226
ThreadInVMfromUnknown tiv;
227
JNIHandles::resolve(value())->print_value_on(st);
228
}
229
230
231
// ConstantOopReadValue
232
233
ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {
234
_value = Handle(stream->read_oop());
235
assert(_value() == NULL ||
236
Universe::heap()->is_in_reserved(_value()), "Should be in heap");
237
}
238
239
void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {
240
ShouldNotReachHere();
241
}
242
243
void ConstantOopReadValue::print_on(outputStream* st) const {
244
value()()->print_value_on(st);
245
}
246
247
248
// MonitorValue
249
250
MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) {
251
_owner = owner;
252
_basic_lock = basic_lock;
253
_eliminated = eliminated;
254
}
255
256
MonitorValue::MonitorValue(DebugInfoReadStream* stream) {
257
_basic_lock = Location(stream);
258
_owner = ScopeValue::read_from(stream);
259
_eliminated = (stream->read_bool() != 0);
260
}
261
262
void MonitorValue::write_on(DebugInfoWriteStream* stream) {
263
_basic_lock.write_on(stream);
264
_owner->write_on(stream);
265
stream->write_bool(_eliminated);
266
}
267
268
#ifndef PRODUCT
269
void MonitorValue::print_on(outputStream* st) const {
270
st->print("monitor{");
271
owner()->print_on(st);
272
st->print(",");
273
basic_lock().print_on(st);
274
st->print("}");
275
if (_eliminated) {
276
st->print(" (eliminated)");
277
}
278
}
279
#endif
280
281