Wed, 08 Apr 2009 10:56:49 -0700
6655638: dynamic languages need method handles
Summary: initial implementation, with known omissions (x86/64, sparc, compiler optim., c-oops, C++ interp.)
Reviewed-by: kvn, twisti, never
duke@435 | 1 | /* |
xdono@631 | 2 | * Copyright 1997-2008 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_nativeInst_sparc.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
kamg@551 | 29 | bool NativeInstruction::is_dtrace_trap() { |
kamg@551 | 30 | return !is_nop(); |
kamg@551 | 31 | } |
kamg@551 | 32 | |
duke@435 | 33 | void NativeInstruction::set_data64_sethi(address instaddr, intptr_t x) { |
duke@435 | 34 | ResourceMark rm; |
duke@435 | 35 | CodeBuffer buf(instaddr, 10 * BytesPerInstWord ); |
duke@435 | 36 | MacroAssembler* _masm = new MacroAssembler(&buf); |
duke@435 | 37 | Register destreg; |
duke@435 | 38 | |
duke@435 | 39 | destreg = inv_rd(*(unsigned int *)instaddr); |
duke@435 | 40 | // Generate a the new sequence |
duke@435 | 41 | Address dest( destreg, (address)x ); |
duke@435 | 42 | _masm->sethi( dest, true ); |
duke@435 | 43 | ICache::invalidate_range(instaddr, 7 * BytesPerInstWord); |
duke@435 | 44 | } |
duke@435 | 45 | |
duke@435 | 46 | void NativeInstruction::verify() { |
duke@435 | 47 | // make sure code pattern is actually an instruction address |
duke@435 | 48 | address addr = addr_at(0); |
duke@435 | 49 | if (addr == 0 || ((intptr_t)addr & 3) != 0) { |
duke@435 | 50 | fatal("not an instruction address"); |
duke@435 | 51 | } |
duke@435 | 52 | } |
duke@435 | 53 | |
duke@435 | 54 | void NativeInstruction::print() { |
duke@435 | 55 | tty->print_cr(INTPTR_FORMAT ": 0x%x", addr_at(0), long_at(0)); |
duke@435 | 56 | } |
duke@435 | 57 | |
duke@435 | 58 | void NativeInstruction::set_long_at(int offset, int i) { |
duke@435 | 59 | address addr = addr_at(offset); |
duke@435 | 60 | *(int*)addr = i; |
duke@435 | 61 | ICache::invalidate_word(addr); |
duke@435 | 62 | } |
duke@435 | 63 | |
duke@435 | 64 | void NativeInstruction::set_jlong_at(int offset, jlong i) { |
duke@435 | 65 | address addr = addr_at(offset); |
duke@435 | 66 | *(jlong*)addr = i; |
duke@435 | 67 | // Don't need to invalidate 2 words here, because |
duke@435 | 68 | // the flush instruction operates on doublewords. |
duke@435 | 69 | ICache::invalidate_word(addr); |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | void NativeInstruction::set_addr_at(int offset, address x) { |
duke@435 | 73 | address addr = addr_at(offset); |
duke@435 | 74 | assert( ((intptr_t)addr & (wordSize-1)) == 0, "set_addr_at bad address alignment"); |
duke@435 | 75 | *(uintptr_t*)addr = (uintptr_t)x; |
duke@435 | 76 | // Don't need to invalidate 2 words here in the 64-bit case, |
duke@435 | 77 | // because the flush instruction operates on doublewords. |
duke@435 | 78 | ICache::invalidate_word(addr); |
duke@435 | 79 | // The Intel code has this assertion for NativeCall::set_destination, |
duke@435 | 80 | // NativeMovConstReg::set_data, NativeMovRegMem::set_offset, |
duke@435 | 81 | // NativeJump::set_jump_destination, and NativePushImm32::set_data |
duke@435 | 82 | //assert (Patching_lock->owned_by_self(), "must hold lock to patch instruction") |
duke@435 | 83 | } |
duke@435 | 84 | |
duke@435 | 85 | bool NativeInstruction::is_zero_test(Register ®) { |
duke@435 | 86 | int x = long_at(0); |
duke@435 | 87 | Assembler::op3s temp = (Assembler::op3s) (Assembler::sub_op3 | Assembler::cc_bit_op3); |
duke@435 | 88 | if (is_op3(x, temp, Assembler::arith_op) && |
duke@435 | 89 | inv_immed(x) && inv_rd(x) == G0) { |
duke@435 | 90 | if (inv_rs1(x) == G0) { |
duke@435 | 91 | reg = inv_rs2(x); |
duke@435 | 92 | return true; |
duke@435 | 93 | } else if (inv_rs2(x) == G0) { |
duke@435 | 94 | reg = inv_rs1(x); |
duke@435 | 95 | return true; |
duke@435 | 96 | } |
duke@435 | 97 | } |
duke@435 | 98 | return false; |
duke@435 | 99 | } |
duke@435 | 100 | |
duke@435 | 101 | bool NativeInstruction::is_load_store_with_small_offset(Register reg) { |
duke@435 | 102 | int x = long_at(0); |
duke@435 | 103 | if (is_op(x, Assembler::ldst_op) && |
duke@435 | 104 | inv_rs1(x) == reg && inv_immed(x)) { |
duke@435 | 105 | return true; |
duke@435 | 106 | } |
duke@435 | 107 | return false; |
duke@435 | 108 | } |
duke@435 | 109 | |
duke@435 | 110 | void NativeCall::verify() { |
duke@435 | 111 | NativeInstruction::verify(); |
duke@435 | 112 | // make sure code pattern is actually a call instruction |
duke@435 | 113 | if (!is_op(long_at(0), Assembler::call_op)) { |
duke@435 | 114 | fatal("not a call"); |
duke@435 | 115 | } |
duke@435 | 116 | } |
duke@435 | 117 | |
duke@435 | 118 | void NativeCall::print() { |
duke@435 | 119 | tty->print_cr(INTPTR_FORMAT ": call " INTPTR_FORMAT, instruction_address(), destination()); |
duke@435 | 120 | } |
duke@435 | 121 | |
duke@435 | 122 | |
duke@435 | 123 | // MT-safe patching of a call instruction (and following word). |
duke@435 | 124 | // First patches the second word, and then atomicly replaces |
duke@435 | 125 | // the first word with the first new instruction word. |
duke@435 | 126 | // Other processors might briefly see the old first word |
duke@435 | 127 | // followed by the new second word. This is OK if the old |
duke@435 | 128 | // second word is harmless, and the new second word may be |
duke@435 | 129 | // harmlessly executed in the delay slot of the call. |
duke@435 | 130 | void NativeCall::replace_mt_safe(address instr_addr, address code_buffer) { |
duke@435 | 131 | assert(Patching_lock->is_locked() || |
duke@435 | 132 | SafepointSynchronize::is_at_safepoint(), "concurrent code patching"); |
duke@435 | 133 | assert (instr_addr != NULL, "illegal address for code patching"); |
duke@435 | 134 | NativeCall* n_call = nativeCall_at (instr_addr); // checking that it is a call |
duke@435 | 135 | assert(NativeCall::instruction_size == 8, "wrong instruction size; must be 8"); |
duke@435 | 136 | int i0 = ((int*)code_buffer)[0]; |
duke@435 | 137 | int i1 = ((int*)code_buffer)[1]; |
duke@435 | 138 | int* contention_addr = (int*) n_call->addr_at(1*BytesPerInstWord); |
duke@435 | 139 | assert(inv_op(*contention_addr) == Assembler::arith_op || |
duke@435 | 140 | *contention_addr == nop_instruction() || !VM_Version::v9_instructions_work(), |
duke@435 | 141 | "must not interfere with original call"); |
duke@435 | 142 | // The set_long_at calls do the ICacheInvalidate so we just need to do them in reverse order |
duke@435 | 143 | n_call->set_long_at(1*BytesPerInstWord, i1); |
duke@435 | 144 | n_call->set_long_at(0*BytesPerInstWord, i0); |
duke@435 | 145 | // NOTE: It is possible that another thread T will execute |
duke@435 | 146 | // only the second patched word. |
duke@435 | 147 | // In other words, since the original instruction is this |
duke@435 | 148 | // call patching_stub; nop (NativeCall) |
duke@435 | 149 | // and the new sequence from the buffer is this: |
duke@435 | 150 | // sethi %hi(K), %r; add %r, %lo(K), %r (NativeMovConstReg) |
duke@435 | 151 | // what T will execute is this: |
duke@435 | 152 | // call patching_stub; add %r, %lo(K), %r |
duke@435 | 153 | // thereby putting garbage into %r before calling the patching stub. |
duke@435 | 154 | // This is OK, because the patching stub ignores the value of %r. |
duke@435 | 155 | |
duke@435 | 156 | // Make sure the first-patched instruction, which may co-exist |
duke@435 | 157 | // briefly with the call, will do something harmless. |
duke@435 | 158 | assert(inv_op(*contention_addr) == Assembler::arith_op || |
duke@435 | 159 | *contention_addr == nop_instruction() || !VM_Version::v9_instructions_work(), |
duke@435 | 160 | "must not interfere with original call"); |
duke@435 | 161 | } |
duke@435 | 162 | |
duke@435 | 163 | // Similar to replace_mt_safe, but just changes the destination. The |
duke@435 | 164 | // important thing is that free-running threads are able to execute this |
duke@435 | 165 | // call instruction at all times. Thus, the displacement field must be |
duke@435 | 166 | // instruction-word-aligned. This is always true on SPARC. |
duke@435 | 167 | // |
duke@435 | 168 | // Used in the runtime linkage of calls; see class CompiledIC. |
duke@435 | 169 | void NativeCall::set_destination_mt_safe(address dest) { |
duke@435 | 170 | assert(Patching_lock->is_locked() || |
duke@435 | 171 | SafepointSynchronize::is_at_safepoint(), "concurrent code patching"); |
duke@435 | 172 | // set_destination uses set_long_at which does the ICache::invalidate |
duke@435 | 173 | set_destination(dest); |
duke@435 | 174 | } |
duke@435 | 175 | |
duke@435 | 176 | // Code for unit testing implementation of NativeCall class |
duke@435 | 177 | void NativeCall::test() { |
duke@435 | 178 | #ifdef ASSERT |
duke@435 | 179 | ResourceMark rm; |
duke@435 | 180 | CodeBuffer cb("test", 100, 100); |
duke@435 | 181 | MacroAssembler* a = new MacroAssembler(&cb); |
duke@435 | 182 | NativeCall *nc; |
duke@435 | 183 | uint idx; |
duke@435 | 184 | int offsets[] = { |
duke@435 | 185 | 0x0, |
duke@435 | 186 | 0xfffffff0, |
duke@435 | 187 | 0x7ffffff0, |
duke@435 | 188 | 0x80000000, |
duke@435 | 189 | 0x20, |
duke@435 | 190 | 0x4000, |
duke@435 | 191 | }; |
duke@435 | 192 | |
duke@435 | 193 | VM_Version::allow_all(); |
duke@435 | 194 | |
duke@435 | 195 | a->call( a->pc(), relocInfo::none ); |
duke@435 | 196 | a->delayed()->nop(); |
duke@435 | 197 | nc = nativeCall_at( cb.code_begin() ); |
duke@435 | 198 | nc->print(); |
duke@435 | 199 | |
duke@435 | 200 | nc = nativeCall_overwriting_at( nc->next_instruction_address() ); |
duke@435 | 201 | for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) { |
duke@435 | 202 | nc->set_destination( cb.code_begin() + offsets[idx] ); |
duke@435 | 203 | assert(nc->destination() == (cb.code_begin() + offsets[idx]), "check unit test"); |
duke@435 | 204 | nc->print(); |
duke@435 | 205 | } |
duke@435 | 206 | |
duke@435 | 207 | nc = nativeCall_before( cb.code_begin() + 8 ); |
duke@435 | 208 | nc->print(); |
duke@435 | 209 | |
duke@435 | 210 | VM_Version::revert(); |
duke@435 | 211 | #endif |
duke@435 | 212 | } |
duke@435 | 213 | // End code for unit testing implementation of NativeCall class |
duke@435 | 214 | |
duke@435 | 215 | //------------------------------------------------------------------- |
duke@435 | 216 | |
duke@435 | 217 | #ifdef _LP64 |
duke@435 | 218 | |
duke@435 | 219 | void NativeFarCall::set_destination(address dest) { |
duke@435 | 220 | // Address materialized in the instruction stream, so nothing to do. |
duke@435 | 221 | return; |
duke@435 | 222 | #if 0 // What we'd do if we really did want to change the destination |
duke@435 | 223 | if (destination() == dest) { |
duke@435 | 224 | return; |
duke@435 | 225 | } |
duke@435 | 226 | ResourceMark rm; |
duke@435 | 227 | CodeBuffer buf(addr_at(0), instruction_size + 1); |
duke@435 | 228 | MacroAssembler* _masm = new MacroAssembler(&buf); |
duke@435 | 229 | // Generate the new sequence |
duke@435 | 230 | Address(O7, dest); |
duke@435 | 231 | _masm->jumpl_to(dest, O7); |
duke@435 | 232 | ICache::invalidate_range(addr_at(0), instruction_size ); |
duke@435 | 233 | #endif |
duke@435 | 234 | } |
duke@435 | 235 | |
duke@435 | 236 | void NativeFarCall::verify() { |
duke@435 | 237 | // make sure code pattern is actually a jumpl_to instruction |
duke@435 | 238 | assert((int)instruction_size == (int)NativeJump::instruction_size, "same as jump_to"); |
duke@435 | 239 | assert((int)jmpl_offset == (int)NativeMovConstReg::add_offset, "sethi size ok"); |
duke@435 | 240 | nativeJump_at(addr_at(0))->verify(); |
duke@435 | 241 | } |
duke@435 | 242 | |
duke@435 | 243 | bool NativeFarCall::is_call_at(address instr) { |
duke@435 | 244 | return nativeInstruction_at(instr)->is_sethi(); |
duke@435 | 245 | } |
duke@435 | 246 | |
duke@435 | 247 | void NativeFarCall::print() { |
duke@435 | 248 | tty->print_cr(INTPTR_FORMAT ": call " INTPTR_FORMAT, instruction_address(), destination()); |
duke@435 | 249 | } |
duke@435 | 250 | |
duke@435 | 251 | bool NativeFarCall::destination_is_compiled_verified_entry_point() { |
duke@435 | 252 | nmethod* callee = CodeCache::find_nmethod(destination()); |
duke@435 | 253 | if (callee == NULL) { |
duke@435 | 254 | return false; |
duke@435 | 255 | } else { |
duke@435 | 256 | return destination() == callee->verified_entry_point(); |
duke@435 | 257 | } |
duke@435 | 258 | } |
duke@435 | 259 | |
duke@435 | 260 | // MT-safe patching of a far call. |
duke@435 | 261 | void NativeFarCall::replace_mt_safe(address instr_addr, address code_buffer) { |
duke@435 | 262 | Unimplemented(); |
duke@435 | 263 | } |
duke@435 | 264 | |
duke@435 | 265 | // Code for unit testing implementation of NativeFarCall class |
duke@435 | 266 | void NativeFarCall::test() { |
duke@435 | 267 | Unimplemented(); |
duke@435 | 268 | } |
duke@435 | 269 | // End code for unit testing implementation of NativeFarCall class |
duke@435 | 270 | |
duke@435 | 271 | #endif // _LP64 |
duke@435 | 272 | |
duke@435 | 273 | //------------------------------------------------------------------- |
duke@435 | 274 | |
duke@435 | 275 | |
duke@435 | 276 | void NativeMovConstReg::verify() { |
duke@435 | 277 | NativeInstruction::verify(); |
duke@435 | 278 | // make sure code pattern is actually a "set_oop" synthetic instruction |
duke@435 | 279 | // see MacroAssembler::set_oop() |
duke@435 | 280 | int i0 = long_at(sethi_offset); |
duke@435 | 281 | int i1 = long_at(add_offset); |
duke@435 | 282 | |
duke@435 | 283 | // verify the pattern "sethi %hi22(imm), reg ; add reg, %lo10(imm), reg" |
duke@435 | 284 | Register rd = inv_rd(i0); |
duke@435 | 285 | #ifndef _LP64 |
duke@435 | 286 | if (!(is_op2(i0, Assembler::sethi_op2) && rd != G0 && |
duke@435 | 287 | is_op3(i1, Assembler::add_op3, Assembler::arith_op) && |
duke@435 | 288 | inv_immed(i1) && (unsigned)get_simm13(i1) < (1 << 10) && |
duke@435 | 289 | rd == inv_rs1(i1) && rd == inv_rd(i1))) { |
duke@435 | 290 | fatal("not a set_oop"); |
duke@435 | 291 | } |
duke@435 | 292 | #else |
duke@435 | 293 | if (!is_op2(i0, Assembler::sethi_op2) && rd != G0 ) { |
duke@435 | 294 | fatal("not a set_oop"); |
duke@435 | 295 | } |
duke@435 | 296 | #endif |
duke@435 | 297 | } |
duke@435 | 298 | |
duke@435 | 299 | |
duke@435 | 300 | void NativeMovConstReg::print() { |
duke@435 | 301 | tty->print_cr(INTPTR_FORMAT ": mov reg, " INTPTR_FORMAT, instruction_address(), data()); |
duke@435 | 302 | } |
duke@435 | 303 | |
duke@435 | 304 | |
duke@435 | 305 | #ifdef _LP64 |
duke@435 | 306 | intptr_t NativeMovConstReg::data() const { |
duke@435 | 307 | return data64(addr_at(sethi_offset), long_at(add_offset)); |
duke@435 | 308 | } |
duke@435 | 309 | #else |
duke@435 | 310 | intptr_t NativeMovConstReg::data() const { |
duke@435 | 311 | return data32(long_at(sethi_offset), long_at(add_offset)); |
duke@435 | 312 | } |
duke@435 | 313 | #endif |
duke@435 | 314 | |
duke@435 | 315 | |
duke@435 | 316 | void NativeMovConstReg::set_data(intptr_t x) { |
duke@435 | 317 | #ifdef _LP64 |
duke@435 | 318 | set_data64_sethi(addr_at(sethi_offset), x); |
duke@435 | 319 | #else |
duke@435 | 320 | set_long_at(sethi_offset, set_data32_sethi( long_at(sethi_offset), x)); |
duke@435 | 321 | #endif |
duke@435 | 322 | set_long_at(add_offset, set_data32_simm13( long_at(add_offset), x)); |
duke@435 | 323 | |
duke@435 | 324 | // also store the value into an oop_Relocation cell, if any |
duke@435 | 325 | CodeBlob* nm = CodeCache::find_blob(instruction_address()); |
duke@435 | 326 | if (nm != NULL) { |
duke@435 | 327 | RelocIterator iter(nm, instruction_address(), next_instruction_address()); |
duke@435 | 328 | oop* oop_addr = NULL; |
duke@435 | 329 | while (iter.next()) { |
duke@435 | 330 | if (iter.type() == relocInfo::oop_type) { |
duke@435 | 331 | oop_Relocation *r = iter.oop_reloc(); |
duke@435 | 332 | if (oop_addr == NULL) { |
duke@435 | 333 | oop_addr = r->oop_addr(); |
duke@435 | 334 | *oop_addr = (oop)x; |
duke@435 | 335 | } else { |
duke@435 | 336 | assert(oop_addr == r->oop_addr(), "must be only one set-oop here"); |
duke@435 | 337 | } |
duke@435 | 338 | } |
duke@435 | 339 | } |
duke@435 | 340 | } |
duke@435 | 341 | } |
duke@435 | 342 | |
duke@435 | 343 | |
duke@435 | 344 | // Code for unit testing implementation of NativeMovConstReg class |
duke@435 | 345 | void NativeMovConstReg::test() { |
duke@435 | 346 | #ifdef ASSERT |
duke@435 | 347 | ResourceMark rm; |
duke@435 | 348 | CodeBuffer cb("test", 100, 100); |
duke@435 | 349 | MacroAssembler* a = new MacroAssembler(&cb); |
duke@435 | 350 | NativeMovConstReg* nm; |
duke@435 | 351 | uint idx; |
duke@435 | 352 | int offsets[] = { |
duke@435 | 353 | 0x0, |
duke@435 | 354 | 0x7fffffff, |
duke@435 | 355 | 0x80000000, |
duke@435 | 356 | 0xffffffff, |
duke@435 | 357 | 0x20, |
duke@435 | 358 | 4096, |
duke@435 | 359 | 4097, |
duke@435 | 360 | }; |
duke@435 | 361 | |
duke@435 | 362 | VM_Version::allow_all(); |
duke@435 | 363 | |
duke@435 | 364 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); |
duke@435 | 365 | a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 366 | a->sethi(0xccccdddd, O2, true, RelocationHolder::none); |
duke@435 | 367 | a->add(O2, low10(0xccccdddd), O2); |
duke@435 | 368 | |
duke@435 | 369 | nm = nativeMovConstReg_at( cb.code_begin() ); |
duke@435 | 370 | nm->print(); |
duke@435 | 371 | |
duke@435 | 372 | nm = nativeMovConstReg_at( nm->next_instruction_address() ); |
duke@435 | 373 | for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) { |
duke@435 | 374 | nm->set_data( offsets[idx] ); |
duke@435 | 375 | assert(nm->data() == offsets[idx], "check unit test"); |
duke@435 | 376 | } |
duke@435 | 377 | nm->print(); |
duke@435 | 378 | |
duke@435 | 379 | VM_Version::revert(); |
duke@435 | 380 | #endif |
duke@435 | 381 | } |
duke@435 | 382 | // End code for unit testing implementation of NativeMovConstReg class |
duke@435 | 383 | |
duke@435 | 384 | //------------------------------------------------------------------- |
duke@435 | 385 | |
duke@435 | 386 | void NativeMovConstRegPatching::verify() { |
duke@435 | 387 | NativeInstruction::verify(); |
duke@435 | 388 | // Make sure code pattern is sethi/nop/add. |
duke@435 | 389 | int i0 = long_at(sethi_offset); |
duke@435 | 390 | int i1 = long_at(nop_offset); |
duke@435 | 391 | int i2 = long_at(add_offset); |
duke@435 | 392 | assert((int)nop_offset == (int)NativeMovConstReg::add_offset, "sethi size ok"); |
duke@435 | 393 | |
duke@435 | 394 | // Verify the pattern "sethi %hi22(imm), reg; nop; add reg, %lo10(imm), reg" |
duke@435 | 395 | // The casual reader should note that on Sparc a nop is a special case if sethi |
duke@435 | 396 | // in which the destination register is %g0. |
duke@435 | 397 | Register rd0 = inv_rd(i0); |
duke@435 | 398 | Register rd1 = inv_rd(i1); |
duke@435 | 399 | if (!(is_op2(i0, Assembler::sethi_op2) && rd0 != G0 && |
duke@435 | 400 | is_op2(i1, Assembler::sethi_op2) && rd1 == G0 && // nop is a special case of sethi |
duke@435 | 401 | is_op3(i2, Assembler::add_op3, Assembler::arith_op) && |
duke@435 | 402 | inv_immed(i2) && (unsigned)get_simm13(i2) < (1 << 10) && |
duke@435 | 403 | rd0 == inv_rs1(i2) && rd0 == inv_rd(i2))) { |
duke@435 | 404 | fatal("not a set_oop"); |
duke@435 | 405 | } |
duke@435 | 406 | } |
duke@435 | 407 | |
duke@435 | 408 | |
duke@435 | 409 | void NativeMovConstRegPatching::print() { |
duke@435 | 410 | tty->print_cr(INTPTR_FORMAT ": mov reg, " INTPTR_FORMAT, instruction_address(), data()); |
duke@435 | 411 | } |
duke@435 | 412 | |
duke@435 | 413 | |
duke@435 | 414 | int NativeMovConstRegPatching::data() const { |
duke@435 | 415 | #ifdef _LP64 |
duke@435 | 416 | return data64(addr_at(sethi_offset), long_at(add_offset)); |
duke@435 | 417 | #else |
duke@435 | 418 | return data32(long_at(sethi_offset), long_at(add_offset)); |
duke@435 | 419 | #endif |
duke@435 | 420 | } |
duke@435 | 421 | |
duke@435 | 422 | |
duke@435 | 423 | void NativeMovConstRegPatching::set_data(int x) { |
duke@435 | 424 | #ifdef _LP64 |
duke@435 | 425 | set_data64_sethi(addr_at(sethi_offset), x); |
duke@435 | 426 | #else |
duke@435 | 427 | set_long_at(sethi_offset, set_data32_sethi(long_at(sethi_offset), x)); |
duke@435 | 428 | #endif |
duke@435 | 429 | set_long_at(add_offset, set_data32_simm13(long_at(add_offset), x)); |
duke@435 | 430 | |
duke@435 | 431 | // also store the value into an oop_Relocation cell, if any |
duke@435 | 432 | CodeBlob* nm = CodeCache::find_blob(instruction_address()); |
duke@435 | 433 | if (nm != NULL) { |
duke@435 | 434 | RelocIterator iter(nm, instruction_address(), next_instruction_address()); |
duke@435 | 435 | oop* oop_addr = NULL; |
duke@435 | 436 | while (iter.next()) { |
duke@435 | 437 | if (iter.type() == relocInfo::oop_type) { |
duke@435 | 438 | oop_Relocation *r = iter.oop_reloc(); |
duke@435 | 439 | if (oop_addr == NULL) { |
duke@435 | 440 | oop_addr = r->oop_addr(); |
duke@435 | 441 | *oop_addr = (oop)x; |
duke@435 | 442 | } else { |
duke@435 | 443 | assert(oop_addr == r->oop_addr(), "must be only one set-oop here"); |
duke@435 | 444 | } |
duke@435 | 445 | } |
duke@435 | 446 | } |
duke@435 | 447 | } |
duke@435 | 448 | } |
duke@435 | 449 | |
duke@435 | 450 | |
duke@435 | 451 | // Code for unit testing implementation of NativeMovConstRegPatching class |
duke@435 | 452 | void NativeMovConstRegPatching::test() { |
duke@435 | 453 | #ifdef ASSERT |
duke@435 | 454 | ResourceMark rm; |
duke@435 | 455 | CodeBuffer cb("test", 100, 100); |
duke@435 | 456 | MacroAssembler* a = new MacroAssembler(&cb); |
duke@435 | 457 | NativeMovConstRegPatching* nm; |
duke@435 | 458 | uint idx; |
duke@435 | 459 | int offsets[] = { |
duke@435 | 460 | 0x0, |
duke@435 | 461 | 0x7fffffff, |
duke@435 | 462 | 0x80000000, |
duke@435 | 463 | 0xffffffff, |
duke@435 | 464 | 0x20, |
duke@435 | 465 | 4096, |
duke@435 | 466 | 4097, |
duke@435 | 467 | }; |
duke@435 | 468 | |
duke@435 | 469 | VM_Version::allow_all(); |
duke@435 | 470 | |
duke@435 | 471 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); |
duke@435 | 472 | a->nop(); |
duke@435 | 473 | a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 474 | a->sethi(0xccccdddd, O2, true, RelocationHolder::none); |
duke@435 | 475 | a->nop(); |
duke@435 | 476 | a->add(O2, low10(0xccccdddd), O2); |
duke@435 | 477 | |
duke@435 | 478 | nm = nativeMovConstRegPatching_at( cb.code_begin() ); |
duke@435 | 479 | nm->print(); |
duke@435 | 480 | |
duke@435 | 481 | nm = nativeMovConstRegPatching_at( nm->next_instruction_address() ); |
duke@435 | 482 | for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) { |
duke@435 | 483 | nm->set_data( offsets[idx] ); |
duke@435 | 484 | assert(nm->data() == offsets[idx], "check unit test"); |
duke@435 | 485 | } |
duke@435 | 486 | nm->print(); |
duke@435 | 487 | |
duke@435 | 488 | VM_Version::revert(); |
duke@435 | 489 | #endif // ASSERT |
duke@435 | 490 | } |
duke@435 | 491 | // End code for unit testing implementation of NativeMovConstRegPatching class |
duke@435 | 492 | |
duke@435 | 493 | |
duke@435 | 494 | //------------------------------------------------------------------- |
duke@435 | 495 | |
duke@435 | 496 | |
duke@435 | 497 | void NativeMovRegMem::copy_instruction_to(address new_instruction_address) { |
duke@435 | 498 | Untested("copy_instruction_to"); |
duke@435 | 499 | int instruction_size = next_instruction_address() - instruction_address(); |
duke@435 | 500 | for (int i = 0; i < instruction_size; i += BytesPerInstWord) { |
duke@435 | 501 | *(int*)(new_instruction_address + i) = *(int*)(address(this) + i); |
duke@435 | 502 | } |
duke@435 | 503 | } |
duke@435 | 504 | |
duke@435 | 505 | |
duke@435 | 506 | void NativeMovRegMem::verify() { |
duke@435 | 507 | NativeInstruction::verify(); |
duke@435 | 508 | // make sure code pattern is actually a "ld" or "st" of some sort. |
duke@435 | 509 | int i0 = long_at(0); |
duke@435 | 510 | int op3 = inv_op3(i0); |
duke@435 | 511 | |
duke@435 | 512 | assert((int)add_offset == NativeMovConstReg::add_offset, "sethi size ok"); |
duke@435 | 513 | |
duke@435 | 514 | if (!(is_op(i0, Assembler::ldst_op) && |
duke@435 | 515 | inv_immed(i0) && |
duke@435 | 516 | 0 != (op3 < op3_ldst_int_limit |
duke@435 | 517 | ? (1 << op3 ) & (op3_mask_ld | op3_mask_st) |
duke@435 | 518 | : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf)))) |
duke@435 | 519 | { |
duke@435 | 520 | int i1 = long_at(ldst_offset); |
duke@435 | 521 | Register rd = inv_rd(i0); |
duke@435 | 522 | |
duke@435 | 523 | op3 = inv_op3(i1); |
duke@435 | 524 | if (!is_op(i1, Assembler::ldst_op) && rd == inv_rs2(i1) && |
duke@435 | 525 | 0 != (op3 < op3_ldst_int_limit |
duke@435 | 526 | ? (1 << op3 ) & (op3_mask_ld | op3_mask_st) |
duke@435 | 527 | : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf))) { |
duke@435 | 528 | fatal("not a ld* or st* op"); |
duke@435 | 529 | } |
duke@435 | 530 | } |
duke@435 | 531 | } |
duke@435 | 532 | |
duke@435 | 533 | |
duke@435 | 534 | void NativeMovRegMem::print() { |
duke@435 | 535 | if (is_immediate()) { |
duke@435 | 536 | tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + %x]", instruction_address(), offset()); |
duke@435 | 537 | } else { |
duke@435 | 538 | tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + reg]", instruction_address()); |
duke@435 | 539 | } |
duke@435 | 540 | } |
duke@435 | 541 | |
duke@435 | 542 | |
duke@435 | 543 | // Code for unit testing implementation of NativeMovRegMem class |
duke@435 | 544 | void NativeMovRegMem::test() { |
duke@435 | 545 | #ifdef ASSERT |
duke@435 | 546 | ResourceMark rm; |
duke@435 | 547 | CodeBuffer cb("test", 1000, 1000); |
duke@435 | 548 | MacroAssembler* a = new MacroAssembler(&cb); |
duke@435 | 549 | NativeMovRegMem* nm; |
duke@435 | 550 | uint idx = 0; |
duke@435 | 551 | uint idx1; |
duke@435 | 552 | int offsets[] = { |
duke@435 | 553 | 0x0, |
duke@435 | 554 | 0xffffffff, |
duke@435 | 555 | 0x7fffffff, |
duke@435 | 556 | 0x80000000, |
duke@435 | 557 | 4096, |
duke@435 | 558 | 4097, |
duke@435 | 559 | 0x20, |
duke@435 | 560 | 0x4000, |
duke@435 | 561 | }; |
duke@435 | 562 | |
duke@435 | 563 | VM_Version::allow_all(); |
duke@435 | 564 | |
duke@435 | 565 | a->ldsw( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 566 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 567 | a->ldsw( G5, I3, G4 ); idx++; |
duke@435 | 568 | a->ldsb( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 569 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 570 | a->ldsb( G5, I3, G4 ); idx++; |
duke@435 | 571 | a->ldsh( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 572 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 573 | a->ldsh( G5, I3, G4 ); idx++; |
duke@435 | 574 | a->lduw( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 575 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 576 | a->lduw( G5, I3, G4 ); idx++; |
duke@435 | 577 | a->ldub( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 578 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 579 | a->ldub( G5, I3, G4 ); idx++; |
duke@435 | 580 | a->lduh( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 581 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 582 | a->lduh( G5, I3, G4 ); idx++; |
duke@435 | 583 | a->ldx( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 584 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 585 | a->ldx( G5, I3, G4 ); idx++; |
duke@435 | 586 | a->ldd( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 587 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 588 | a->ldd( G5, I3, G4 ); idx++; |
duke@435 | 589 | a->ldf( FloatRegisterImpl::D, O2, -1, F14 ); idx++; |
duke@435 | 590 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 591 | a->ldf( FloatRegisterImpl::S, O0, I3, F15 ); idx++; |
duke@435 | 592 | |
duke@435 | 593 | a->stw( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 594 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 595 | a->stw( G5, G4, I3 ); idx++; |
duke@435 | 596 | a->stb( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 597 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 598 | a->stb( G5, G4, I3 ); idx++; |
duke@435 | 599 | a->sth( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 600 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 601 | a->sth( G5, G4, I3 ); idx++; |
duke@435 | 602 | a->stx( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 603 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 604 | a->stx( G5, G4, I3 ); idx++; |
duke@435 | 605 | a->std( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 606 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 607 | a->std( G5, G4, I3 ); idx++; |
duke@435 | 608 | a->stf( FloatRegisterImpl::S, F18, O2, -1 ); idx++; |
duke@435 | 609 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 610 | a->stf( FloatRegisterImpl::S, F15, O0, I3 ); idx++; |
duke@435 | 611 | |
duke@435 | 612 | nm = nativeMovRegMem_at( cb.code_begin() ); |
duke@435 | 613 | nm->print(); |
duke@435 | 614 | nm->set_offset( low10(0) ); |
duke@435 | 615 | nm->print(); |
duke@435 | 616 | nm->add_offset_in_bytes( low10(0xbb) * wordSize ); |
duke@435 | 617 | nm->print(); |
duke@435 | 618 | |
duke@435 | 619 | while (--idx) { |
duke@435 | 620 | nm = nativeMovRegMem_at( nm->next_instruction_address() ); |
duke@435 | 621 | nm->print(); |
duke@435 | 622 | for (idx1 = 0; idx1 < ARRAY_SIZE(offsets); idx1++) { |
duke@435 | 623 | nm->set_offset( nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1] ); |
duke@435 | 624 | assert(nm->offset() == (nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1]), |
duke@435 | 625 | "check unit test"); |
duke@435 | 626 | nm->print(); |
duke@435 | 627 | } |
duke@435 | 628 | nm->add_offset_in_bytes( low10(0xbb) * wordSize ); |
duke@435 | 629 | nm->print(); |
duke@435 | 630 | } |
duke@435 | 631 | |
duke@435 | 632 | VM_Version::revert(); |
duke@435 | 633 | #endif // ASSERT |
duke@435 | 634 | } |
duke@435 | 635 | |
duke@435 | 636 | // End code for unit testing implementation of NativeMovRegMem class |
duke@435 | 637 | |
duke@435 | 638 | //-------------------------------------------------------------------------------- |
duke@435 | 639 | |
duke@435 | 640 | |
duke@435 | 641 | void NativeMovRegMemPatching::copy_instruction_to(address new_instruction_address) { |
duke@435 | 642 | Untested("copy_instruction_to"); |
duke@435 | 643 | int instruction_size = next_instruction_address() - instruction_address(); |
duke@435 | 644 | for (int i = 0; i < instruction_size; i += wordSize) { |
duke@435 | 645 | *(long*)(new_instruction_address + i) = *(long*)(address(this) + i); |
duke@435 | 646 | } |
duke@435 | 647 | } |
duke@435 | 648 | |
duke@435 | 649 | |
duke@435 | 650 | void NativeMovRegMemPatching::verify() { |
duke@435 | 651 | NativeInstruction::verify(); |
duke@435 | 652 | // make sure code pattern is actually a "ld" or "st" of some sort. |
duke@435 | 653 | int i0 = long_at(0); |
duke@435 | 654 | int op3 = inv_op3(i0); |
duke@435 | 655 | |
duke@435 | 656 | assert((int)nop_offset == (int)NativeMovConstReg::add_offset, "sethi size ok"); |
duke@435 | 657 | |
duke@435 | 658 | if (!(is_op(i0, Assembler::ldst_op) && |
duke@435 | 659 | inv_immed(i0) && |
duke@435 | 660 | 0 != (op3 < op3_ldst_int_limit |
duke@435 | 661 | ? (1 << op3 ) & (op3_mask_ld | op3_mask_st) |
duke@435 | 662 | : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf)))) { |
duke@435 | 663 | int i1 = long_at(ldst_offset); |
duke@435 | 664 | Register rd = inv_rd(i0); |
duke@435 | 665 | |
duke@435 | 666 | op3 = inv_op3(i1); |
duke@435 | 667 | if (!is_op(i1, Assembler::ldst_op) && rd == inv_rs2(i1) && |
duke@435 | 668 | 0 != (op3 < op3_ldst_int_limit |
duke@435 | 669 | ? (1 << op3 ) & (op3_mask_ld | op3_mask_st) |
duke@435 | 670 | : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf))) { |
duke@435 | 671 | fatal("not a ld* or st* op"); |
duke@435 | 672 | } |
duke@435 | 673 | } |
duke@435 | 674 | } |
duke@435 | 675 | |
duke@435 | 676 | |
duke@435 | 677 | void NativeMovRegMemPatching::print() { |
duke@435 | 678 | if (is_immediate()) { |
duke@435 | 679 | tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + %x]", instruction_address(), offset()); |
duke@435 | 680 | } else { |
duke@435 | 681 | tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + reg]", instruction_address()); |
duke@435 | 682 | } |
duke@435 | 683 | } |
duke@435 | 684 | |
duke@435 | 685 | |
duke@435 | 686 | // Code for unit testing implementation of NativeMovRegMemPatching class |
duke@435 | 687 | void NativeMovRegMemPatching::test() { |
duke@435 | 688 | #ifdef ASSERT |
duke@435 | 689 | ResourceMark rm; |
duke@435 | 690 | CodeBuffer cb("test", 1000, 1000); |
duke@435 | 691 | MacroAssembler* a = new MacroAssembler(&cb); |
duke@435 | 692 | NativeMovRegMemPatching* nm; |
duke@435 | 693 | uint idx = 0; |
duke@435 | 694 | uint idx1; |
duke@435 | 695 | int offsets[] = { |
duke@435 | 696 | 0x0, |
duke@435 | 697 | 0xffffffff, |
duke@435 | 698 | 0x7fffffff, |
duke@435 | 699 | 0x80000000, |
duke@435 | 700 | 4096, |
duke@435 | 701 | 4097, |
duke@435 | 702 | 0x20, |
duke@435 | 703 | 0x4000, |
duke@435 | 704 | }; |
duke@435 | 705 | |
duke@435 | 706 | VM_Version::allow_all(); |
duke@435 | 707 | |
duke@435 | 708 | a->ldsw( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 709 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 710 | a->ldsw( G5, I3, G4 ); idx++; |
duke@435 | 711 | a->ldsb( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 712 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 713 | a->ldsb( G5, I3, G4 ); idx++; |
duke@435 | 714 | a->ldsh( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 715 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 716 | a->ldsh( G5, I3, G4 ); idx++; |
duke@435 | 717 | a->lduw( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 718 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 719 | a->lduw( G5, I3, G4 ); idx++; |
duke@435 | 720 | a->ldub( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 721 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 722 | a->ldub( G5, I3, G4 ); idx++; |
duke@435 | 723 | a->lduh( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 724 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 725 | a->lduh( G5, I3, G4 ); idx++; |
duke@435 | 726 | a->ldx( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 727 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 728 | a->ldx( G5, I3, G4 ); idx++; |
duke@435 | 729 | a->ldd( G5, low10(0xffffffff), G4 ); idx++; |
duke@435 | 730 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 731 | a->ldd( G5, I3, G4 ); idx++; |
duke@435 | 732 | a->ldf( FloatRegisterImpl::D, O2, -1, F14 ); idx++; |
duke@435 | 733 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 734 | a->ldf( FloatRegisterImpl::S, O0, I3, F15 ); idx++; |
duke@435 | 735 | |
duke@435 | 736 | a->stw( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 737 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 738 | a->stw( G5, G4, I3 ); idx++; |
duke@435 | 739 | a->stb( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 740 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 741 | a->stb( G5, G4, I3 ); idx++; |
duke@435 | 742 | a->sth( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 743 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 744 | a->sth( G5, G4, I3 ); idx++; |
duke@435 | 745 | a->stx( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 746 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 747 | a->stx( G5, G4, I3 ); idx++; |
duke@435 | 748 | a->std( G5, G4, low10(0xffffffff) ); idx++; |
duke@435 | 749 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 750 | a->std( G5, G4, I3 ); idx++; |
duke@435 | 751 | a->stf( FloatRegisterImpl::S, F18, O2, -1 ); idx++; |
duke@435 | 752 | a->sethi(0xaaaabbbb, I3, true, RelocationHolder::none); a->nop(); a->add(I3, low10(0xaaaabbbb), I3); |
duke@435 | 753 | a->stf( FloatRegisterImpl::S, F15, O0, I3 ); idx++; |
duke@435 | 754 | |
duke@435 | 755 | nm = nativeMovRegMemPatching_at( cb.code_begin() ); |
duke@435 | 756 | nm->print(); |
duke@435 | 757 | nm->set_offset( low10(0) ); |
duke@435 | 758 | nm->print(); |
duke@435 | 759 | nm->add_offset_in_bytes( low10(0xbb) * wordSize ); |
duke@435 | 760 | nm->print(); |
duke@435 | 761 | |
duke@435 | 762 | while (--idx) { |
duke@435 | 763 | nm = nativeMovRegMemPatching_at( nm->next_instruction_address() ); |
duke@435 | 764 | nm->print(); |
duke@435 | 765 | for (idx1 = 0; idx1 < ARRAY_SIZE(offsets); idx1++) { |
duke@435 | 766 | nm->set_offset( nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1] ); |
duke@435 | 767 | assert(nm->offset() == (nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1]), |
duke@435 | 768 | "check unit test"); |
duke@435 | 769 | nm->print(); |
duke@435 | 770 | } |
duke@435 | 771 | nm->add_offset_in_bytes( low10(0xbb) * wordSize ); |
duke@435 | 772 | nm->print(); |
duke@435 | 773 | } |
duke@435 | 774 | |
duke@435 | 775 | VM_Version::revert(); |
duke@435 | 776 | #endif // ASSERT |
duke@435 | 777 | } |
duke@435 | 778 | // End code for unit testing implementation of NativeMovRegMemPatching class |
duke@435 | 779 | |
duke@435 | 780 | |
duke@435 | 781 | //-------------------------------------------------------------------------------- |
duke@435 | 782 | |
duke@435 | 783 | |
duke@435 | 784 | void NativeJump::verify() { |
duke@435 | 785 | NativeInstruction::verify(); |
duke@435 | 786 | int i0 = long_at(sethi_offset); |
duke@435 | 787 | int i1 = long_at(jmpl_offset); |
duke@435 | 788 | assert((int)jmpl_offset == (int)NativeMovConstReg::add_offset, "sethi size ok"); |
duke@435 | 789 | // verify the pattern "sethi %hi22(imm), treg ; jmpl treg, %lo10(imm), lreg" |
duke@435 | 790 | Register rd = inv_rd(i0); |
duke@435 | 791 | #ifndef _LP64 |
duke@435 | 792 | if (!(is_op2(i0, Assembler::sethi_op2) && rd != G0 && |
duke@435 | 793 | (is_op3(i1, Assembler::jmpl_op3, Assembler::arith_op) || |
duke@435 | 794 | (TraceJumps && is_op3(i1, Assembler::add_op3, Assembler::arith_op))) && |
duke@435 | 795 | inv_immed(i1) && (unsigned)get_simm13(i1) < (1 << 10) && |
duke@435 | 796 | rd == inv_rs1(i1))) { |
duke@435 | 797 | fatal("not a jump_to instruction"); |
duke@435 | 798 | } |
duke@435 | 799 | #else |
duke@435 | 800 | // In LP64, the jump instruction location varies for non relocatable |
duke@435 | 801 | // jumps, for example is could be sethi, xor, jmp instead of the |
duke@435 | 802 | // 7 instructions for sethi. So let's check sethi only. |
duke@435 | 803 | if (!is_op2(i0, Assembler::sethi_op2) && rd != G0 ) { |
duke@435 | 804 | fatal("not a jump_to instruction"); |
duke@435 | 805 | } |
duke@435 | 806 | #endif |
duke@435 | 807 | } |
duke@435 | 808 | |
duke@435 | 809 | |
duke@435 | 810 | void NativeJump::print() { |
duke@435 | 811 | tty->print_cr(INTPTR_FORMAT ": jmpl reg, " INTPTR_FORMAT, instruction_address(), jump_destination()); |
duke@435 | 812 | } |
duke@435 | 813 | |
duke@435 | 814 | |
duke@435 | 815 | // Code for unit testing implementation of NativeJump class |
duke@435 | 816 | void NativeJump::test() { |
duke@435 | 817 | #ifdef ASSERT |
duke@435 | 818 | ResourceMark rm; |
duke@435 | 819 | CodeBuffer cb("test", 100, 100); |
duke@435 | 820 | MacroAssembler* a = new MacroAssembler(&cb); |
duke@435 | 821 | NativeJump* nj; |
duke@435 | 822 | uint idx; |
duke@435 | 823 | int offsets[] = { |
duke@435 | 824 | 0x0, |
duke@435 | 825 | 0xffffffff, |
duke@435 | 826 | 0x7fffffff, |
duke@435 | 827 | 0x80000000, |
duke@435 | 828 | 4096, |
duke@435 | 829 | 4097, |
duke@435 | 830 | 0x20, |
duke@435 | 831 | 0x4000, |
duke@435 | 832 | }; |
duke@435 | 833 | |
duke@435 | 834 | VM_Version::allow_all(); |
duke@435 | 835 | |
duke@435 | 836 | a->sethi(0x7fffbbbb, I3, true, RelocationHolder::none); |
duke@435 | 837 | a->jmpl(I3, low10(0x7fffbbbb), G0, RelocationHolder::none); |
duke@435 | 838 | a->delayed()->nop(); |
duke@435 | 839 | a->sethi(0x7fffbbbb, I3, true, RelocationHolder::none); |
duke@435 | 840 | a->jmpl(I3, low10(0x7fffbbbb), L3, RelocationHolder::none); |
duke@435 | 841 | a->delayed()->nop(); |
duke@435 | 842 | |
duke@435 | 843 | nj = nativeJump_at( cb.code_begin() ); |
duke@435 | 844 | nj->print(); |
duke@435 | 845 | |
duke@435 | 846 | nj = nativeJump_at( nj->next_instruction_address() ); |
duke@435 | 847 | for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) { |
duke@435 | 848 | nj->set_jump_destination( nj->instruction_address() + offsets[idx] ); |
duke@435 | 849 | assert(nj->jump_destination() == (nj->instruction_address() + offsets[idx]), "check unit test"); |
duke@435 | 850 | nj->print(); |
duke@435 | 851 | } |
duke@435 | 852 | |
duke@435 | 853 | VM_Version::revert(); |
duke@435 | 854 | #endif // ASSERT |
duke@435 | 855 | } |
duke@435 | 856 | // End code for unit testing implementation of NativeJump class |
duke@435 | 857 | |
duke@435 | 858 | |
duke@435 | 859 | void NativeJump::insert(address code_pos, address entry) { |
duke@435 | 860 | Unimplemented(); |
duke@435 | 861 | } |
duke@435 | 862 | |
duke@435 | 863 | // MT safe inserting of a jump over an unknown instruction sequence (used by nmethod::makeZombie) |
duke@435 | 864 | // The problem: jump_to <dest> is a 3-word instruction (including its delay slot). |
duke@435 | 865 | // Atomic write can be only with 1 word. |
duke@435 | 866 | void NativeJump::patch_verified_entry(address entry, address verified_entry, address dest) { |
duke@435 | 867 | // Here's one way to do it: Pre-allocate a three-word jump sequence somewhere |
duke@435 | 868 | // in the header of the nmethod, within a short branch's span of the patch point. |
duke@435 | 869 | // Set up the jump sequence using NativeJump::insert, and then use an annulled |
duke@435 | 870 | // unconditional branch at the target site (an atomic 1-word update). |
duke@435 | 871 | // Limitations: You can only patch nmethods, with any given nmethod patched at |
duke@435 | 872 | // most once, and the patch must be in the nmethod's header. |
duke@435 | 873 | // It's messy, but you can ask the CodeCache for the nmethod containing the |
duke@435 | 874 | // target address. |
duke@435 | 875 | |
duke@435 | 876 | // %%%%% For now, do something MT-stupid: |
duke@435 | 877 | ResourceMark rm; |
duke@435 | 878 | int code_size = 1 * BytesPerInstWord; |
duke@435 | 879 | CodeBuffer cb(verified_entry, code_size + 1); |
duke@435 | 880 | MacroAssembler* a = new MacroAssembler(&cb); |
duke@435 | 881 | if (VM_Version::v9_instructions_work()) { |
duke@435 | 882 | a->ldsw(G0, 0, O7); // "ld" must agree with code in the signal handler |
duke@435 | 883 | } else { |
duke@435 | 884 | a->lduw(G0, 0, O7); // "ld" must agree with code in the signal handler |
duke@435 | 885 | } |
duke@435 | 886 | ICache::invalidate_range(verified_entry, code_size); |
duke@435 | 887 | } |
duke@435 | 888 | |
duke@435 | 889 | |
duke@435 | 890 | void NativeIllegalInstruction::insert(address code_pos) { |
duke@435 | 891 | NativeIllegalInstruction* nii = (NativeIllegalInstruction*) nativeInstruction_at(code_pos); |
duke@435 | 892 | nii->set_long_at(0, illegal_instruction()); |
duke@435 | 893 | } |
duke@435 | 894 | |
duke@435 | 895 | static int illegal_instruction_bits = 0; |
duke@435 | 896 | |
duke@435 | 897 | int NativeInstruction::illegal_instruction() { |
duke@435 | 898 | if (illegal_instruction_bits == 0) { |
duke@435 | 899 | ResourceMark rm; |
duke@435 | 900 | char buf[40]; |
duke@435 | 901 | CodeBuffer cbuf((address)&buf[0], 20); |
duke@435 | 902 | MacroAssembler* a = new MacroAssembler(&cbuf); |
duke@435 | 903 | address ia = a->pc(); |
duke@435 | 904 | a->trap(ST_RESERVED_FOR_USER_0 + 1); |
duke@435 | 905 | int bits = *(int*)ia; |
duke@435 | 906 | assert(is_op3(bits, Assembler::trap_op3, Assembler::arith_op), "bad instruction"); |
duke@435 | 907 | illegal_instruction_bits = bits; |
duke@435 | 908 | assert(illegal_instruction_bits != 0, "oops"); |
duke@435 | 909 | } |
duke@435 | 910 | return illegal_instruction_bits; |
duke@435 | 911 | } |
duke@435 | 912 | |
duke@435 | 913 | static int ic_miss_trap_bits = 0; |
duke@435 | 914 | |
duke@435 | 915 | bool NativeInstruction::is_ic_miss_trap() { |
duke@435 | 916 | if (ic_miss_trap_bits == 0) { |
duke@435 | 917 | ResourceMark rm; |
duke@435 | 918 | char buf[40]; |
duke@435 | 919 | CodeBuffer cbuf((address)&buf[0], 20); |
duke@435 | 920 | MacroAssembler* a = new MacroAssembler(&cbuf); |
duke@435 | 921 | address ia = a->pc(); |
duke@435 | 922 | a->trap(Assembler::notEqual, Assembler::ptr_cc, G0, ST_RESERVED_FOR_USER_0 + 2); |
duke@435 | 923 | int bits = *(int*)ia; |
duke@435 | 924 | assert(is_op3(bits, Assembler::trap_op3, Assembler::arith_op), "bad instruction"); |
duke@435 | 925 | ic_miss_trap_bits = bits; |
duke@435 | 926 | assert(ic_miss_trap_bits != 0, "oops"); |
duke@435 | 927 | } |
duke@435 | 928 | return long_at(0) == ic_miss_trap_bits; |
duke@435 | 929 | } |
duke@435 | 930 | |
duke@435 | 931 | |
duke@435 | 932 | bool NativeInstruction::is_illegal() { |
duke@435 | 933 | if (illegal_instruction_bits == 0) { |
duke@435 | 934 | return false; |
duke@435 | 935 | } |
duke@435 | 936 | return long_at(0) == illegal_instruction_bits; |
duke@435 | 937 | } |
duke@435 | 938 | |
duke@435 | 939 | |
duke@435 | 940 | void NativeGeneralJump::verify() { |
duke@435 | 941 | assert(((NativeInstruction *)this)->is_jump() || |
duke@435 | 942 | ((NativeInstruction *)this)->is_cond_jump(), "not a general jump instruction"); |
duke@435 | 943 | } |
duke@435 | 944 | |
duke@435 | 945 | |
duke@435 | 946 | void NativeGeneralJump::insert_unconditional(address code_pos, address entry) { |
duke@435 | 947 | Assembler::Condition condition = Assembler::always; |
duke@435 | 948 | int x = Assembler::op2(Assembler::br_op2) | Assembler::annul(false) | |
duke@435 | 949 | Assembler::cond(condition) | Assembler::wdisp((intptr_t)entry, (intptr_t)code_pos, 22); |
duke@435 | 950 | NativeGeneralJump* ni = (NativeGeneralJump*) nativeInstruction_at(code_pos); |
duke@435 | 951 | ni->set_long_at(0, x); |
duke@435 | 952 | } |
duke@435 | 953 | |
duke@435 | 954 | |
duke@435 | 955 | // MT-safe patching of a jmp instruction (and following word). |
duke@435 | 956 | // First patches the second word, and then atomicly replaces |
duke@435 | 957 | // the first word with the first new instruction word. |
duke@435 | 958 | // Other processors might briefly see the old first word |
duke@435 | 959 | // followed by the new second word. This is OK if the old |
duke@435 | 960 | // second word is harmless, and the new second word may be |
duke@435 | 961 | // harmlessly executed in the delay slot of the call. |
duke@435 | 962 | void NativeGeneralJump::replace_mt_safe(address instr_addr, address code_buffer) { |
duke@435 | 963 | assert(Patching_lock->is_locked() || |
duke@435 | 964 | SafepointSynchronize::is_at_safepoint(), "concurrent code patching"); |
duke@435 | 965 | assert (instr_addr != NULL, "illegal address for code patching"); |
duke@435 | 966 | NativeGeneralJump* h_jump = nativeGeneralJump_at (instr_addr); // checking that it is a call |
duke@435 | 967 | assert(NativeGeneralJump::instruction_size == 8, "wrong instruction size; must be 8"); |
duke@435 | 968 | int i0 = ((int*)code_buffer)[0]; |
duke@435 | 969 | int i1 = ((int*)code_buffer)[1]; |
duke@435 | 970 | int* contention_addr = (int*) h_jump->addr_at(1*BytesPerInstWord); |
duke@435 | 971 | assert(inv_op(*contention_addr) == Assembler::arith_op || |
duke@435 | 972 | *contention_addr == nop_instruction() || !VM_Version::v9_instructions_work(), |
duke@435 | 973 | "must not interfere with original call"); |
duke@435 | 974 | // The set_long_at calls do the ICacheInvalidate so we just need to do them in reverse order |
duke@435 | 975 | h_jump->set_long_at(1*BytesPerInstWord, i1); |
duke@435 | 976 | h_jump->set_long_at(0*BytesPerInstWord, i0); |
duke@435 | 977 | // NOTE: It is possible that another thread T will execute |
duke@435 | 978 | // only the second patched word. |
duke@435 | 979 | // In other words, since the original instruction is this |
duke@435 | 980 | // jmp patching_stub; nop (NativeGeneralJump) |
duke@435 | 981 | // and the new sequence from the buffer is this: |
duke@435 | 982 | // sethi %hi(K), %r; add %r, %lo(K), %r (NativeMovConstReg) |
duke@435 | 983 | // what T will execute is this: |
duke@435 | 984 | // jmp patching_stub; add %r, %lo(K), %r |
duke@435 | 985 | // thereby putting garbage into %r before calling the patching stub. |
duke@435 | 986 | // This is OK, because the patching stub ignores the value of %r. |
duke@435 | 987 | |
duke@435 | 988 | // Make sure the first-patched instruction, which may co-exist |
duke@435 | 989 | // briefly with the call, will do something harmless. |
duke@435 | 990 | assert(inv_op(*contention_addr) == Assembler::arith_op || |
duke@435 | 991 | *contention_addr == nop_instruction() || !VM_Version::v9_instructions_work(), |
duke@435 | 992 | "must not interfere with original call"); |
duke@435 | 993 | } |