21 * questions. 22 * 23 */ 24 25 #ifndef CPU_X86_VM_NATIVEINST_X86_HPP 26 #define CPU_X86_VM_NATIVEINST_X86_HPP 27 28 #include "asm/assembler.hpp" 29 #include "memory/allocation.hpp" 30 #include "runtime/icache.hpp" 31 #include "runtime/os.hpp" 32 33 // We have interfaces for the following instructions: 34 // - NativeInstruction 35 // - - NativeCall 36 // - - NativeMovConstReg 37 // - - NativeMovConstRegPatching 38 // - - NativeMovRegMem 39 // - - NativeMovRegMemPatching 40 // - - NativeJump 41 // - - NativeIllegalOpCode 42 // - - NativeGeneralJump 43 // - - NativeReturn 44 // - - NativeReturnX (return with argument) 45 // - - NativePushConst 46 // - - NativeTstRegMem 47 48 // The base class for different kinds of native instruction abstractions. 49 // Provides the primitive operations to manipulate code relative to this. 50 51 class NativeInstruction VALUE_OBJ_CLASS_SPEC { 52 friend class Relocation; 53 54 public: 55 enum Intel_specific_constants { 56 nop_instruction_code = 0x90, 57 nop_instruction_size = 1 58 }; 59 60 bool is_nop() { return ubyte_at(0) == nop_instruction_code; } 61 inline bool is_call(); 62 inline bool is_call_reg(); 63 inline bool is_illegal(); 64 inline bool is_return(); 65 inline bool is_jump(); 66 inline bool is_cond_jump(); 67 inline bool is_safepoint_poll(); 68 inline bool is_mov_literal64(); 69 70 protected: 71 address addr_at(int offset) const { return address(this) + offset; } 72 73 s_char sbyte_at(int offset) const { return *(s_char*) addr_at(offset); } 74 u_char ubyte_at(int offset) const { return *(u_char*) addr_at(offset); } 75 76 jint int_at(int offset) const { return *(jint*) addr_at(offset); } 77 78 intptr_t ptr_at(int offset) const { return *(intptr_t*) addr_at(offset); } 79 80 oop oop_at (int offset) const { return *(oop*) addr_at(offset); } 81 82 83 void set_char_at(int offset, char c) { *addr_at(offset) = (u_char)c; wrote(offset); } 84 void set_int_at(int offset, jint i) { *(jint*)addr_at(offset) = i; wrote(offset); } 85 void set_ptr_at (int offset, intptr_t ptr) { *(intptr_t*) addr_at(offset) = ptr; wrote(offset); } 88 // This doesn't really do anything on Intel, but it is the place where 89 // cache invalidation belongs, generically: 90 void wrote(int offset); 91 92 public: 93 94 // unit test stuff 95 static void test() {} // override for testing 96 97 inline friend NativeInstruction* nativeInstruction_at(address address); 98 }; 99 100 inline NativeInstruction* nativeInstruction_at(address address) { 101 NativeInstruction* inst = (NativeInstruction*)address; 102 #ifdef ASSERT 103 //inst->verify(); 104 #endif 105 return inst; 106 } 107 108 inline NativeCall* nativeCall_at(address address); 109 // The NativeCall is an abstraction for accessing/manipulating native call imm32/rel32off 110 // instructions (used to manipulate inline caches, primitive & dll calls, etc.). 111 112 class NativeCall: public NativeInstruction { 113 public: 114 enum Intel_specific_constants { 115 instruction_code = 0xE8, 116 instruction_size = 5, 117 instruction_offset = 0, 118 displacement_offset = 1, 119 return_address_offset = 5 120 }; 121 122 enum { cache_line_size = BytesPerWord }; // conservative estimate! 123 124 address instruction_address() const { return addr_at(instruction_offset); } 125 address next_instruction_address() const { return addr_at(return_address_offset); } 126 int displacement() const { return (jint) int_at(displacement_offset); } 127 address displacement_address() const { return addr_at(displacement_offset); } 128 address return_address() const { return addr_at(return_address_offset); } 129 address destination() const; 130 void set_destination(address dest) { 131 #ifdef AMD64 132 assert((labs((intptr_t) dest - (intptr_t) return_address()) & 133 0xFFFFFFFF00000000) == 0, 134 "must be 32bit offset"); 135 #endif // AMD64 136 set_int_at(displacement_offset, dest - return_address()); 137 } 138 void set_destination_mt_safe(address dest); 139 140 void verify_alignment() { assert((intptr_t)addr_at(displacement_offset) % BytesPerInt == 0, "must be aligned"); } 141 void verify(); 142 void print(); 143 144 // Creation 145 inline friend NativeCall* nativeCall_at(address address); 146 inline friend NativeCall* nativeCall_before(address return_address); 147 148 static bool is_call_at(address instr) { 149 return ((*instr) & 0xFF) == NativeCall::instruction_code; 150 } 151 152 static bool is_call_before(address return_address) { 153 return is_call_at(return_address - NativeCall::return_address_offset); 154 } 155 156 static bool is_call_to(address instr, address target) { 157 return nativeInstruction_at(instr)->is_call() && 158 nativeCall_at(instr)->destination() == target; 159 } 160 161 // MT-safe patching of a call instruction. 162 static void insert(address code_pos, address entry); 163 164 static void replace_mt_safe(address instr_addr, address code_buffer); 165 }; 166 167 inline NativeCall* nativeCall_at(address address) { 168 NativeCall* call = (NativeCall*)(address - NativeCall::instruction_offset); 169 #ifdef ASSERT 170 call->verify(); 171 #endif 172 return call; 173 } 174 175 inline NativeCall* nativeCall_before(address return_address) { 176 NativeCall* call = (NativeCall*)(return_address - NativeCall::return_address_offset); 177 #ifdef ASSERT 178 call->verify(); 179 #endif 180 return call; 363 lea_instruction_code = 0x8D, 364 mov64_instruction_code = 0xB8 365 }; 366 367 void verify(); 368 void print (); 369 370 // unit test stuff 371 static void test() {} 372 373 private: 374 friend NativeLoadAddress* nativeLoadAddress_at (address address) { 375 NativeLoadAddress* test = (NativeLoadAddress*)(address - instruction_offset); 376 #ifdef ASSERT 377 test->verify(); 378 #endif 379 return test; 380 } 381 }; 382 383 // jump rel32off 384 385 class NativeJump: public NativeInstruction { 386 public: 387 enum Intel_specific_constants { 388 instruction_code = 0xe9, 389 instruction_size = 5, 390 instruction_offset = 0, 391 data_offset = 1, 392 next_instruction_offset = 5 393 }; 394 395 address instruction_address() const { return addr_at(instruction_offset); } 396 address next_instruction_address() const { return addr_at(next_instruction_offset); } 397 address jump_destination() const { 398 address dest = (int_at(data_offset)+next_instruction_address()); 399 // 32bit used to encode unresolved jmp as jmp -1 400 // 64bit can't produce this so it used jump to self. 401 // Now 32bit and 64bit use jump to self as the unresolved address 402 // which the inline cache code (and relocs) know about 423 void verify(); 424 425 // Unit testing stuff 426 static void test() {} 427 428 // Insertion of native jump instruction 429 static void insert(address code_pos, address entry); 430 // MT-safe insertion of native jump at verified method entry 431 static void check_verified_entry_alignment(address entry, address verified_entry); 432 static void patch_verified_entry(address entry, address verified_entry, address dest); 433 }; 434 435 inline NativeJump* nativeJump_at(address address) { 436 NativeJump* jump = (NativeJump*)(address - NativeJump::instruction_offset); 437 #ifdef ASSERT 438 jump->verify(); 439 #endif 440 return jump; 441 } 442 443 // Handles all kinds of jump on Intel. Long/far, conditional/unconditional 444 class NativeGeneralJump: public NativeInstruction { 445 public: 446 enum Intel_specific_constants { 447 // Constants does not apply, since the lengths and offsets depends on the actual jump 448 // used 449 // Instruction codes: 450 // Unconditional jumps: 0xE9 (rel32off), 0xEB (rel8off) 451 // Conditional jumps: 0x0F8x (rel32off), 0x7x (rel8off) 452 unconditional_long_jump = 0xe9, 453 unconditional_short_jump = 0xeb, 454 instruction_size = 5 455 }; 456 457 address instruction_address() const { return addr_at(0); } 458 address jump_destination() const; 459 460 // Creation 461 inline friend NativeGeneralJump* nativeGeneralJump_at(address address); 462 463 // Insertion of native general jump instruction 464 static void insert_unconditional(address code_pos, address entry); 465 static void replace_mt_safe(address instr_addr, address code_buffer); 466 467 void verify(); 468 }; 469 470 inline NativeGeneralJump* nativeGeneralJump_at(address address) { 471 NativeGeneralJump* jump = (NativeGeneralJump*)(address); 472 debug_only(jump->verify();) 473 return jump; 474 } 475 476 class NativePopReg : public NativeInstruction { 477 public: 478 enum Intel_specific_constants { 479 instruction_code = 0x58, 480 instruction_size = 1, 481 instruction_offset = 0, 482 data_offset = 1, 483 next_instruction_offset = 1 484 }; 485 486 // Insert a pop instruction 487 static void insert(address code_pos, Register reg); 488 }; 489 490 491 class NativeIllegalInstruction: public NativeInstruction { 492 public: 493 enum Intel_specific_constants { 494 instruction_code = 0x0B0F, // Real byte order is: 0x0F, 0x0B 495 instruction_size = 2, 527 class NativeTstRegMem: public NativeInstruction { 528 public: 529 enum Intel_specific_constants { 530 instruction_rex_prefix_mask = 0xF0, 531 instruction_rex_prefix = Assembler::REX, 532 instruction_code_memXregl = 0x85, 533 modrm_mask = 0x38, // select reg from the ModRM byte 534 modrm_reg = 0x00 // rax 535 }; 536 }; 537 538 inline bool NativeInstruction::is_illegal() { return (short)int_at(0) == (short)NativeIllegalInstruction::instruction_code; } 539 inline bool NativeInstruction::is_call() { return ubyte_at(0) == NativeCall::instruction_code; } 540 inline bool NativeInstruction::is_call_reg() { return ubyte_at(0) == NativeCallReg::instruction_code || 541 (ubyte_at(1) == NativeCallReg::instruction_code && 542 (ubyte_at(0) == Assembler::REX || ubyte_at(0) == Assembler::REX_B)); } 543 inline bool NativeInstruction::is_return() { return ubyte_at(0) == NativeReturn::instruction_code || 544 ubyte_at(0) == NativeReturnX::instruction_code; } 545 inline bool NativeInstruction::is_jump() { return ubyte_at(0) == NativeJump::instruction_code || 546 ubyte_at(0) == 0xEB; /* short jump */ } 547 inline bool NativeInstruction::is_cond_jump() { return (int_at(0) & 0xF0FF) == 0x800F /* long jump */ || 548 (ubyte_at(0) & 0xF0) == 0x70; /* short jump */ } 549 inline bool NativeInstruction::is_safepoint_poll() { 550 #ifdef AMD64 551 // Try decoding a near safepoint first: 552 if (ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl && 553 ubyte_at(1) == 0x05) { // 00 rax 101 554 address fault = addr_at(6) + int_at(2); 555 NOT_JVMCI(assert(!Assembler::is_polling_page_far(), "unexpected poll encoding");) 556 return os::is_poll_address(fault); 557 } 558 // Now try decoding a far safepoint: 559 // two cases, depending on the choice of the base register in the address. 560 if (((ubyte_at(0) & NativeTstRegMem::instruction_rex_prefix_mask) == NativeTstRegMem::instruction_rex_prefix && 561 ubyte_at(1) == NativeTstRegMem::instruction_code_memXregl && 562 (ubyte_at(2) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) || 563 ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl && 564 (ubyte_at(1) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) { 565 NOT_JVMCI(assert(Assembler::is_polling_page_far(), "unexpected poll encoding");) 566 return true; | 21 * questions. 22 * 23 */ 24 25 #ifndef CPU_X86_VM_NATIVEINST_X86_HPP 26 #define CPU_X86_VM_NATIVEINST_X86_HPP 27 28 #include "asm/assembler.hpp" 29 #include "memory/allocation.hpp" 30 #include "runtime/icache.hpp" 31 #include "runtime/os.hpp" 32 33 // We have interfaces for the following instructions: 34 // - NativeInstruction 35 // - - NativeCall 36 // - - NativeMovConstReg 37 // - - NativeMovConstRegPatching 38 // - - NativeMovRegMem 39 // - - NativeMovRegMemPatching 40 // - - NativeJump 41 // - - NativeFarJump 42 // - - NativeIllegalOpCode 43 // - - NativeGeneralJump 44 // - - NativeReturn 45 // - - NativeReturnX (return with argument) 46 // - - NativePushConst 47 // - - NativeTstRegMem 48 49 // The base class for different kinds of native instruction abstractions. 50 // Provides the primitive operations to manipulate code relative to this. 51 52 class NativeInstruction VALUE_OBJ_CLASS_SPEC { 53 friend class Relocation; 54 55 public: 56 enum Intel_specific_constants { 57 nop_instruction_code = 0x90, 58 nop_instruction_size = 1 59 }; 60 61 bool is_nop() { return ubyte_at(0) == nop_instruction_code; } 62 inline bool is_call(); 63 inline bool is_call_reg(); 64 inline bool is_illegal(); 65 inline bool is_return(); 66 inline bool is_jump(); 67 inline bool is_jump_reg(); 68 inline bool is_far_jump(); 69 inline bool is_cond_jump(); 70 inline bool is_safepoint_poll(); 71 inline bool is_mov_literal64(); 72 73 protected: 74 address addr_at(int offset) const { return address(this) + offset; } 75 76 s_char sbyte_at(int offset) const { return *(s_char*) addr_at(offset); } 77 u_char ubyte_at(int offset) const { return *(u_char*) addr_at(offset); } 78 79 jint int_at(int offset) const { return *(jint*) addr_at(offset); } 80 81 intptr_t ptr_at(int offset) const { return *(intptr_t*) addr_at(offset); } 82 83 oop oop_at (int offset) const { return *(oop*) addr_at(offset); } 84 85 86 void set_char_at(int offset, char c) { *addr_at(offset) = (u_char)c; wrote(offset); } 87 void set_int_at(int offset, jint i) { *(jint*)addr_at(offset) = i; wrote(offset); } 88 void set_ptr_at (int offset, intptr_t ptr) { *(intptr_t*) addr_at(offset) = ptr; wrote(offset); } 91 // This doesn't really do anything on Intel, but it is the place where 92 // cache invalidation belongs, generically: 93 void wrote(int offset); 94 95 public: 96 97 // unit test stuff 98 static void test() {} // override for testing 99 100 inline friend NativeInstruction* nativeInstruction_at(address address); 101 }; 102 103 inline NativeInstruction* nativeInstruction_at(address address) { 104 NativeInstruction* inst = (NativeInstruction*)address; 105 #ifdef ASSERT 106 //inst->verify(); 107 #endif 108 return inst; 109 } 110 111 class NativePltCall: public NativeInstruction { 112 public: 113 enum Intel_specific_constants { 114 instruction_code = 0xE8, 115 instruction_size = 5, 116 instruction_offset = 0, 117 displacement_offset = 1, 118 return_address_offset = 5 119 }; 120 address instruction_address() const { return addr_at(instruction_offset); } 121 address next_instruction_address() const { return addr_at(return_address_offset); } 122 address displacement_address() const { return addr_at(displacement_offset); } 123 int displacement() const { return (jint) int_at(displacement_offset); } 124 address return_address() const { return addr_at(return_address_offset); } 125 address destination() const; 126 address plt_entry() const; 127 address plt_jump() const; 128 address plt_load_got() const; 129 address plt_resolve_call() const; 130 address plt_c2i_stub() const; 131 void set_stub_to_clean(); 132 133 void reset_to_plt_resolve_call(); 134 void set_destination_mt_safe(address dest); 135 136 void verify() const; 137 }; 138 139 inline NativePltCall* nativePltCall_at(address address) { 140 NativePltCall* call = (NativePltCall*) address; 141 #ifdef ASSERT 142 call->verify(); 143 #endif 144 return call; 145 } 146 147 inline NativePltCall* nativePltCall_before(address addr) { 148 address at = addr - NativePltCall::instruction_size; 149 return nativePltCall_at(at); 150 } 151 152 inline NativeCall* nativeCall_at(address address); 153 // The NativeCall is an abstraction for accessing/manipulating native call imm32/rel32off 154 // instructions (used to manipulate inline caches, primitive & dll calls, etc.). 155 156 class NativeCall: public NativeInstruction { 157 public: 158 enum Intel_specific_constants { 159 instruction_code = 0xE8, 160 instruction_size = 5, 161 instruction_offset = 0, 162 displacement_offset = 1, 163 return_address_offset = 5 164 }; 165 166 enum { cache_line_size = BytesPerWord }; // conservative estimate! 167 168 address instruction_address() const { return addr_at(instruction_offset); } 169 address next_instruction_address() const { return addr_at(return_address_offset); } 170 int displacement() const { return (jint) int_at(displacement_offset); } 171 address displacement_address() const { return addr_at(displacement_offset); } 172 address return_address() const { return addr_at(return_address_offset); } 173 address destination() const; 174 void set_destination(address dest) { 175 #ifdef AMD64 176 intptr_t disp = dest - return_address(); 177 guarantee(disp == (intptr_t)(jint)disp, "must be 32-bit offset"); 178 #endif // AMD64 179 set_int_at(displacement_offset, dest - return_address()); 180 } 181 void set_destination_mt_safe(address dest); 182 183 void verify_alignment() { assert((intptr_t)addr_at(displacement_offset) % BytesPerInt == 0, "must be aligned"); } 184 void verify(); 185 void print(); 186 187 // Creation 188 inline friend NativeCall* nativeCall_at(address address); 189 inline friend NativeCall* nativeCall_before(address return_address); 190 191 static bool is_call_at(address instr) { 192 return ((*instr) & 0xFF) == NativeCall::instruction_code; 193 } 194 195 static bool is_call_before(address return_address) { 196 return is_call_at(return_address - NativeCall::return_address_offset); 197 } 198 199 static bool is_call_to(address instr, address target) { 200 return nativeInstruction_at(instr)->is_call() && 201 nativeCall_at(instr)->destination() == target; 202 } 203 204 #if INCLUDE_AOT 205 static bool is_far_call(address instr, address target) { 206 intptr_t disp = target - (instr + sizeof(int32_t)); 207 return !Assembler::is_simm32(disp); 208 } 209 #endif 210 211 // MT-safe patching of a call instruction. 212 static void insert(address code_pos, address entry); 213 214 static void replace_mt_safe(address instr_addr, address code_buffer); 215 }; 216 217 inline NativeCall* nativeCall_at(address address) { 218 NativeCall* call = (NativeCall*)(address - NativeCall::instruction_offset); 219 #ifdef ASSERT 220 call->verify(); 221 #endif 222 return call; 223 } 224 225 inline NativeCall* nativeCall_before(address return_address) { 226 NativeCall* call = (NativeCall*)(return_address - NativeCall::return_address_offset); 227 #ifdef ASSERT 228 call->verify(); 229 #endif 230 return call; 413 lea_instruction_code = 0x8D, 414 mov64_instruction_code = 0xB8 415 }; 416 417 void verify(); 418 void print (); 419 420 // unit test stuff 421 static void test() {} 422 423 private: 424 friend NativeLoadAddress* nativeLoadAddress_at (address address) { 425 NativeLoadAddress* test = (NativeLoadAddress*)(address - instruction_offset); 426 #ifdef ASSERT 427 test->verify(); 428 #endif 429 return test; 430 } 431 }; 432 433 // destination is rbx or rax 434 // mov rbx, [rip + offset] 435 class NativeLoadGot: public NativeInstruction { 436 #ifdef AMD64 437 static const bool has_rex = true; 438 static const int rex_size = 1; 439 #else 440 static const bool has_rex = false; 441 static const int rex_size = 0; 442 #endif 443 public: 444 enum Intel_specific_constants { 445 rex_prefix = 0x48, 446 instruction_code = 0x8b, 447 modrm_rbx_code = 0x1d, 448 modrm_rax_code = 0x05, 449 instruction_length = 6 + rex_size, 450 offset_offset = 2 + rex_size 451 }; 452 453 address instruction_address() const { return addr_at(0); } 454 address rip_offset_address() const { return addr_at(offset_offset); } 455 int rip_offset() const { return int_at(offset_offset); } 456 address return_address() const { return addr_at(instruction_length); } 457 address got_address() const { return return_address() + rip_offset(); } 458 address next_instruction_address() const { return return_address(); } 459 intptr_t data() const; 460 void set_data(intptr_t data) { 461 intptr_t *addr = (intptr_t *) got_address(); 462 *addr = data; 463 } 464 465 void verify() const; 466 private: 467 void report_and_fail() const; 468 }; 469 470 inline NativeLoadGot* nativeLoadGot_at(address addr) { 471 NativeLoadGot* load = (NativeLoadGot*) addr; 472 #ifdef ASSERT 473 load->verify(); 474 #endif 475 return load; 476 } 477 478 // jump rel32off 479 480 class NativeJump: public NativeInstruction { 481 public: 482 enum Intel_specific_constants { 483 instruction_code = 0xe9, 484 instruction_size = 5, 485 instruction_offset = 0, 486 data_offset = 1, 487 next_instruction_offset = 5 488 }; 489 490 address instruction_address() const { return addr_at(instruction_offset); } 491 address next_instruction_address() const { return addr_at(next_instruction_offset); } 492 address jump_destination() const { 493 address dest = (int_at(data_offset)+next_instruction_address()); 494 // 32bit used to encode unresolved jmp as jmp -1 495 // 64bit can't produce this so it used jump to self. 496 // Now 32bit and 64bit use jump to self as the unresolved address 497 // which the inline cache code (and relocs) know about 518 void verify(); 519 520 // Unit testing stuff 521 static void test() {} 522 523 // Insertion of native jump instruction 524 static void insert(address code_pos, address entry); 525 // MT-safe insertion of native jump at verified method entry 526 static void check_verified_entry_alignment(address entry, address verified_entry); 527 static void patch_verified_entry(address entry, address verified_entry, address dest); 528 }; 529 530 inline NativeJump* nativeJump_at(address address) { 531 NativeJump* jump = (NativeJump*)(address - NativeJump::instruction_offset); 532 #ifdef ASSERT 533 jump->verify(); 534 #endif 535 return jump; 536 } 537 538 // far jump reg 539 class NativeFarJump: public NativeInstruction { 540 public: 541 address jump_destination() const; 542 543 // Creation 544 inline friend NativeFarJump* nativeFarJump_at(address address); 545 546 void verify(); 547 548 // Unit testing stuff 549 static void test() {} 550 551 }; 552 553 inline NativeFarJump* nativeFarJump_at(address address) { 554 NativeFarJump* jump = (NativeFarJump*)(address); 555 #ifdef ASSERT 556 jump->verify(); 557 #endif 558 return jump; 559 } 560 561 // Handles all kinds of jump on Intel. Long/far, conditional/unconditional 562 class NativeGeneralJump: public NativeInstruction { 563 public: 564 enum Intel_specific_constants { 565 // Constants does not apply, since the lengths and offsets depends on the actual jump 566 // used 567 // Instruction codes: 568 // Unconditional jumps: 0xE9 (rel32off), 0xEB (rel8off) 569 // Conditional jumps: 0x0F8x (rel32off), 0x7x (rel8off) 570 unconditional_long_jump = 0xe9, 571 unconditional_short_jump = 0xeb, 572 instruction_size = 5 573 }; 574 575 address instruction_address() const { return addr_at(0); } 576 address jump_destination() const; 577 578 // Creation 579 inline friend NativeGeneralJump* nativeGeneralJump_at(address address); 580 581 // Insertion of native general jump instruction 582 static void insert_unconditional(address code_pos, address entry); 583 static void replace_mt_safe(address instr_addr, address code_buffer); 584 585 void verify(); 586 }; 587 588 inline NativeGeneralJump* nativeGeneralJump_at(address address) { 589 NativeGeneralJump* jump = (NativeGeneralJump*)(address); 590 debug_only(jump->verify();) 591 return jump; 592 } 593 594 class NativeGotJump: public NativeInstruction { 595 public: 596 enum Intel_specific_constants { 597 instruction_code = 0xff, 598 instruction_offset = 0, 599 instruction_size = 6, 600 rip_offset = 2 601 }; 602 603 void verify() const; 604 address instruction_address() const { return addr_at(instruction_offset); } 605 address destination() const; 606 address return_address() const { return addr_at(instruction_size); } 607 int got_offset() const { return (jint) int_at(rip_offset); } 608 address got_address() const { return return_address() + got_offset(); } 609 address next_instruction_address() const { return addr_at(instruction_size); } 610 bool is_GotJump() const { return ubyte_at(0) == instruction_code; } 611 612 void set_jump_destination(address dest) { 613 address *got_entry = (address *) got_address(); 614 *got_entry = dest; 615 } 616 }; 617 618 inline NativeGotJump* nativeGotJump_at(address addr) { 619 NativeGotJump* jump = (NativeGotJump*)(addr); 620 debug_only(jump->verify()); 621 return jump; 622 } 623 624 class NativePopReg : public NativeInstruction { 625 public: 626 enum Intel_specific_constants { 627 instruction_code = 0x58, 628 instruction_size = 1, 629 instruction_offset = 0, 630 data_offset = 1, 631 next_instruction_offset = 1 632 }; 633 634 // Insert a pop instruction 635 static void insert(address code_pos, Register reg); 636 }; 637 638 639 class NativeIllegalInstruction: public NativeInstruction { 640 public: 641 enum Intel_specific_constants { 642 instruction_code = 0x0B0F, // Real byte order is: 0x0F, 0x0B 643 instruction_size = 2, 675 class NativeTstRegMem: public NativeInstruction { 676 public: 677 enum Intel_specific_constants { 678 instruction_rex_prefix_mask = 0xF0, 679 instruction_rex_prefix = Assembler::REX, 680 instruction_code_memXregl = 0x85, 681 modrm_mask = 0x38, // select reg from the ModRM byte 682 modrm_reg = 0x00 // rax 683 }; 684 }; 685 686 inline bool NativeInstruction::is_illegal() { return (short)int_at(0) == (short)NativeIllegalInstruction::instruction_code; } 687 inline bool NativeInstruction::is_call() { return ubyte_at(0) == NativeCall::instruction_code; } 688 inline bool NativeInstruction::is_call_reg() { return ubyte_at(0) == NativeCallReg::instruction_code || 689 (ubyte_at(1) == NativeCallReg::instruction_code && 690 (ubyte_at(0) == Assembler::REX || ubyte_at(0) == Assembler::REX_B)); } 691 inline bool NativeInstruction::is_return() { return ubyte_at(0) == NativeReturn::instruction_code || 692 ubyte_at(0) == NativeReturnX::instruction_code; } 693 inline bool NativeInstruction::is_jump() { return ubyte_at(0) == NativeJump::instruction_code || 694 ubyte_at(0) == 0xEB; /* short jump */ } 695 inline bool NativeInstruction::is_jump_reg() { 696 int pos = 0; 697 if (ubyte_at(0) == Assembler::REX_B) pos = 1; 698 return ubyte_at(pos) == 0xFF && (ubyte_at(pos + 1) & 0xF0) == 0xE0; 699 } 700 inline bool NativeInstruction::is_far_jump() { return is_mov_literal64(); } 701 inline bool NativeInstruction::is_cond_jump() { return (int_at(0) & 0xF0FF) == 0x800F /* long jump */ || 702 (ubyte_at(0) & 0xF0) == 0x70; /* short jump */ } 703 inline bool NativeInstruction::is_safepoint_poll() { 704 #ifdef AMD64 705 // Try decoding a near safepoint first: 706 if (ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl && 707 ubyte_at(1) == 0x05) { // 00 rax 101 708 address fault = addr_at(6) + int_at(2); 709 NOT_JVMCI(assert(!Assembler::is_polling_page_far(), "unexpected poll encoding");) 710 return os::is_poll_address(fault); 711 } 712 // Now try decoding a far safepoint: 713 // two cases, depending on the choice of the base register in the address. 714 if (((ubyte_at(0) & NativeTstRegMem::instruction_rex_prefix_mask) == NativeTstRegMem::instruction_rex_prefix && 715 ubyte_at(1) == NativeTstRegMem::instruction_code_memXregl && 716 (ubyte_at(2) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) || 717 ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl && 718 (ubyte_at(1) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) { 719 NOT_JVMCI(assert(Assembler::is_polling_page_far(), "unexpected poll encoding");) 720 return true; |