< prev index next >

src/hotspot/share/code/relocInfo.hpp

Print this page
rev 53683 : 8218625: Remove dead code in relocInfo
Reviewed-by: TBD


 328   // accessors
 329  public:
 330   relocType  type()       const { return (relocType)((unsigned)_value >> nontype_width); }
 331   int  format()           const { return format_mask==0? 0: format_mask &
 332                                          ((unsigned)_value >> offset_width); }
 333   int  addr_offset()      const { assert(!is_prefix(), "must have offset");
 334                                   return (_value & offset_mask)*offset_unit; }
 335 
 336  protected:
 337   const short* data()     const { assert(is_datalen(), "must have data");
 338                                   return (const short*)(this + 1); }
 339   int          datalen()  const { assert(is_datalen(), "must have data");
 340                                   return (_value & datalen_mask); }
 341   int         immediate() const { assert(is_immediate(), "must have immed");
 342                                   return (_value & datalen_mask); }
 343  public:
 344   static int addr_unit()        { return offset_unit; }
 345   static int offset_limit()     { return (1 << offset_width) * offset_unit; }
 346 
 347   void set_type(relocType type);
 348   void set_format(int format);
 349 
 350   void remove() { set_type(none); }
 351 
 352  protected:
 353   bool is_none()                const { return type() == none; }
 354   bool is_prefix()              const { return type() == data_prefix_tag; }
 355   bool is_datalen()             const { assert(is_prefix(), "must be prefix");
 356                                         return (_value & datalen_tag) != 0; }
 357   bool is_immediate()           const { assert(is_prefix(), "must be prefix");
 358                                         return (_value & datalen_tag) == 0; }
 359 
 360  public:
 361   // Occasionally records of type relocInfo::none will appear in the stream.
 362   // We do not bother to filter these out, but clients should ignore them.
 363   // These records serve as "filler" in three ways:
 364   //  - to skip large spans of unrelocated code (this is rare)
 365   //  - to pad out the relocInfo array to the required oop alignment
 366   //  - to disable old relocation information which is no longer applicable
 367 
 368   inline friend relocInfo filler_relocInfo();


 405   // but the shorts within the word are ordered big-endian.
 406   // This is an arbitrary choice, made this way mainly to ease debugging.
 407   static int data0_from_int(jint x)         { return x >> value_width; }
 408   static int data1_from_int(jint x)         { return (short)x; }
 409   static jint jint_from_data(short* data) {
 410     return (data[0] << value_width) + (unsigned short)data[1];
 411   }
 412 
 413   static jint short_data_at(int n, short* data, int datalen) {
 414     return datalen > n ? data[n] : 0;
 415   }
 416 
 417   static jint jint_data_at(int n, short* data, int datalen) {
 418     return datalen > n+1 ? jint_from_data(&data[n]) : short_data_at(n, data, datalen);
 419   }
 420 
 421   // Update methods for relocation information
 422   // (since code is dynamically patched, we also need to dynamically update the relocation info)
 423   // Both methods takes old_type, so it is able to performe sanity checks on the information removed.
 424   static void change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type);
 425   static void remove_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type);
 426 
 427   // Machine dependent stuff
 428 #include CPU_HEADER(relocInfo)
 429 
 430  protected:
 431   // Derived constant, based on format_width which is PD:
 432   enum {
 433     offset_width       = nontype_width - format_width,
 434     offset_mask        = (1<<offset_width) - 1,
 435     format_mask        = (1<<format_width) - 1
 436   };
 437  public:
 438   enum {
 439 #ifdef _LP64
 440     // for use in format
 441     // format_width must be at least 1 on _LP64
 442     narrow_oop_in_const = 1,
 443 #endif
 444     // Conservatively large estimate of maximum length (in shorts)
 445     // of any relocation record.


 514 //      case relocInfo::external_word_type:
 515 //      ...
 516 //     }
 517 //   }
 518 
 519 class RelocIterator : public StackObj {
 520   enum { SECT_LIMIT = 3 };  // must be equal to CodeBuffer::SECT_LIMIT, checked in ctor
 521   friend class Relocation;
 522   friend class relocInfo;       // for change_reloc_info_for_address only
 523   typedef relocInfo::relocType relocType;
 524 
 525  private:
 526   address         _limit;   // stop producing relocations after this _addr
 527   relocInfo*      _current; // the current relocation information
 528   relocInfo*      _end;     // end marker; we're done iterating when _current == _end
 529   CompiledMethod* _code;    // compiled method containing _addr
 530   address         _addr;    // instruction to which the relocation applies
 531   short           _databuf; // spare buffer for compressed data
 532   short*          _data;    // pointer to the relocation's data
 533   short           _datalen; // number of halfwords in _data
 534   char            _format;  // position within the instruction
 535 
 536   // Base addresses needed to compute targets of section_word_type relocs.
 537   address _section_start[SECT_LIMIT];
 538   address _section_end  [SECT_LIMIT];
 539 
 540   void set_has_current(bool b) {
 541     _datalen = !b ? -1 : 0;
 542     debug_only(_data = NULL);
 543   }
 544   void set_current(relocInfo& ri) {
 545     _current = &ri;
 546     set_has_current(true);
 547   }
 548 
 549   RelocationHolder _rh; // where the current relocation is allocated
 550 
 551   relocInfo* current() const { assert(has_current(), "must have current");
 552                                return _current; }
 553 
 554   void set_limits(address begin, address limit);


 571     _current++;
 572     assert(_current <= _end, "must not overrun relocInfo");
 573     if (_current == _end) {
 574       set_has_current(false);
 575       return false;
 576     }
 577     set_has_current(true);
 578 
 579     if (_current->is_prefix()) {
 580       advance_over_prefix();
 581       assert(!current()->is_prefix(), "only one prefix at a time");
 582     }
 583 
 584     _addr += _current->addr_offset();
 585 
 586     if (_limit != NULL && _addr >= _limit) {
 587       set_has_current(false);
 588       return false;
 589     }
 590 
 591     if (relocInfo::have_format)  _format = current()->format();
 592     return true;
 593   }
 594 
 595   // accessors
 596   address      limit()        const { return _limit; }
 597   void     set_limit(address x);
 598   relocType    type()         const { return current()->type(); }
 599   int          format()       const { return (relocInfo::have_format) ? current()->format() : 0; }
 600   address      addr()         const { return _addr; }
 601   CompiledMethod*     code()  const { return _code; }
 602   nmethod*     code_as_nmethod() const;
 603   short*       data()         const { return _data; }
 604   int          datalen()      const { return _datalen; }
 605   bool     has_current()      const { return _datalen >= 0; }
 606 
 607   void       set_addr(address addr) { _addr = addr; }
 608   bool   addr_in_const()      const;
 609 
 610   address section_start(int n) const {
 611     assert(_section_start[n], "must be initialized");
 612     return _section_start[n];
 613   }
 614   address section_end(int n) const {
 615     assert(_section_end[n], "must be initialized");
 616     return _section_end[n];
 617   }
 618 
 619   // The address points to the affected displacement part of the instruction.
 620   // For RISC, this is just the whole instruction.
 621   // For Intel, this is an unaligned 32-bit word.
 622 
 623   // type-specific relocation accessors:  oop_Relocation* oop_reloc(), etc.
 624   #define EACH_TYPE(name)                               \
 625   inline name##_Relocation* name##_reloc();
 626   APPLY_TO_RELOCATIONS(EACH_TYPE)
 627   #undef EACH_TYPE


 776     // Some relocations treat offset=0 as meaning NULL.
 777     // Handle this extra convention carefully.
 778     if (x == NULL)  return 0;
 779     assert(x != base, "offset must not be zero");
 780     return scaled_offset(x, base);
 781   }
 782   static address address_from_scaled_offset(jint offset, address base) {
 783     int byte_offset = -( offset * relocInfo::addr_unit() );
 784     return base + byte_offset;
 785   }
 786 
 787   // helpers for mapping between old and new addresses after a move or resize
 788   address old_addr_for(address newa, const CodeBuffer* src, CodeBuffer* dest);
 789   address new_addr_for(address olda, const CodeBuffer* src, CodeBuffer* dest);
 790   void normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections = false);
 791 
 792  public:
 793   // accessors which only make sense for a bound Relocation
 794   address         addr()            const { return binding()->addr(); }
 795   CompiledMethod* code()            const { return binding()->code(); }
 796   nmethod*        code_as_nmethod() const { return binding()->code_as_nmethod(); }
 797   bool            addr_in_const()   const { return binding()->addr_in_const(); }
 798  protected:
 799   short*   data()         const { return binding()->data(); }
 800   int      datalen()      const { return binding()->datalen(); }
 801   int      format()       const { return binding()->format(); }
 802 
 803  public:
 804   virtual relocInfo::relocType type()            { return relocInfo::none; }
 805 
 806   // is it a call instruction?
 807   virtual bool is_call()                         { return false; }
 808 
 809   // is it a data movement instruction?
 810   virtual bool is_data()                         { return false; }
 811 
 812   // some relocations can compute their own values
 813   virtual address  value();
 814 
 815   // all relocations are able to reassert their values
 816   virtual void set_value(address x);


 984     _metadata_index = metadata_index; _offset = offset;
 985   }
 986 
 987   friend class RelocIterator;
 988   metadata_Relocation() { }
 989 
 990   // Fixes a Metadata pointer in the code. Most platforms embeds the
 991   // Metadata pointer in the code at compile time so this is empty
 992   // for them.
 993   void pd_fix_value(address x);
 994 
 995  public:
 996   int metadata_index() { return _metadata_index; }
 997   int offset()    { return _offset; }
 998 
 999   // data is packed in "2_ints" format:  [i o] or [Ii Oo]
