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