hotspot Sdiff src/share/vm/code (original) (raw)
1 /* 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 *
193 // put no restrictions whatever upon code reorganization. 194 // 195 // The compiler is responsible for ensuring that transition from a clean 196 // state to a monomorphic compiled state is MP-safe. This implies that 197 // the system must respond well to intermediate states where a random 198 // subset of the set-oops has been correctly from the clean state 199 // upon entry to the VEP of the compiled method. In the case of a 200 // machine (Intel) with a single set-oop instruction, the 32-bit 201 // immediate field must not straddle a unit of memory coherence. 202 // //%note reloc_3 203 // 204 // relocInfo::static_stub_type -- an extra stub for each static_call_type 205 // Value: none 206 // Instruction types: a virtual call: { set_oop; jump; } 207 // Data: [[N]n] the offset of the associated static_call reloc 208 // This stub becomes the target of a static call which must be upgraded 209 // to a virtual call (because the callee is interpreted). 210 // See [About Offsets] below. 211 // //%note reloc_2 212 //
213 // For example: 214 // 215 // INSTRUCTIONS RELOC: TYPE PREFIX DATA 216 // ------------ ---- ----------- 217 // sethi %hi(myObject), R oop_type [n(myObject)] 218 // ld [R+%lo(myObject)+fldOffset], R2 oop_type [n(myObject) fldOffset] 219 // add R2, 1, R2 220 // st R2, [R+%lo(myObject)+fldOffset] oop_type [n(myObject) fldOffset] 221 //%note reloc_1 222 // 223 // This uses 4 instruction words, 8 relocation halfwords, 224 // and an entry (which is sharable) in the CodeBlob's oop pool, 225 // for a total of 36 bytes. 226 // 227 // Note that the compiler is responsible for ensuring the "fldOffset" when 228 // added to "%lo(myObject)" does not overflow the immediate fields of the 229 // memory instructions. 230 // 231 // 232 // [About Offsets] Relative offsets are supplied to this module as
426 #endif 427 #ifdef TARGET_ARCH_arm 428 # include "relocInfo_arm.hpp" 429 #endif 430 #ifdef TARGET_ARCH_ppc 431 # include "relocInfo_ppc.hpp" 432 #endif 433 #ifdef TARGET_ARCH_aarch64 434 # include "relocInfo_aarch64.hpp" 435 #endif 436 437 protected: 438 // Derived constant, based on format_width which is PD: 439 enum { 440 offset_width = nontype_width - format_width, 441 offset_mask = (1<<offset_width) - 1, 442 format_mask = (1<<format_width) - 1 443 }; 444 public: 445 enum {
446 // Conservatively large estimate of maximum length (in shorts)
447 // of any relocation record.
448 // Extended format is length prefix, data words, and tag/offset suffix.
449 length_limit = 1 + 1 + (3*BytesPerWord/BytesPerShort) + 1,
450 have_format = format_width > 0
451 };
452 };
453
454 #define FORWARD_DECLARE_EACH_CLASS(name)
455 class name##_Relocation;
456 APPLY_TO_RELOCATIONS(FORWARD_DECLARE_EACH_CLASS)
457 #undef FORWARD_DECLARE_EACH_CLASS
458
459
460
461 inline relocInfo filler_relocInfo() {
462 return relocInfo(relocInfo::none, relocInfo::offset_limit() - relocInfo::offset_unit);
463 }
464
465 inline relocInfo prefix_relocInfo(int datalen = 0) {
745 } else { 746 // 3-4 halfwords needed to store jints 747 p = add_jint(p, x0); p = add_var_int(p, x1); 748 } 749 return p; 750 } 751 void unpack_2_ints(jint& x0, jint& x1) { 752 int dlen = datalen(); 753 short* dp = data(); 754 if (dlen <= 2) { 755 x0 = relocInfo::short_data_at(0, dp, dlen); 756 x1 = relocInfo::short_data_at(1, dp, dlen); 757 } else { 758 assert(dlen <= 4, "too much data"); 759 x0 = relocInfo::jint_data_at(0, dp, dlen); 760 x1 = relocInfo::jint_data_at(2, dp, dlen); 761 } 762 } 763 764 protected:
765 // platform-dependent utilities for decoding and patching instructions 766 void pd_set_data_value (address x, intptr_t off, bool verify_only = false); // a set or mem-ref 767 void pd_verify_data_value (address x, intptr_t off) { pd_set_data_value(x, off, true); } 768 address pd_call_destination (address orig_addr = NULL); 769 void pd_set_call_destination (address x); 770 771 // this extracts the address of an address in the code stream instead of the reloc data 772 address* pd_address_in_code (); 773 774 // this extracts an address from the code stream instead of the reloc data 775 address pd_get_address_from_code (); 776 777 // these convert from byte offsets, to scaled offsets, to addresses 778 static jint scaled_offset(address x, address base) { 779 int byte_offset = x - base; 780 int offset = -byte_offset / relocInfo::addr_unit(); 781 assert(address_from_scaled_offset(offset, base) == x, "just checkin'"); 782 return offset; 783 } 784 static jint scaled_offset_null_special(address x, address base) {
855 856 857 relocInfo::relocType RelocationHolder::type() const { 858 return reloc()->type(); 859 } 860 861 // A DataRelocation always points at a memory or load-constant instruction.. 862 // It is absolute on most machines, and the constant is split on RISCs. 863 // The specific subtypes are oop, external_word, and internal_word. 864 // By convention, the "value" does not include a separately reckoned "offset". 865 class DataRelocation : public Relocation { 866 public: 867 bool is_data() { return true; } 868 869 // both target and offset must be computed somehow from relocation data 870 virtual int offset() { return 0; } 871 address value() = 0; 872 void set_value(address x) { set_value(x, offset()); } 873 void set_value(address x, intptr_t o) { 874 if (addr_in_const()) 875 (address)addr() = x; 876 else 877 pd_set_data_value(x, o); 878 } 879 void verify_value(address x) { 880 if (addr_in_const()) 881 assert((address)addr() == x, "must agree"); 882 else 883 pd_verify_data_value(x, offset()); 884 } 885 886 // The "o" (displacement) argument is relevant only to split relocations 887 // on RISC machines. In some CPUs (SPARC), the set-hi and set-lo ins'ns 888 // can encode more than 32 bits between them. This allows compilers to 889 // share set-hi instructions between addresses that differ by a small 890 // offset (e.g., different static variables in the same class). 891 // On such machines, the "x" argument to set_value on all set-lo 892 // instructions must be the same as the "x" argument for the 893 // corresponding set-hi instructions. The "o" arguments for the 894 // set-hi instructions are ignored, and must not affect the high-half 895 // immediate constant. The "o" arguments for the set-lo instructions are 896 // added into the low-half immediate constant, and must not overflow it. 897 }; 898 899 // A CallRelocation always points at a call instruction. 900 // It is PC-relative on most machines. 901 class CallRelocation : public Relocation {
1301 assert(section >= 0, "must be a valid section");
1302 _target = target;
1303 _section = section;
1304 }
1305
1306 //void pack_data_to -- inherited
1307 void unpack_data();
1308
1309 private:
1310 friend class RelocIterator;
1311 section_word_Relocation() { }
1312 };
1313
1314
1315 class poll_Relocation : public Relocation {
1316 bool is_data() { return true; }
1317 relocInfo::relocType type() { return relocInfo::poll_type; }
1318 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1319 };
1320
1321 class poll_return_Relocation : public Relocation {
1322 bool is_data() { return true; }
1323 relocInfo::relocType type() { return relocInfo::poll_return_type; }
1324 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest);
1325 };
1326
1327 // We know all the xxx_Relocation classes, so now we can define these:
1328 #define EACH_CASE(name)
1329 inline name##_Relocation* RelocIterator::name##_reloc() {
1330 assert(type() == relocInfo::name##_type, "type must agree");
1331 /* The purpose of the placed "new" is to re-use the same /
1332 / stack storage for each new iteration. /
1333 name##_Relocation r = new(_rh) name##_Relocation();
1334 r->set_binding(this);
1335 r->name##_Relocation::unpack_data();
1336 return r;
1337 }
1338 APPLY_TO_RELOCATIONS(EACH_CASE);
1339 #undef EACH_CASE
1340
1341 inline RelocIterator::RelocIterator(nmethod* nm, address begin, address limit) {
1342 initialize(nm, begin, limit);
1343 }
1344
1 /* 2 * Copyright (c) 1997, 2014, 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 *
193 // put no restrictions whatever upon code reorganization. 194 // 195 // The compiler is responsible for ensuring that transition from a clean 196 // state to a monomorphic compiled state is MP-safe. This implies that 197 // the system must respond well to intermediate states where a random 198 // subset of the set-oops has been correctly from the clean state 199 // upon entry to the VEP of the compiled method. In the case of a 200 // machine (Intel) with a single set-oop instruction, the 32-bit 201 // immediate field must not straddle a unit of memory coherence. 202 // //%note reloc_3 203 // 204 // relocInfo::static_stub_type -- an extra stub for each static_call_type 205 // Value: none 206 // Instruction types: a virtual call: { set_oop; jump; } 207 // Data: [[N]n] the offset of the associated static_call reloc 208 // This stub becomes the target of a static call which must be upgraded 209 // to a virtual call (because the callee is interpreted). 210 // See [About Offsets] below. 211 // //%note reloc_2 212 // 213 // relocInfo::poll_[return_]type -- a safepoint poll 214 // Value: none 215 // Instruction types: memory load or test 216 // Data: none 217 // 218 // For example: 219 // 220 // INSTRUCTIONS RELOC: TYPE PREFIX DATA 221 // ------------ ---- ----------- 222 // sethi %hi(myObject), R oop_type [n(myObject)] 223 // ld [R+%lo(myObject)+fldOffset], R2 oop_type [n(myObject) fldOffset] 224 // add R2, 1, R2 225 // st R2, [R+%lo(myObject)+fldOffset] oop_type [n(myObject) fldOffset] 226 //%note reloc_1 227 // 228 // This uses 4 instruction words, 8 relocation halfwords, 229 // and an entry (which is sharable) in the CodeBlob's oop pool, 230 // for a total of 36 bytes. 231 // 232 // Note that the compiler is responsible for ensuring the "fldOffset" when 233 // added to "%lo(myObject)" does not overflow the immediate fields of the 234 // memory instructions. 235 // 236 // 237 // [About Offsets] Relative offsets are supplied to this module as
431 #endif
432 #ifdef TARGET_ARCH_arm
433 # include "relocInfo_arm.hpp"
434 #endif
435 #ifdef TARGET_ARCH_ppc
436 # include "relocInfo_ppc.hpp"
437 #endif
438 #ifdef TARGET_ARCH_aarch64
439 # include "relocInfo_aarch64.hpp"
440 #endif
441
442 protected:
443 // Derived constant, based on format_width which is PD:
444 enum {
445 offset_width = nontype_width - format_width,
446 offset_mask = (1<<offset_width) - 1,
447 format_mask = (1<<format_width) - 1
448 };
449 public:
450 enum {
451 #ifdef _LP64
452 // for use in format
453 // format_width must be at least 1 on _LP64
454 narrow_oop_in_const = 1,
455 #endif
456 // Conservatively large estimate of maximum length (in shorts)
457 // of any relocation record.
458 // Extended format is length prefix, data words, and tag/offset suffix.
459 length_limit = 1 + 1 + (3*BytesPerWord/BytesPerShort) + 1,
460 have_format = format_width > 0
461 };
462 };
463
464 #define FORWARD_DECLARE_EACH_CLASS(name)
465 class name##_Relocation;
466 APPLY_TO_RELOCATIONS(FORWARD_DECLARE_EACH_CLASS)
467 #undef FORWARD_DECLARE_EACH_CLASS
468
469
470
471 inline relocInfo filler_relocInfo() {
472 return relocInfo(relocInfo::none, relocInfo::offset_limit() - relocInfo::offset_unit);
473 }
474
475 inline relocInfo prefix_relocInfo(int datalen = 0) {
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) {
868 869 870 relocInfo::relocType RelocationHolder::type() const { 871 return reloc()->type(); 872 } 873 874 // A DataRelocation always points at a memory or load-constant instruction.. 875 // It is absolute on most machines, and the constant is split on RISCs. 876 // The specific subtypes are oop, external_word, and internal_word. 877 // By convention, the "value" does not include a separately reckoned "offset". 878 class DataRelocation : public Relocation { 879 public: 880 bool is_data() { return true; } 881 882 // both target and offset must be computed somehow from relocation data 883 virtual int offset() { return 0; } 884 address value() = 0; 885 void set_value(address x) { set_value(x, offset()); } 886 void set_value(address x, intptr_t o) { 887 if (addr_in_const()) 888 const_set_data_value(x); 889 else 890 pd_set_data_value(x, o); 891 } 892 void verify_value(address x) { 893 if (addr_in_const()) 894 const_verify_data_value(x); 895 else 896 pd_verify_data_value(x, offset()); 897 } 898 899 // The "o" (displacement) argument is relevant only to split relocations 900 // on RISC machines. In some CPUs (SPARC), the set-hi and set-lo ins'ns 901 // can encode more than 32 bits between them. This allows compilers to 902 // share set-hi instructions between addresses that differ by a small 903 // offset (e.g., different static variables in the same class). 904 // On such machines, the "x" argument to set_value on all set-lo 905 // instructions must be the same as the "x" argument for the 906 // corresponding set-hi instructions. The "o" arguments for the 907 // set-hi instructions are ignored, and must not affect the high-half 908 // immediate constant. The "o" arguments for the set-lo instructions are 909 // added into the low-half immediate constant, and must not overflow it. 910 }; 911 912 // A CallRelocation always points at a call instruction. 913 // It is PC-relative on most machines. 914 class CallRelocation : public Relocation {
1314 assert(section >= 0, "must be a valid section"); 1315 _target = target; 1316 _section = section; 1317 } 1318 1319 //void pack_data_to -- inherited 1320 void unpack_data(); 1321 1322 private: 1323 friend class RelocIterator; 1324 section_word_Relocation() { } 1325 }; 1326 1327 1328 class poll_Relocation : public Relocation { 1329 bool is_data() { return true; } 1330 relocInfo::relocType type() { return relocInfo::poll_type; } 1331 void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest); 1332 }; 1333 1334 class poll_return_Relocation : public poll_Relocation {
1335 relocInfo::relocType type() { return relocInfo::poll_return_type; }
1336 };
1337
1338 // We know all the xxx_Relocation classes, so now we can define these:
1339 #define EACH_CASE(name)
1340 inline name##_Relocation* RelocIterator::name##_reloc() {
1341 assert(type() == relocInfo::name##_type, "type must agree");
1342 /* The purpose of the placed "new" is to re-use the same /
1343 / stack storage for each new iteration. /
1344 name##_Relocation r = new(_rh) name##_Relocation();
1345 r->set_binding(this);
1346 r->name##_Relocation::unpack_data();
1347 return r;
1348 }
1349 APPLY_TO_RELOCATIONS(EACH_CASE);
1350 #undef EACH_CASE
1351
1352 inline RelocIterator::RelocIterator(nmethod* nm, address begin, address limit) {
1353 initialize(nm, begin, limit);
1354 }
1355