1000   void pack_data_to(CodeSection* dest);
1001   void unpack_data();
1002 
1003   void fix_metadata_relocation();        // reasserts metadata value
1004 
1005   void verify_metadata_relocation();
1006 
1007   address value()  { return (address) *metadata_addr(); }
1008 
1009   bool metadata_is_immediate()  { return metadata_index() == 0; }
1010 
1011   Metadata**   metadata_addr();                  // addr or &pool[jint_data]
1012   Metadata*    metadata_value();                 // *metadata_addr
1013   // Note:  metadata_value transparently converts Universe::non_metadata_word to NULL.
1014 };
1015 
1016 
1017 class virtual_call_Relocation : public CallRelocation {
1018   relocInfo::relocType type() { return relocInfo::virtual_call_type; }
1019 
1020  public:
1021   // "cached_value" points to the first associated set-oop.
1022   // The oop_limit helps find the last associated set-oop.
1023   // (See comments at the top of this file.)
1024   static RelocationHolder spec(address cached_value, jint method_index = 0) {
1025     RelocationHolder rh = newHolder();




 328   // accessors
 329  public:
 330   relocType  type()       const { return (relocType)((unsigned)_value >> nontype_width); }
 331   int  format()           const { return format_mask==0? 0: format_mask &
 332                                          ((unsigned)_value >> offset_width); }
 333   int  addr_offset()      const { assert(!is_prefix(), "must have offset");
 334                                   return (_value & offset_mask)*offset_unit; }
 335 
 336  protected:
 337   const short* data()     const { assert(is_datalen(), "must have data");
 338                                   return (const short*)(this + 1); }
 339   int          datalen()  const { assert(is_datalen(), "must have data");
 340                                   return (_value & datalen_mask); }
 341   int         immediate() const { assert(is_immediate(), "must have immed");
 342                                   return (_value & datalen_mask); }
 343  public:
 344   static int addr_unit()        { return offset_unit; }
 345   static int offset_limit()     { return (1 << offset_width) * offset_unit; }
 346 
 347   void set_type(relocType type);

 348 
 349   void remove() { set_type(none); }
 350 
 351  protected:
 352   bool is_none()                const { return type() == none; }
 353   bool is_prefix()              const { return type() == data_prefix_tag; }
 354   bool is_datalen()             const { assert(is_prefix(), "must be prefix");
 355                                         return (_value & datalen_tag) != 0; }
 356   bool is_immediate()           const { assert(is_prefix(), "must be prefix");
 357                                         return (_value & datalen_tag) == 0; }
 358 
 359  public:
 360   // Occasionally records of type relocInfo::none will appear in the stream.
 361   // We do not bother to filter these out, but clients should ignore them.
 362   // These records serve as "filler" in three ways:
 363   //  - to skip large spans of unrelocated code (this is rare)
 364   //  - to pad out the relocInfo array to the required oop alignment
 365   //  - to disable old relocation information which is no longer applicable
 366 
 367   inline friend relocInfo filler_relocInfo();


 404   // but the shorts within the word are ordered big-endian.
 405   // This is an arbitrary choice, made this way mainly to ease debugging.
 406   static int data0_from_int(jint x)         { return x >> value_width; }
 407   static int data1_from_int(jint x)         { return (short)x; }
 408   static jint jint_from_data(short* data) {
 409     return (data[0] << value_width) + (unsigned short)data[1];
 410   }
 411 
 412   static jint short_data_at(int n, short* data, int datalen) {
 413     return datalen > n ? data[n] : 0;
 414   }
 415 
 416   static jint jint_data_at(int n, short* data, int datalen) {
 417     return datalen > n+1 ? jint_from_data(&data[n]) : short_data_at(n, data, datalen);
 418   }
 419 
 420   // Update methods for relocation information
 421   // (since code is dynamically patched, we also need to dynamically update the relocation info)
 422   // Both methods takes old_type, so it is able to performe sanity checks on the information removed.
 423   static void change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type);

 424 
 425   // Machine dependent stuff
 426 #include CPU_HEADER(relocInfo)
 427 
 428  protected:
 429   // Derived constant, based on format_width which is PD:
 430   enum {
 431     offset_width       = nontype_width - format_width,
 432     offset_mask        = (1<<offset_width) - 1,
 433     format_mask        = (1<<format_width) - 1
 434   };
 435  public:
 436   enum {
 437 #ifdef _LP64
 438     // for use in format
 439     // format_width must be at least 1 on _LP64
 440     narrow_oop_in_const = 1,
 441 #endif
 442     // Conservatively large estimate of maximum length (in shorts)
 443     // of any relocation record.


 512 //      case relocInfo::external_word_type:
 513 //      ...
 514 //     }
 515 //   }
 516 
 517 class RelocIterator : public StackObj {
 518   enum { SECT_LIMIT = 3 };  // must be equal to CodeBuffer::SECT_LIMIT, checked in ctor
 519   friend class Relocation;
 520   friend class relocInfo;       // for change_reloc_info_for_address only
 521   typedef relocInfo::relocType relocType;
 522 
 523  private:
 524   address         _limit;   // stop producing relocations after this _addr
 525   relocInfo*      _current; // the current relocation information
 526   relocInfo*      _end;     // end marker; we're done iterating when _current == _end
 527   CompiledMethod* _code;    // compiled method containing _addr
 528   address         _addr;    // instruction to which the relocation applies
 529   short           _databuf; // spare buffer for compressed data
 530   short*          _data;    // pointer to the relocation's data
 531   short           _datalen; // number of halfwords in _data

 532 
 533   // Base addresses needed to compute targets of section_word_type relocs.
 534   address _section_start[SECT_LIMIT];
 535   address _section_end  [SECT_LIMIT];
 536 
 537   void set_has_current(bool b) {
 538     _datalen = !b ? -1 : 0;
 539     debug_only(_data = NULL);
 540   }
 541   void set_current(relocInfo& ri) {
 542     _current = &ri;
 543     set_has_current(true);
 544   }
 545 
 546   RelocationHolder _rh; // where the current relocation is allocated
 547 
 548   relocInfo* current() const { assert(has_current(), "must have current");
 549                                return _current; }
 550 
 551   void set_limits(address begin, address limit);


 568     _current++;
 569     assert(_current <= _end, "must not overrun relocInfo");
 570     if (_current == _end) {
 571       set_has_current(false);
 572       return false;
 573     }
 574     set_has_current(true);
 575 
 576     if (_current->is_prefix()) {
 577       advance_over_prefix();
 578       assert(!current()->is_prefix(), "only one prefix at a time");
 579     }
 580 
 581     _addr += _current->addr_offset();
 582 
 583     if (_limit != NULL && _addr >= _limit) {
 584       set_has_current(false);
 585       return false;
 586     }
 587 

 588     return true;
 589   }
 590 
 591   // accessors
 592   address      limit()        const { return _limit; }

 593   relocType    type()         const { return current()->type(); }
 594   int          format()       const { return (relocInfo::have_format) ? current()->format() : 0; }
 595   address      addr()         const { return _addr; }
 596   CompiledMethod*     code()  const { return _code; }

 597   short*       data()         const { return _data; }
 598   int          datalen()      const { return _datalen; }
 599   bool     has_current()      const { return _datalen >= 0; }


 600   bool   addr_in_const()      const;
 601 
 602   address section_start(int n) const {
 603     assert(_section_start[n], "must be initialized");
 604     return _section_start[n];
 605   }
 606   address section_end(int n) const {
 607     assert(_section_end[n], "must be initialized");
 608     return _section_end[n];
 609   }
 610 
 611   // The address points to the affected displacement part of the instruction.
 612   // For RISC, this is just the whole instruction.
 613   // For Intel, this is an unaligned 32-bit word.
 614 
 615   // type-specific relocation accessors:  oop_Relocation* oop_reloc(), etc.
 616   #define EACH_TYPE(name)                               \
 617   inline name##_Relocation* name##_reloc();
 618   APPLY_TO_RELOCATIONS(EACH_TYPE)
 619   #undef EACH_TYPE


 768     // Some relocations treat offset=0 as meaning NULL.
 769     // Handle this extra convention carefully.
 770     if (x == NULL)  return 0;
 771     assert(x != base, "offset must not be zero");
 772     return scaled_offset(x, base);
 773   }
 774   static address address_from_scaled_offset(jint offset, address base) {
 775     int byte_offset = -( offset * relocInfo::addr_unit() );
 776     return base + byte_offset;
 777   }
 778 
 779   // helpers for mapping between old and new addresses after a move or resize
 780   address old_addr_for(address newa, const CodeBuffer* src, CodeBuffer* dest);
 781   address new_addr_for(address olda, const CodeBuffer* src, CodeBuffer* dest);
 782   void normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections = false);
 783 
 784  public:
 785   // accessors which only make sense for a bound Relocation
 786   address         addr()            const { return binding()->addr(); }
 787   CompiledMethod* code()            const { return binding()->code(); }

 788   bool            addr_in_const()   const { return binding()->addr_in_const(); }
 789  protected:
 790   short*   data()         const { return binding()->data(); }
 791   int      datalen()      const { return binding()->datalen(); }
 792   int      format()       const { return binding()->format(); }
 793 
 794  public:
 795   virtual relocInfo::relocType type()            { return relocInfo::none; }
 796 
 797   // is it a call instruction?
 798   virtual bool is_call()                         { return false; }
 799 
 800   // is it a data movement instruction?
 801   virtual bool is_data()                         { return false; }
 802 
 803   // some relocations can compute their own values
 804   virtual address  value();
 805 
 806   // all relocations are able to reassert their values
 807   virtual void set_value(address x);


 975     _metadata_index = metadata_index; _offset = offset;
 976   }
 977 
 978   friend class RelocIterator;
 979   metadata_Relocation() { }
 980 
 981   // Fixes a Metadata pointer in the code. Most platforms embeds the
 982   // Metadata pointer in the code at compile time so this is empty
 983   // for them.
 984   void pd_fix_value(address x);
 985 
 986  public:
 987   int metadata_index() { return _metadata_index; }
 988   int offset()    { return _offset; }
 989 
 990   // data is packed in "2_ints" format:  [i o] or [Ii Oo]
 991   void pack_data_to(CodeSection* dest);
 992   void unpack_data();
 993 
 994   void fix_metadata_relocation();        // reasserts metadata value


 995 
 996   address value()  { return (address) *metadata_addr(); }
 997 
 998   bool metadata_is_immediate()  { return metadata_index() == 0; }
 999 
1000   Metadata**   metadata_addr();                  // addr or &pool[jint_data]
1001   Metadata*    metadata_value();                 // *metadata_addr
1002   // Note:  metadata_value transparently converts Universe::non_metadata_word to NULL.
1003 };
1004 
1005 
1006 class virtual_call_Relocation : public CallRelocation {
1007   relocInfo::relocType type() { return relocInfo::virtual_call_type; }
1008 
1009  public:
1010   // "cached_value" points to the first associated set-oop.
1011   // The oop_limit helps find the last associated set-oop.
1012   // (See comments at the top of this file.)
1013   static RelocationHolder spec(address cached_value, jint method_index = 0) {
1014     RelocationHolder rh = newHolder();


< prev index next >