src/share/vm/code/relocInfo.hpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

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

mercurial