2
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
25
#include "precompiled.hpp"
26
#include "ci/ciMetadata.hpp"
27
#include "ci/ciMethodData.hpp"
28
#include "ci/ciReplay.hpp"
29
#include "ci/ciUtilities.inline.hpp"
30
#include "compiler/compiler_globals.hpp"
31
#include "memory/allocation.inline.hpp"
32
#include "memory/resourceArea.hpp"
33
#include "oops/klass.inline.hpp"
34
#include "oops/methodData.inline.hpp"
35
#include "runtime/deoptimization.hpp"
36
#include "utilities/copy.hpp"
40
// ------------------------------------------------------------------
41
// ciMethodData::ciMethodData
43
ciMethodData::ciMethodData(MethodData* md)
45
_data_size(0), _extra_data_size(0), _data(nullptr),
46
_parameters_data_offset(0),
47
_exception_handlers_data_offset(0),
48
// Set an initial hint. Don't use set_hint_di() because
49
// first_di() may be out of bounds if data_size is 0.
52
_saw_free_extra_data(false),
53
// Initialize the escape information (to "don't know.");
54
_eflags(0), _arg_local(0), _arg_stack(0), _arg_returned(0),
55
_invocation_counter(0),
58
// Check for entries that reference an unloaded method
59
class PrepareExtraDataClosure : public CleanExtraDataClosure {
61
SafepointStateTracker _safepoint_tracker;
62
GrowableArray<Method*> _uncached_methods;
65
PrepareExtraDataClosure(MethodData* mdo)
67
_safepoint_tracker(SafepointSynchronize::safepoint_state_tracker()),
71
bool is_live(Method* m) {
72
if (!m->method_holder()->is_loader_alive()) {
75
if (CURRENT_ENV->cached_metadata(m) == nullptr) {
76
// Uncached entries need to be pre-populated.
77
_uncached_methods.append(m);
82
bool has_safepointed() {
83
return _safepoint_tracker.safepoint_state_changed();
87
if (_uncached_methods.length() == 0) {
88
// Preparation finished iff all Methods* were already cached.
91
// We are currently holding the extra_data_lock and ensuring
92
// no safepoint breaks the lock.
93
_mdo->check_extra_data_locked();
95
// We now want to cache some method data. This could cause a safepoint.
96
// We temporarily release the lock and allow safepoints, and revert that
97
// at the end of the scope. This is safe, since we currently do not hold
98
// any extra_method_data: finish is called only after clean_extra_data,
99
// and the outer scope that first aquired the lock should not hold any
100
// extra_method_data while cleaning is performed, as the offsets can change.
101
MutexUnlocker mu(_mdo->extra_data_lock(), Mutex::_no_safepoint_check_flag);
103
for (int i = 0; i < _uncached_methods.length(); ++i) {
104
if (has_safepointed()) {
105
// The metadata in the growable array might contain stale
106
// entries after a safepoint.
109
Method* method = _uncached_methods.at(i);
110
// Populating ciEnv caches may cause safepoints due
111
// to taking the Compile_lock with safepoint checks.
112
(void)CURRENT_ENV->get_method(method);
118
void ciMethodData::prepare_metadata() {
119
MethodData* mdo = get_MethodData();
123
PrepareExtraDataClosure cl(mdo);
124
mdo->clean_extra_data(&cl);
126
// When encountering uncached metadata, the Compile_lock might be
127
// acquired when creating ciMetadata handles, causing safepoints
128
// which requires a new round of preparation to clean out potentially
129
// new unloading metadata.
135
void ciMethodData::load_remaining_extra_data() {
136
MethodData* mdo = get_MethodData();
138
// Lock to read ProfileData, and ensure lock is not unintentionally broken by a safepoint
139
MutexLocker ml(mdo->extra_data_lock(), Mutex::_no_safepoint_check_flag);
141
// Deferred metadata cleaning due to concurrent class unloading.
143
// After metadata preparation, there is no stale metadata,
144
// and no safepoints can introduce more stale metadata.
145
NoSafepointVerifier no_safepoint;
147
assert((mdo->data_size() == _data_size) && (mdo->extra_data_size() == _extra_data_size), "sanity, unchanged");
148
assert(extra_data_base() == (DataLayout*)((address) _data + _data_size), "sanity");
150
// Copy the extra data once it is prepared (i.e. cache populated, no release of extra data lock anymore)
151
Copy::disjoint_words_atomic((HeapWord*) mdo->extra_data_base(),
152
(HeapWord*) extra_data_base(),
153
// copy everything from extra_data_base() up to parameters_data_base()
154
pointer_delta(parameters_data_base(), extra_data_base(), HeapWordSize));
156
// skip parameter data copying. Already done in 'load_data'
158
// copy exception handler data
159
Copy::disjoint_words_atomic((HeapWord*) mdo->exception_handler_data_base(),
160
(HeapWord*) exception_handler_data_base(),
161
exception_handler_data_size() / HeapWordSize);
163
// speculative trap entries also hold a pointer to a Method so need to be translated
164
DataLayout* dp_src = mdo->extra_data_base();
165
DataLayout* end_src = mdo->args_data_limit();
166
DataLayout* dp_dst = extra_data_base();
167
for (;; dp_src = MethodData::next_extra(dp_src), dp_dst = MethodData::next_extra(dp_dst)) {
168
assert(dp_src < end_src, "moved past end of extra data");
169
assert(((intptr_t)dp_dst) - ((intptr_t)extra_data_base()) == ((intptr_t)dp_src) - ((intptr_t)mdo->extra_data_base()), "source and destination don't match");
171
int tag = dp_src->tag();
173
case DataLayout::speculative_trap_data_tag: {
174
ciSpeculativeTrapData data_dst(dp_dst);
175
SpeculativeTrapData data_src(dp_src);
176
data_dst.translate_from(&data_src);
179
case DataLayout::bit_data_tag:
181
case DataLayout::no_tag:
182
case DataLayout::arg_info_data_tag:
183
// An empty slot or ArgInfoData entry marks the end of the trap data
185
return; // Need a block to avoid SS compiler bug
188
fatal("bad tag = %d", tag);
193
bool ciMethodData::load_data() {
194
MethodData* mdo = get_MethodData();
195
if (mdo == nullptr) {
199
// To do: don't copy the data if it is not "ripe" -- require a minimum #
202
// Snapshot the data and extra parameter data first without the extra trap and arg info data.
203
// Those are copied in a second step. Actually, an approximate snapshot of the data is taken.
204
// Any concurrently executing threads may be changing the data as we copy it.
206
// The first snapshot step requires two copies (data entries and parameter data entries) since
207
// the MDO is laid out as follows:
209
// data_base: ---------------------------
212
// extra_data_base: ---------------------------
213
// | trap data entries |
215
// | one arg info data entry |
216
// | data for each arg |
218
// args_data_limit: ---------------------------
219
// | parameter data entries |
221
// param_data_limit: ---------------------------
222
// | ex handler data entries |
224
// extra_data_limit: ---------------------------
226
// _data_size = extra_data_base - data_base
227
// _extra_data_size = extra_data_limit - extra_data_base
228
// total_size = _data_size + _extra_data_size
229
// args_data_limit = param_data_base
230
// param_data_limit = exception_handler_data_base
231
// extra_data_limit = extra_data_limit
234
// Some Zero platforms do not have expected alignment, and do not use
235
// this code. static_assert would still fire and fail for them.
236
static_assert(sizeof(_orig) % HeapWordSize == 0, "align");
238
Copy::disjoint_words_atomic((HeapWord*) &mdo->_compiler_counters,
240
sizeof(_orig) / HeapWordSize);
241
Arena* arena = CURRENT_ENV->arena();
242
_data_size = mdo->data_size();
243
_extra_data_size = mdo->extra_data_size();
244
int total_size = _data_size + _extra_data_size;
245
_data = (intptr_t *) arena->Amalloc(total_size);
246
Copy::disjoint_words_atomic((HeapWord*) mdo->data_base(),
248
_data_size / HeapWordSize);
249
// Copy offsets. This is used below
250
_parameters_data_offset = mdo->parameters_type_data_di();
251
_exception_handlers_data_offset = mdo->exception_handlers_data_di();
253
int parameters_data_size = mdo->parameters_size_in_bytes();
254
if (parameters_data_size > 0) {
255
// Snapshot the parameter data
256
Copy::disjoint_words_atomic((HeapWord*) mdo->parameters_data_base(),
257
(HeapWord*) parameters_data_base(),
258
parameters_data_size / HeapWordSize);
260
// Traverse the profile data, translating any oops into their
263
ciProfileData* ci_data = first_data();
264
ProfileData* data = mdo->first_data();
265
while (is_valid(ci_data)) {
266
ci_data->translate_from(data);
267
ci_data = next_data(ci_data);
268
data = mdo->next_data(data);
270
if (mdo->parameters_type_data() != nullptr) {
271
DataLayout* parameters_data = data_layout_at(_parameters_data_offset);
272
ciParametersTypeData* parameters = new ciParametersTypeData(parameters_data);
273
parameters->translate_from(mdo->parameters_type_data());
276
assert((DataLayout*) ((address)_data + total_size - parameters_data_size - exception_handler_data_size()) == args_data_limit(),
277
"sanity - parameter data starts after the argument data of the single ArgInfoData entry");
278
load_remaining_extra_data();
280
// Note: Extra data are all BitData, and do not need translation.
281
_invocation_counter = mdo->invocation_count();
282
if (_invocation_counter == 0 && mdo->backedge_count() > 0) {
283
// Avoid skewing counter data during OSR compilation.
284
// Sometimes, MDO is allocated during the very first invocation and OSR compilation is triggered
285
// solely by backedge counter while invocation counter stays zero. In such case, it's important
286
// to observe non-zero invocation count to properly scale profile counts (see ciMethod::scale_count()).
287
_invocation_counter = 1;
290
_state = mdo->is_mature() ? mature_state : immature_state;
291
_eflags = mdo->eflags();
292
_arg_local = mdo->arg_local();
293
_arg_stack = mdo->arg_stack();
294
_arg_returned = mdo->arg_returned();
295
if (ReplayCompiles) {
296
ciReplay::initialize(this);
304
void ciReceiverTypeData::translate_receiver_data_from(const ProfileData* data) {
305
for (uint row = 0; row < row_limit(); row++) {
306
Klass* k = data->as_ReceiverTypeData()->receiver(row);
308
if (k->is_loader_alive()) {
309
ciKlass* klass = CURRENT_ENV->get_klass(k);
310
set_receiver(row, klass);
312
// With concurrent class unloading, the MDO could have stale metadata; override it
316
set_receiver(row, nullptr);
321
void ciTypeStackSlotEntries::translate_type_data_from(const TypeStackSlotEntries* entries) {
322
for (int i = 0; i < number_of_entries(); i++) {
323
intptr_t k = entries->type(i);
324
Klass* klass = (Klass*)klass_part(k);
325
if (klass != nullptr && !klass->is_loader_alive()) {
326
// With concurrent class unloading, the MDO could have stale metadata; override it
327
TypeStackSlotEntries::set_type(i, TypeStackSlotEntries::with_status((Klass*)nullptr, k));
329
TypeStackSlotEntries::set_type(i, translate_klass(k));
334
void ciReturnTypeEntry::translate_type_data_from(const ReturnTypeEntry* ret) {
335
intptr_t k = ret->type();
336
Klass* klass = (Klass*)klass_part(k);
337
if (klass != nullptr && !klass->is_loader_alive()) {
338
// With concurrent class unloading, the MDO could have stale metadata; override it
339
set_type(ReturnTypeEntry::with_status((Klass*)nullptr, k));
341
set_type(translate_klass(k));
345
void ciSpeculativeTrapData::translate_from(const ProfileData* data) {
346
Method* m = data->as_SpeculativeTrapData()->method();
347
ciMethod* ci_m = CURRENT_ENV->get_method(m);
351
// Get the data at an arbitrary (sort of) data index.
352
ciProfileData* ciMethodData::data_at(int data_index) {
353
if (out_of_bounds(data_index)) {
356
DataLayout* data_layout = data_layout_at(data_index);
357
return data_from(data_layout);
360
ciProfileData* ciMethodData::data_from(DataLayout* data_layout) {
361
switch (data_layout->tag()) {
362
case DataLayout::no_tag:
364
ShouldNotReachHere();
366
case DataLayout::bit_data_tag:
367
return new ciBitData(data_layout);
368
case DataLayout::counter_data_tag:
369
return new ciCounterData(data_layout);
370
case DataLayout::jump_data_tag:
371
return new ciJumpData(data_layout);
372
case DataLayout::receiver_type_data_tag:
373
return new ciReceiverTypeData(data_layout);
374
case DataLayout::virtual_call_data_tag:
375
return new ciVirtualCallData(data_layout);
376
case DataLayout::ret_data_tag:
377
return new ciRetData(data_layout);
378
case DataLayout::branch_data_tag:
379
return new ciBranchData(data_layout);
380
case DataLayout::multi_branch_data_tag:
381
return new ciMultiBranchData(data_layout);
382
case DataLayout::arg_info_data_tag:
383
return new ciArgInfoData(data_layout);
384
case DataLayout::call_type_data_tag:
385
return new ciCallTypeData(data_layout);
386
case DataLayout::virtual_call_type_data_tag:
387
return new ciVirtualCallTypeData(data_layout);
388
case DataLayout::parameters_type_data_tag:
389
return new ciParametersTypeData(data_layout);
393
// Iteration over data.
394
ciProfileData* ciMethodData::next_data(ciProfileData* current) {
395
int current_index = dp_to_di(current->dp());
396
int next_index = current_index + current->size_in_bytes();
397
ciProfileData* next = data_at(next_index);
401
DataLayout* ciMethodData::next_data_layout_helper(DataLayout* current, bool extra) {
402
int current_index = dp_to_di((address)current);
403
int next_index = current_index + current->size_in_bytes();
404
if (extra ? out_of_bounds_extra(next_index) : out_of_bounds(next_index)) {
407
DataLayout* next = data_layout_at(next_index);
411
DataLayout* ciMethodData::next_data_layout(DataLayout* current) {
412
return next_data_layout_helper(current, false);
415
DataLayout* ciMethodData::next_extra_data_layout(DataLayout* current) {
416
return next_data_layout_helper(current, true);
419
ciProfileData* ciMethodData::bci_to_extra_data(int bci, ciMethod* m, bool& two_free_slots) {
420
DataLayout* dp = extra_data_base();
421
DataLayout* end = args_data_limit();
422
two_free_slots = false;
423
for (;dp < end; dp = MethodData::next_extra(dp)) {
425
case DataLayout::no_tag:
426
_saw_free_extra_data = true; // observed an empty slot (common case)
427
two_free_slots = (MethodData::next_extra(dp)->tag() == DataLayout::no_tag);
429
case DataLayout::arg_info_data_tag:
430
return nullptr; // ArgInfoData is after the trap data right before the parameter data.
431
case DataLayout::bit_data_tag:
432
if (m == nullptr && dp->bci() == bci) {
433
return new ciBitData(dp);
436
case DataLayout::speculative_trap_data_tag: {
437
ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
438
// data->method() might be null if the MDO is snapshotted
439
// concurrently with a trap
440
if (m != nullptr && data->method() == m && dp->bci() == bci) {
446
fatal("bad tag = %d", dp->tag());
452
// Translate a bci to its corresponding data, or nullptr.
453
ciProfileData* ciMethodData::bci_to_data(int bci, ciMethod* m) {
454
// If m is not nullptr we look for a SpeculativeTrapData entry
456
DataLayout* data_layout = data_layout_before(bci);
457
for ( ; is_valid(data_layout); data_layout = next_data_layout(data_layout)) {
458
if (data_layout->bci() == bci) {
459
set_hint_di(dp_to_di((address)data_layout));
460
return data_from(data_layout);
461
} else if (data_layout->bci() > bci) {
466
bool two_free_slots = false;
467
ciProfileData* result = bci_to_extra_data(bci, m, two_free_slots);
468
if (result != nullptr) {
471
if (m != nullptr && !two_free_slots) {
472
// We were looking for a SpeculativeTrapData entry we didn't
473
// find. Room is not available for more SpeculativeTrapData
474
// entries, look in the non SpeculativeTrapData entries.
475
return bci_to_data(bci, nullptr);
480
ciBitData ciMethodData::exception_handler_bci_to_data(int bci) {
481
assert(ProfileExceptionHandlers, "not profiling");
482
assert(_data != nullptr, "must be initialized");
483
for (DataLayout* data = exception_handler_data_base(); data < exception_handler_data_limit(); data = next_extra_data_layout(data)) {
484
assert(data != nullptr, "out of bounds?");
485
if (data->bci() == bci) {
486
return ciBitData(data);
489
// called with invalid bci or wrong Method/MethodData
490
ShouldNotReachHere();
491
return ciBitData(nullptr);
494
// Conservatively decode the trap_state of a ciProfileData.
495
int ciMethodData::has_trap_at(ciProfileData* data, int reason) {
496
typedef Deoptimization::DeoptReason DR_t;
498
= Deoptimization::reason_recorded_per_bytecode_if_any((DR_t) reason);
499
if (trap_count(reason) == 0) {
500
// Impossible for this trap to have occurred, regardless of trap_state.
501
// Note: This happens if the MDO is empty.
503
} else if (per_bc_reason == Deoptimization::Reason_none) {
504
// We cannot conclude anything; a trap happened somewhere, maybe here.
506
} else if (data == nullptr) {
507
// No profile here, not even an extra_data record allocated on the fly.
508
// If there are empty extra_data records, and there had been a trap,
509
// there would have been a non-null data pointer. If there are no
510
// free extra_data records, we must return a conservative -1.
511
if (_saw_free_extra_data)
514
return -1; // bail with a conservative answer
516
return Deoptimization::trap_state_has_reason(data->trap_state(), per_bc_reason);
520
int ciMethodData::trap_recompiled_at(ciProfileData* data) {
521
if (data == nullptr) {
522
return (_saw_free_extra_data? 0: -1); // (see previous method)
524
return Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0;
528
void ciMethodData::clear_escape_info() {
530
MethodData* mdo = get_MethodData();
531
if (mdo != nullptr) {
532
mdo->clear_escape_info();
533
ArgInfoData *aid = arg_info();
534
int arg_count = (aid == nullptr) ? 0 : aid->number_of_args();
535
for (int i = 0; i < arg_count; i++) {
536
set_arg_modified(i, 0);
539
_eflags = _arg_local = _arg_stack = _arg_returned = 0;
542
// copy our escape info to the MethodData* if it exists
543
void ciMethodData::update_escape_info() {
545
MethodData* mdo = get_MethodData();
546
if ( mdo != nullptr) {
547
mdo->set_eflags(_eflags);
548
mdo->set_arg_local(_arg_local);
549
mdo->set_arg_stack(_arg_stack);
550
mdo->set_arg_returned(_arg_returned);
551
int arg_count = mdo->method()->size_of_parameters();
552
for (int i = 0; i < arg_count; i++) {
553
mdo->set_arg_modified(i, arg_modified(i));
558
void ciMethodData::set_compilation_stats(short loops, short blocks) {
560
MethodData* mdo = get_MethodData();
561
if (mdo != nullptr) {
562
mdo->set_num_loops(loops);
563
mdo->set_num_blocks(blocks);
567
void ciMethodData::set_would_profile(bool p) {
569
MethodData* mdo = get_MethodData();
570
if (mdo != nullptr) {
571
mdo->set_would_profile(p);
575
void ciMethodData::set_argument_type(int bci, int i, ciKlass* k) {
577
MethodData* mdo = get_MethodData();
578
if (mdo != nullptr) {
579
// Lock to read ProfileData, and ensure lock is not broken by a safepoint
580
MutexLocker ml(mdo->extra_data_lock(), Mutex::_no_safepoint_check_flag);
582
ProfileData* data = mdo->bci_to_data(bci);
583
if (data != nullptr) {
584
if (data->is_CallTypeData()) {
585
data->as_CallTypeData()->set_argument_type(i, k->get_Klass());
587
assert(data->is_VirtualCallTypeData(), "no arguments!");
588
data->as_VirtualCallTypeData()->set_argument_type(i, k->get_Klass());
594
void ciMethodData::set_parameter_type(int i, ciKlass* k) {
596
MethodData* mdo = get_MethodData();
597
if (mdo != nullptr) {
598
mdo->parameters_type_data()->set_type(i, k->get_Klass());
602
void ciMethodData::set_return_type(int bci, ciKlass* k) {
604
MethodData* mdo = get_MethodData();
605
if (mdo != nullptr) {
606
// Lock to read ProfileData, and ensure lock is not broken by a safepoint
607
MutexLocker ml(mdo->extra_data_lock(), Mutex::_no_safepoint_check_flag);
609
ProfileData* data = mdo->bci_to_data(bci);
610
if (data != nullptr) {
611
if (data->is_CallTypeData()) {
612
data->as_CallTypeData()->set_return_type(k->get_Klass());
614
assert(data->is_VirtualCallTypeData(), "no arguments!");
615
data->as_VirtualCallTypeData()->set_return_type(k->get_Klass());
621
bool ciMethodData::has_escape_info() {
622
return eflag_set(MethodData::estimated);
625
void ciMethodData::set_eflag(MethodData::EscapeFlag f) {
626
set_bits(_eflags, f);
629
bool ciMethodData::eflag_set(MethodData::EscapeFlag f) const {
630
return mask_bits(_eflags, f) != 0;
633
void ciMethodData::set_arg_local(int i) {
634
set_nth_bit(_arg_local, i);
637
void ciMethodData::set_arg_stack(int i) {
638
set_nth_bit(_arg_stack, i);
641
void ciMethodData::set_arg_returned(int i) {
642
set_nth_bit(_arg_returned, i);
645
void ciMethodData::set_arg_modified(int arg, uint val) {
646
ArgInfoData *aid = arg_info();
649
assert(arg >= 0 && arg < aid->number_of_args(), "valid argument number");
650
aid->set_arg_modified(arg, val);
653
bool ciMethodData::is_arg_local(int i) const {
654
return is_set_nth_bit(_arg_local, i);
657
bool ciMethodData::is_arg_stack(int i) const {
658
return is_set_nth_bit(_arg_stack, i);
661
bool ciMethodData::is_arg_returned(int i) const {
662
return is_set_nth_bit(_arg_returned, i);
665
uint ciMethodData::arg_modified(int arg) const {
666
ArgInfoData *aid = arg_info();
669
assert(arg >= 0 && arg < aid->number_of_args(), "valid argument number");
670
return aid->arg_modified(arg);
673
ciParametersTypeData* ciMethodData::parameters_type_data() const {
674
return parameter_data_size() != 0 ? new ciParametersTypeData(data_layout_at(_parameters_data_offset)) : nullptr;
677
ByteSize ciMethodData::offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data) {
678
// Get offset within MethodData* of the data array
679
ByteSize data_offset = MethodData::data_offset();
681
// Get cell offset of the ProfileData within data array
682
int cell_offset = dp_to_di(data->dp());
684
// Add in counter_offset, the # of bytes into the ProfileData of counter or flag
685
int offset = in_bytes(data_offset) + cell_offset + in_bytes(slot_offset_in_data);
687
return in_ByteSize(offset);
690
ciArgInfoData *ciMethodData::arg_info() const {
691
// Should be last, have to skip all traps.
692
DataLayout* dp = extra_data_base();
693
DataLayout* end = args_data_limit();
694
for (; dp < end; dp = MethodData::next_extra(dp)) {
695
if (dp->tag() == DataLayout::arg_info_data_tag)
696
return new ciArgInfoData(dp);
702
// Implementation of the print method.
703
void ciMethodData::print_impl(outputStream* st) {
704
ciMetadata::print_impl(st);
707
void ciMethodData::dump_replay_data_type_helper(outputStream* out, int round, int& count, ProfileData* pdata, ByteSize offset, ciKlass* k) {
712
out->print(" %d %s", (int)(dp_to_di(pdata->dp() + in_bytes(offset)) / sizeof(intptr_t)),
713
CURRENT_ENV->replay_name(k));
718
template<class T> void ciMethodData::dump_replay_data_receiver_type_helper(outputStream* out, int round, int& count, T* vdata) {
719
for (uint i = 0; i < vdata->row_limit(); i++) {
720
dump_replay_data_type_helper(out, round, count, vdata, vdata->receiver_offset(i), vdata->receiver(i));
724
template<class T> void ciMethodData::dump_replay_data_call_type_helper(outputStream* out, int round, int& count, T* call_type_data) {
725
if (call_type_data->has_arguments()) {
726
for (int i = 0; i < call_type_data->number_of_arguments(); i++) {
727
dump_replay_data_type_helper(out, round, count, call_type_data, call_type_data->argument_type_offset(i), call_type_data->valid_argument_type(i));
730
if (call_type_data->has_return()) {
731
dump_replay_data_type_helper(out, round, count, call_type_data, call_type_data->return_type_offset(), call_type_data->valid_return_type());
735
void ciMethodData::dump_replay_data_extra_data_helper(outputStream* out, int round, int& count) {
736
DataLayout* dp = extra_data_base();
737
DataLayout* end = args_data_limit();
739
for (;dp < end; dp = MethodData::next_extra(dp)) {
741
case DataLayout::no_tag:
742
case DataLayout::arg_info_data_tag:
744
case DataLayout::bit_data_tag:
746
case DataLayout::speculative_trap_data_tag: {
747
ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
748
ciMethod* m = data->method();
753
out->print(" %d ", (int)(dp_to_di(((address)dp) + in_bytes(ciSpeculativeTrapData::method_offset())) / sizeof(intptr_t)));
754
m->dump_name_as_ascii(out);
760
fatal("bad tag = %d", dp->tag());
765
void ciMethodData::dump_replay_data(outputStream* out) {
767
MethodData* mdo = get_MethodData();
768
Method* method = mdo->method();
769
out->print("ciMethodData ");
770
ciMethod::dump_name_as_ascii(out, method);
771
out->print(" %d %d", _state, _invocation_counter);
773
// dump the contents of the MDO header as raw data
774
unsigned char* orig = (unsigned char*)&_orig;
775
int length = sizeof(_orig);
776
out->print(" orig %d", length);
777
for (int i = 0; i < length; i++) {
778
out->print(" %d", orig[i]);
781
// dump the MDO data as raw data
782
int elements = (data_size() + extra_data_size()) / sizeof(intptr_t);
783
out->print(" data %d", elements);
784
for (int i = 0; i < elements; i++) {
785
// We could use INTPTR_FORMAT here but that's zero justified
786
// which makes comparing it with the SA version of this output
787
// harder. data()'s element type is intptr_t.
788
out->print(" " INTX_FORMAT_X, data()[i]);
791
// The MDO contained oop references as ciObjects, so scan for those
792
// and emit pairs of offset and klass name so that they can be
793
// reconstructed at runtime. The first round counts the number of
794
// oop references and the second actually emits them.
795
ciParametersTypeData* parameters = parameters_type_data();
796
for (int count = 0, round = 0; round < 2; round++) {
797
if (round == 1) out->print(" oops %d", count);
798
ProfileData* pdata = first_data();
799
for ( ; is_valid(pdata); pdata = next_data(pdata)) {
800
if (pdata->is_VirtualCallData()) {
801
ciVirtualCallData* vdata = (ciVirtualCallData*)pdata;
802
dump_replay_data_receiver_type_helper<ciVirtualCallData>(out, round, count, vdata);
803
if (pdata->is_VirtualCallTypeData()) {
804
ciVirtualCallTypeData* call_type_data = (ciVirtualCallTypeData*)pdata;
805
dump_replay_data_call_type_helper<ciVirtualCallTypeData>(out, round, count, call_type_data);
807
} else if (pdata->is_ReceiverTypeData()) {
808
ciReceiverTypeData* vdata = (ciReceiverTypeData*)pdata;
809
dump_replay_data_receiver_type_helper<ciReceiverTypeData>(out, round, count, vdata);
810
} else if (pdata->is_CallTypeData()) {
811
ciCallTypeData* call_type_data = (ciCallTypeData*)pdata;
812
dump_replay_data_call_type_helper<ciCallTypeData>(out, round, count, call_type_data);
815
if (parameters != nullptr) {
816
for (int i = 0; i < parameters->number_of_parameters(); i++) {
817
dump_replay_data_type_helper(out, round, count, parameters, ParametersTypeData::type_offset(i), parameters->valid_parameter_type(i));
821
for (int count = 0, round = 0; round < 2; round++) {
822
if (round == 1) out->print(" methods %d", count);
823
dump_replay_data_extra_data_helper(out, round, count);
829
void ciMethodData::print() {
833
void ciMethodData::print_data_on(outputStream* st) {
835
ciParametersTypeData* parameters = parameters_type_data();
836
if (parameters != nullptr) {
837
parameters->print_data_on(st);
840
for (data = first_data(); is_valid(data); data = next_data(data)) {
841
st->print("%d", dp_to_di(data->dp()));
843
data->print_data_on(st);
845
st->print_cr("--- Extra data:");
846
DataLayout* dp = extra_data_base();
847
DataLayout* end = args_data_limit();
848
for (;; dp = MethodData::next_extra(dp)) {
849
assert(dp < end, "moved past end of extra data");
851
case DataLayout::no_tag:
853
case DataLayout::bit_data_tag:
854
data = new BitData(dp);
856
case DataLayout::arg_info_data_tag:
857
data = new ciArgInfoData(dp);
858
dp = end; // ArgInfoData is after the trap data right before the parameter data.
860
case DataLayout::speculative_trap_data_tag:
861
data = new ciSpeculativeTrapData(dp);
864
fatal("unexpected tag %d", dp->tag());
866
st->print("%d", dp_to_di(data->dp()));
868
data->print_data_on(st);
869
if (dp >= end) return;
873
void ciTypeEntries::print_ciklass(outputStream* st, intptr_t k) {
874
if (TypeEntries::is_type_none(k)) {
876
} else if (TypeEntries::is_type_unknown(k)) {
877
st->print("unknown");
879
valid_ciklass(k)->print_name_on(st);
881
if (TypeEntries::was_null_seen(k)) {
882
st->print(" (null seen)");
886
void ciTypeStackSlotEntries::print_data_on(outputStream* st) const {
887
for (int i = 0; i < number_of_entries(); i++) {
889
st->print("%d: stack (%u) ", i, stack_slot(i));
890
print_ciklass(st, type(i));
895
void ciReturnTypeEntry::print_data_on(outputStream* st) const {
898
print_ciklass(st, type());
902
void ciCallTypeData::print_data_on(outputStream* st, const char* extra) const {
903
print_shared(st, "ciCallTypeData", extra);
904
if (has_arguments()) {
906
st->print_cr("argument types");
907
args()->print_data_on(st);
911
st->print_cr("return type");
912
ret()->print_data_on(st);
916
void ciReceiverTypeData::print_receiver_data_on(outputStream* st) const {
919
for (row = 0; row < row_limit(); row++) {
920
if (receiver(row) != nullptr) entries++;
922
st->print_cr("count(%u) entries(%u)", count(), entries);
923
for (row = 0; row < row_limit(); row++) {
924
if (receiver(row) != nullptr) {
926
receiver(row)->print_name_on(st);
927
st->print_cr("(%u)", receiver_count(row));
932
void ciReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
933
print_shared(st, "ciReceiverTypeData", extra);
934
print_receiver_data_on(st);
937
void ciVirtualCallData::print_data_on(outputStream* st, const char* extra) const {
938
print_shared(st, "ciVirtualCallData", extra);
939
rtd_super()->print_receiver_data_on(st);
942
void ciVirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {
943
print_shared(st, "ciVirtualCallTypeData", extra);
944
rtd_super()->print_receiver_data_on(st);
945
if (has_arguments()) {
947
st->print("argument types");
948
args()->print_data_on(st);
952
st->print("return type");
953
ret()->print_data_on(st);
957
void ciParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
958
st->print_cr("ciParametersTypeData");
959
parameters()->print_data_on(st);
962
void ciSpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
963
st->print_cr("ciSpeculativeTrapData");
965
method()->print_short_name(st);