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 #ifdef _LP64
444 // for use in format
445 // format_width must be at least 1 on _LP64
446 narrow_oop_in_const = 1,
447 #endif
448 // Conservatively large estimate of maximum length (in shorts)
449 // of any relocation record.
450 // Extended format is length prefix, data words, and tag/offset suffix.
451 length_limit = 1 + 1 + (3*BytesPerWord/BytesPerShort) + 1,
452 have_format = format_width > 0
453 };
454 };
455
456 #define FORWARD_DECLARE_EACH_CLASS(name) \
457 class name##_Relocation;
458 APPLY_TO_RELOCATIONS(FORWARD_DECLARE_EACH_CLASS)
459 #undef FORWARD_DECLARE_EACH_CLASS
460
461 // Holder for flyweight relocation objects.
462 // Although the flyweight subclasses are of varying sizes,
463 // the holder is "one size fits all".
464 class RelocationHolder {
465 friend class Relocation;
466
467 private:
468 // A Relocation is "held" by placement constructing a Relocation into
469 // _relocbuf. Hence, _relocbuf must accomodate all subclasses of
470 // Relocation. We also need the Relocation base class to be at the same
471 // address as the start of the object, e.g. at the address of _relocbuf.
472 // Both of these requirements are checked (see emplace_relocation).
473 // The placement of the base class subobject isn't guaranteed by C++, since
621 if (_limit != nullptr && _addr >= _limit) {
622 set_has_current(false);
623 return false;
624 }
625
626 return true;
627 }
628
629 // accessors
630 address limit() const { return _limit; }
631 relocType type() const { return current()->type(); }
632 int format() const { return (relocInfo::have_format) ? current()->format() : 0; }
633 address addr() const { return _addr; }
634 nmethod* code() const { return _code; }
635 short* data() const { return _data; }
636 int datalen() const { return _datalen; }
637 bool has_current() const { return _datalen >= 0; }
638 bool addr_in_const() const;
639
640 address section_start(int n) const {
641 assert(_section_start[n], "must be initialized");
642 return _section_start[n];
643 }
644 address section_end(int n) const {
645 assert(_section_end[n], "must be initialized");
646 return _section_end[n];
647 }
648
649 // The address points to the affected displacement part of the instruction.
650 // For RISC, this is just the whole instruction.
651 // For Intel, this is an unaligned 32-bit word.
652
653 // type-specific relocation accessors: oop_Relocation* oop_reloc(), etc.
654 #define EACH_TYPE(name) \
655 inline name##_Relocation* name##_reloc();
656 APPLY_TO_RELOCATIONS(EACH_TYPE)
657 #undef EACH_TYPE
658 // generic relocation accessor; switches on type to call the above
659 Relocation* reloc();
660
661 #ifndef PRODUCT
662 public:
663 void print();
664 void print_current();
665 #endif
666 };
667
668
669 // A Relocation is a flyweight object allocated within a RelocationHolder.
670 // It represents the relocation data of relocation record.
671 // So, the RelocIterator unpacks relocInfos into Relocations.
672
673 class Relocation {
674 friend class RelocIterator;
675
676 private:
677 // When a relocation has been created by a RelocIterator,
678 // this field is non-null. It allows the relocation to know
679 // its context, such as the address to which it applies.
680 RelocIterator* _binding;
681
682 relocInfo::relocType _rtype;
683
684 protected:
685 RelocIterator* binding() const {
686 assert(_binding != nullptr, "must be bound");
687 return _binding;
688 }
689 void set_binding(RelocIterator* b) {
690 assert(_binding == nullptr, "must be unbound");
691 _binding = b;
692 assert(_binding != nullptr, "must now be bound");
693 }
694
1270
1271 void copy_into(RelocationHolder& holder) const override;
1272
1273 private:
1274 address _owner; // Address of the NativeCall that owns the trampoline.
1275
1276 trampoline_stub_Relocation(address owner)
1277 : Relocation(relocInfo::trampoline_stub_type),
1278 _owner(owner) { }
1279
1280 friend class RelocationHolder;
1281 trampoline_stub_Relocation() : Relocation(relocInfo::trampoline_stub_type) { }
1282
1283 public:
1284
1285 // Return the address of the NativeCall that owns the trampoline.
1286 address owner() { return _owner; }
1287
1288 void pack_data_to(CodeSection * dest) override;
1289 void unpack_data() override;
1290
1291 // Find the trampoline stub for a call.
1292 static address get_trampoline_for(address call, nmethod* code);
1293 };
1294
1295 class external_word_Relocation : public DataRelocation {
1296 public:
1297 static RelocationHolder spec(address target) {
1298 assert(target != nullptr, "must not be null");
1299 return RelocationHolder::construct<external_word_Relocation>(target);
1300 }
1301
1302 // Use this one where all 32/64 bits of the target live in the code stream.
1303 // The target must be an intptr_t, and must be absolute (not relative).
1304 static RelocationHolder spec_for_immediate() {
1305 return RelocationHolder::construct<external_word_Relocation>(nullptr);
1306 }
1307
1308 void copy_into(RelocationHolder& holder) const override;
1309
|
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 #ifdef _LP64
444 // for use in format
445 // format_width must be at least 1 on _LP64
446 narrow_oop_in_const = 1,
447 #endif
448 // Conservatively large estimate of maximum length (in shorts)
449 // of any relocation record.
450 // Extended format is length prefix, data words, and tag/offset suffix.
451 length_limit = 1 + 1 + (3*BytesPerWord/BytesPerShort) + 1,
452 have_format = format_width > 0
453 };
454
455 static const char* type_name(relocInfo::relocType t);
456 };
457
458 #define FORWARD_DECLARE_EACH_CLASS(name) \
459 class name##_Relocation;
460 APPLY_TO_RELOCATIONS(FORWARD_DECLARE_EACH_CLASS)
461 #undef FORWARD_DECLARE_EACH_CLASS
462
463 // Holder for flyweight relocation objects.
464 // Although the flyweight subclasses are of varying sizes,
465 // the holder is "one size fits all".
466 class RelocationHolder {
467 friend class Relocation;
468
469 private:
470 // A Relocation is "held" by placement constructing a Relocation into
471 // _relocbuf. Hence, _relocbuf must accomodate all subclasses of
472 // Relocation. We also need the Relocation base class to be at the same
473 // address as the start of the object, e.g. at the address of _relocbuf.
474 // Both of these requirements are checked (see emplace_relocation).
475 // The placement of the base class subobject isn't guaranteed by C++, since
623 if (_limit != nullptr && _addr >= _limit) {
624 set_has_current(false);
625 return false;
626 }
627
628 return true;
629 }
630
631 // accessors
632 address limit() const { return _limit; }
633 relocType type() const { return current()->type(); }
634 int format() const { return (relocInfo::have_format) ? current()->format() : 0; }
635 address addr() const { return _addr; }
636 nmethod* code() const { return _code; }
637 short* data() const { return _data; }
638 int datalen() const { return _datalen; }
639 bool has_current() const { return _datalen >= 0; }
640 bool addr_in_const() const;
641
642 address section_start(int n) const {
643 assert(_section_start[n], "section %d must be initialized", n);
644 return _section_start[n];
645 }
646 address section_end(int n) const {
647 assert(_section_end[n], "section %d must be initialized", n);
648 return _section_end[n];
649 }
650
651 // The address points to the affected displacement part of the instruction.
652 // For RISC, this is just the whole instruction.
653 // For Intel, this is an unaligned 32-bit word.
654
655 // type-specific relocation accessors: oop_Relocation* oop_reloc(), etc.
656 #define EACH_TYPE(name) \
657 inline name##_Relocation* name##_reloc();
658 APPLY_TO_RELOCATIONS(EACH_TYPE)
659 #undef EACH_TYPE
660 // generic relocation accessor; switches on type to call the above
661 Relocation* reloc();
662
663 public:
664 void print_on(outputStream* st);
665 void print_current_on(outputStream* st);
666 };
667
668
669 // A Relocation is a flyweight object allocated within a RelocationHolder.
670 // It represents the relocation data of relocation record.
671 // So, the RelocIterator unpacks relocInfos into Relocations.
672
673 class Relocation {
674 friend class RelocIterator;
675 friend class SCCReader;
676
677 private:
678 // When a relocation has been created by a RelocIterator,
679 // this field is non-null. It allows the relocation to know
680 // its context, such as the address to which it applies.
681 RelocIterator* _binding;
682
683 relocInfo::relocType _rtype;
684
685 protected:
686 RelocIterator* binding() const {
687 assert(_binding != nullptr, "must be bound");
688 return _binding;
689 }
690 void set_binding(RelocIterator* b) {
691 assert(_binding == nullptr, "must be unbound");
692 _binding = b;
693 assert(_binding != nullptr, "must now be bound");
694 }
695
1271
1272 void copy_into(RelocationHolder& holder) const override;
1273
1274 private:
1275 address _owner; // Address of the NativeCall that owns the trampoline.
1276
1277 trampoline_stub_Relocation(address owner)
1278 : Relocation(relocInfo::trampoline_stub_type),
1279 _owner(owner) { }
1280
1281 friend class RelocationHolder;
1282 trampoline_stub_Relocation() : Relocation(relocInfo::trampoline_stub_type) { }
1283
1284 public:
1285
1286 // Return the address of the NativeCall that owns the trampoline.
1287 address owner() { return _owner; }
1288
1289 void pack_data_to(CodeSection * dest) override;
1290 void unpack_data() override;
1291 #if defined(AARCH64)
1292 address pd_destination ();
1293 void pd_set_destination (address x);
1294 #endif
1295 address destination() {
1296 #if defined(AARCH64)
1297 return pd_destination();
1298 #else
1299 fatal("trampoline_stub_Relocation::destination() unimplemented");
1300 return (address)-1;
1301 #endif
1302 }
1303 void set_destination(address x) {
1304 #if defined(AARCH64)
1305 pd_set_destination(x);
1306 #else
1307 fatal("trampoline_stub_Relocation::set_destination() unimplemented");
1308 #endif
1309 }
1310
1311 // Find the trampoline stub for a call.
1312 static address get_trampoline_for(address call, nmethod* code);
1313 };
1314
1315 class external_word_Relocation : public DataRelocation {
1316 public:
1317 static RelocationHolder spec(address target) {
1318 assert(target != nullptr, "must not be null");
1319 return RelocationHolder::construct<external_word_Relocation>(target);
1320 }
1321
1322 // Use this one where all 32/64 bits of the target live in the code stream.
1323 // The target must be an intptr_t, and must be absolute (not relative).
1324 static RelocationHolder spec_for_immediate() {
1325 return RelocationHolder::construct<external_word_Relocation>(nullptr);
1326 }
1327
1328 void copy_into(RelocationHolder& holder) const override;
1329
|