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