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