Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/code/relocInfo.hpp
40931 views
1
/*
2
* Copyright (c) 1997, 2021, 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
#ifndef SHARE_CODE_RELOCINFO_HPP
26
#define SHARE_CODE_RELOCINFO_HPP
27
28
#include "runtime/os.hpp"
29
#include "utilities/macros.hpp"
30
31
class nmethod;
32
class CodeBlob;
33
class CompiledMethod;
34
class Metadata;
35
class NativeMovConstReg;
36
37
// Types in this file:
38
// relocInfo
39
// One element of an array of halfwords encoding compressed relocations.
40
// Also, the source of relocation types (relocInfo::oop_type, ...).
41
// Relocation
42
// A flyweight object representing a single relocation.
43
// It is fully unpacked from the compressed relocation array.
44
// metadata_Relocation, ... (subclasses of Relocation)
45
// The location of some type-specific operations (metadata_addr, ...).
46
// Also, the source of relocation specs (metadata_Relocation::spec, ...).
47
// oop_Relocation, ... (subclasses of Relocation)
48
// oops in the code stream (strings, class loaders)
49
// Also, the source of relocation specs (oop_Relocation::spec, ...).
50
// RelocationHolder
51
// A value type which acts as a union holding a Relocation object.
52
// Represents a relocation spec passed into a CodeBuffer during assembly.
53
// RelocIterator
54
// A StackObj which iterates over the relocations associated with
55
// a range of code addresses. Can be used to operate a copy of code.
56
57
58
// Notes on relocType:
59
//
60
// These hold enough information to read or write a value embedded in
61
// the instructions of an CodeBlob. They're used to update:
62
//
63
// 1) embedded oops (isOop() == true)
64
// 2) inline caches (isIC() == true)
65
// 3) runtime calls (isRuntimeCall() == true)
66
// 4) internal word ref (isInternalWord() == true)
67
// 5) external word ref (isExternalWord() == true)
68
//
69
// when objects move (GC) or if code moves (compacting the code heap).
70
// They are also used to patch the code (if a call site must change)
71
//
72
// A relocInfo is represented in 16 bits:
73
// 4 bits indicating the relocation type
74
// 12 bits indicating the offset from the previous relocInfo address
75
//
76
// The offsets accumulate along the relocInfo stream to encode the
77
// address within the CodeBlob, which is named RelocIterator::addr().
78
// The address of a particular relocInfo always points to the first
79
// byte of the relevant instruction (and not to any of its subfields
80
// or embedded immediate constants).
81
//
82
// The offset value is scaled appropriately for the target machine.
83
// (See relocInfo_<arch>.hpp for the offset scaling.)
84
//
85
// On some machines, there may also be a "format" field which may provide
86
// additional information about the format of the instruction stream
87
// at the corresponding code address. The format value is usually zero.
88
// Any machine (such as Intel) whose instructions can sometimes contain
89
// more than one relocatable constant needs format codes to distinguish
90
// which operand goes with a given relocation.
91
//
92
// If the target machine needs N format bits, the offset has 12-N bits,
93
// the format is encoded between the offset and the type, and the
94
// relocInfo_<arch>.hpp file has manifest constants for the format codes.
95
//
96
// If the type is "data_prefix_tag" then the offset bits are further encoded,
97
// and in fact represent not a code-stream offset but some inline data.
98
// The data takes the form of a counted sequence of halfwords, which
99
// precedes the actual relocation record. (Clients never see it directly.)
100
// The interpetation of this extra data depends on the relocation type.
101
//
102
// On machines that have 32-bit immediate fields, there is usually
103
// little need for relocation "prefix" data, because the instruction stream
104
// is a perfectly reasonable place to store the value. On machines in
105
// which 32-bit values must be "split" across instructions, the relocation
106
// data is the "true" specification of the value, which is then applied
107
// to some field of the instruction (22 or 13 bits, on SPARC).
108
//
109
// Whenever the location of the CodeBlob changes, any PC-relative
110
// relocations, and any internal_word_type relocations, must be reapplied.
111
// After the GC runs, oop_type relocations must be reapplied.
112
//
113
//
114
// Here are meanings of the types:
115
//
116
// relocInfo::none -- a filler record
117
// Value: none
118
// Instruction: The corresponding code address is ignored
119
// Data: Any data prefix and format code are ignored
120
// (This means that any relocInfo can be disabled by setting
121
// its type to none. See relocInfo::remove.)
122
//
123
// relocInfo::oop_type, relocInfo::metadata_type -- a reference to an oop or meta data
124
// Value: an oop, or else the address (handle) of an oop
125
// Instruction types: memory (load), set (load address)
126
// Data: [] an oop stored in 4 bytes of instruction
127
// [n] n is the index of an oop in the CodeBlob's oop pool
128
// [[N]n l] and l is a byte offset to be applied to the oop
129
// [Nn Ll] both index and offset may be 32 bits if necessary
130
// Here is a special hack, used only by the old compiler:
131
// [[N]n 00] the value is the __address__ of the nth oop in the pool
132
// (Note that the offset allows optimal references to class variables.)
133
//
134
// relocInfo::internal_word_type -- an address within the same CodeBlob
135
// relocInfo::section_word_type -- same, but can refer to another section
136
// Value: an address in the CodeBlob's code or constants section
137
// Instruction types: memory (load), set (load address)
138
// Data: [] stored in 4 bytes of instruction
139
// [[L]l] a relative offset (see [About Offsets] below)
140
// In the case of section_word_type, the offset is relative to a section
141
// base address, and the section number (e.g., SECT_INSTS) is encoded
142
// into the low two bits of the offset L.
143
//
144
// relocInfo::external_word_type -- a fixed address in the runtime system
145
// Value: an address
146
// Instruction types: memory (load), set (load address)
147
// Data: [] stored in 4 bytes of instruction
148
// [n] the index of a "well-known" stub (usual case on RISC)
149
// [Ll] a 32-bit address
150
//
151
// relocInfo::runtime_call_type -- a fixed subroutine in the runtime system
152
// Value: an address
153
// Instruction types: PC-relative call (or a PC-relative branch)
154
// Data: [] stored in 4 bytes of instruction
155
//
156
// relocInfo::static_call_type -- a static call
157
// Value: an CodeBlob, a stub, or a fixup routine
158
// Instruction types: a call
159
// Data: []
160
// The identity of the callee is extracted from debugging information.
161
// //%note reloc_3
162
//
163
// relocInfo::virtual_call_type -- a virtual call site (which includes an inline
164
// cache)
165
// Value: an CodeBlob, a stub, the interpreter, or a fixup routine
166
// Instruction types: a call, plus some associated set-oop instructions
167
// Data: [] the associated set-oops are adjacent to the call
168
// [n] n is a relative offset to the first set-oop
169
// [[N]n l] and l is a limit within which the set-oops occur
170
// [Nn Ll] both n and l may be 32 bits if necessary
171
// The identity of the callee is extracted from debugging information.
172
//
173
// relocInfo::opt_virtual_call_type -- a virtual call site that is statically bound
174
//
175
// Same info as a static_call_type. We use a special type, so the handling of
176
// virtuals and statics are separated.
177
//
178
//
179
// The offset n points to the first set-oop. (See [About Offsets] below.)
180
// In turn, the set-oop instruction specifies or contains an oop cell devoted
181
// exclusively to the IC call, which can be patched along with the call.
182
//
183
// The locations of any other set-oops are found by searching the relocation
184
// information starting at the first set-oop, and continuing until all
185
// relocations up through l have been inspected. The value l is another
186
// relative offset. (Both n and l are relative to the call's first byte.)
187
//
188
// The limit l of the search is exclusive. However, if it points within
189
// the call (e.g., offset zero), it is adjusted to point after the call and
190
// any associated machine-specific delay slot.
191
//
192
// Since the offsets could be as wide as 32-bits, these conventions
193
// put no restrictions whatever upon code reorganization.
194
//
195
// The compiler is responsible for ensuring that transition from a clean
196
// state to a monomorphic compiled state is MP-safe. This implies that
197
// the system must respond well to intermediate states where a random
198
// subset of the set-oops has been correctly from the clean state
199
// upon entry to the VEP of the compiled method. In the case of a
200
// machine (Intel) with a single set-oop instruction, the 32-bit
201
// immediate field must not straddle a unit of memory coherence.
202
// //%note reloc_3
203
//
204
// relocInfo::static_stub_type -- an extra stub for each static_call_type
205
// Value: none
206
// Instruction types: a virtual call: { set_oop; jump; }
207
// Data: [[N]n] the offset of the associated static_call reloc
208
// This stub becomes the target of a static call which must be upgraded
209
// to a virtual call (because the callee is interpreted).
210
// See [About Offsets] below.
211
// //%note reloc_2
212
//
213
// relocInfo::poll_[return_]type -- a safepoint poll
214
// Value: none
215
// Instruction types: memory load or test
216
// Data: none
217
//
218
// For example:
219
//
220
// INSTRUCTIONS RELOC: TYPE PREFIX DATA
221
// ------------ ---- -----------
222
// sethi %hi(myObject), R oop_type [n(myObject)]
223
// ld [R+%lo(myObject)+fldOffset], R2 oop_type [n(myObject) fldOffset]
224
// add R2, 1, R2
225
// st R2, [R+%lo(myObject)+fldOffset] oop_type [n(myObject) fldOffset]
226
//%note reloc_1
227
//
228
// This uses 4 instruction words, 8 relocation halfwords,
229
// and an entry (which is sharable) in the CodeBlob's oop pool,
230
// for a total of 36 bytes.
231
//
232
// Note that the compiler is responsible for ensuring the "fldOffset" when
233
// added to "%lo(myObject)" does not overflow the immediate fields of the
234
// memory instructions.
235
//
236
//
237
// [About Offsets] Relative offsets are supplied to this module as
238
// positive byte offsets, but they may be internally stored scaled
239
// and/or negated, depending on what is most compact for the target
240
// system. Since the object pointed to by the offset typically
241
// precedes the relocation address, it is profitable to store
242
// these negative offsets as positive numbers, but this decision
243
// is internal to the relocation information abstractions.
244
//
245
246
class Relocation;
247
class CodeBuffer;
248
class CodeSection;
249
class RelocIterator;
250
251
class relocInfo {
252
friend class RelocIterator;
253
public:
254
enum relocType {
255
none = 0, // Used when no relocation should be generated
256
oop_type = 1, // embedded oop
257
virtual_call_type = 2, // a standard inline cache call for a virtual send
258
opt_virtual_call_type = 3, // a virtual call that has been statically bound (i.e., no IC cache)
259
static_call_type = 4, // a static send
260
static_stub_type = 5, // stub-entry for static send (takes care of interpreter case)
261
runtime_call_type = 6, // call to fixed external routine
262
external_word_type = 7, // reference to fixed external address
263
internal_word_type = 8, // reference within the current code blob
264
section_word_type = 9, // internal, but a cross-section reference
265
poll_type = 10, // polling instruction for safepoints
266
poll_return_type = 11, // polling instruction for safepoints at return
267
metadata_type = 12, // metadata that used to be oops
268
trampoline_stub_type = 13, // stub-entry for trampoline
269
runtime_call_w_cp_type = 14, // Runtime call which may load its target from the constant pool
270
data_prefix_tag = 15, // tag for a prefix (carries data arguments)
271
type_mask = 15 // A mask which selects only the above values
272
};
273
274
private:
275
unsigned short _value;
276
277
static const enum class RawBitsToken {} RAW_BITS{};
278
279
relocInfo(relocType type, RawBitsToken, int bits)
280
: _value((type << nontype_width) + bits) { }
281
282
static relocType check_relocType(relocType type) NOT_DEBUG({ return type; });
283
284
static void check_offset_and_format(int offset, int format) NOT_DEBUG_RETURN;
285
286
static int compute_bits(int offset, int format) {
287
check_offset_and_format(offset, format);
288
return (offset / offset_unit) + (format << offset_width);
289
}
290
291
public:
292
relocInfo(relocType type, int offset, int format = 0)
293
: relocInfo(check_relocType(type), RAW_BITS, compute_bits(offset, format)) {}
294
295
#define APPLY_TO_RELOCATIONS(visitor) \
296
visitor(oop) \
297
visitor(metadata) \
298
visitor(virtual_call) \
299
visitor(opt_virtual_call) \
300
visitor(static_call) \
301
visitor(static_stub) \
302
visitor(runtime_call) \
303
visitor(runtime_call_w_cp) \
304
visitor(external_word) \
305
visitor(internal_word) \
306
visitor(poll) \
307
visitor(poll_return) \
308
visitor(section_word) \
309
visitor(trampoline_stub) \
310
311
312
public:
313
enum {
314
value_width = sizeof(unsigned short) * BitsPerByte,
315
type_width = 4, // == log2(type_mask+1)
316
nontype_width = value_width - type_width,
317
datalen_width = nontype_width-1,
318
datalen_tag = 1 << datalen_width, // or-ed into _value
319
datalen_limit = 1 << datalen_width,
320
datalen_mask = (1 << datalen_width)-1
321
};
322
323
// accessors
324
public:
325
relocType type() const { return (relocType)((unsigned)_value >> nontype_width); }
326
int format() const { return format_mask==0? 0: format_mask &
327
((unsigned)_value >> offset_width); }
328
int addr_offset() const { assert(!is_prefix(), "must have offset");
329
return (_value & offset_mask)*offset_unit; }
330
331
protected:
332
const short* data() const { assert(is_datalen(), "must have data");
333
return (const short*)(this + 1); }
334
int datalen() const { assert(is_datalen(), "must have data");
335
return (_value & datalen_mask); }
336
int immediate() const { assert(is_immediate(), "must have immed");
337
return (_value & datalen_mask); }
338
public:
339
static int addr_unit() { return offset_unit; }
340
static int offset_limit() { return (1 << offset_width) * offset_unit; }
341
342
void set_type(relocType type);
343
344
void remove() { set_type(none); }
345
346
protected:
347
bool is_none() const { return type() == none; }
348
bool is_prefix() const { return type() == data_prefix_tag; }
349
bool is_datalen() const { assert(is_prefix(), "must be prefix");
350
return (_value & datalen_tag) != 0; }
351
bool is_immediate() const { assert(is_prefix(), "must be prefix");
352
return (_value & datalen_tag) == 0; }
353
354
public:
355
// Occasionally records of type relocInfo::none will appear in the stream.
356
// We do not bother to filter these out, but clients should ignore them.
357
// These records serve as "filler" in three ways:
358
// - to skip large spans of unrelocated code (this is rare)
359
// - to pad out the relocInfo array to the required oop alignment
360
// - to disable old relocation information which is no longer applicable
361
362
inline friend relocInfo filler_relocInfo();
363
364
// Every non-prefix relocation may be preceded by at most one prefix,
365
// which supplies 1 or more halfwords of associated data. Conventionally,
366
// an int is represented by 0, 1, or 2 halfwords, depending on how
367
// many bits are required to represent the value. (In addition,
368
// if the sole halfword is a 10-bit unsigned number, it is made
369
// "immediate" in the prefix header word itself. This optimization
370
// is invisible outside this module.)
371
372
inline friend relocInfo prefix_relocInfo(int datalen);
373
374
private:
375
// an immediate relocInfo optimizes a prefix with one 10-bit unsigned value
376
static relocInfo immediate_relocInfo(int data0) {
377
assert(fits_into_immediate(data0), "data0 in limits");
378
return relocInfo(relocInfo::data_prefix_tag, RAW_BITS, data0);
379
}
380
static bool fits_into_immediate(int data0) {
381
return (data0 >= 0 && data0 < datalen_limit);
382
}
383
384
public:
385
// Support routines for compilers.
386
387
// This routine takes an infant relocInfo (unprefixed) and
388
// edits in its prefix, if any. It also updates dest.locs_end.
389
void initialize(CodeSection* dest, Relocation* reloc);
390
391
// This routine updates a prefix and returns the limit pointer.
392
// It tries to compress the prefix from 32 to 16 bits, and if
393
// successful returns a reduced "prefix_limit" pointer.
394
relocInfo* finish_prefix(short* prefix_limit);
395
396
// bit-packers for the data array:
397
398
// As it happens, the bytes within the shorts are ordered natively,
399
// but the shorts within the word are ordered big-endian.
400
// This is an arbitrary choice, made this way mainly to ease debugging.
401
static int data0_from_int(jint x) { return x >> value_width; }
402
static int data1_from_int(jint x) { return (short)x; }
403
static jint jint_from_data(short* data) {
404
return (data[0] << value_width) + (unsigned short)data[1];
405
}
406
407
static jint short_data_at(int n, short* data, int datalen) {
408
return datalen > n ? data[n] : 0;
409
}
410
411
static jint jint_data_at(int n, short* data, int datalen) {
412
return datalen > n+1 ? jint_from_data(&data[n]) : short_data_at(n, data, datalen);
413
}
414
415
// Update methods for relocation information
416
// (since code is dynamically patched, we also need to dynamically update the relocation info)
417
// Both methods takes old_type, so it is able to performe sanity checks on the information removed.
418
static void change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type);
419
420
// Machine dependent stuff
421
#include CPU_HEADER(relocInfo)
422
423
protected:
424
// Derived constant, based on format_width which is PD:
425
enum {
426
offset_width = nontype_width - format_width,
427
offset_mask = (1<<offset_width) - 1,
428
format_mask = (1<<format_width) - 1
429
};
430
public:
431
enum {
432
#ifdef _LP64
433
// for use in format
434
// format_width must be at least 1 on _LP64
435
narrow_oop_in_const = 1,
436
#endif
437
// Conservatively large estimate of maximum length (in shorts)
438
// of any relocation record.
439
// Extended format is length prefix, data words, and tag/offset suffix.
440
length_limit = 1 + 1 + (3*BytesPerWord/BytesPerShort) + 1,
441
have_format = format_width > 0
442
};
443
};
444
445
#define FORWARD_DECLARE_EACH_CLASS(name) \
446
class name##_Relocation;
447
APPLY_TO_RELOCATIONS(FORWARD_DECLARE_EACH_CLASS)
448
#undef FORWARD_DECLARE_EACH_CLASS
449
450
451
452
inline relocInfo filler_relocInfo() {
453
return relocInfo(relocInfo::none, relocInfo::offset_limit() - relocInfo::offset_unit);
454
}
455
456
inline relocInfo prefix_relocInfo(int datalen = 0) {
457
assert(relocInfo::fits_into_immediate(datalen), "datalen in limits");
458
return relocInfo(relocInfo::data_prefix_tag, relocInfo::RAW_BITS, relocInfo::datalen_tag | datalen);
459
}
460
461
462
// Holder for flyweight relocation objects.
463
// Although the flyweight subclasses are of varying sizes,
464
// the holder is "one size fits all".
465
class RelocationHolder {
466
friend class Relocation;
467
friend class CodeSection;
468
469
private:
470
// this preallocated memory must accommodate all subclasses of Relocation
471
// (this number is assertion-checked in Relocation::operator new)
472
enum { _relocbuf_size = 5 };
473
void* _relocbuf[ _relocbuf_size ];
474
475
public:
476
Relocation* reloc() const { return (Relocation*) &_relocbuf[0]; }
477
inline relocInfo::relocType type() const;
478
479
// Add a constant offset to a relocation. Helper for class Address.
480
RelocationHolder plus(int offset) const;
481
482
inline RelocationHolder(); // initializes type to none
483
484
inline RelocationHolder(Relocation* r); // make a copy
485
486
static const RelocationHolder none;
487
};
488
489
// A RelocIterator iterates through the relocation information of a CodeBlob.
490
// It provides access to successive relocations as it is advanced through a
491
// code stream.
492
// Usage:
493
// RelocIterator iter(nm);
494
// while (iter.next()) {
495
// iter.reloc()->some_operation();
496
// }
497
// or:
498
// RelocIterator iter(nm);
499
// while (iter.next()) {
500
// switch (iter.type()) {
501
// case relocInfo::oop_type :
502
// case relocInfo::ic_type :
503
// case relocInfo::prim_type :
504
// case relocInfo::uncommon_type :
505
// case relocInfo::runtime_call_type :
506
// case relocInfo::internal_word_type:
507
// case relocInfo::external_word_type:
508
// ...
509
// }
510
// }
511
512
class RelocIterator : public StackObj {
513
friend class section_word_Relocation; // for section verification
514
enum { SECT_LIMIT = 3 }; // must be equal to CodeBuffer::SECT_LIMIT, checked in ctor
515
friend class Relocation;
516
friend class relocInfo; // for change_reloc_info_for_address only
517
typedef relocInfo::relocType relocType;
518
519
private:
520
address _limit; // stop producing relocations after this _addr
521
relocInfo* _current; // the current relocation information
522
relocInfo* _end; // end marker; we're done iterating when _current == _end
523
CompiledMethod* _code; // compiled method containing _addr
524
address _addr; // instruction to which the relocation applies
525
short _databuf; // spare buffer for compressed data
526
short* _data; // pointer to the relocation's data
527
short _datalen; // number of halfwords in _data
528
529
// Base addresses needed to compute targets of section_word_type relocs.
530
address _section_start[SECT_LIMIT];
531
address _section_end [SECT_LIMIT];
532
533
void set_has_current(bool b) {
534
_datalen = !b ? -1 : 0;
535
debug_only(_data = NULL);
536
}
537
void set_current(relocInfo& ri) {
538
_current = &ri;
539
set_has_current(true);
540
}
541
542
RelocationHolder _rh; // where the current relocation is allocated
543
544
relocInfo* current() const { assert(has_current(), "must have current");
545
return _current; }
546
547
void set_limits(address begin, address limit);
548
549
void advance_over_prefix(); // helper method
550
551
void initialize_misc();
552
553
void initialize(CompiledMethod* nm, address begin, address limit);
554
555
RelocIterator() { initialize_misc(); }
556
557
public:
558
// constructor
559
RelocIterator(CompiledMethod* nm, address begin = NULL, address limit = NULL);
560
RelocIterator(CodeSection* cb, address begin = NULL, address limit = NULL);
561
562
// get next reloc info, return !eos
563
bool next() {
564
_current++;
565
assert(_current <= _end, "must not overrun relocInfo");
566
if (_current == _end) {
567
set_has_current(false);
568
return false;
569
}
570
set_has_current(true);
571
572
if (_current->is_prefix()) {
573
advance_over_prefix();
574
assert(!current()->is_prefix(), "only one prefix at a time");
575
}
576
577
_addr += _current->addr_offset();
578
579
if (_limit != NULL && _addr >= _limit) {
580
set_has_current(false);
581
return false;
582
}
583
584
return true;
585
}
586
587
// accessors
588
address limit() const { return _limit; }
589
relocType type() const { return current()->type(); }
590
int format() const { return (relocInfo::have_format) ? current()->format() : 0; }
591
address addr() const { return _addr; }
592
CompiledMethod* code() const { return _code; }
593
short* data() const { return _data; }
594
int datalen() const { return _datalen; }
595
bool has_current() const { return _datalen >= 0; }
596
bool addr_in_const() const;
597
598
address section_start(int n) const {
599
assert(_section_start[n], "must be initialized");
600
return _section_start[n];
601
}
602
address section_end(int n) const {
603
assert(_section_end[n], "must be initialized");
604
return _section_end[n];
605
}
606
607
// The address points to the affected displacement part of the instruction.
608
// For RISC, this is just the whole instruction.
609
// For Intel, this is an unaligned 32-bit word.
610
611
// type-specific relocation accessors: oop_Relocation* oop_reloc(), etc.
612
#define EACH_TYPE(name) \
613
inline name##_Relocation* name##_reloc();
614
APPLY_TO_RELOCATIONS(EACH_TYPE)
615
#undef EACH_TYPE
616
// generic relocation accessor; switches on type to call the above
617
Relocation* reloc();
618
619
#ifndef PRODUCT
620
public:
621
void print();
622
void print_current();
623
#endif
624
};
625
626
627
// A Relocation is a flyweight object allocated within a RelocationHolder.
628
// It represents the relocation data of relocation record.
629
// So, the RelocIterator unpacks relocInfos into Relocations.
630
631
class Relocation {
632
friend class RelocationHolder;
633
friend class RelocIterator;
634
635
private:
636
// When a relocation has been created by a RelocIterator,
637
// this field is non-null. It allows the relocation to know
638
// its context, such as the address to which it applies.
639
RelocIterator* _binding;
640
641
relocInfo::relocType _rtype;
642
643
protected:
644
RelocIterator* binding() const {
645
assert(_binding != NULL, "must be bound");
646
return _binding;
647
}
648
void set_binding(RelocIterator* b) {
649
assert(_binding == NULL, "must be unbound");
650
_binding = b;
651
assert(_binding != NULL, "must now be bound");
652
}
653
654
Relocation(relocInfo::relocType rtype) : _binding(NULL), _rtype(rtype) { }
655
656
static RelocationHolder newHolder() {
657
return RelocationHolder();
658
}
659
660
public:
661
void* operator new(size_t size, const RelocationHolder& holder) throw() {
662
assert(size <= sizeof(holder._relocbuf), "Make _relocbuf bigger!");
663
assert((void* const *)holder.reloc() == &holder._relocbuf[0], "ptrs must agree");
664
return holder.reloc();
665
}
666
667
// make a generic relocation for a given type (if possible)
668
static RelocationHolder spec_simple(relocInfo::relocType rtype);
669
670
// here is the type-specific hook which writes relocation data:
671
virtual void pack_data_to(CodeSection* dest) { }
672
673
// here is the type-specific hook which reads (unpacks) relocation data:
674
virtual void unpack_data() {
675
assert(datalen()==0 || type()==relocInfo::none, "no data here");
676
}
677
678
protected:
679
// Helper functions for pack_data_to() and unpack_data().
680
681
// Most of the compression logic is confined here.
682
// (The "immediate data" mechanism of relocInfo works independently
683
// of this stuff, and acts to further compress most 1-word data prefixes.)
684
685
// A variable-width int is encoded as a short if it will fit in 16 bits.
686
// The decoder looks at datalen to decide whether to unpack short or jint.
687
// Most relocation records are quite simple, containing at most two ints.
688
689
static bool is_short(jint x) { return x == (short)x; }
690
static short* add_short(short* p, int x) { *p++ = x; return p; }
691
static short* add_jint (short* p, jint x) {
692
*p++ = relocInfo::data0_from_int(x); *p++ = relocInfo::data1_from_int(x);
693
return p;
694
}
695
static short* add_var_int(short* p, jint x) { // add a variable-width int
696
if (is_short(x)) p = add_short(p, x);
697
else p = add_jint (p, x);
698
return p;
699
}
700
701
static short* pack_1_int_to(short* p, jint x0) {
702
// Format is one of: [] [x] [Xx]
703
if (x0 != 0) p = add_var_int(p, x0);
704
return p;
705
}
706
int unpack_1_int() {
707
assert(datalen() <= 2, "too much data");
708
return relocInfo::jint_data_at(0, data(), datalen());
709
}
710
711
// With two ints, the short form is used only if both ints are short.
712
short* pack_2_ints_to(short* p, jint x0, jint x1) {
713
// Format is one of: [] [x y?] [Xx Y?y]
714
if (x0 == 0 && x1 == 0) {
715
// no halfwords needed to store zeroes
716
} else if (is_short(x0) && is_short(x1)) {
717
// 1-2 halfwords needed to store shorts
718
p = add_short(p, x0); if (x1!=0) p = add_short(p, x1);
719
} else {
720
// 3-4 halfwords needed to store jints
721
p = add_jint(p, x0); p = add_var_int(p, x1);
722
}
723
return p;
724
}
725
void unpack_2_ints(jint& x0, jint& x1) {
726
int dlen = datalen();
727
short* dp = data();
728
if (dlen <= 2) {
729
x0 = relocInfo::short_data_at(0, dp, dlen);
730
x1 = relocInfo::short_data_at(1, dp, dlen);
731
} else {
732
assert(dlen <= 4, "too much data");
733
x0 = relocInfo::jint_data_at(0, dp, dlen);
734
x1 = relocInfo::jint_data_at(2, dp, dlen);
735
}
736
}
737
738
protected:
739
// platform-independent utility for patching constant section
740
void const_set_data_value (address x);
741
void const_verify_data_value (address x);
742
// platform-dependent utilities for decoding and patching instructions
743
void pd_set_data_value (address x, intptr_t off, bool verify_only = false); // a set or mem-ref
744
void pd_verify_data_value (address x, intptr_t off) { pd_set_data_value(x, off, true); }
745
address pd_call_destination (address orig_addr = NULL);
746
void pd_set_call_destination (address x);
747
748
// this extracts the address of an address in the code stream instead of the reloc data
749
address* pd_address_in_code ();
750
751
// this extracts an address from the code stream instead of the reloc data
752
address pd_get_address_from_code ();
753
754
// these convert from byte offsets, to scaled offsets, to addresses
755
static jint scaled_offset(address x, address base) {
756
int byte_offset = x - base;
757
int offset = -byte_offset / relocInfo::addr_unit();
758
assert(address_from_scaled_offset(offset, base) == x, "just checkin'");
759
return offset;
760
}
761
static jint scaled_offset_null_special(address x, address base) {
762
// Some relocations treat offset=0 as meaning NULL.
763
// Handle this extra convention carefully.
764
if (x == NULL) return 0;
765
assert(x != base, "offset must not be zero");
766
return scaled_offset(x, base);
767
}
768
static address address_from_scaled_offset(jint offset, address base) {
769
int byte_offset = -( offset * relocInfo::addr_unit() );
770
return base + byte_offset;
771
}
772
773
// helpers for mapping between old and new addresses after a move or resize
774
address old_addr_for(address newa, const CodeBuffer* src, CodeBuffer* dest);
775
address new_addr_for(address olda, const CodeBuffer* src, CodeBuffer* dest);
776
void normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections = false);
777
778
public:
779
// accessors which only make sense for a bound Relocation
780
address addr() const { return binding()->addr(); }
781
CompiledMethod* code() const { return binding()->code(); }
782
bool addr_in_const() const { return binding()->addr_in_const(); }
783
protected:
784
short* data() const { return binding()->data(); }
785
int datalen() const { return binding()->datalen(); }
786
int format() const { return binding()->format(); }
787
788
public:
789
relocInfo::relocType type() const { return _rtype; }
790
791
// is it a call instruction?
792
virtual bool is_call() { return false; }
793
794
// is it a data movement instruction?
795
virtual bool is_data() { return false; }
796
797
// some relocations can compute their own values
798
virtual address value();
799
800
// all relocations are able to reassert their values
801
virtual void set_value(address x);
802
803
virtual bool clear_inline_cache() { return true; }
804
805
// This method assumes that all virtual/static (inline) caches are cleared (since for static_call_type and
806
// ic_call_type is not always posisition dependent (depending on the state of the cache)). However, this is
807
// probably a reasonable assumption, since empty caches simplifies code reloacation.
808
virtual void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { }
809
};
810
811
812
// certain inlines must be deferred until class Relocation is defined:
813
814
inline RelocationHolder::RelocationHolder() {
815
// initialize the vtbl, just to keep things type-safe
816
new(*this) Relocation(relocInfo::none);
817
}
818
819
820
inline RelocationHolder::RelocationHolder(Relocation* r) {
821
// wordwise copy from r (ok if it copies garbage after r)
822
for (int i = 0; i < _relocbuf_size; i++) {
823
_relocbuf[i] = ((void**)r)[i];
824
}
825
}
826
827
relocInfo::relocType RelocationHolder::type() const {
828
return reloc()->type();
829
}
830
831
// A DataRelocation always points at a memory or load-constant instruction..
832
// It is absolute on most machines, and the constant is split on RISCs.
833
// The specific subtypes are oop, external_word, and internal_word.
834
// By convention, the "value" does not include a separately reckoned "offset".
835
class DataRelocation : public Relocation {
836
public:
837
DataRelocation(relocInfo::relocType type) : Relocation(type) {}
838
839
bool is_data() { return true; }
840
841
// both target and offset must be computed somehow from relocation data
842
virtual int offset() { return 0; }
843
address value() = 0;
844
void set_value(address x) { set_value(x, offset()); }
845
void set_value(address x, intptr_t o) {
846
if (addr_in_const())
847
const_set_data_value(x);
848
else
849
pd_set_data_value(x, o);
850
}
851
void verify_value(address x) {
852
if (addr_in_const())
853
const_verify_data_value(x);
854
else
855
pd_verify_data_value(x, offset());
856
}
857
858
// The "o" (displacement) argument is relevant only to split relocations
859
// on RISC machines. In some CPUs (SPARC), the set-hi and set-lo ins'ns
860
// can encode more than 32 bits between them. This allows compilers to
861
// share set-hi instructions between addresses that differ by a small
862
// offset (e.g., different static variables in the same class).
863
// On such machines, the "x" argument to set_value on all set-lo
864
// instructions must be the same as the "x" argument for the
865
// corresponding set-hi instructions. The "o" arguments for the
866
// set-hi instructions are ignored, and must not affect the high-half
867
// immediate constant. The "o" arguments for the set-lo instructions are
868
// added into the low-half immediate constant, and must not overflow it.
869
};
870
871
// A CallRelocation always points at a call instruction.
872
// It is PC-relative on most machines.
873
class CallRelocation : public Relocation {
874
public:
875
CallRelocation(relocInfo::relocType type) : Relocation(type) { }
876
877
bool is_call() { return true; }
878
879
address destination() { return pd_call_destination(); }
880
void set_destination(address x); // pd_set_call_destination
881
882
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
883
address value() { return destination(); }
884
void set_value(address x) { set_destination(x); }
885
};
886
887
class oop_Relocation : public DataRelocation {
888
public:
889
// encode in one of these formats: [] [n] [n l] [Nn l] [Nn Ll]
890
// an oop in the CodeBlob's oop pool
891
static RelocationHolder spec(int oop_index, int offset = 0) {
892
assert(oop_index > 0, "must be a pool-resident oop");
893
RelocationHolder rh = newHolder();
894
new(rh) oop_Relocation(oop_index, offset);
895
return rh;
896
}
897
// an oop in the instruction stream
898
static RelocationHolder spec_for_immediate() {
899
// If no immediate oops are generated, we can skip some walks over nmethods.
900
// Assert that they don't get generated accidently!
901
assert(relocInfo::mustIterateImmediateOopsInCode(),
902
"Must return true so we will search for oops as roots etc. in the code.");
903
const int oop_index = 0;
904
const int offset = 0; // if you want an offset, use the oop pool
905
RelocationHolder rh = newHolder();
906
new(rh) oop_Relocation(oop_index, offset);
907
return rh;
908
}
909
910
private:
911
jint _oop_index; // if > 0, index into CodeBlob::oop_at
912
jint _offset; // byte offset to apply to the oop itself
913
914
oop_Relocation(int oop_index, int offset)
915
: DataRelocation(relocInfo::oop_type), _oop_index(oop_index), _offset(offset) { }
916
917
friend class RelocIterator;
918
oop_Relocation() : DataRelocation(relocInfo::oop_type) {}
919
920
public:
921
int oop_index() { return _oop_index; }
922
int offset() { return _offset; }
923
924
// data is packed in "2_ints" format: [i o] or [Ii Oo]
925
void pack_data_to(CodeSection* dest);
926
void unpack_data();
927
928
void fix_oop_relocation(); // reasserts oop value
929
930
void verify_oop_relocation();
931
932
address value() { return cast_from_oop<address>(*oop_addr()); }
933
934
bool oop_is_immediate() { return oop_index() == 0; }
935
936
oop* oop_addr(); // addr or &pool[jint_data]
937
oop oop_value(); // *oop_addr
938
// Note: oop_value transparently converts Universe::non_oop_word to NULL.
939
};
940
941
942
// copy of oop_Relocation for now but may delete stuff in both/either
943
class metadata_Relocation : public DataRelocation {
944
945
public:
946
// encode in one of these formats: [] [n] [n l] [Nn l] [Nn Ll]
947
// an metadata in the CodeBlob's metadata pool
948
static RelocationHolder spec(int metadata_index, int offset = 0) {
949
assert(metadata_index > 0, "must be a pool-resident metadata");
950
RelocationHolder rh = newHolder();
951
new(rh) metadata_Relocation(metadata_index, offset);
952
return rh;
953
}
954
// an metadata in the instruction stream
955
static RelocationHolder spec_for_immediate() {
956
const int metadata_index = 0;
957
const int offset = 0; // if you want an offset, use the metadata pool
958
RelocationHolder rh = newHolder();
959
new(rh) metadata_Relocation(metadata_index, offset);
960
return rh;
961
}
962
963
private:
964
jint _metadata_index; // if > 0, index into nmethod::metadata_at
965
jint _offset; // byte offset to apply to the metadata itself
966
967
metadata_Relocation(int metadata_index, int offset)
968
: DataRelocation(relocInfo::metadata_type), _metadata_index(metadata_index), _offset(offset) { }
969
970
friend class RelocIterator;
971
metadata_Relocation() : DataRelocation(relocInfo::metadata_type) { }
972
973
// Fixes a Metadata pointer in the code. Most platforms embeds the
974
// Metadata pointer in the code at compile time so this is empty
975
// for them.
976
void pd_fix_value(address x);
977
978
public:
979
int metadata_index() { return _metadata_index; }
980
int offset() { return _offset; }
981
982
// data is packed in "2_ints" format: [i o] or [Ii Oo]
983
void pack_data_to(CodeSection* dest);
984
void unpack_data();
985
986
void fix_metadata_relocation(); // reasserts metadata value
987
988
address value() { return (address) *metadata_addr(); }
989
990
bool metadata_is_immediate() { return metadata_index() == 0; }
991
992
Metadata** metadata_addr(); // addr or &pool[jint_data]
993
Metadata* metadata_value(); // *metadata_addr
994
// Note: metadata_value transparently converts Universe::non_metadata_word to NULL.
995
};
996
997
998
class virtual_call_Relocation : public CallRelocation {
999
1000
public:
1001
// "cached_value" points to the first associated set-oop.
1002
// The oop_limit helps find the last associated set-oop.
1003
// (See comments at the top of this file.)
1004
static RelocationHolder spec(address cached_value, jint method_index = 0) {
1005
RelocationHolder rh = newHolder();
1006
new(rh) virtual_call_Relocation(cached_value, method_index);
1007
return rh;
1008
}
1009
1010
private:
1011
address _cached_value; // location of set-value instruction
1012
jint _method_index; // resolved method for a Java call
1013
1014
virtual_call_Relocation(address cached_value, int method_index)
1015
: CallRelocation(relocInfo::virtual_call_type),
1016
_cached_value(cached_value),
1017
_method_index(method_index) {
1018
assert(cached_value != NULL, "first oop address must be specified");
1019
}
1020
1021
friend class RelocIterator;
1022
virtual_call_Relocation() : CallRelocation(relocInfo::virtual_call_type) { }
1023
1024
public:
1025
address cached_value();
1026
1027
int method_index() { return _method_index; }
1028
Method* method_value();
1029
1030
// data is packed as scaled offsets in "2_ints" format: [f l] or [Ff Ll]
1031
// oop_limit is set to 0 if the limit falls somewhere within the call.
1032
// When unpacking, a zero oop_limit is taken to refer to the end of the call.
1033
// (This has the effect of bringing in the call's delay slot on SPARC.)
1034
void pack_data_to(CodeSection* dest);
1035
void unpack_data();
1036
1037
bool clear_inline_cache();
1038
};
1039
1040
1041
class opt_virtual_call_Relocation : public CallRelocation {
1042
public:
1043
static RelocationHolder spec(int method_index = 0) {
1044
RelocationHolder rh = newHolder();
1045
new(rh) opt_virtual_call_Relocation(method_index);
1046
return rh;
1047
}
1048
1049
private:
1050
jint _method_index; // resolved method for a Java call
1051
1052
opt_virtual_call_Relocation(int method_index)
1053
: CallRelocation(relocInfo::opt_virtual_call_type),
1054
_method_index(method_index) { }
1055
1056
friend class RelocIterator;
1057
opt_virtual_call_Relocation() : CallRelocation(relocInfo::opt_virtual_call_type) {}
1058
1059
public:
1060
int method_index() { return _method_index; }
1061
Method* method_value();
1062
1063
void pack_data_to(CodeSection* dest);
1064
void unpack_data();
1065
1066
bool clear_inline_cache();
1067
1068
// find the matching static_stub
1069
address static_stub();
1070
};
1071
1072
1073
class static_call_Relocation : public CallRelocation {
1074
public:
1075
static RelocationHolder spec(int method_index = 0) {
1076
RelocationHolder rh = newHolder();
1077
new(rh) static_call_Relocation(method_index);
1078
return rh;
1079
}
1080
1081
private:
1082
jint _method_index; // resolved method for a Java call
1083
1084
static_call_Relocation(int method_index)
1085
: CallRelocation(relocInfo::static_call_type),
1086
_method_index(method_index) { }
1087
1088
friend class RelocIterator;
1089
static_call_Relocation() : CallRelocation(relocInfo::static_call_type) {}
1090
1091
public:
1092
int method_index() { return _method_index; }
1093
Method* method_value();
1094
1095
void pack_data_to(CodeSection* dest);
1096
void unpack_data();
1097
1098
bool clear_inline_cache();
1099
1100
// find the matching static_stub
1101
address static_stub();
1102
};
1103
1104
class static_stub_Relocation : public Relocation {
1105
public:
1106
static RelocationHolder spec(address static_call) {
1107
RelocationHolder rh = newHolder();
1108
new(rh) static_stub_Relocation(static_call);
1109
return rh;
1110
}
1111
1112
private:
1113
address _static_call; // location of corresponding static_call
1114
1115
static_stub_Relocation(address static_call)
1116
: Relocation(relocInfo::static_stub_type),
1117
_static_call(static_call) { }
1118
1119
friend class RelocIterator;
1120
static_stub_Relocation() : Relocation(relocInfo::static_stub_type) { }
1121
1122
public:
1123
bool clear_inline_cache();
1124
1125
address static_call() { return _static_call; }
1126
1127
// data is packed as a scaled offset in "1_int" format: [c] or [Cc]
1128
void pack_data_to(CodeSection* dest);
1129
void unpack_data();
1130
};
1131
1132
class runtime_call_Relocation : public CallRelocation {
1133
1134
public:
1135
static RelocationHolder spec() {
1136
RelocationHolder rh = newHolder();
1137
new(rh) runtime_call_Relocation();
1138
return rh;
1139
}
1140
1141
private:
1142
friend class RelocIterator;
1143
runtime_call_Relocation() : CallRelocation(relocInfo::runtime_call_type) { }
1144
1145
public:
1146
};
1147
1148
1149
class runtime_call_w_cp_Relocation : public CallRelocation {
1150
public:
1151
static RelocationHolder spec() {
1152
RelocationHolder rh = newHolder();
1153
new(rh) runtime_call_w_cp_Relocation();
1154
return rh;
1155
}
1156
1157
private:
1158
friend class RelocIterator;
1159
runtime_call_w_cp_Relocation()
1160
: CallRelocation(relocInfo::runtime_call_w_cp_type),
1161
_offset(-4) /* <0 = invalid */ { }
1162
1163
// On z/Architecture, runtime calls are either a sequence
1164
// of two instructions (load destination of call from constant pool + do call)
1165
// or a pc-relative call. The pc-relative call is faster, but it can only
1166
// be used if the destination of the call is not too far away.
1167
// In order to be able to patch a pc-relative call back into one using
1168
// the constant pool, we have to remember the location of the call's destination
1169
// in the constant pool.
1170
int _offset;
1171
1172
public:
1173
void set_constant_pool_offset(int offset) { _offset = offset; }
1174
int get_constant_pool_offset() { return _offset; }
1175
void pack_data_to(CodeSection * dest);
1176
void unpack_data();
1177
};
1178
1179
// Trampoline Relocations.
1180
// A trampoline allows to encode a small branch in the code, even if there
1181
// is the chance that this branch can not reach all possible code locations.
1182
// If the relocation finds that a branch is too far for the instruction
1183
// in the code, it can patch it to jump to the trampoline where is
1184
// sufficient space for a far branch. Needed on PPC.
1185
class trampoline_stub_Relocation : public Relocation {
1186
public:
1187
static RelocationHolder spec(address static_call) {
1188
RelocationHolder rh = newHolder();
1189
return (new (rh) trampoline_stub_Relocation(static_call));
1190
}
1191
1192
private:
1193
address _owner; // Address of the NativeCall that owns the trampoline.
1194
1195
trampoline_stub_Relocation(address owner)
1196
: Relocation(relocInfo::trampoline_stub_type),
1197
_owner(owner) { }
1198
1199
friend class RelocIterator;
1200
trampoline_stub_Relocation() : Relocation(relocInfo::trampoline_stub_type) { }
1201
1202
public:
1203
1204
// Return the address of the NativeCall that owns the trampoline.
1205
address owner() { return _owner; }
1206
1207
void pack_data_to(CodeSection * dest);
1208
void unpack_data();
1209
1210
// Find the trampoline stub for a call.
1211
static address get_trampoline_for(address call, nmethod* code);
1212
};
1213
1214
class external_word_Relocation : public DataRelocation {
1215
public:
1216
static RelocationHolder spec(address target) {
1217
assert(target != NULL, "must not be null");
1218
RelocationHolder rh = newHolder();
1219
new(rh) external_word_Relocation(target);
1220
return rh;
1221
}
1222
1223
// Use this one where all 32/64 bits of the target live in the code stream.
1224
// The target must be an intptr_t, and must be absolute (not relative).
1225
static RelocationHolder spec_for_immediate() {
1226
RelocationHolder rh = newHolder();
1227
new(rh) external_word_Relocation(NULL);
1228
return rh;
1229
}
1230
1231
// Some address looking values aren't safe to treat as relocations
1232
// and should just be treated as constants.
1233
static bool can_be_relocated(address target) {
1234
assert(target == NULL || (uintptr_t)target >= (uintptr_t)os::vm_page_size(), INTPTR_FORMAT, (intptr_t)target);
1235
return target != NULL;
1236
}
1237
1238
private:
1239
address _target; // address in runtime
1240
1241
external_word_Relocation(address target)
1242
: DataRelocation(relocInfo::external_word_type), _target(target) { }
1243
1244
friend class RelocIterator;
1245
external_word_Relocation() : DataRelocation(relocInfo::external_word_type) { }
1246
1247
public:
1248
// data is packed as a well-known address in "1_int" format: [a] or [Aa]
1249
// The function runtime_address_to_index is used to turn full addresses
1250
// to short indexes, if they are pre-registered by the stub mechanism.
1251
// If the "a" value is 0 (i.e., _target is NULL), the address is stored
1252
// in the code stream. See external_word_Relocation::target().
1253
void pack_data_to(CodeSection* dest);
1254
void unpack_data();
1255
1256
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1257
address target(); // if _target==NULL, fetch addr from code stream
1258
address value() { return target(); }
1259
};
1260
1261
class internal_word_Relocation : public DataRelocation {
1262
1263
public:
1264
static RelocationHolder spec(address target) {
1265
assert(target != NULL, "must not be null");
1266
RelocationHolder rh = newHolder();
1267
new(rh) internal_word_Relocation(target);
1268
return rh;
1269
}
1270
1271
// use this one where all the bits of the target can fit in the code stream:
1272
static RelocationHolder spec_for_immediate() {
1273
RelocationHolder rh = newHolder();
1274
new(rh) internal_word_Relocation(NULL);
1275
return rh;
1276
}
1277
1278
// default section -1 means self-relative
1279
internal_word_Relocation(address target, int section = -1,
1280
relocInfo::relocType type = relocInfo::internal_word_type)
1281
: DataRelocation(type), _target(target), _section(section) { }
1282
1283
protected:
1284
address _target; // address in CodeBlob
1285
int _section; // section providing base address, if any
1286
1287
friend class RelocIterator;
1288
internal_word_Relocation(relocInfo::relocType type = relocInfo::internal_word_type)
1289
: DataRelocation(type) { }
1290
1291
// bit-width of LSB field in packed offset, if section >= 0
1292
enum { section_width = 2 }; // must equal CodeBuffer::sect_bits
1293
1294
public:
1295
// data is packed as a scaled offset in "1_int" format: [o] or [Oo]
1296
// If the "o" value is 0 (i.e., _target is NULL), the offset is stored
1297
// in the code stream. See internal_word_Relocation::target().
1298
// If _section is not -1, it is appended to the low bits of the offset.
1299
void pack_data_to(CodeSection* dest);
1300
void unpack_data();
1301
1302
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1303
address target(); // if _target==NULL, fetch addr from code stream
1304
int section() { return _section; }
1305
address value() { return target(); }
1306
};
1307
1308
class section_word_Relocation : public internal_word_Relocation {
1309
public:
1310
static RelocationHolder spec(address target, int section) {
1311
RelocationHolder rh = newHolder();
1312
new(rh) section_word_Relocation(target, section);
1313
return rh;
1314
}
1315
1316
section_word_Relocation(address target, int section)
1317
: internal_word_Relocation(target, section, relocInfo::section_word_type) {
1318
assert(target != NULL, "must not be null");
1319
assert(section >= 0 && section < RelocIterator::SECT_LIMIT, "must be a valid section");
1320
}
1321
1322
//void pack_data_to -- inherited
1323
void unpack_data();
1324
1325
private:
1326
friend class RelocIterator;
1327
section_word_Relocation() : internal_word_Relocation(relocInfo::section_word_type) { }
1328
};
1329
1330
1331
class poll_Relocation : public Relocation {
1332
bool is_data() { return true; }
1333
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1334
public:
1335
poll_Relocation(relocInfo::relocType type = relocInfo::poll_type) : Relocation(type) { }
1336
};
1337
1338
class poll_return_Relocation : public poll_Relocation {
1339
public:
1340
poll_return_Relocation() : poll_Relocation(relocInfo::relocInfo::poll_return_type) { }
1341
};
1342
1343
// We know all the xxx_Relocation classes, so now we can define these:
1344
#define EACH_CASE(name) \
1345
inline name##_Relocation* RelocIterator::name##_reloc() { \
1346
assert(type() == relocInfo::name##_type, "type must agree"); \
1347
/* The purpose of the placed "new" is to re-use the same */ \
1348
/* stack storage for each new iteration. */ \
1349
name##_Relocation* r = new(_rh) name##_Relocation(); \
1350
r->set_binding(this); \
1351
r->name##_Relocation::unpack_data(); \
1352
return r; \
1353
}
1354
APPLY_TO_RELOCATIONS(EACH_CASE);
1355
#undef EACH_CASE
1356
1357
inline RelocIterator::RelocIterator(CompiledMethod* nm, address begin, address limit) {
1358
initialize(nm, begin, limit);
1359
}
1360
1361
#endif // SHARE_CODE_RELOCINFO_HPP
1362
1363