32
33 // Types in this file:
34 // relocInfo
35 // One element of an array of halfwords encoding compressed relocations.
36 // Also, the source of relocation types (relocInfo::oop_type, ...).
37 // Relocation
38 // A flyweight object representing a single relocation.
39 // It is fully unpacked from the compressed relocation array.
40 // metadata_Relocation, ... (subclasses of Relocation)
41 // The location of some type-specific operations (metadata_addr, ...).
42 // Also, the source of relocation specs (metadata_Relocation::spec, ...).
43 // oop_Relocation, ... (subclasses of Relocation)
44 // oops in the code stream (strings, class loaders)
45 // Also, the source of relocation specs (oop_Relocation::spec, ...).
46 // RelocationHolder
47 // A ValueObj type which acts as a union holding a Relocation object.
48 // Represents a relocation spec passed into a CodeBuffer during assembly.
49 // RelocIterator
50 // A StackObj which iterates over the relocations associated with
51 // a range of code addresses. Can be used to operate a copy of code.
52 // PatchingRelocIterator
53 // Specialized subtype of RelocIterator which removes breakpoints
54 // temporarily during iteration, then restores them.
55 // BoundRelocation
56 // An _internal_ type shared by packers and unpackers of relocations.
57 // It pastes together a RelocationHolder with some pointers into
58 // code and relocInfo streams.
59
60
61 // Notes on relocType:
62 //
63 // These hold enough information to read or write a value embedded in
64 // the instructions of an CodeBlob. They're used to update:
65 //
66 // 1) embedded oops (isOop() == true)
67 // 2) inline caches (isIC() == true)
68 // 3) runtime calls (isRuntimeCall() == true)
69 // 4) internal word ref (isInternalWord() == true)
70 // 5) external word ref (isExternalWord() == true)
71 //
72 // when objects move (GC) or if code moves (compacting the code heap).
73 // They are also used to patch the code (if a call site must change)
74 //
187 // information starting at the first set-oop, and continuing until all
188 // relocations up through l have been inspected. The value l is another
189 // relative offset. (Both n and l are relative to the call's first byte.)
190 //
191 // The limit l of the search is exclusive. However, if it points within
192 // the call (e.g., offset zero), it is adjusted to point after the call and
193 // any associated machine-specific delay slot.
194 //
195 // Since the offsets could be as wide as 32-bits, these conventions
196 // put no restrictions whatever upon code reorganization.
197 //
198 // The compiler is responsible for ensuring that transition from a clean
199 // state to a monomorphic compiled state is MP-safe. This implies that
200 // the system must respond well to intermediate states where a random
201 // subset of the set-oops has been correctly from the clean state
202 // upon entry to the VEP of the compiled method. In the case of a
203 // machine (Intel) with a single set-oop instruction, the 32-bit
204 // immediate field must not straddle a unit of memory coherence.
205 // //%note reloc_3
206 //
207 // relocInfo::breakpoint_type -- a conditional breakpoint in the code
208 // Value: none
209 // Instruction types: any whatsoever
210 // Data: [b [T]t i...]
211 // The b is a bit-packed word representing the breakpoint's attributes.
212 // The t is a target address which the breakpoint calls (when it is enabled).
213 // The i... is a place to store one or two instruction words overwritten
214 // by a trap, so that the breakpoint may be subsequently removed.
215 //
216 // relocInfo::static_stub_type -- an extra stub for each static_call_type
217 // Value: none
218 // Instruction types: a virtual call: { set_oop; jump; }
219 // Data: [[N]n] the offset of the associated static_call reloc
220 // This stub becomes the target of a static call which must be upgraded
221 // to a virtual call (because the callee is interpreted).
222 // See [About Offsets] below.
223 // //%note reloc_2
224 //
225 // For example:
226 //
227 // INSTRUCTIONS RELOC: TYPE PREFIX DATA
228 // ------------ ---- -----------
229 // sethi %hi(myObject), R oop_type [n(myObject)]
230 // ld [R+%lo(myObject)+fldOffset], R2 oop_type [n(myObject) fldOffset]
231 // add R2, 1, R2
232 // st R2, [R+%lo(myObject)+fldOffset] oop_type [n(myObject) fldOffset]
233 //%note reloc_1
234 //
235 // This uses 4 instruction words, 8 relocation halfwords,
254 class CodeBuffer;
255 class CodeSection;
256 class RelocIterator;
257
258 class relocInfo VALUE_OBJ_CLASS_SPEC {
259 friend class RelocIterator;
260 public:
261 enum relocType {
262 none = 0, // Used when no relocation should be generated
263 oop_type = 1, // embedded oop
264 virtual_call_type = 2, // a standard inline cache call for a virtual send
265 opt_virtual_call_type = 3, // a virtual call that has been statically bound (i.e., no IC cache)
266 static_call_type = 4, // a static send
267 static_stub_type = 5, // stub-entry for static send (takes care of interpreter case)
268 runtime_call_type = 6, // call to fixed external routine
269 external_word_type = 7, // reference to fixed external address
270 internal_word_type = 8, // reference within the current code blob
271 section_word_type = 9, // internal, but a cross-section reference
272 poll_type = 10, // polling instruction for safepoints
273 poll_return_type = 11, // polling instruction for safepoints at return
274 breakpoint_type = 12, // an initialization barrier or safepoint
275 metadata_type = 13, // metadata that used to be oops
276 yet_unused_type_2 = 14, // Still unused
277 data_prefix_tag = 15, // tag for a prefix (carries data arguments)
278 type_mask = 15 // A mask which selects only the above values
279 };
280
281 protected:
282 unsigned short _value;
283
284 enum RawBitsToken { RAW_BITS };
285 relocInfo(relocType type, RawBitsToken ignore, int bits)
286 : _value((type << nontype_width) + bits) { }
287
288 relocInfo(relocType type, RawBitsToken ignore, int off, int f)
289 : _value((type << nontype_width) + (off / (unsigned)offset_unit) + (f << offset_width)) { }
290
291 public:
292 // constructor
293 relocInfo(relocType type, int offset, int format = 0)
294 #ifndef ASSERT
295 {
296 (*this) = relocInfo(type, RAW_BITS, offset, format);
297 }
298 #else
299 // Put a bunch of assertions out-of-line.
300 ;
301 #endif
302
303 #define APPLY_TO_RELOCATIONS(visitor) \
304 visitor(oop) \
305 visitor(metadata) \
306 visitor(virtual_call) \
307 visitor(opt_virtual_call) \
308 visitor(static_call) \
309 visitor(static_stub) \
310 visitor(runtime_call) \
311 visitor(external_word) \
312 visitor(internal_word) \
313 visitor(poll) \
314 visitor(poll_return) \
315 visitor(breakpoint) \
316 visitor(section_word) \
317
318
319 public:
320 enum {
321 value_width = sizeof(unsigned short) * BitsPerByte,
322 type_width = 4, // == log2(type_mask+1)
323 nontype_width = value_width - type_width,
324 datalen_width = nontype_width-1,
325 datalen_tag = 1 << datalen_width, // or-ed into _value
326 datalen_limit = 1 << datalen_width,
327 datalen_mask = (1 << datalen_width)-1
328 };
329
330 // accessors
331 public:
332 relocType type() const { return (relocType)((unsigned)_value >> nontype_width); }
333 int format() const { return format_mask==0? 0: format_mask &
334 ((unsigned)_value >> offset_width); }
335 int addr_offset() const { assert(!is_prefix(), "must have offset");
437 # include "relocInfo_zero.hpp"
438 #endif
439 #ifdef TARGET_ARCH_arm
440 # include "relocInfo_arm.hpp"
441 #endif
442 #ifdef TARGET_ARCH_ppc
443 # include "relocInfo_ppc.hpp"
444 #endif
445
446
447 protected:
448 // Derived constant, based on format_width which is PD:
449 enum {
450 offset_width = nontype_width - format_width,
451 offset_mask = (1<<offset_width) - 1,
452 format_mask = (1<<format_width) - 1
453 };
454 public:
455 enum {
456 // Conservatively large estimate of maximum length (in shorts)
457 // of any relocation record (probably breakpoints are largest).
458 // Extended format is length prefix, data words, and tag/offset suffix.
459 length_limit = 1 + 1 + (3*BytesPerWord/BytesPerShort) + 1,
460 have_format = format_width > 0
461 };
462 };
463
464 #define FORWARD_DECLARE_EACH_CLASS(name) \
465 class name##_Relocation;
466 APPLY_TO_RELOCATIONS(FORWARD_DECLARE_EACH_CLASS)
467 #undef FORWARD_DECLARE_EACH_CLASS
468
469
470
471 inline relocInfo filler_relocInfo() {
472 return relocInfo(relocInfo::none, relocInfo::offset_limit() - relocInfo::offset_unit);
473 }
474
475 inline relocInfo prefix_relocInfo(int datalen) {
476 assert(relocInfo::fits_into_immediate(datalen), "datalen in limits");
477 return relocInfo(relocInfo::data_prefix_tag, relocInfo::RAW_BITS, relocInfo::datalen_tag | datalen);
554 debug_only(_data = NULL);
555 }
556 void set_current(relocInfo& ri) {
557 _current = &ri;
558 set_has_current(true);
559 }
560
561 RelocationHolder _rh; // where the current relocation is allocated
562
563 relocInfo* current() const { assert(has_current(), "must have current");
564 return _current; }
565
566 void set_limits(address begin, address limit);
567
568 void advance_over_prefix(); // helper method
569
570 void initialize_misc();
571
572 void initialize(nmethod* nm, address begin, address limit);
573
574 friend class PatchingRelocIterator;
575 // make an uninitialized one, for PatchingRelocIterator:
576 RelocIterator() { initialize_misc(); }
577
578 public:
579 // constructor
580 RelocIterator(nmethod* nm, address begin = NULL, address limit = NULL);
581 RelocIterator(CodeSection* cb, address begin = NULL, address limit = NULL);
582
583 // get next reloc info, return !eos
584 bool next() {
585 _current++;
586 assert(_current <= _end, "must not overrun relocInfo");
587 if (_current == _end) {
588 set_has_current(false);
589 return false;
590 }
591 set_has_current(true);
592
593 if (_current->is_prefix()) {
594 advance_over_prefix();
595 assert(!current()->is_prefix(), "only one prefix at a time");
762 }
763 void unpack_2_ints(jint& x0, jint& x1) {
764 int dlen = datalen();
765 short* dp = data();
766 if (dlen <= 2) {
767 x0 = relocInfo::short_data_at(0, dp, dlen);
768 x1 = relocInfo::short_data_at(1, dp, dlen);
769 } else {
770 assert(dlen <= 4, "too much data");
771 x0 = relocInfo::jint_data_at(0, dp, dlen);
772 x1 = relocInfo::jint_data_at(2, dp, dlen);
773 }
774 }
775
776 protected:
777 // platform-dependent utilities for decoding and patching instructions
778 void pd_set_data_value (address x, intptr_t off, bool verify_only = false); // a set or mem-ref
779 void pd_verify_data_value (address x, intptr_t off) { pd_set_data_value(x, off, true); }
780 address pd_call_destination (address orig_addr = NULL);
781 void pd_set_call_destination (address x);
782 void pd_swap_in_breakpoint (address x, short* instrs, int instrlen);
783 void pd_swap_out_breakpoint (address x, short* instrs, int instrlen);
784 static int pd_breakpoint_size ();
785
786 // this extracts the address of an address in the code stream instead of the reloc data
787 address* pd_address_in_code ();
788
789 // this extracts an address from the code stream instead of the reloc data
790 address pd_get_address_from_code ();
791
792 // these convert from byte offsets, to scaled offsets, to addresses
793 static jint scaled_offset(address x, address base) {
794 int byte_offset = x - base;
795 int offset = -byte_offset / relocInfo::addr_unit();
796 assert(address_from_scaled_offset(offset, base) == x, "just checkin'");
797 return offset;
798 }
799 static jint scaled_offset_null_special(address x, address base) {
800 // Some relocations treat offset=0 as meaning NULL.
801 // Handle this extra convention carefully.
802 if (x == NULL) return 0;
803 assert(x != base, "offset must not be zero");
804 return scaled_offset(x, base);
1285 void unpack_data();
1286
1287 private:
1288 friend class RelocIterator;
1289 section_word_Relocation() { }
1290 };
1291
1292
1293 class poll_Relocation : public Relocation {
1294 bool is_data() { return true; }
1295 relocInfo::relocType type() { return relocInfo::poll_type; }
1296 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1297 };
1298
1299 class poll_return_Relocation : public Relocation {
1300 bool is_data() { return true; }
1301 relocInfo::relocType type() { return relocInfo::poll_return_type; }
1302 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1303 };
1304
1305
1306 class breakpoint_Relocation : public Relocation {
1307 relocInfo::relocType type() { return relocInfo::breakpoint_type; }
1308
1309 enum {
1310 // attributes which affect the interpretation of the data:
1311 removable_attr = 0x0010, // buffer [i...] allows for undoing the trap
1312 internal_attr = 0x0020, // the target is an internal addr (local stub)
1313 settable_attr = 0x0040, // the target is settable
1314
1315 // states which can change over time:
1316 enabled_state = 0x0100, // breakpoint must be active in running code
1317 active_state = 0x0200, // breakpoint instruction actually in code
1318
1319 kind_mask = 0x000F, // mask for extracting kind
1320 high_bit = 0x4000 // extra bit which is always set
1321 };
1322
1323 public:
1324 enum {
1325 // kinds:
1326 initialization = 1,
1327 safepoint = 2
1328 };
1329
1330 // If target is NULL, 32 bits are reserved for a later set_target().
1331 static RelocationHolder spec(int kind, address target = NULL, bool internal_target = false) {
1332 RelocationHolder rh = newHolder();
1333 new(rh) breakpoint_Relocation(kind, target, internal_target);
1334 return rh;
1335 }
1336
1337 private:
1338 // We require every bits value to NOT to fit into relocInfo::datalen_width,
1339 // because we are going to actually store state in the reloc, and so
1340 // cannot allow it to be compressed (and hence copied by the iterator).
1341
1342 short _bits; // bit-encoded kind, attrs, & state
1343 address _target;
1344
1345 breakpoint_Relocation(int kind, address target, bool internal_target);
1346
1347 friend class RelocIterator;
1348 breakpoint_Relocation() { }
1349
1350 short bits() const { return _bits; }
1351 short& live_bits() const { return data()[0]; }
1352 short* instrs() const { return data() + datalen() - instrlen(); }
1353 int instrlen() const { return removable() ? pd_breakpoint_size() : 0; }
1354
1355 void set_bits(short x) {
1356 assert(live_bits() == _bits, "must be the only mutator of reloc info");
1357 live_bits() = _bits = x;
1358 }
1359
1360 public:
1361 address target() const;
1362 void set_target(address x);
1363
1364 int kind() const { return bits() & kind_mask; }
1365 bool enabled() const { return (bits() & enabled_state) != 0; }
1366 bool active() const { return (bits() & active_state) != 0; }
1367 bool internal() const { return (bits() & internal_attr) != 0; }
1368 bool removable() const { return (bits() & removable_attr) != 0; }
1369 bool settable() const { return (bits() & settable_attr) != 0; }
1370
1371 void set_enabled(bool b); // to activate, you must also say set_active
1372 void set_active(bool b); // actually inserts bpt (must be enabled 1st)
1373
1374 // data is packed as 16 bits, followed by the target (1 or 2 words), followed
1375 // if necessary by empty storage for saving away original instruction bytes.
1376 void pack_data_to(CodeSection* dest);
1377 void unpack_data();
1378
1379 // during certain operations, breakpoints must be out of the way:
1380 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
1381 assert(!active(), "cannot perform relocation on enabled breakpoints");
1382 }
1383 };
1384
1385
1386 // We know all the xxx_Relocation classes, so now we can define these:
1387 #define EACH_CASE(name) \
1388 inline name##_Relocation* RelocIterator::name##_reloc() { \
1389 assert(type() == relocInfo::name##_type, "type must agree"); \
1390 /* The purpose of the placed "new" is to re-use the same */ \
1391 /* stack storage for each new iteration. */ \
1392 name##_Relocation* r = new(_rh) name##_Relocation(); \
1393 r->set_binding(this); \
1394 r->name##_Relocation::unpack_data(); \
1395 return r; \
1396 }
1397 APPLY_TO_RELOCATIONS(EACH_CASE);
1398 #undef EACH_CASE
1399
1400 inline RelocIterator::RelocIterator(nmethod* nm, address begin, address limit) {
1401 initialize(nm, begin, limit);
1402 }
1403
1404 // if you are going to patch code, you should use this subclass of
1405 // RelocIterator
1406 class PatchingRelocIterator : public RelocIterator {
1407 private:
1408 RelocIterator _init_state;
1409
1410 void prepass(); // deactivates all breakpoints
1411 void postpass(); // reactivates all enabled breakpoints
1412
1413 // do not copy these puppies; it would have unpredictable side effects
1414 // these are private and have no bodies defined because they should not be called
1415 PatchingRelocIterator(const RelocIterator&);
1416 void operator=(const RelocIterator&);
1417
1418 public:
1419 PatchingRelocIterator(nmethod* nm, address begin = NULL, address limit = NULL)
1420 : RelocIterator(nm, begin, limit) { prepass(); }
1421
1422 ~PatchingRelocIterator() { postpass(); }
1423 };
1424
1425 #endif // SHARE_VM_CODE_RELOCINFO_HPP
|
32
33 // Types in this file:
34 // relocInfo
35 // One element of an array of halfwords encoding compressed relocations.
36 // Also, the source of relocation types (relocInfo::oop_type, ...).
37 // Relocation
38 // A flyweight object representing a single relocation.
39 // It is fully unpacked from the compressed relocation array.
40 // metadata_Relocation, ... (subclasses of Relocation)
41 // The location of some type-specific operations (metadata_addr, ...).
42 // Also, the source of relocation specs (metadata_Relocation::spec, ...).
43 // oop_Relocation, ... (subclasses of Relocation)
44 // oops in the code stream (strings, class loaders)
45 // Also, the source of relocation specs (oop_Relocation::spec, ...).
46 // RelocationHolder
47 // A ValueObj type which acts as a union holding a Relocation object.
48 // Represents a relocation spec passed into a CodeBuffer during assembly.
49 // RelocIterator
50 // A StackObj which iterates over the relocations associated with
51 // a range of code addresses. Can be used to operate a copy of code.
52 // BoundRelocation
53 // An _internal_ type shared by packers and unpackers of relocations.
54 // It pastes together a RelocationHolder with some pointers into
55 // code and relocInfo streams.
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 //
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 // For example:
214 //
215 // INSTRUCTIONS RELOC: TYPE PREFIX DATA
216 // ------------ ---- -----------
217 // sethi %hi(myObject), R oop_type [n(myObject)]
218 // ld [R+%lo(myObject)+fldOffset], R2 oop_type [n(myObject) fldOffset]
219 // add R2, 1, R2
220 // st R2, [R+%lo(myObject)+fldOffset] oop_type [n(myObject) fldOffset]
221 //%note reloc_1
222 //
223 // This uses 4 instruction words, 8 relocation halfwords,
242 class CodeBuffer;
243 class CodeSection;
244 class RelocIterator;
245
246 class relocInfo VALUE_OBJ_CLASS_SPEC {
247 friend class RelocIterator;
248 public:
249 enum relocType {
250 none = 0, // Used when no relocation should be generated
251 oop_type = 1, // embedded oop
252 virtual_call_type = 2, // a standard inline cache call for a virtual send
253 opt_virtual_call_type = 3, // a virtual call that has been statically bound (i.e., no IC cache)
254 static_call_type = 4, // a static send
255 static_stub_type = 5, // stub-entry for static send (takes care of interpreter case)
256 runtime_call_type = 6, // call to fixed external routine
257 external_word_type = 7, // reference to fixed external address
258 internal_word_type = 8, // reference within the current code blob
259 section_word_type = 9, // internal, but a cross-section reference
260 poll_type = 10, // polling instruction for safepoints
261 poll_return_type = 11, // polling instruction for safepoints at return
262 metadata_type = 12, // metadata that used to be oops
263 yet_unused_type_2 = 13, // Still unused
264 yet_unused_type_1 = 14, // Still unused
265 data_prefix_tag = 15, // tag for a prefix (carries data arguments)
266 type_mask = 15 // A mask which selects only the above values
267 };
268
269 protected:
270 unsigned short _value;
271
272 enum RawBitsToken { RAW_BITS };
273 relocInfo(relocType type, RawBitsToken ignore, int bits)
274 : _value((type << nontype_width) + bits) { }
275
276 relocInfo(relocType type, RawBitsToken ignore, int off, int f)
277 : _value((type << nontype_width) + (off / (unsigned)offset_unit) + (f << offset_width)) { }
278
279 public:
280 // constructor
281 relocInfo(relocType type, int offset, int format = 0)
282 #ifndef ASSERT
283 {
284 (*this) = relocInfo(type, RAW_BITS, offset, format);
285 }
286 #else
287 // Put a bunch of assertions out-of-line.
288 ;
289 #endif
290
291 #define APPLY_TO_RELOCATIONS(visitor) \
292 visitor(oop) \
293 visitor(metadata) \
294 visitor(virtual_call) \
295 visitor(opt_virtual_call) \
296 visitor(static_call) \
297 visitor(static_stub) \
298 visitor(runtime_call) \
299 visitor(external_word) \
300 visitor(internal_word) \
301 visitor(poll) \
302 visitor(poll_return) \
303 visitor(section_word) \
304
305
306 public:
307 enum {
308 value_width = sizeof(unsigned short) * BitsPerByte,
309 type_width = 4, // == log2(type_mask+1)
310 nontype_width = value_width - type_width,
311 datalen_width = nontype_width-1,
312 datalen_tag = 1 << datalen_width, // or-ed into _value
313 datalen_limit = 1 << datalen_width,
314 datalen_mask = (1 << datalen_width)-1
315 };
316
317 // accessors
318 public:
319 relocType type() const { return (relocType)((unsigned)_value >> nontype_width); }
320 int format() const { return format_mask==0? 0: format_mask &
321 ((unsigned)_value >> offset_width); }
322 int addr_offset() const { assert(!is_prefix(), "must have offset");
424 # include "relocInfo_zero.hpp"
425 #endif
426 #ifdef TARGET_ARCH_arm
427 # include "relocInfo_arm.hpp"
428 #endif
429 #ifdef TARGET_ARCH_ppc
430 # include "relocInfo_ppc.hpp"
431 #endif
432
433
434 protected:
435 // Derived constant, based on format_width which is PD:
436 enum {
437 offset_width = nontype_width - format_width,
438 offset_mask = (1<<offset_width) - 1,
439 format_mask = (1<<format_width) - 1
440 };
441 public:
442 enum {
443 // Conservatively large estimate of maximum length (in shorts)
444 // of any relocation record.
445 // Extended format is length prefix, data words, and tag/offset suffix.
446 length_limit = 1 + 1 + (3*BytesPerWord/BytesPerShort) + 1,
447 have_format = format_width > 0
448 };
449 };
450
451 #define FORWARD_DECLARE_EACH_CLASS(name) \
452 class name##_Relocation;
453 APPLY_TO_RELOCATIONS(FORWARD_DECLARE_EACH_CLASS)
454 #undef FORWARD_DECLARE_EACH_CLASS
455
456
457
458 inline relocInfo filler_relocInfo() {
459 return relocInfo(relocInfo::none, relocInfo::offset_limit() - relocInfo::offset_unit);
460 }
461
462 inline relocInfo prefix_relocInfo(int datalen) {
463 assert(relocInfo::fits_into_immediate(datalen), "datalen in limits");
464 return relocInfo(relocInfo::data_prefix_tag, relocInfo::RAW_BITS, relocInfo::datalen_tag | datalen);
541 debug_only(_data = NULL);
542 }
543 void set_current(relocInfo& ri) {
544 _current = &ri;
545 set_has_current(true);
546 }
547
548 RelocationHolder _rh; // where the current relocation is allocated
549
550 relocInfo* current() const { assert(has_current(), "must have current");
551 return _current; }
552
553 void set_limits(address begin, address limit);
554
555 void advance_over_prefix(); // helper method
556
557 void initialize_misc();
558
559 void initialize(nmethod* nm, address begin, address limit);
560
561 RelocIterator() { initialize_misc(); }
562
563 public:
564 // constructor
565 RelocIterator(nmethod* nm, address begin = NULL, address limit = NULL);
566 RelocIterator(CodeSection* cb, address begin = NULL, address limit = NULL);
567
568 // get next reloc info, return !eos
569 bool next() {
570 _current++;
571 assert(_current <= _end, "must not overrun relocInfo");
572 if (_current == _end) {
573 set_has_current(false);
574 return false;
575 }
576 set_has_current(true);
577
578 if (_current->is_prefix()) {
579 advance_over_prefix();
580 assert(!current()->is_prefix(), "only one prefix at a time");
747 }
748 void unpack_2_ints(jint& x0, jint& x1) {
749 int dlen = datalen();
750 short* dp = data();
751 if (dlen <= 2) {
752 x0 = relocInfo::short_data_at(0, dp, dlen);
753 x1 = relocInfo::short_data_at(1, dp, dlen);
754 } else {
755 assert(dlen <= 4, "too much data");
756 x0 = relocInfo::jint_data_at(0, dp, dlen);
757 x1 = relocInfo::jint_data_at(2, dp, dlen);
758 }
759 }
760
761 protected:
762 // platform-dependent utilities for decoding and patching instructions
763 void pd_set_data_value (address x, intptr_t off, bool verify_only = false); // a set or mem-ref
764 void pd_verify_data_value (address x, intptr_t off) { pd_set_data_value(x, off, true); }
765 address pd_call_destination (address orig_addr = NULL);
766 void pd_set_call_destination (address x);
767
768 // this extracts the address of an address in the code stream instead of the reloc data
769 address* pd_address_in_code ();
770
771 // this extracts an address from the code stream instead of the reloc data
772 address pd_get_address_from_code ();
773
774 // these convert from byte offsets, to scaled offsets, to addresses
775 static jint scaled_offset(address x, address base) {
776 int byte_offset = x - base;
777 int offset = -byte_offset / relocInfo::addr_unit();
778 assert(address_from_scaled_offset(offset, base) == x, "just checkin'");
779 return offset;
780 }
781 static jint scaled_offset_null_special(address x, address base) {
782 // Some relocations treat offset=0 as meaning NULL.
783 // Handle this extra convention carefully.
784 if (x == NULL) return 0;
785 assert(x != base, "offset must not be zero");
786 return scaled_offset(x, base);
1267 void unpack_data();
1268
1269 private:
1270 friend class RelocIterator;
1271 section_word_Relocation() { }
1272 };
1273
1274
1275 class poll_Relocation : public Relocation {
1276 bool is_data() { return true; }
1277 relocInfo::relocType type() { return relocInfo::poll_type; }
1278 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1279 };
1280
1281 class poll_return_Relocation : public Relocation {
1282 bool is_data() { return true; }
1283 relocInfo::relocType type() { return relocInfo::poll_return_type; }
1284 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1285 };
1286
1287 // We know all the xxx_Relocation classes, so now we can define these:
1288 #define EACH_CASE(name) \
1289 inline name##_Relocation* RelocIterator::name##_reloc() { \
1290 assert(type() == relocInfo::name##_type, "type must agree"); \
1291 /* The purpose of the placed "new" is to re-use the same */ \
1292 /* stack storage for each new iteration. */ \
1293 name##_Relocation* r = new(_rh) name##_Relocation(); \
1294 r->set_binding(this); \
1295 r->name##_Relocation::unpack_data(); \
1296 return r; \
1297 }
1298 APPLY_TO_RELOCATIONS(EACH_CASE);
1299 #undef EACH_CASE
1300
1301 inline RelocIterator::RelocIterator(nmethod* nm, address begin, address limit) {
1302 initialize(nm, begin, limit);
1303 }
1304
1305 #endif // SHARE_VM_CODE_RELOCINFO_HPP
|