495 // case relocInfo::prim_type :
496 // case relocInfo::uncommon_type :
497 // case relocInfo::runtime_call_type :
498 // case relocInfo::internal_word_type:
499 // case relocInfo::external_word_type:
500 // ...
501 // }
502 // }
503
504 class RelocIterator : public StackObj {
505 enum { SECT_CONSTS = 2,
506 SECT_LIMIT = 3 }; // must be equal to CodeBuffer::SECT_LIMIT
507 friend class Relocation;
508 friend class relocInfo; // for change_reloc_info_for_address only
509 typedef relocInfo::relocType relocType;
510
511 private:
512 address _limit; // stop producing relocations after this _addr
513 relocInfo* _current; // the current relocation information
514 relocInfo* _end; // end marker; we're done iterating when _current == _end
515 CodeBlob* _code; // compiled method containing _addr
516 address _addr; // instruction to which the relocation applies
517 short _databuf; // spare buffer for compressed data
518 short* _data; // pointer to the relocation's data
519 short _datalen; // number of halfwords in _data
520 char _format; // position within the instruction
521
522 // Base addresses needed to compute targets of section_word_type relocs.
523 address _section_start[SECT_LIMIT];
524
525 void set_has_current(bool b) {
526 _datalen = !b ? -1 : 0;
527 debug_only(_data = NULL);
528 }
529 void set_current(relocInfo& ri) {
530 _current = &ri;
531 set_has_current(true);
532 }
533
534 RelocationHolder _rh; // where the current relocation is allocated
535
536 relocInfo* current() const { assert(has_current(), "must have current");
537 return _current; }
538
539 void set_limits(address begin, address limit);
540
541 void advance_over_prefix(); // helper method
542
543 void initialize_misc() {
544 set_has_current(false);
545 for (int i = 0; i < SECT_LIMIT; i++) {
546 _section_start[i] = NULL; // these will be lazily computed, if needed
547 }
548 }
549
550 address compute_section_start(int n) const; // out-of-line helper
551
552 void initialize(CodeBlob* nm, address begin, address limit);
553
554 friend class PatchingRelocIterator;
555 // make an uninitialized one, for PatchingRelocIterator:
556 RelocIterator() { initialize_misc(); }
557
558 public:
559 // constructor
560 RelocIterator(CodeBlob* cb, address begin = NULL, address limit = NULL);
561 RelocIterator(CodeSection* cb, address begin = NULL, address limit = NULL);
562
563 // get next reloc info, return !eos
564 bool next() {
565 _current++;
566 assert(_current <= _end, "must not overrun relocInfo");
567 if (_current == _end) {
568 set_has_current(false);
569 return false;
570 }
571 set_has_current(true);
572
573 if (_current->is_prefix()) {
574 advance_over_prefix();
575 assert(!current()->is_prefix(), "only one prefix at a time");
576 }
577
578 _addr += _current->addr_offset();
579
580 if (_limit != NULL && _addr >= _limit) {
581 set_has_current(false);
582 return false;
583 }
584
585 if (relocInfo::have_format) _format = current()->format();
586 return true;
587 }
588
589 // accessors
590 address limit() const { return _limit; }
591 void set_limit(address x);
592 relocType type() const { return current()->type(); }
593 int format() const { return (relocInfo::have_format) ? current()->format() : 0; }
594 address addr() const { return _addr; }
595 CodeBlob* code() const { return _code; }
596 short* data() const { return _data; }
597 int datalen() const { return _datalen; }
598 bool has_current() const { return _datalen >= 0; }
599
600 void set_addr(address addr) { _addr = addr; }
601 bool addr_in_const() const { return addr() >= section_start(SECT_CONSTS); }
602
603 address section_start(int n) const {
604 address res = _section_start[n];
605 return (res != NULL) ? res : compute_section_start(n);
606 }
607
608 // The address points to the affected displacement part of the instruction.
609 // For RISC, this is just the whole instruction.
610 // For Intel, this is an unaligned 32-bit word.
611
612 // type-specific relocation accessors: oop_Relocation* oop_reloc(), etc.
613 #define EACH_TYPE(name) \
614 inline name##_Relocation* name##_reloc();
615 APPLY_TO_RELOCATIONS(EACH_TYPE)
774 assert(x != base, "offset must not be zero");
775 return scaled_offset(x, base);
776 }
777 static address address_from_scaled_offset(jint offset, address base) {
778 int byte_offset = -( offset * relocInfo::addr_unit() );
779 return base + byte_offset;
780 }
781
782 // these convert between indexes and addresses in the runtime system
783 static int32_t runtime_address_to_index(address runtime_address);
784 static address index_to_runtime_address(int32_t index);
785
786 // helpers for mapping between old and new addresses after a move or resize
787 address old_addr_for(address newa, const CodeBuffer* src, CodeBuffer* dest);
788 address new_addr_for(address olda, const CodeBuffer* src, CodeBuffer* dest);
789 void normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections = false);
790
791 public:
792 // accessors which only make sense for a bound Relocation
793 address addr() const { return binding()->addr(); }
794 CodeBlob* code() const { return binding()->code(); }
795 bool addr_in_const() const { return binding()->addr_in_const(); }
796 protected:
797 short* data() const { return binding()->data(); }
798 int datalen() const { return binding()->datalen(); }
799 int format() const { return binding()->format(); }
800
801 public:
802 virtual relocInfo::relocType type() { return relocInfo::none; }
803
804 // is it a call instruction?
805 virtual bool is_call() { return false; }
806
807 // is it a data movement instruction?
808 virtual bool is_data() { return false; }
809
810 // some relocations can compute their own values
811 virtual address value();
812
813 // all relocations are able to reassert their values
814 virtual void set_value(address x);
965
966 friend class RelocIterator;
967 virtual_call_Relocation() { }
968
969
970 public:
971 address first_oop();
972 address oop_limit();
973
974 // data is packed as scaled offsets in "2_ints" format: [f l] or [Ff Ll]
975 // oop_limit is set to 0 if the limit falls somewhere within the call.
976 // When unpacking, a zero oop_limit is taken to refer to the end of the call.
977 // (This has the effect of bringing in the call's delay slot on SPARC.)
978 void pack_data_to(CodeSection* dest);
979 void unpack_data();
980
981 void clear_inline_cache();
982
983 // Figure out where an ic_call is hiding, given a set-oop or call.
984 // Either ic_call or first_oop must be non-null; the other is deduced.
985 // Code if non-NULL must be the CodeBlob, else it is deduced.
986 // The address of the patchable oop is also deduced.
987 // The returned iterator will enumerate over the oops and the ic_call,
988 // as well as any other relocations that happen to be in that span of code.
989 // Recognize relevant set_oops with: oop_reloc()->oop_addr() == oop_addr.
990 static RelocIterator parse_ic(CodeBlob* &code, address &ic_call, address &first_oop, oop* &oop_addr, bool *is_optimized);
991 };
992
993
994 class opt_virtual_call_Relocation : public CallRelocation {
995 relocInfo::relocType type() { return relocInfo::opt_virtual_call_type; }
996
997 public:
998 static RelocationHolder spec() {
999 RelocationHolder rh = newHolder();
1000 new(rh) opt_virtual_call_Relocation();
1001 return rh;
1002 }
1003
1004 private:
1005 friend class RelocIterator;
1006 opt_virtual_call_Relocation() { }
1007
1008 public:
1009 void clear_inline_cache();
1010
1287 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
1288 assert(!active(), "cannot perform relocation on enabled breakpoints");
1289 }
1290 };
1291
1292
1293 // We know all the xxx_Relocation classes, so now we can define these:
1294 #define EACH_CASE(name) \
1295 inline name##_Relocation* RelocIterator::name##_reloc() { \
1296 assert(type() == relocInfo::name##_type, "type must agree"); \
1297 /* The purpose of the placed "new" is to re-use the same */ \
1298 /* stack storage for each new iteration. */ \
1299 name##_Relocation* r = new(_rh) name##_Relocation(); \
1300 r->set_binding(this); \
1301 r->name##_Relocation::unpack_data(); \
1302 return r; \
1303 }
1304 APPLY_TO_RELOCATIONS(EACH_CASE);
1305 #undef EACH_CASE
1306
1307 inline RelocIterator::RelocIterator(CodeBlob* cb, address begin, address limit) {
1308 initialize(cb, begin, limit);
1309 }
1310
1311 // if you are going to patch code, you should use this subclass of
1312 // RelocIterator
1313 class PatchingRelocIterator : public RelocIterator {
1314 private:
1315 RelocIterator _init_state;
1316
1317 void prepass(); // deactivates all breakpoints
1318 void postpass(); // reactivates all enabled breakpoints
1319
1320 // do not copy these puppies; it would have unpredictable side effects
1321 // these are private and have no bodies defined because they should not be called
1322 PatchingRelocIterator(const RelocIterator&);
1323 void operator=(const RelocIterator&);
1324
1325 public:
1326 PatchingRelocIterator(CodeBlob* cb, address begin =NULL, address limit =NULL)
1327 : RelocIterator(cb, begin, limit) { prepass(); }
1328
1329 ~PatchingRelocIterator() { postpass(); }
1330 };
|
495 // case relocInfo::prim_type :
496 // case relocInfo::uncommon_type :
497 // case relocInfo::runtime_call_type :
498 // case relocInfo::internal_word_type:
499 // case relocInfo::external_word_type:
500 // ...
501 // }
502 // }
503
504 class RelocIterator : public StackObj {
505 enum { SECT_CONSTS = 2,
506 SECT_LIMIT = 3 }; // must be equal to CodeBuffer::SECT_LIMIT
507 friend class Relocation;
508 friend class relocInfo; // for change_reloc_info_for_address only
509 typedef relocInfo::relocType relocType;
510
511 private:
512 address _limit; // stop producing relocations after this _addr
513 relocInfo* _current; // the current relocation information
514 relocInfo* _end; // end marker; we're done iterating when _current == _end
515 nmethod* _code; // compiled method containing _addr
516 address _addr; // instruction to which the relocation applies
517 short _databuf; // spare buffer for compressed data
518 short* _data; // pointer to the relocation's data
519 short _datalen; // number of halfwords in _data
520 char _format; // position within the instruction
521
522 // Base addresses needed to compute targets of section_word_type relocs.
523 address _section_start[SECT_LIMIT];
524
525 void set_has_current(bool b) {
526 _datalen = !b ? -1 : 0;
527 debug_only(_data = NULL);
528 }
529 void set_current(relocInfo& ri) {
530 _current = &ri;
531 set_has_current(true);
532 }
533
534 RelocationHolder _rh; // where the current relocation is allocated
535
536 relocInfo* current() const { assert(has_current(), "must have current");
537 return _current; }
538
539 void set_limits(address begin, address limit);
540
541 void advance_over_prefix(); // helper method
542
543 void initialize_misc() {
544 set_has_current(false);
545 for (int i = 0; i < SECT_LIMIT; i++) {
546 _section_start[i] = NULL; // these will be lazily computed, if needed
547 }
548 }
549
550 address compute_section_start(int n) const; // out-of-line helper
551
552 void initialize(nmethod* nm, address begin, address limit);
553
554 friend class PatchingRelocIterator;
555 // make an uninitialized one, for PatchingRelocIterator:
556 RelocIterator() { initialize_misc(); }
557
558 public:
559 // constructor
560 RelocIterator(nmethod* nm, address begin = NULL, address limit = NULL);
561 RelocIterator(CodeSection* cb, address begin = NULL, address limit = NULL);
562
563 // get next reloc info, return !eos
564 bool next() {
565 _current++;
566 assert(_current <= _end, "must not overrun relocInfo");
567 if (_current == _end) {
568 set_has_current(false);
569 return false;
570 }
571 set_has_current(true);
572
573 if (_current->is_prefix()) {
574 advance_over_prefix();
575 assert(!current()->is_prefix(), "only one prefix at a time");
576 }
577
578 _addr += _current->addr_offset();
579
580 if (_limit != NULL && _addr >= _limit) {
581 set_has_current(false);
582 return false;
583 }
584
585 if (relocInfo::have_format) _format = current()->format();
586 return true;
587 }
588
589 // accessors
590 address limit() const { return _limit; }
591 void set_limit(address x);
592 relocType type() const { return current()->type(); }
593 int format() const { return (relocInfo::have_format) ? current()->format() : 0; }
594 address addr() const { return _addr; }
595 nmethod* code() const { return _code; }
596 short* data() const { return _data; }
597 int datalen() const { return _datalen; }
598 bool has_current() const { return _datalen >= 0; }
599
600 void set_addr(address addr) { _addr = addr; }
601 bool addr_in_const() const { return addr() >= section_start(SECT_CONSTS); }
602
603 address section_start(int n) const {
604 address res = _section_start[n];
605 return (res != NULL) ? res : compute_section_start(n);
606 }
607
608 // The address points to the affected displacement part of the instruction.
609 // For RISC, this is just the whole instruction.
610 // For Intel, this is an unaligned 32-bit word.
611
612 // type-specific relocation accessors: oop_Relocation* oop_reloc(), etc.
613 #define EACH_TYPE(name) \
614 inline name##_Relocation* name##_reloc();
615 APPLY_TO_RELOCATIONS(EACH_TYPE)
774 assert(x != base, "offset must not be zero");
775 return scaled_offset(x, base);
776 }
777 static address address_from_scaled_offset(jint offset, address base) {
778 int byte_offset = -( offset * relocInfo::addr_unit() );
779 return base + byte_offset;
780 }
781
782 // these convert between indexes and addresses in the runtime system
783 static int32_t runtime_address_to_index(address runtime_address);
784 static address index_to_runtime_address(int32_t index);
785
786 // helpers for mapping between old and new addresses after a move or resize
787 address old_addr_for(address newa, const CodeBuffer* src, CodeBuffer* dest);
788 address new_addr_for(address olda, const CodeBuffer* src, CodeBuffer* dest);
789 void normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections = false);
790
791 public:
792 // accessors which only make sense for a bound Relocation
793 address addr() const { return binding()->addr(); }
794 nmethod* code() const { return binding()->code(); }
795 bool addr_in_const() const { return binding()->addr_in_const(); }
796 protected:
797 short* data() const { return binding()->data(); }
798 int datalen() const { return binding()->datalen(); }
799 int format() const { return binding()->format(); }
800
801 public:
802 virtual relocInfo::relocType type() { return relocInfo::none; }
803
804 // is it a call instruction?
805 virtual bool is_call() { return false; }
806
807 // is it a data movement instruction?
808 virtual bool is_data() { return false; }
809
810 // some relocations can compute their own values
811 virtual address value();
812
813 // all relocations are able to reassert their values
814 virtual void set_value(address x);
965
966 friend class RelocIterator;
967 virtual_call_Relocation() { }
968
969
970 public:
971 address first_oop();
972 address oop_limit();
973
974 // data is packed as scaled offsets in "2_ints" format: [f l] or [Ff Ll]
975 // oop_limit is set to 0 if the limit falls somewhere within the call.
976 // When unpacking, a zero oop_limit is taken to refer to the end of the call.
977 // (This has the effect of bringing in the call's delay slot on SPARC.)
978 void pack_data_to(CodeSection* dest);
979 void unpack_data();
980
981 void clear_inline_cache();
982
983 // Figure out where an ic_call is hiding, given a set-oop or call.
984 // Either ic_call or first_oop must be non-null; the other is deduced.
985 // Code if non-NULL must be the nmethod, else it is deduced.
986 // The address of the patchable oop is also deduced.
987 // The returned iterator will enumerate over the oops and the ic_call,
988 // as well as any other relocations that happen to be in that span of code.
989 // Recognize relevant set_oops with: oop_reloc()->oop_addr() == oop_addr.
990 static RelocIterator parse_ic(nmethod* &nm, address &ic_call, address &first_oop, oop* &oop_addr, bool *is_optimized);
991 };
992
993
994 class opt_virtual_call_Relocation : public CallRelocation {
995 relocInfo::relocType type() { return relocInfo::opt_virtual_call_type; }
996
997 public:
998 static RelocationHolder spec() {
999 RelocationHolder rh = newHolder();
1000 new(rh) opt_virtual_call_Relocation();
1001 return rh;
1002 }
1003
1004 private:
1005 friend class RelocIterator;
1006 opt_virtual_call_Relocation() { }
1007
1008 public:
1009 void clear_inline_cache();
1010
1287 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
1288 assert(!active(), "cannot perform relocation on enabled breakpoints");
1289 }
1290 };
1291
1292
1293 // We know all the xxx_Relocation classes, so now we can define these:
1294 #define EACH_CASE(name) \
1295 inline name##_Relocation* RelocIterator::name##_reloc() { \
1296 assert(type() == relocInfo::name##_type, "type must agree"); \
1297 /* The purpose of the placed "new" is to re-use the same */ \
1298 /* stack storage for each new iteration. */ \
1299 name##_Relocation* r = new(_rh) name##_Relocation(); \
1300 r->set_binding(this); \
1301 r->name##_Relocation::unpack_data(); \
1302 return r; \
1303 }
1304 APPLY_TO_RELOCATIONS(EACH_CASE);
1305 #undef EACH_CASE
1306
1307 inline RelocIterator::RelocIterator(nmethod* nm, address begin, address limit) {
1308 initialize(nm, begin, limit);
1309 }
1310
1311 // if you are going to patch code, you should use this subclass of
1312 // RelocIterator
1313 class PatchingRelocIterator : public RelocIterator {
1314 private:
1315 RelocIterator _init_state;
1316
1317 void prepass(); // deactivates all breakpoints
1318 void postpass(); // reactivates all enabled breakpoints
1319
1320 // do not copy these puppies; it would have unpredictable side effects
1321 // these are private and have no bodies defined because they should not be called
1322 PatchingRelocIterator(const RelocIterator&);
1323 void operator=(const RelocIterator&);
1324
1325 public:
1326 PatchingRelocIterator(nmethod* nm, address begin = NULL, address limit = NULL)
1327 : RelocIterator(nm, begin, limit) { prepass(); }
1328
1329 ~PatchingRelocIterator() { postpass(); }
1330 };
|