2
* Copyright (c) 1997, 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 "code/codeCache.hpp"
27
#include "code/compiledIC.hpp"
28
#include "code/nmethod.hpp"
29
#include "code/relocInfo.hpp"
30
#include "memory/resourceArea.hpp"
31
#include "memory/universe.hpp"
32
#include "oops/compressedOops.inline.hpp"
33
#include "oops/oop.inline.hpp"
34
#include "runtime/flags/flagSetting.hpp"
35
#include "runtime/stubCodeGenerator.hpp"
36
#include "utilities/align.hpp"
37
#include "utilities/checkedCast.hpp"
38
#include "utilities/copy.hpp"
43
const RelocationHolder RelocationHolder::none; // its type is relocInfo::none
46
// Implementation of relocInfo
49
relocInfo::relocType relocInfo::check_relocType(relocType type) {
50
assert(type != data_prefix_tag, "cannot build a prefix this way");
51
assert((type & type_mask) == type, "wrong type");
55
void relocInfo::check_offset_and_format(int offset, int format) {
56
assert(offset >= 0 && offset < offset_limit(), "offset out off bounds");
57
assert(is_aligned(offset, offset_unit), "misaligned offset");
58
assert((format & format_mask) == format, "wrong format");
62
void relocInfo::initialize(CodeSection* dest, Relocation* reloc) {
63
relocInfo* data = this+1; // here's where the data might go
64
dest->set_locs_end(data); // sync end: the next call may read dest.locs_end
65
reloc->pack_data_to(dest); // maybe write data into locs, advancing locs_end
66
relocInfo* data_limit = dest->locs_end();
67
if (data_limit > data) {
68
relocInfo suffix = (*this);
69
data_limit = this->finish_prefix((short*) data_limit);
70
// Finish up with the suffix. (Hack note: pack_data_to might edit this.)
72
dest->set_locs_end(data_limit+1);
76
relocInfo* relocInfo::finish_prefix(short* prefix_limit) {
77
assert(sizeof(relocInfo) == sizeof(short), "change this code");
78
short* p = (short*)(this+1);
79
assert(prefix_limit >= p, "must be a valid span of data");
80
int plen = checked_cast<int>(prefix_limit - p);
82
debug_only(_value = 0xFFFF);
83
return this; // no data: remove self completely
85
if (plen == 1 && fits_into_immediate(p[0])) {
86
(*this) = immediate_relocInfo(p[0]); // move data inside self
89
// cannot compact, so just update the count and return the limit pointer
90
(*this) = prefix_info(plen); // write new datalen
91
assert(data() + datalen() == prefix_limit, "pointers must line up");
92
return (relocInfo*)prefix_limit;
95
void relocInfo::set_type(relocType t) {
96
int old_offset = addr_offset();
97
int old_format = format();
98
(*this) = relocInfo(t, old_offset, old_format);
99
assert(type()==(int)t, "sanity check");
100
assert(addr_offset()==old_offset, "sanity check");
101
assert(format()==old_format, "sanity check");
104
void relocInfo::change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type) {
106
while (itr->next() && !found) {
107
if (itr->addr() == pc) {
108
assert(itr->type()==old_type, "wrong relocInfo type found");
109
itr->current()->set_type(new_type);
113
assert(found, "no relocInfo found for pc");
117
// ----------------------------------------------------------------------------------------------------
118
// Implementation of RelocIterator
120
void RelocIterator::initialize(nmethod* nm, address begin, address limit) {
123
if (nm == nullptr && begin != nullptr) {
124
// allow nmethod to be deduced from beginning address
125
CodeBlob* cb = CodeCache::find_blob(begin);
126
nm = (cb != nullptr) ? cb->as_nmethod_or_null() : nullptr;
128
guarantee(nm != nullptr, "must be able to deduce nmethod from other arguments");
131
_current = nm->relocation_begin() - 1;
132
_end = nm->relocation_end();
133
_addr = nm->content_begin();
135
// Initialize code sections.
136
_section_start[CodeBuffer::SECT_CONSTS] = nm->consts_begin();
137
_section_start[CodeBuffer::SECT_INSTS ] = nm->insts_begin() ;
138
_section_start[CodeBuffer::SECT_STUBS ] = nm->stub_begin() ;
140
_section_end [CodeBuffer::SECT_CONSTS] = nm->consts_end() ;
141
_section_end [CodeBuffer::SECT_INSTS ] = nm->insts_end() ;
142
_section_end [CodeBuffer::SECT_STUBS ] = nm->stub_end() ;
144
assert(!has_current(), "just checking");
145
assert(begin == nullptr || begin >= nm->code_begin(), "in bounds");
146
assert(limit == nullptr || limit <= nm->code_end(), "in bounds");
147
set_limits(begin, limit);
151
RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) {
153
assert(((cs->locs_start() != nullptr) && (cs->locs_end() != nullptr)), "valid start and end pointer");
154
_current = cs->locs_start()-1;
155
_end = cs->locs_end();
157
_code = nullptr; // Not cb->blob();
159
CodeBuffer* cb = cs->outer();
160
assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal");
161
for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
162
CodeSection* cs = cb->code_section(n);
163
_section_start[n] = cs->start();
164
_section_end [n] = cs->end();
167
assert(!has_current(), "just checking");
169
assert(begin == nullptr || begin >= cs->start(), "in bounds");
170
assert(limit == nullptr || limit <= cs->end(), "in bounds");
171
set_limits(begin, limit);
174
bool RelocIterator::addr_in_const() const {
175
const int n = CodeBuffer::SECT_CONSTS;
176
return section_start(n) <= addr() && addr() < section_end(n);
180
void RelocIterator::set_limits(address begin, address limit) {
183
// the limit affects this next stuff:
184
if (begin != nullptr) {
190
if (!next() || addr() >= begin) break;
192
// At this point, either we are at the first matching record,
193
// or else there is no such record, and !has_current().
194
// In either case, revert to the immediately preceding state.
197
set_has_current(false);
202
// All the strange bit-encodings are in here.
203
// The idea is to encode relocation data which are small integers
204
// very efficiently (a single extra halfword). Larger chunks of
205
// relocation data need a halfword header to hold their size.
206
void RelocIterator::advance_over_prefix() {
207
if (_current->is_datalen()) {
208
_data = (short*) _current->data();
209
_datalen = _current->datalen();
210
_current += _datalen + 1; // skip the embedded data & header
212
_databuf = _current->immediate();
215
_current++; // skip the header
217
// The client will see the following relocInfo, whatever that is.
218
// It is the reloc to which the preceding data applies.
222
void RelocIterator::initialize_misc() {
223
set_has_current(false);
224
for (int i = (int) CodeBuffer::SECT_FIRST; i < (int) CodeBuffer::SECT_LIMIT; i++) {
225
_section_start[i] = nullptr; // these will be lazily computed, if needed
226
_section_end [i] = nullptr;
231
Relocation* RelocIterator::reloc() {
232
// (take the "switch" out-of-line)
233
relocInfo::relocType t = type();
235
#define EACH_TYPE(name) \
236
else if (t == relocInfo::name##_type) { \
237
return name##_reloc(); \
239
APPLY_TO_RELOCATIONS(EACH_TYPE);
241
assert(t == relocInfo::none, "must be padding");
242
_rh = RelocationHolder::none;
246
// Verify all the destructors are trivial, so we don't need to worry about
247
// destroying old contents of a RelocationHolder being assigned or destroyed.
248
#define VERIFY_TRIVIALLY_DESTRUCTIBLE_AUX(Reloc) \
249
static_assert(std::is_trivially_destructible<Reloc>::value, "must be");
251
#define VERIFY_TRIVIALLY_DESTRUCTIBLE(name) \
252
VERIFY_TRIVIALLY_DESTRUCTIBLE_AUX(PASTE_TOKENS(name, _Relocation));
254
APPLY_TO_RELOCATIONS(VERIFY_TRIVIALLY_DESTRUCTIBLE)
255
VERIFY_TRIVIALLY_DESTRUCTIBLE_AUX(Relocation)
257
#undef VERIFY_TRIVIALLY_DESTRUCTIBLE_AUX
258
#undef VERIFY_TRIVIALLY_DESTRUCTIBLE
260
// Define all the copy_into functions. These rely on all Relocation types
261
// being trivially destructible (verified above). So it doesn't matter
262
// whether the target holder has been previously initialized or not. There's
263
// no need to consider that distinction and destruct the relocation in an
264
// already initialized holder.
265
#define DEFINE_COPY_INTO_AUX(Reloc) \
266
void Reloc::copy_into(RelocationHolder& holder) const { \
267
copy_into_helper(*this, holder); \
270
#define DEFINE_COPY_INTO(name) \
271
DEFINE_COPY_INTO_AUX(PASTE_TOKENS(name, _Relocation))
273
APPLY_TO_RELOCATIONS(DEFINE_COPY_INTO)
274
DEFINE_COPY_INTO_AUX(Relocation)
276
#undef DEFINE_COPY_INTO_AUX
277
#undef DEFINE_COPY_INTO
279
//////// Methods for flyweight Relocation types
281
// some relocations can compute their own values
282
address Relocation::value() {
283
ShouldNotReachHere();
288
void Relocation::set_value(address x) {
289
ShouldNotReachHere();
292
void Relocation::const_set_data_value(address x) {
294
if (format() == relocInfo::narrow_oop_in_const) {
295
*(narrowOop*)addr() = CompressedOops::encode(cast_to_oop(x));
298
*(address*)addr() = x;
304
void Relocation::const_verify_data_value(address x) {
306
if (format() == relocInfo::narrow_oop_in_const) {
307
guarantee(*(narrowOop*)addr() == CompressedOops::encode(cast_to_oop(x)), "must agree");
310
guarantee(*(address*)addr() == x, "must agree");
317
RelocationHolder Relocation::spec_simple(relocInfo::relocType rtype) {
318
if (rtype == relocInfo::none) return RelocationHolder::none;
319
relocInfo ri = relocInfo(rtype, 0);
326
address Relocation::old_addr_for(address newa,
327
const CodeBuffer* src, CodeBuffer* dest) {
328
int sect = dest->section_index_of(newa);
329
guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address");
330
address ostart = src->code_section(sect)->start();
331
address nstart = dest->code_section(sect)->start();
332
return ostart + (newa - nstart);
335
address Relocation::new_addr_for(address olda,
336
const CodeBuffer* src, CodeBuffer* dest) {
337
debug_only(const CodeBuffer* src0 = src);
338
int sect = CodeBuffer::SECT_NONE;
339
// Look for olda in the source buffer, and all previous incarnations
340
// if the source buffer has been expanded.
341
for (; src != nullptr; src = src->before_expand()) {
342
sect = src->section_index_of(olda);
343
if (sect != CodeBuffer::SECT_NONE) break;
345
guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address");
346
address ostart = src->code_section(sect)->start();
347
address nstart = dest->code_section(sect)->start();
348
return nstart + (olda - ostart);
351
void Relocation::normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections) {
352
address addr0 = addr;
353
if (addr0 == nullptr || dest->allocates2(addr0)) return;
354
CodeBuffer* cb = dest->outer();
355
addr = new_addr_for(addr0, cb, cb);
356
assert(allow_other_sections || dest->contains2(addr),
357
"addr must be in required section");
361
void CallRelocation::set_destination(address x) {
362
pd_set_call_destination(x);
365
void CallRelocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
366
// Usually a self-relative reference to an external routine.
367
// On some platforms, the reference is absolute (not self-relative).
368
// The enhanced use of pd_call_destination sorts this all out.
369
address orig_addr = old_addr_for(addr(), src, dest);
370
address callee = pd_call_destination(orig_addr);
371
// Reassert the callee address, this time in the new copy of the code.
372
pd_set_call_destination(callee);
376
#ifdef USE_TRAMPOLINE_STUB_FIX_OWNER
377
void trampoline_stub_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
378
// Finalize owner destination only for nmethods
379
if (dest->blob() != nullptr) return;
380
pd_fix_owner_after_move();
384
//// pack/unpack methods
386
void oop_Relocation::pack_data_to(CodeSection* dest) {
387
short* p = (short*) dest->locs_end();
388
p = pack_1_int_to(p, _oop_index);
389
dest->set_locs_end((relocInfo*) p);
393
void oop_Relocation::unpack_data() {
394
_oop_index = unpack_1_int();
397
void metadata_Relocation::pack_data_to(CodeSection* dest) {
398
short* p = (short*) dest->locs_end();
399
p = pack_1_int_to(p, _metadata_index);
400
dest->set_locs_end((relocInfo*) p);
404
void metadata_Relocation::unpack_data() {
405
_metadata_index = unpack_1_int();
409
void virtual_call_Relocation::pack_data_to(CodeSection* dest) {
410
short* p = (short*) dest->locs_end();
411
address point = dest->locs_point();
413
normalize_address(_cached_value, dest);
414
jint x0 = scaled_offset_null_special(_cached_value, point);
415
p = pack_2_ints_to(p, x0, _method_index);
416
dest->set_locs_end((relocInfo*) p);
420
void virtual_call_Relocation::unpack_data() {
422
unpack_2_ints(x0, _method_index);
423
address point = addr();
424
_cached_value = x0==0? nullptr: address_from_scaled_offset(x0, point);
427
void runtime_call_w_cp_Relocation::pack_data_to(CodeSection * dest) {
428
short* p = pack_1_int_to((short *)dest->locs_end(), (jint)(_offset >> 2));
429
dest->set_locs_end((relocInfo*) p);
432
void runtime_call_w_cp_Relocation::unpack_data() {
433
_offset = unpack_1_int() << 2;
436
void static_stub_Relocation::pack_data_to(CodeSection* dest) {
437
short* p = (short*) dest->locs_end();
438
CodeSection* insts = dest->outer()->insts();
439
normalize_address(_static_call, insts);
440
p = pack_1_int_to(p, scaled_offset(_static_call, insts->start()));
441
dest->set_locs_end((relocInfo*) p);
444
void static_stub_Relocation::unpack_data() {
445
address base = binding()->section_start(CodeBuffer::SECT_INSTS);
446
jint offset = unpack_1_int();
447
_static_call = address_from_scaled_offset(offset, base);
450
void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) {
451
short* p = (short*) dest->locs_end();
452
CodeSection* insts = dest->outer()->insts();
453
normalize_address(_owner, insts);
454
p = pack_1_int_to(p, scaled_offset(_owner, insts->start()));
455
dest->set_locs_end((relocInfo*) p);
458
void trampoline_stub_Relocation::unpack_data() {
459
address base = binding()->section_start(CodeBuffer::SECT_INSTS);
460
_owner = address_from_scaled_offset(unpack_1_int(), base);
463
void external_word_Relocation::pack_data_to(CodeSection* dest) {
464
short* p = (short*) dest->locs_end();
465
int index = ExternalsRecorder::find_index(_target);
466
p = pack_1_int_to(p, index);
467
dest->set_locs_end((relocInfo*) p);
471
void external_word_Relocation::unpack_data() {
472
int index = unpack_1_int();
473
_target = ExternalsRecorder::at(index);
477
void internal_word_Relocation::pack_data_to(CodeSection* dest) {
478
short* p = (short*) dest->locs_end();
479
normalize_address(_target, dest, true);
481
// Check whether my target address is valid within this section.
482
// If not, strengthen the relocation type to point to another section.
483
int sindex = _section;
484
if (sindex == CodeBuffer::SECT_NONE && _target != nullptr
485
&& (!dest->allocates(_target) || _target == dest->locs_point())) {
486
sindex = dest->outer()->section_index_of(_target);
487
guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere");
488
relocInfo* base = dest->locs_end() - 1;
489
assert(base->type() == this->type(), "sanity");
490
// Change the written type, to be section_word_type instead.
491
base->set_type(relocInfo::section_word_type);
494
// Note: An internal_word relocation cannot refer to its own instruction,
495
// because we reserve "0" to mean that the pointer itself is embedded
496
// in the code stream. We use a section_word relocation for such cases.
498
if (sindex == CodeBuffer::SECT_NONE) {
499
assert(type() == relocInfo::internal_word_type, "must be base class");
500
guarantee(_target == nullptr || dest->allocates2(_target), "must be within the given code section");
501
jint x0 = scaled_offset_null_special(_target, dest->locs_point());
502
assert(!(x0 == 0 && _target != nullptr), "correct encoding of null target");
503
p = pack_1_int_to(p, x0);
505
assert(_target != nullptr, "sanity");
506
CodeSection* sect = dest->outer()->code_section(sindex);
507
guarantee(sect->allocates2(_target), "must be in correct section");
508
address base = sect->start();
509
jint offset = scaled_offset(_target, base);
510
assert((uint)sindex < (uint)CodeBuffer::SECT_LIMIT, "sanity");
511
assert(CodeBuffer::SECT_LIMIT <= (1 << section_width), "section_width++");
512
p = pack_1_int_to(p, (offset << section_width) | sindex);
515
dest->set_locs_end((relocInfo*) p);
519
void internal_word_Relocation::unpack_data() {
520
jint x0 = unpack_1_int();
521
_target = x0==0? nullptr: address_from_scaled_offset(x0, addr());
522
_section = CodeBuffer::SECT_NONE;
526
void section_word_Relocation::unpack_data() {
527
jint x = unpack_1_int();
528
jint offset = (x >> section_width);
529
int sindex = (x & ((1<<section_width)-1));
530
address base = binding()->section_start(sindex);
533
_target = address_from_scaled_offset(offset, base);
536
//// miscellaneous methods
537
oop* oop_Relocation::oop_addr() {
540
// oop is stored in the code stream
541
return (oop*) pd_address_in_code();
543
// oop is stored in table at nmethod::oops_begin
544
return code()->oop_addr_at(n);
549
oop oop_Relocation::oop_value() {
550
// clean inline caches store a special pseudo-null
551
if (Universe::contains_non_oop_word(oop_addr())) {
558
void oop_Relocation::fix_oop_relocation() {
559
if (!oop_is_immediate()) {
560
// get the oop from the pool, and re-insert it into the instruction:
566
void oop_Relocation::verify_oop_relocation() {
567
if (!oop_is_immediate()) {
568
// get the oop from the pool, and re-insert it into the instruction:
569
verify_value(value());
574
Metadata** metadata_Relocation::metadata_addr() {
575
int n = _metadata_index;
577
// metadata is stored in the code stream
578
return (Metadata**) pd_address_in_code();
580
// metadata is stored in table at nmethod::metadatas_begin
581
return code()->metadata_addr_at(n);
586
Metadata* metadata_Relocation::metadata_value() {
587
Metadata* v = *metadata_addr();
588
// clean inline caches store a special pseudo-null
589
if (v == (Metadata*)Universe::non_oop_word()) v = nullptr;
594
void metadata_Relocation::fix_metadata_relocation() {
595
if (!metadata_is_immediate()) {
596
// get the metadata from the pool, and re-insert it into the instruction:
597
pd_fix_value(value());
601
address virtual_call_Relocation::cached_value() {
602
assert(_cached_value != nullptr && _cached_value < addr(), "must precede ic_call");
603
return _cached_value;
606
Method* virtual_call_Relocation::method_value() {
607
nmethod* nm = code();
608
if (nm == nullptr) return (Method*)nullptr;
609
Metadata* m = nm->metadata_at(_method_index);
610
assert(m != nullptr || _method_index == 0, "should be non-null for non-zero index");
611
assert(m == nullptr || m->is_method(), "not a method");
615
void virtual_call_Relocation::clear_inline_cache() {
617
CompiledIC* icache = CompiledIC_at(this);
618
icache->set_to_clean();
622
void opt_virtual_call_Relocation::pack_data_to(CodeSection* dest) {
623
short* p = (short*) dest->locs_end();
624
p = pack_1_int_to(p, _method_index);
625
dest->set_locs_end((relocInfo*) p);
628
void opt_virtual_call_Relocation::unpack_data() {
629
_method_index = unpack_1_int();
632
Method* opt_virtual_call_Relocation::method_value() {
633
nmethod* nm = code();
634
if (nm == nullptr) return (Method*)nullptr;
635
Metadata* m = nm->metadata_at(_method_index);
636
assert(m != nullptr || _method_index == 0, "should be non-null for non-zero index");
637
assert(m == nullptr || m->is_method(), "not a method");
641
void opt_virtual_call_Relocation::clear_inline_cache() {
643
CompiledDirectCall* callsite = CompiledDirectCall::at(this);
644
callsite->set_to_clean();
647
address opt_virtual_call_Relocation::static_stub() {
648
// search for the static stub who points back to this static call
649
address static_call_addr = addr();
650
RelocIterator iter(code());
651
while (iter.next()) {
652
if (iter.type() == relocInfo::static_stub_type) {
653
static_stub_Relocation* stub_reloc = iter.static_stub_reloc();
654
if (stub_reloc->static_call() == static_call_addr) {
662
Method* static_call_Relocation::method_value() {
663
nmethod* nm = code();
664
if (nm == nullptr) return (Method*)nullptr;
665
Metadata* m = nm->metadata_at(_method_index);
666
assert(m != nullptr || _method_index == 0, "should be non-null for non-zero index");
667
assert(m == nullptr || m->is_method(), "not a method");
671
void static_call_Relocation::pack_data_to(CodeSection* dest) {
672
short* p = (short*) dest->locs_end();
673
p = pack_1_int_to(p, _method_index);
674
dest->set_locs_end((relocInfo*) p);
677
void static_call_Relocation::unpack_data() {
678
_method_index = unpack_1_int();
681
void static_call_Relocation::clear_inline_cache() {
683
CompiledDirectCall* callsite = CompiledDirectCall::at(this);
684
callsite->set_to_clean();
688
address static_call_Relocation::static_stub() {
689
// search for the static stub who points back to this static call
690
address static_call_addr = addr();
691
RelocIterator iter(code());
692
while (iter.next()) {
693
if (iter.type() == relocInfo::static_stub_type) {
694
static_stub_Relocation* stub_reloc = iter.static_stub_reloc();
695
if (stub_reloc->static_call() == static_call_addr) {
703
// Finds the trampoline address for a call. If no trampoline stub is
704
// found nullptr is returned which can be handled by the caller.
705
address trampoline_stub_Relocation::get_trampoline_for(address call, nmethod* code) {
706
// There are no relocations available when the code gets relocated
707
// because of CodeBuffer expansion.
708
if (code->relocation_size() == 0)
711
RelocIterator iter(code, call);
712
while (iter.next()) {
713
if (iter.type() == relocInfo::trampoline_stub_type) {
714
if (iter.trampoline_stub_reloc()->owner() == call) {
723
void static_stub_Relocation::clear_inline_cache() {
724
// Call stub is only used when calling the interpreted code.
725
// It does not really need to be cleared, except that we want to clean out the methodoop.
726
CompiledDirectCall::set_stub_to_clean(this);
730
void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
731
if (_target != nullptr) {
732
// Probably this reference is absolute, not relative, so the following is
736
// If target is nullptr, this is an absolute embedded reference to an external
737
// location, which means there is nothing to fix here. In either case, the
738
// resulting target should be an "external" address.
739
postcond(src->section_index_of(target()) == CodeBuffer::SECT_NONE);
740
postcond(dest->section_index_of(target()) == CodeBuffer::SECT_NONE);
744
address external_word_Relocation::target() {
745
address target = _target;
746
if (target == nullptr) {
747
target = pd_get_address_from_code();
753
void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
754
address target = _target;
755
if (target == nullptr) {
756
target = new_addr_for(this->target(), src, dest);
762
address internal_word_Relocation::target() {
763
address target = _target;
764
if (target == nullptr) {
765
if (addr_in_const()) {
766
target = *(address*)addr();
768
target = pd_get_address_from_code();
774
//---------------------------------------------------------------------------------
779
static const char* reloc_type_string(relocInfo::relocType t) {
781
#define EACH_CASE(name) \
782
case relocInfo::name##_type: \
785
APPLY_TO_RELOCATIONS(EACH_CASE);
788
case relocInfo::none:
790
case relocInfo::data_prefix_tag:
793
return "UNKNOWN RELOC TYPE";
798
void RelocIterator::print_current() {
799
if (!has_current()) {
800
tty->print_cr("(no relocs)");
803
tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d",
804
p2i(_current), type(), reloc_type_string((relocInfo::relocType) type()), p2i(_addr), _current->addr_offset());
805
if (current()->format() != 0)
806
tty->print(" format=%d", current()->format());
807
if (datalen() == 1) {
808
tty->print(" data=%d", data()[0]);
809
} else if (datalen() > 0) {
810
tty->print(" data={");
811
for (int i = 0; i < datalen(); i++) {
812
tty->print("%04x", data()[i] & 0xFFFF);
818
case relocInfo::oop_type:
820
oop_Relocation* r = oop_reloc();
821
oop* oop_addr = nullptr;
822
oop raw_oop = nullptr;
823
oop oop_value = nullptr;
824
if (code() != nullptr || r->oop_is_immediate()) {
825
oop_addr = r->oop_addr();
827
oop_value = r->oop_value();
829
tty->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT "]",
830
p2i(oop_addr), p2i(raw_oop));
831
// Do not print the oop by default--we want this routine to
832
// work even during GC or other inconvenient times.
833
if (WizardMode && oop_value != nullptr) {
834
tty->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));
835
if (oopDesc::is_oop(oop_value)) {
836
oop_value->print_value_on(tty);
841
case relocInfo::metadata_type:
843
metadata_Relocation* r = metadata_reloc();
844
Metadata** metadata_addr = nullptr;
845
Metadata* raw_metadata = nullptr;
846
Metadata* metadata_value = nullptr;
847
if (code() != nullptr || r->metadata_is_immediate()) {
848
metadata_addr = r->metadata_addr();
849
raw_metadata = *metadata_addr;
850
metadata_value = r->metadata_value();
852
tty->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT "]",
853
p2i(metadata_addr), p2i(raw_metadata));
854
if (metadata_value != nullptr) {
855
tty->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));
856
metadata_value->print_value_on(tty);
860
case relocInfo::external_word_type:
861
case relocInfo::internal_word_type:
862
case relocInfo::section_word_type:
864
DataRelocation* r = (DataRelocation*) reloc();
865
tty->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target
868
case relocInfo::static_call_type:
870
static_call_Relocation* r = (static_call_Relocation*) reloc();
871
tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
872
p2i(r->destination()), p2i(r->method_value()));
875
case relocInfo::runtime_call_type:
876
case relocInfo::runtime_call_w_cp_type:
878
CallRelocation* r = (CallRelocation*) reloc();
879
tty->print(" | [destination=" INTPTR_FORMAT "]", p2i(r->destination()));
882
case relocInfo::virtual_call_type:
884
virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
885
tty->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
886
p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));
889
case relocInfo::static_stub_type:
891
static_stub_Relocation* r = (static_stub_Relocation*) reloc();
892
tty->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call()));
895
case relocInfo::trampoline_stub_type:
897
trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc();
898
tty->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner()));
901
case relocInfo::opt_virtual_call_type:
903
opt_virtual_call_Relocation* r = (opt_virtual_call_Relocation*) reloc();
904
tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
905
p2i(r->destination()), p2i(r->method_value()));
915
void RelocIterator::print() {
916
RelocIterator save_this = (*this);
917
relocInfo* scan = _current;
918
if (!has_current()) scan += 1; // nothing to scan here!
920
bool skip_next = has_current();
923
got_next = (skip_next || next());
926
tty->print(" @" INTPTR_FORMAT ": ", p2i(scan));
927
relocInfo* newscan = _current+1;
928
if (!has_current()) newscan -= 1; // nothing to scan here!
929
while (scan < newscan) {
930
tty->print("%04x", *(short*)scan & 0xFFFF);
935
if (!got_next) break;
944
void print_blob_locs(nmethod* nm) {
946
RelocIterator iter(nm);
950
void print_buf_locs(CodeBuffer* cb) {
951
FlagSetting fs(PrintRelocations, true);