src/cpu/x86/vm/nativeInst_x86.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef CPU_X86_VM_NATIVEINST_X86_HPP
aoqi@0 26 #define CPU_X86_VM_NATIVEINST_X86_HPP
aoqi@0 27
aoqi@0 28 #include "asm/assembler.hpp"
aoqi@0 29 #include "memory/allocation.hpp"
aoqi@0 30 #include "runtime/icache.hpp"
aoqi@0 31 #include "runtime/os.hpp"
aoqi@0 32 #include "utilities/top.hpp"
aoqi@0 33
aoqi@0 34 // We have interfaces for the following instructions:
aoqi@0 35 // - NativeInstruction
aoqi@0 36 // - - NativeCall
aoqi@0 37 // - - NativeMovConstReg
aoqi@0 38 // - - NativeMovConstRegPatching
aoqi@0 39 // - - NativeMovRegMem
aoqi@0 40 // - - NativeMovRegMemPatching
aoqi@0 41 // - - NativeJump
aoqi@0 42 // - - NativeIllegalOpCode
aoqi@0 43 // - - NativeGeneralJump
aoqi@0 44 // - - NativeReturn
aoqi@0 45 // - - NativeReturnX (return with argument)
aoqi@0 46 // - - NativePushConst
aoqi@0 47 // - - NativeTstRegMem
aoqi@0 48
aoqi@0 49 // The base class for different kinds of native instruction abstractions.
aoqi@0 50 // Provides the primitive operations to manipulate code relative to this.
aoqi@0 51
aoqi@0 52 class NativeInstruction VALUE_OBJ_CLASS_SPEC {
aoqi@0 53 friend class Relocation;
aoqi@0 54
aoqi@0 55 public:
aoqi@0 56 enum Intel_specific_constants {
aoqi@0 57 nop_instruction_code = 0x90,
aoqi@0 58 nop_instruction_size = 1
aoqi@0 59 };
aoqi@0 60
aoqi@0 61 bool is_nop() { return ubyte_at(0) == nop_instruction_code; }
aoqi@0 62 bool is_dtrace_trap();
aoqi@0 63 inline bool is_call();
aoqi@0 64 inline bool is_illegal();
aoqi@0 65 inline bool is_return();
aoqi@0 66 inline bool is_jump();
aoqi@0 67 inline bool is_cond_jump();
aoqi@0 68 inline bool is_safepoint_poll();
aoqi@0 69 inline bool is_mov_literal64();
aoqi@0 70
aoqi@0 71 protected:
aoqi@0 72 address addr_at(int offset) const { return address(this) + offset; }
aoqi@0 73
aoqi@0 74 s_char sbyte_at(int offset) const { return *(s_char*) addr_at(offset); }
aoqi@0 75 u_char ubyte_at(int offset) const { return *(u_char*) addr_at(offset); }
aoqi@0 76
aoqi@0 77 jint int_at(int offset) const { return *(jint*) addr_at(offset); }
aoqi@0 78
aoqi@0 79 intptr_t ptr_at(int offset) const { return *(intptr_t*) addr_at(offset); }
aoqi@0 80
aoqi@0 81 oop oop_at (int offset) const { return *(oop*) addr_at(offset); }
aoqi@0 82
aoqi@0 83
aoqi@0 84 void set_char_at(int offset, char c) { *addr_at(offset) = (u_char)c; wrote(offset); }
aoqi@0 85 void set_int_at(int offset, jint i) { *(jint*)addr_at(offset) = i; wrote(offset); }
aoqi@0 86 void set_ptr_at (int offset, intptr_t ptr) { *(intptr_t*) addr_at(offset) = ptr; wrote(offset); }
aoqi@0 87 void set_oop_at (int offset, oop o) { *(oop*) addr_at(offset) = o; wrote(offset); }
aoqi@0 88
aoqi@0 89 // This doesn't really do anything on Intel, but it is the place where
aoqi@0 90 // cache invalidation belongs, generically:
aoqi@0 91 void wrote(int offset);
aoqi@0 92
aoqi@0 93 public:
aoqi@0 94
aoqi@0 95 // unit test stuff
aoqi@0 96 static void test() {} // override for testing
aoqi@0 97
aoqi@0 98 inline friend NativeInstruction* nativeInstruction_at(address address);
aoqi@0 99 };
aoqi@0 100
aoqi@0 101 inline NativeInstruction* nativeInstruction_at(address address) {
aoqi@0 102 NativeInstruction* inst = (NativeInstruction*)address;
aoqi@0 103 #ifdef ASSERT
aoqi@0 104 //inst->verify();
aoqi@0 105 #endif
aoqi@0 106 return inst;
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 inline NativeCall* nativeCall_at(address address);
aoqi@0 110 // The NativeCall is an abstraction for accessing/manipulating native call imm32/rel32off
aoqi@0 111 // instructions (used to manipulate inline caches, primitive & dll calls, etc.).
aoqi@0 112
aoqi@0 113 class NativeCall: public NativeInstruction {
aoqi@0 114 public:
aoqi@0 115 enum Intel_specific_constants {
aoqi@0 116 instruction_code = 0xE8,
aoqi@0 117 instruction_size = 5,
aoqi@0 118 instruction_offset = 0,
aoqi@0 119 displacement_offset = 1,
aoqi@0 120 return_address_offset = 5
aoqi@0 121 };
aoqi@0 122
aoqi@0 123 enum { cache_line_size = BytesPerWord }; // conservative estimate!
aoqi@0 124
aoqi@0 125 address instruction_address() const { return addr_at(instruction_offset); }
aoqi@0 126 address next_instruction_address() const { return addr_at(return_address_offset); }
aoqi@0 127 int displacement() const { return (jint) int_at(displacement_offset); }
aoqi@0 128 address displacement_address() const { return addr_at(displacement_offset); }
aoqi@0 129 address return_address() const { return addr_at(return_address_offset); }
aoqi@0 130 address destination() const;
aoqi@0 131 void set_destination(address dest) {
aoqi@0 132 #ifdef AMD64
aoqi@0 133 assert((labs((intptr_t) dest - (intptr_t) return_address()) &
aoqi@0 134 0xFFFFFFFF00000000) == 0,
aoqi@0 135 "must be 32bit offset");
aoqi@0 136 #endif // AMD64
aoqi@0 137 set_int_at(displacement_offset, dest - return_address());
aoqi@0 138 }
aoqi@0 139 void set_destination_mt_safe(address dest);
aoqi@0 140
aoqi@0 141 void verify_alignment() { assert((intptr_t)addr_at(displacement_offset) % BytesPerInt == 0, "must be aligned"); }
aoqi@0 142 void verify();
aoqi@0 143 void print();
aoqi@0 144
aoqi@0 145 // Creation
aoqi@0 146 inline friend NativeCall* nativeCall_at(address address);
aoqi@0 147 inline friend NativeCall* nativeCall_before(address return_address);
aoqi@0 148
aoqi@0 149 static bool is_call_at(address instr) {
aoqi@0 150 return ((*instr) & 0xFF) == NativeCall::instruction_code;
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 static bool is_call_before(address return_address) {
aoqi@0 154 return is_call_at(return_address - NativeCall::return_address_offset);
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 static bool is_call_to(address instr, address target) {
aoqi@0 158 return nativeInstruction_at(instr)->is_call() &&
aoqi@0 159 nativeCall_at(instr)->destination() == target;
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 // MT-safe patching of a call instruction.
aoqi@0 163 static void insert(address code_pos, address entry);
aoqi@0 164
aoqi@0 165 static void replace_mt_safe(address instr_addr, address code_buffer);
aoqi@0 166 };
aoqi@0 167
aoqi@0 168 inline NativeCall* nativeCall_at(address address) {
aoqi@0 169 NativeCall* call = (NativeCall*)(address - NativeCall::instruction_offset);
aoqi@0 170 #ifdef ASSERT
aoqi@0 171 call->verify();
aoqi@0 172 #endif
aoqi@0 173 return call;
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 inline NativeCall* nativeCall_before(address return_address) {
aoqi@0 177 NativeCall* call = (NativeCall*)(return_address - NativeCall::return_address_offset);
aoqi@0 178 #ifdef ASSERT
aoqi@0 179 call->verify();
aoqi@0 180 #endif
aoqi@0 181 return call;
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 // An interface for accessing/manipulating native mov reg, imm32 instructions.
aoqi@0 185 // (used to manipulate inlined 32bit data dll calls, etc.)
aoqi@0 186 class NativeMovConstReg: public NativeInstruction {
aoqi@0 187 #ifdef AMD64
aoqi@0 188 static const bool has_rex = true;
aoqi@0 189 static const int rex_size = 1;
aoqi@0 190 #else
aoqi@0 191 static const bool has_rex = false;
aoqi@0 192 static const int rex_size = 0;
aoqi@0 193 #endif // AMD64
aoqi@0 194 public:
aoqi@0 195 enum Intel_specific_constants {
aoqi@0 196 instruction_code = 0xB8,
aoqi@0 197 instruction_size = 1 + rex_size + wordSize,
aoqi@0 198 instruction_offset = 0,
aoqi@0 199 data_offset = 1 + rex_size,
aoqi@0 200 next_instruction_offset = instruction_size,
aoqi@0 201 register_mask = 0x07
aoqi@0 202 };
aoqi@0 203
aoqi@0 204 address instruction_address() const { return addr_at(instruction_offset); }
aoqi@0 205 address next_instruction_address() const { return addr_at(next_instruction_offset); }
aoqi@0 206 intptr_t data() const { return ptr_at(data_offset); }
aoqi@0 207 void set_data(intptr_t x) { set_ptr_at(data_offset, x); }
aoqi@0 208
aoqi@0 209 void verify();
aoqi@0 210 void print();
aoqi@0 211
aoqi@0 212 // unit test stuff
aoqi@0 213 static void test() {}
aoqi@0 214
aoqi@0 215 // Creation
aoqi@0 216 inline friend NativeMovConstReg* nativeMovConstReg_at(address address);
aoqi@0 217 inline friend NativeMovConstReg* nativeMovConstReg_before(address address);
aoqi@0 218 };
aoqi@0 219
aoqi@0 220 inline NativeMovConstReg* nativeMovConstReg_at(address address) {
aoqi@0 221 NativeMovConstReg* test = (NativeMovConstReg*)(address - NativeMovConstReg::instruction_offset);
aoqi@0 222 #ifdef ASSERT
aoqi@0 223 test->verify();
aoqi@0 224 #endif
aoqi@0 225 return test;
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 inline NativeMovConstReg* nativeMovConstReg_before(address address) {
aoqi@0 229 NativeMovConstReg* test = (NativeMovConstReg*)(address - NativeMovConstReg::instruction_size - NativeMovConstReg::instruction_offset);
aoqi@0 230 #ifdef ASSERT
aoqi@0 231 test->verify();
aoqi@0 232 #endif
aoqi@0 233 return test;
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 class NativeMovConstRegPatching: public NativeMovConstReg {
aoqi@0 237 private:
aoqi@0 238 friend NativeMovConstRegPatching* nativeMovConstRegPatching_at(address address) {
aoqi@0 239 NativeMovConstRegPatching* test = (NativeMovConstRegPatching*)(address - instruction_offset);
aoqi@0 240 #ifdef ASSERT
aoqi@0 241 test->verify();
aoqi@0 242 #endif
aoqi@0 243 return test;
aoqi@0 244 }
aoqi@0 245 };
aoqi@0 246
aoqi@0 247 // An interface for accessing/manipulating native moves of the form:
aoqi@0 248 // mov[b/w/l/q] [reg + offset], reg (instruction_code_reg2mem)
aoqi@0 249 // mov[b/w/l/q] reg, [reg+offset] (instruction_code_mem2reg
aoqi@0 250 // mov[s/z]x[w/b/q] [reg + offset], reg
aoqi@0 251 // fld_s [reg+offset]
aoqi@0 252 // fld_d [reg+offset]
aoqi@0 253 // fstp_s [reg + offset]
aoqi@0 254 // fstp_d [reg + offset]
aoqi@0 255 // mov_literal64 scratch,<pointer> ; mov[b/w/l/q] 0(scratch),reg | mov[b/w/l/q] reg,0(scratch)
aoqi@0 256 //
aoqi@0 257 // Warning: These routines must be able to handle any instruction sequences
aoqi@0 258 // that are generated as a result of the load/store byte,word,long
aoqi@0 259 // macros. For example: The load_unsigned_byte instruction generates
aoqi@0 260 // an xor reg,reg inst prior to generating the movb instruction. This
aoqi@0 261 // class must skip the xor instruction.
aoqi@0 262
aoqi@0 263 class NativeMovRegMem: public NativeInstruction {
aoqi@0 264 public:
aoqi@0 265 enum Intel_specific_constants {
aoqi@0 266 instruction_prefix_wide_lo = Assembler::REX,
aoqi@0 267 instruction_prefix_wide_hi = Assembler::REX_WRXB,
aoqi@0 268 instruction_code_xor = 0x33,
aoqi@0 269 instruction_extended_prefix = 0x0F,
aoqi@0 270 instruction_code_mem2reg_movslq = 0x63,
aoqi@0 271 instruction_code_mem2reg_movzxb = 0xB6,
aoqi@0 272 instruction_code_mem2reg_movsxb = 0xBE,
aoqi@0 273 instruction_code_mem2reg_movzxw = 0xB7,
aoqi@0 274 instruction_code_mem2reg_movsxw = 0xBF,
aoqi@0 275 instruction_operandsize_prefix = 0x66,
aoqi@0 276 instruction_code_reg2mem = 0x89,
aoqi@0 277 instruction_code_mem2reg = 0x8b,
aoqi@0 278 instruction_code_reg2memb = 0x88,
aoqi@0 279 instruction_code_mem2regb = 0x8a,
aoqi@0 280 instruction_code_float_s = 0xd9,
aoqi@0 281 instruction_code_float_d = 0xdd,
aoqi@0 282 instruction_code_long_volatile = 0xdf,
aoqi@0 283 instruction_code_xmm_ss_prefix = 0xf3,
aoqi@0 284 instruction_code_xmm_sd_prefix = 0xf2,
aoqi@0 285 instruction_code_xmm_code = 0x0f,
aoqi@0 286 instruction_code_xmm_load = 0x10,
aoqi@0 287 instruction_code_xmm_store = 0x11,
aoqi@0 288 instruction_code_xmm_lpd = 0x12,
aoqi@0 289
aoqi@0 290 instruction_VEX_prefix_2bytes = Assembler::VEX_2bytes,
aoqi@0 291 instruction_VEX_prefix_3bytes = Assembler::VEX_3bytes,
aoqi@0 292
aoqi@0 293 instruction_size = 4,
aoqi@0 294 instruction_offset = 0,
aoqi@0 295 data_offset = 2,
aoqi@0 296 next_instruction_offset = 4
aoqi@0 297 };
aoqi@0 298
aoqi@0 299 // helper
aoqi@0 300 int instruction_start() const;
aoqi@0 301
aoqi@0 302 address instruction_address() const;
aoqi@0 303
aoqi@0 304 address next_instruction_address() const;
aoqi@0 305
aoqi@0 306 int offset() const;
aoqi@0 307
aoqi@0 308 void set_offset(int x);
aoqi@0 309
aoqi@0 310 void add_offset_in_bytes(int add_offset) { set_offset ( ( offset() + add_offset ) ); }
aoqi@0 311
aoqi@0 312 void verify();
aoqi@0 313 void print ();
aoqi@0 314
aoqi@0 315 // unit test stuff
aoqi@0 316 static void test() {}
aoqi@0 317
aoqi@0 318 private:
aoqi@0 319 inline friend NativeMovRegMem* nativeMovRegMem_at (address address);
aoqi@0 320 };
aoqi@0 321
aoqi@0 322 inline NativeMovRegMem* nativeMovRegMem_at (address address) {
aoqi@0 323 NativeMovRegMem* test = (NativeMovRegMem*)(address - NativeMovRegMem::instruction_offset);
aoqi@0 324 #ifdef ASSERT
aoqi@0 325 test->verify();
aoqi@0 326 #endif
aoqi@0 327 return test;
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 class NativeMovRegMemPatching: public NativeMovRegMem {
aoqi@0 331 private:
aoqi@0 332 friend NativeMovRegMemPatching* nativeMovRegMemPatching_at (address address) {
aoqi@0 333 NativeMovRegMemPatching* test = (NativeMovRegMemPatching*)(address - instruction_offset);
aoqi@0 334 #ifdef ASSERT
aoqi@0 335 test->verify();
aoqi@0 336 #endif
aoqi@0 337 return test;
aoqi@0 338 }
aoqi@0 339 };
aoqi@0 340
aoqi@0 341
aoqi@0 342
aoqi@0 343 // An interface for accessing/manipulating native leal instruction of form:
aoqi@0 344 // leal reg, [reg + offset]
aoqi@0 345
aoqi@0 346 class NativeLoadAddress: public NativeMovRegMem {
aoqi@0 347 #ifdef AMD64
aoqi@0 348 static const bool has_rex = true;
aoqi@0 349 static const int rex_size = 1;
aoqi@0 350 #else
aoqi@0 351 static const bool has_rex = false;
aoqi@0 352 static const int rex_size = 0;
aoqi@0 353 #endif // AMD64
aoqi@0 354 public:
aoqi@0 355 enum Intel_specific_constants {
aoqi@0 356 instruction_prefix_wide = Assembler::REX_W,
aoqi@0 357 instruction_prefix_wide_extended = Assembler::REX_WB,
aoqi@0 358 lea_instruction_code = 0x8D,
aoqi@0 359 mov64_instruction_code = 0xB8
aoqi@0 360 };
aoqi@0 361
aoqi@0 362 void verify();
aoqi@0 363 void print ();
aoqi@0 364
aoqi@0 365 // unit test stuff
aoqi@0 366 static void test() {}
aoqi@0 367
aoqi@0 368 private:
aoqi@0 369 friend NativeLoadAddress* nativeLoadAddress_at (address address) {
aoqi@0 370 NativeLoadAddress* test = (NativeLoadAddress*)(address - instruction_offset);
aoqi@0 371 #ifdef ASSERT
aoqi@0 372 test->verify();
aoqi@0 373 #endif
aoqi@0 374 return test;
aoqi@0 375 }
aoqi@0 376 };
aoqi@0 377
aoqi@0 378 // jump rel32off
aoqi@0 379
aoqi@0 380 class NativeJump: public NativeInstruction {
aoqi@0 381 public:
aoqi@0 382 enum Intel_specific_constants {
aoqi@0 383 instruction_code = 0xe9,
aoqi@0 384 instruction_size = 5,
aoqi@0 385 instruction_offset = 0,
aoqi@0 386 data_offset = 1,
aoqi@0 387 next_instruction_offset = 5
aoqi@0 388 };
aoqi@0 389
aoqi@0 390 address instruction_address() const { return addr_at(instruction_offset); }
aoqi@0 391 address next_instruction_address() const { return addr_at(next_instruction_offset); }
aoqi@0 392 address jump_destination() const {
aoqi@0 393 address dest = (int_at(data_offset)+next_instruction_address());
aoqi@0 394 // 32bit used to encode unresolved jmp as jmp -1
aoqi@0 395 // 64bit can't produce this so it used jump to self.
aoqi@0 396 // Now 32bit and 64bit use jump to self as the unresolved address
aoqi@0 397 // which the inline cache code (and relocs) know about
aoqi@0 398
aoqi@0 399 // return -1 if jump to self
aoqi@0 400 dest = (dest == (address) this) ? (address) -1 : dest;
aoqi@0 401 return dest;
aoqi@0 402 }
aoqi@0 403
aoqi@0 404 void set_jump_destination(address dest) {
aoqi@0 405 intptr_t val = dest - next_instruction_address();
aoqi@0 406 if (dest == (address) -1) {
aoqi@0 407 val = -5; // jump to self
aoqi@0 408 }
aoqi@0 409 #ifdef AMD64
aoqi@0 410 assert((labs(val) & 0xFFFFFFFF00000000) == 0 || dest == (address)-1, "must be 32bit offset or -1");
aoqi@0 411 #endif // AMD64
aoqi@0 412 set_int_at(data_offset, (jint)val);
aoqi@0 413 }
aoqi@0 414
aoqi@0 415 // Creation
aoqi@0 416 inline friend NativeJump* nativeJump_at(address address);
aoqi@0 417
aoqi@0 418 void verify();
aoqi@0 419
aoqi@0 420 // Unit testing stuff
aoqi@0 421 static void test() {}
aoqi@0 422
aoqi@0 423 // Insertion of native jump instruction
aoqi@0 424 static void insert(address code_pos, address entry);
aoqi@0 425 // MT-safe insertion of native jump at verified method entry
aoqi@0 426 static void check_verified_entry_alignment(address entry, address verified_entry);
aoqi@0 427 static void patch_verified_entry(address entry, address verified_entry, address dest);
aoqi@0 428 };
aoqi@0 429
aoqi@0 430 inline NativeJump* nativeJump_at(address address) {
aoqi@0 431 NativeJump* jump = (NativeJump*)(address - NativeJump::instruction_offset);
aoqi@0 432 #ifdef ASSERT
aoqi@0 433 jump->verify();
aoqi@0 434 #endif
aoqi@0 435 return jump;
aoqi@0 436 }
aoqi@0 437
aoqi@0 438 // Handles all kinds of jump on Intel. Long/far, conditional/unconditional
aoqi@0 439 class NativeGeneralJump: public NativeInstruction {
aoqi@0 440 public:
aoqi@0 441 enum Intel_specific_constants {
aoqi@0 442 // Constants does not apply, since the lengths and offsets depends on the actual jump
aoqi@0 443 // used
aoqi@0 444 // Instruction codes:
aoqi@0 445 // Unconditional jumps: 0xE9 (rel32off), 0xEB (rel8off)
aoqi@0 446 // Conditional jumps: 0x0F8x (rel32off), 0x7x (rel8off)
aoqi@0 447 unconditional_long_jump = 0xe9,
aoqi@0 448 unconditional_short_jump = 0xeb,
aoqi@0 449 instruction_size = 5
aoqi@0 450 };
aoqi@0 451
aoqi@0 452 address instruction_address() const { return addr_at(0); }
aoqi@0 453 address jump_destination() const;
aoqi@0 454
aoqi@0 455 // Creation
aoqi@0 456 inline friend NativeGeneralJump* nativeGeneralJump_at(address address);
aoqi@0 457
aoqi@0 458 // Insertion of native general jump instruction
aoqi@0 459 static void insert_unconditional(address code_pos, address entry);
aoqi@0 460 static void replace_mt_safe(address instr_addr, address code_buffer);
aoqi@0 461
aoqi@0 462 void verify();
aoqi@0 463 };
aoqi@0 464
aoqi@0 465 inline NativeGeneralJump* nativeGeneralJump_at(address address) {
aoqi@0 466 NativeGeneralJump* jump = (NativeGeneralJump*)(address);
aoqi@0 467 debug_only(jump->verify();)
aoqi@0 468 return jump;
aoqi@0 469 }
aoqi@0 470
aoqi@0 471 class NativePopReg : public NativeInstruction {
aoqi@0 472 public:
aoqi@0 473 enum Intel_specific_constants {
aoqi@0 474 instruction_code = 0x58,
aoqi@0 475 instruction_size = 1,
aoqi@0 476 instruction_offset = 0,
aoqi@0 477 data_offset = 1,
aoqi@0 478 next_instruction_offset = 1
aoqi@0 479 };
aoqi@0 480
aoqi@0 481 // Insert a pop instruction
aoqi@0 482 static void insert(address code_pos, Register reg);
aoqi@0 483 };
aoqi@0 484
aoqi@0 485
aoqi@0 486 class NativeIllegalInstruction: public NativeInstruction {
aoqi@0 487 public:
aoqi@0 488 enum Intel_specific_constants {
aoqi@0 489 instruction_code = 0x0B0F, // Real byte order is: 0x0F, 0x0B
aoqi@0 490 instruction_size = 2,
aoqi@0 491 instruction_offset = 0,
aoqi@0 492 next_instruction_offset = 2
aoqi@0 493 };
aoqi@0 494
aoqi@0 495 // Insert illegal opcode as specific address
aoqi@0 496 static void insert(address code_pos);
aoqi@0 497 };
aoqi@0 498
aoqi@0 499 // return instruction that does not pop values of the stack
aoqi@0 500 class NativeReturn: public NativeInstruction {
aoqi@0 501 public:
aoqi@0 502 enum Intel_specific_constants {
aoqi@0 503 instruction_code = 0xC3,
aoqi@0 504 instruction_size = 1,
aoqi@0 505 instruction_offset = 0,
aoqi@0 506 next_instruction_offset = 1
aoqi@0 507 };
aoqi@0 508 };
aoqi@0 509
aoqi@0 510 // return instruction that does pop values of the stack
aoqi@0 511 class NativeReturnX: public NativeInstruction {
aoqi@0 512 public:
aoqi@0 513 enum Intel_specific_constants {
aoqi@0 514 instruction_code = 0xC2,
aoqi@0 515 instruction_size = 2,
aoqi@0 516 instruction_offset = 0,
aoqi@0 517 next_instruction_offset = 2
aoqi@0 518 };
aoqi@0 519 };
aoqi@0 520
aoqi@0 521 // Simple test vs memory
aoqi@0 522 class NativeTstRegMem: public NativeInstruction {
aoqi@0 523 public:
aoqi@0 524 enum Intel_specific_constants {
aoqi@0 525 instruction_rex_prefix_mask = 0xF0,
aoqi@0 526 instruction_rex_prefix = Assembler::REX,
aoqi@0 527 instruction_code_memXregl = 0x85,
aoqi@0 528 modrm_mask = 0x38, // select reg from the ModRM byte
aoqi@0 529 modrm_reg = 0x00 // rax
aoqi@0 530 };
aoqi@0 531 };
aoqi@0 532
aoqi@0 533 inline bool NativeInstruction::is_illegal() { return (short)int_at(0) == (short)NativeIllegalInstruction::instruction_code; }
aoqi@0 534 inline bool NativeInstruction::is_call() { return ubyte_at(0) == NativeCall::instruction_code; }
aoqi@0 535 inline bool NativeInstruction::is_return() { return ubyte_at(0) == NativeReturn::instruction_code ||
aoqi@0 536 ubyte_at(0) == NativeReturnX::instruction_code; }
aoqi@0 537 inline bool NativeInstruction::is_jump() { return ubyte_at(0) == NativeJump::instruction_code ||
aoqi@0 538 ubyte_at(0) == 0xEB; /* short jump */ }
aoqi@0 539 inline bool NativeInstruction::is_cond_jump() { return (int_at(0) & 0xF0FF) == 0x800F /* long jump */ ||
aoqi@0 540 (ubyte_at(0) & 0xF0) == 0x70; /* short jump */ }
aoqi@0 541 inline bool NativeInstruction::is_safepoint_poll() {
aoqi@0 542 #ifdef AMD64
aoqi@0 543 if (Assembler::is_polling_page_far()) {
aoqi@0 544 // two cases, depending on the choice of the base register in the address.
aoqi@0 545 if (((ubyte_at(0) & NativeTstRegMem::instruction_rex_prefix_mask) == NativeTstRegMem::instruction_rex_prefix &&
aoqi@0 546 ubyte_at(1) == NativeTstRegMem::instruction_code_memXregl &&
aoqi@0 547 (ubyte_at(2) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) ||
aoqi@0 548 ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl &&
aoqi@0 549 (ubyte_at(1) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) {
aoqi@0 550 return true;
aoqi@0 551 } else {
aoqi@0 552 return false;
aoqi@0 553 }
aoqi@0 554 } else {
aoqi@0 555 if (ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl &&
aoqi@0 556 ubyte_at(1) == 0x05) { // 00 rax 101
aoqi@0 557 address fault = addr_at(6) + int_at(2);
aoqi@0 558 return os::is_poll_address(fault);
aoqi@0 559 } else {
aoqi@0 560 return false;
aoqi@0 561 }
aoqi@0 562 }
aoqi@0 563 #else
aoqi@0 564 return ( ubyte_at(0) == NativeMovRegMem::instruction_code_mem2reg ||
aoqi@0 565 ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl ) &&
aoqi@0 566 (ubyte_at(1)&0xC7) == 0x05 && /* Mod R/M == disp32 */
aoqi@0 567 (os::is_poll_address((address)int_at(2)));
aoqi@0 568 #endif // AMD64
aoqi@0 569 }
aoqi@0 570
aoqi@0 571 inline bool NativeInstruction::is_mov_literal64() {
aoqi@0 572 #ifdef AMD64
aoqi@0 573 return ((ubyte_at(0) == Assembler::REX_W || ubyte_at(0) == Assembler::REX_WB) &&
aoqi@0 574 (ubyte_at(1) & (0xff ^ NativeMovConstReg::register_mask)) == 0xB8);
aoqi@0 575 #else
aoqi@0 576 return false;
aoqi@0 577 #endif // AMD64
aoqi@0 578 }
aoqi@0 579
aoqi@0 580 #endif // CPU_X86_VM_NATIVEINST_X86_HPP

mercurial