duke@435: /* hseigel@5784: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" twisti@4323: #include "asm/macroAssembler.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "nativeInst_sparc.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "runtime/handles.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "runtime/stubRoutines.hpp" stefank@2314: #include "utilities/ostream.hpp" stefank@2314: #ifdef COMPILER1 stefank@2314: #include "c1/c1_Runtime1.hpp" stefank@2314: #endif duke@435: duke@435: kamg@551: bool NativeInstruction::is_dtrace_trap() { kamg@551: return !is_nop(); kamg@551: } kamg@551: duke@435: void NativeInstruction::set_data64_sethi(address instaddr, intptr_t x) { duke@435: ResourceMark rm; duke@435: CodeBuffer buf(instaddr, 10 * BytesPerInstWord ); duke@435: MacroAssembler* _masm = new MacroAssembler(&buf); duke@435: Register destreg; duke@435: duke@435: destreg = inv_rd(*(unsigned int *)instaddr); duke@435: // Generate a the new sequence twisti@1162: _masm->patchable_sethi(x, destreg); duke@435: ICache::invalidate_range(instaddr, 7 * BytesPerInstWord); duke@435: } duke@435: never@2657: void NativeInstruction::verify_data64_sethi(address instaddr, intptr_t x) { never@2657: ResourceMark rm; never@2657: unsigned char buffer[10 * BytesPerInstWord]; never@2657: CodeBuffer buf(buffer, 10 * BytesPerInstWord); never@2657: MacroAssembler masm(&buf); never@2657: never@2657: Register destreg = inv_rd(*(unsigned int *)instaddr); never@2657: // Generate the proper sequence into a temporary buffer and compare never@2657: // it with the original sequence. never@2657: masm.patchable_sethi(x, destreg); never@2657: int len = buffer - masm.pc(); never@2657: for (int i = 0; i < len; i++) { never@2657: assert(instaddr[i] == buffer[i], "instructions must match"); never@2657: } never@2657: } never@2657: duke@435: void NativeInstruction::verify() { duke@435: // make sure code pattern is actually an instruction address duke@435: address addr = addr_at(0); duke@435: if (addr == 0 || ((intptr_t)addr & 3) != 0) { duke@435: fatal("not an instruction address"); duke@435: } duke@435: } duke@435: duke@435: void NativeInstruction::print() { duke@435: tty->print_cr(INTPTR_FORMAT ": 0x%x", addr_at(0), long_at(0)); duke@435: } duke@435: duke@435: void NativeInstruction::set_long_at(int offset, int i) { duke@435: address addr = addr_at(offset); duke@435: *(int*)addr = i; duke@435: ICache::invalidate_word(addr); duke@435: } duke@435: duke@435: void NativeInstruction::set_jlong_at(int offset, jlong i) { duke@435: address addr = addr_at(offset); duke@435: *(jlong*)addr = i; duke@435: // Don't need to invalidate 2 words here, because duke@435: // the flush instruction operates on doublewords. duke@435: ICache::invalidate_word(addr); duke@435: } duke@435: duke@435: void NativeInstruction::set_addr_at(int offset, address x) { duke@435: address addr = addr_at(offset); duke@435: assert( ((intptr_t)addr & (wordSize-1)) == 0, "set_addr_at bad address alignment"); duke@435: *(uintptr_t*)addr = (uintptr_t)x; duke@435: // Don't need to invalidate 2 words here in the 64-bit case, duke@435: // because the flush instruction operates on doublewords. duke@435: ICache::invalidate_word(addr); duke@435: // The Intel code has this assertion for NativeCall::set_destination, duke@435: // NativeMovConstReg::set_data, NativeMovRegMem::set_offset, duke@435: // NativeJump::set_jump_destination, and NativePushImm32::set_data duke@435: //assert (Patching_lock->owned_by_self(), "must hold lock to patch instruction") duke@435: } duke@435: duke@435: bool NativeInstruction::is_zero_test(Register ®) { duke@435: int x = long_at(0); duke@435: Assembler::op3s temp = (Assembler::op3s) (Assembler::sub_op3 | Assembler::cc_bit_op3); duke@435: if (is_op3(x, temp, Assembler::arith_op) && duke@435: inv_immed(x) && inv_rd(x) == G0) { duke@435: if (inv_rs1(x) == G0) { duke@435: reg = inv_rs2(x); duke@435: return true; duke@435: } else if (inv_rs2(x) == G0) { duke@435: reg = inv_rs1(x); duke@435: return true; duke@435: } duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: bool NativeInstruction::is_load_store_with_small_offset(Register reg) { duke@435: int x = long_at(0); duke@435: if (is_op(x, Assembler::ldst_op) && duke@435: inv_rs1(x) == reg && inv_immed(x)) { duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: void NativeCall::verify() { duke@435: NativeInstruction::verify(); duke@435: // make sure code pattern is actually a call instruction duke@435: if (!is_op(long_at(0), Assembler::call_op)) { duke@435: fatal("not a call"); duke@435: } duke@435: } duke@435: duke@435: void NativeCall::print() { duke@435: tty->print_cr(INTPTR_FORMAT ": call " INTPTR_FORMAT, instruction_address(), destination()); duke@435: } duke@435: duke@435: duke@435: // MT-safe patching of a call instruction (and following word). duke@435: // First patches the second word, and then atomicly replaces duke@435: // the first word with the first new instruction word. duke@435: // Other processors might briefly see the old first word duke@435: // followed by the new second word. This is OK if the old duke@435: // second word is harmless, and the new second word may be duke@435: // harmlessly executed in the delay slot of the call. duke@435: void NativeCall::replace_mt_safe(address instr_addr, address code_buffer) { duke@435: assert(Patching_lock->is_locked() || duke@435: SafepointSynchronize::is_at_safepoint(), "concurrent code patching"); duke@435: assert (instr_addr != NULL, "illegal address for code patching"); duke@435: NativeCall* n_call = nativeCall_at (instr_addr); // checking that it is a call duke@435: assert(NativeCall::instruction_size == 8, "wrong instruction size; must be 8"); duke@435: int i0 = ((int*)code_buffer)[0]; duke@435: int i1 = ((int*)code_buffer)[1]; duke@435: int* contention_addr = (int*) n_call->addr_at(1*BytesPerInstWord); duke@435: assert(inv_op(*contention_addr) == Assembler::arith_op || morris@5283: *contention_addr == nop_instruction(), duke@435: "must not interfere with original call"); duke@435: // The set_long_at calls do the ICacheInvalidate so we just need to do them in reverse order duke@435: n_call->set_long_at(1*BytesPerInstWord, i1); duke@435: n_call->set_long_at(0*BytesPerInstWord, i0); duke@435: // NOTE: It is possible that another thread T will execute duke@435: // only the second patched word. duke@435: // In other words, since the original instruction is this duke@435: // call patching_stub; nop (NativeCall) duke@435: // and the new sequence from the buffer is this: duke@435: // sethi %hi(K), %r; add %r, %lo(K), %r (NativeMovConstReg) duke@435: // what T will execute is this: duke@435: // call patching_stub; add %r, %lo(K), %r duke@435: // thereby putting garbage into %r before calling the patching stub. duke@435: // This is OK, because the patching stub ignores the value of %r. duke@435: duke@435: // Make sure the first-patched instruction, which may co-exist duke@435: // briefly with the call, will do something harmless. duke@435: assert(inv_op(*contention_addr) == Assembler::arith_op || morris@5283: *contention_addr == nop_instruction(), duke@435: "must not interfere with original call"); duke@435: } duke@435: duke@435: // Similar to replace_mt_safe, but just changes the destination. The duke@435: // important thing is that free-running threads are able to execute this duke@435: // call instruction at all times. Thus, the displacement field must be duke@435: // instruction-word-aligned. This is always true on SPARC. duke@435: // duke@435: // Used in the runtime linkage of calls; see class CompiledIC. duke@435: void NativeCall::set_destination_mt_safe(address dest) { duke@435: assert(Patching_lock->is_locked() || duke@435: SafepointSynchronize::is_at_safepoint(), "concurrent code patching"); duke@435: // set_destination uses set_long_at which does the ICache::invalidate duke@435: set_destination(dest); duke@435: } duke@435: duke@435: // Code for unit testing implementation of NativeCall class duke@435: void NativeCall::test() { duke@435: #ifdef ASSERT duke@435: ResourceMark rm; duke@435: CodeBuffer cb("test", 100, 100); duke@435: MacroAssembler* a = new MacroAssembler(&cb); duke@435: NativeCall *nc; duke@435: uint idx; duke@435: int offsets[] = { duke@435: 0x0, duke@435: 0xfffffff0, duke@435: 0x7ffffff0, duke@435: 0x80000000, duke@435: 0x20, duke@435: 0x4000, duke@435: }; duke@435: duke@435: VM_Version::allow_all(); duke@435: duke@435: a->call( a->pc(), relocInfo::none ); duke@435: a->delayed()->nop(); twisti@2103: nc = nativeCall_at( cb.insts_begin() ); duke@435: nc->print(); duke@435: duke@435: nc = nativeCall_overwriting_at( nc->next_instruction_address() ); duke@435: for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) { twisti@2103: nc->set_destination( cb.insts_begin() + offsets[idx] ); twisti@2103: assert(nc->destination() == (cb.insts_begin() + offsets[idx]), "check unit test"); duke@435: nc->print(); duke@435: } duke@435: twisti@2103: nc = nativeCall_before( cb.insts_begin() + 8 ); duke@435: nc->print(); duke@435: duke@435: VM_Version::revert(); duke@435: #endif duke@435: } duke@435: // End code for unit testing implementation of NativeCall class duke@435: duke@435: //------------------------------------------------------------------- duke@435: duke@435: #ifdef _LP64 duke@435: duke@435: void NativeFarCall::set_destination(address dest) { duke@435: // Address materialized in the instruction stream, so nothing to do. duke@435: return; duke@435: #if 0 // What we'd do if we really did want to change the destination duke@435: if (destination() == dest) { duke@435: return; duke@435: } duke@435: ResourceMark rm; duke@435: CodeBuffer buf(addr_at(0), instruction_size + 1); duke@435: MacroAssembler* _masm = new MacroAssembler(&buf); duke@435: // Generate the new sequence twisti@1162: AddressLiteral(dest); twisti@1162: _masm->jumpl_to(dest, O7, O7); duke@435: ICache::invalidate_range(addr_at(0), instruction_size ); duke@435: #endif duke@435: } duke@435: duke@435: void NativeFarCall::verify() { duke@435: // make sure code pattern is actually a jumpl_to instruction duke@435: assert((int)instruction_size == (int)NativeJump::instruction_size, "same as jump_to"); duke@435: assert((int)jmpl_offset == (int)NativeMovConstReg::add_offset, "sethi size ok"); duke@435: nativeJump_at(addr_at(0))->verify(); duke@435: } duke@435: duke@435: bool NativeFarCall::is_call_at(address instr) { duke@435: return nativeInstruction_at(instr)->is_sethi(); duke@435: } duke@435: duke@435: void NativeFarCall::print() { duke@435: tty->print_cr(INTPTR_FORMAT ": call " INTPTR_FORMAT, instruction_address(), destination()); duke@435: } duke@435: duke@435: bool NativeFarCall::destination_is_compiled_verified_entry_point() { duke@435: nmethod* callee = CodeCache::find_nmethod(destination()); duke@435: if (callee == NULL) { duke@435: return false; duke@435: } else { duke@435: return destination() == callee->verified_entry_point(); duke@435: } duke@435: } duke@435: duke@435: // MT-safe patching of a far call. duke@435: void NativeFarCall::replace_mt_safe(address instr_addr, address code_buffer) { duke@435: Unimplemented(); duke@435: } duke@435: duke@435: // Code for unit testing implementation of NativeFarCall class duke@435: void NativeFarCall::test() { duke@435: Unimplemented(); duke@435: } duke@435: // End code for unit testing implementation of NativeFarCall class duke@435: duke@435: #endif // _LP64 duke@435: duke@435: //------------------------------------------------------------------- duke@435: duke@435: duke@435: void NativeMovConstReg::verify() { duke@435: NativeInstruction::verify(); coleenp@4037: // make sure code pattern is actually a "set_metadata" synthetic instruction duke@435: // see MacroAssembler::set_oop() duke@435: int i0 = long_at(sethi_offset); duke@435: int i1 = long_at(add_offset); duke@435: duke@435: // verify the pattern "sethi %hi22(imm), reg ; add reg, %lo10(imm), reg" duke@435: Register rd = inv_rd(i0); duke@435: #ifndef _LP64 duke@435: if (!(is_op2(i0, Assembler::sethi_op2) && rd != G0 && duke@435: is_op3(i1, Assembler::add_op3, Assembler::arith_op) && duke@435: inv_immed(i1) && (unsigned)get_simm13(i1) < (1 << 10) && duke@435: rd == inv_rs1(i1) && rd == inv_rd(i1))) { coleenp@4037: fatal("not a set_metadata"); duke@435: } duke@435: #else duke@435: if (!is_op2(i0, Assembler::sethi_op2) && rd != G0 ) { coleenp@4037: fatal("not a set_metadata"); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: duke@435: void NativeMovConstReg::print() { duke@435: tty->print_cr(INTPTR_FORMAT ": mov reg, " INTPTR_FORMAT, instruction_address(), data()); duke@435: } duke@435: duke@435: duke@435: #ifdef _LP64 duke@435: intptr_t NativeMovConstReg::data() const { duke@435: return data64(addr_at(sethi_offset), long_at(add_offset)); duke@435: } duke@435: #else duke@435: intptr_t NativeMovConstReg::data() const { duke@435: return data32(long_at(sethi_offset), long_at(add_offset)); duke@435: } duke@435: #endif duke@435: duke@435: duke@435: void NativeMovConstReg::set_data(intptr_t x) { duke@435: #ifdef _LP64 duke@435: set_data64_sethi(addr_at(sethi_offset), x); duke@435: #else duke@435: set_long_at(sethi_offset, set_data32_sethi( long_at(sethi_offset), x)); duke@435: #endif duke@435: set_long_at(add_offset, set_data32_simm13( long_at(add_offset), x)); duke@435: duke@435: // also store the value into an oop_Relocation cell, if any twisti@1918: CodeBlob* cb = CodeCache::find_blob(instruction_address()); twisti@1918: nmethod* nm = cb ? cb->as_nmethod_or_null() : NULL; duke@435: if (nm != NULL) { duke@435: RelocIterator iter(nm, instruction_address(), next_instruction_address()); duke@435: oop* oop_addr = NULL; coleenp@4037: Metadata** metadata_addr = NULL; duke@435: while (iter.next()) { duke@435: if (iter.type() == relocInfo::oop_type) { duke@435: oop_Relocation *r = iter.oop_reloc(); duke@435: if (oop_addr == NULL) { duke@435: oop_addr = r->oop_addr(); hseigel@5784: *oop_addr = cast_to_oop(x); duke@435: } else { duke@435: assert(oop_addr == r->oop_addr(), "must be only one set-oop here"); duke@435: } duke@435: } coleenp@4037: if (iter.type() == relocInfo::metadata_type) { coleenp@4037: metadata_Relocation *r = iter.metadata_reloc(); coleenp@4037: if (metadata_addr == NULL) { coleenp@4037: metadata_addr = r->metadata_addr(); coleenp@4037: *metadata_addr = (Metadata*)x; coleenp@4037: } else { coleenp@4037: assert(metadata_addr == r->metadata_addr(), "must be only one set-metadata here"); coleenp@4037: } coleenp@4037: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: // Code for unit testing implementation of NativeMovConstReg class duke@435: void NativeMovConstReg::test() { duke@435: #ifdef ASSERT duke@435: ResourceMark rm; duke@435: CodeBuffer cb("test", 100, 100); duke@435: MacroAssembler* a = new MacroAssembler(&cb); duke@435: NativeMovConstReg* nm; duke@435: uint idx; duke@435: int offsets[] = { duke@435: 0x0, duke@435: 0x7fffffff, duke@435: 0x80000000, duke@435: 0xffffffff, duke@435: 0x20, duke@435: 4096, duke@435: 4097, duke@435: }; duke@435: duke@435: VM_Version::allow_all(); duke@435: twisti@1162: AddressLiteral al1(0xaaaabbbb, relocInfo::external_word_type); twisti@1162: a->sethi(al1, I3); twisti@1162: a->add(I3, al1.low10(), I3); twisti@1162: AddressLiteral al2(0xccccdddd, relocInfo::external_word_type); twisti@1162: a->sethi(al2, O2); twisti@1162: a->add(O2, al2.low10(), O2); duke@435: twisti@2103: nm = nativeMovConstReg_at( cb.insts_begin() ); duke@435: nm->print(); duke@435: duke@435: nm = nativeMovConstReg_at( nm->next_instruction_address() ); duke@435: for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) { duke@435: nm->set_data( offsets[idx] ); duke@435: assert(nm->data() == offsets[idx], "check unit test"); duke@435: } duke@435: nm->print(); duke@435: duke@435: VM_Version::revert(); duke@435: #endif duke@435: } duke@435: // End code for unit testing implementation of NativeMovConstReg class duke@435: duke@435: //------------------------------------------------------------------- duke@435: duke@435: void NativeMovConstRegPatching::verify() { duke@435: NativeInstruction::verify(); duke@435: // Make sure code pattern is sethi/nop/add. duke@435: int i0 = long_at(sethi_offset); duke@435: int i1 = long_at(nop_offset); duke@435: int i2 = long_at(add_offset); duke@435: assert((int)nop_offset == (int)NativeMovConstReg::add_offset, "sethi size ok"); duke@435: duke@435: // Verify the pattern "sethi %hi22(imm), reg; nop; add reg, %lo10(imm), reg" duke@435: // The casual reader should note that on Sparc a nop is a special case if sethi duke@435: // in which the destination register is %g0. duke@435: Register rd0 = inv_rd(i0); duke@435: Register rd1 = inv_rd(i1); duke@435: if (!(is_op2(i0, Assembler::sethi_op2) && rd0 != G0 && duke@435: is_op2(i1, Assembler::sethi_op2) && rd1 == G0 && // nop is a special case of sethi duke@435: is_op3(i2, Assembler::add_op3, Assembler::arith_op) && duke@435: inv_immed(i2) && (unsigned)get_simm13(i2) < (1 << 10) && duke@435: rd0 == inv_rs1(i2) && rd0 == inv_rd(i2))) { coleenp@4037: fatal("not a set_metadata"); duke@435: } duke@435: } duke@435: duke@435: duke@435: void NativeMovConstRegPatching::print() { duke@435: tty->print_cr(INTPTR_FORMAT ": mov reg, " INTPTR_FORMAT, instruction_address(), data()); duke@435: } duke@435: duke@435: duke@435: int NativeMovConstRegPatching::data() const { duke@435: #ifdef _LP64 duke@435: return data64(addr_at(sethi_offset), long_at(add_offset)); duke@435: #else duke@435: return data32(long_at(sethi_offset), long_at(add_offset)); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: void NativeMovConstRegPatching::set_data(int x) { duke@435: #ifdef _LP64 duke@435: set_data64_sethi(addr_at(sethi_offset), x); duke@435: #else duke@435: set_long_at(sethi_offset, set_data32_sethi(long_at(sethi_offset), x)); duke@435: #endif duke@435: set_long_at(add_offset, set_data32_simm13(long_at(add_offset), x)); duke@435: duke@435: // also store the value into an oop_Relocation cell, if any twisti@1918: CodeBlob* cb = CodeCache::find_blob(instruction_address()); twisti@1918: nmethod* nm = cb ? cb->as_nmethod_or_null() : NULL; duke@435: if (nm != NULL) { duke@435: RelocIterator iter(nm, instruction_address(), next_instruction_address()); duke@435: oop* oop_addr = NULL; coleenp@4037: Metadata** metadata_addr = NULL; duke@435: while (iter.next()) { duke@435: if (iter.type() == relocInfo::oop_type) { duke@435: oop_Relocation *r = iter.oop_reloc(); duke@435: if (oop_addr == NULL) { duke@435: oop_addr = r->oop_addr(); hseigel@5784: *oop_addr = cast_to_oop(x); duke@435: } else { duke@435: assert(oop_addr == r->oop_addr(), "must be only one set-oop here"); duke@435: } duke@435: } coleenp@4037: if (iter.type() == relocInfo::metadata_type) { coleenp@4037: metadata_Relocation *r = iter.metadata_reloc(); coleenp@4037: if (metadata_addr == NULL) { coleenp@4037: metadata_addr = r->metadata_addr(); coleenp@4037: *metadata_addr = (Metadata*)x; coleenp@4037: } else { coleenp@4037: assert(metadata_addr == r->metadata_addr(), "must be only one set-metadata here"); coleenp@4037: } coleenp@4037: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: // Code for unit testing implementation of NativeMovConstRegPatching class duke@435: void NativeMovConstRegPatching::test() { duke@435: #ifdef ASSERT duke@435: ResourceMark rm; duke@435: CodeBuffer cb("test", 100, 100); duke@435: MacroAssembler* a = new MacroAssembler(&cb); duke@435: NativeMovConstRegPatching* nm; duke@435: uint idx; duke@435: int offsets[] = { duke@435: 0x0, duke@435: 0x7fffffff, duke@435: 0x80000000, duke@435: 0xffffffff, duke@435: 0x20, duke@435: 4096, duke@435: 4097, duke@435: }; duke@435: duke@435: VM_Version::allow_all(); duke@435: twisti@1162: AddressLiteral al1(0xaaaabbbb, relocInfo::external_word_type); twisti@1162: a->sethi(al1, I3); duke@435: a->nop(); twisti@1162: a->add(I3, al1.low10(), I3); twisti@1162: AddressLiteral al2(0xccccdddd, relocInfo::external_word_type); twisti@1162: a->sethi(al2, O2); duke@435: a->nop(); twisti@1162: a->add(O2, al2.low10(), O2); duke@435: twisti@2103: nm = nativeMovConstRegPatching_at( cb.insts_begin() ); duke@435: nm->print(); duke@435: duke@435: nm = nativeMovConstRegPatching_at( nm->next_instruction_address() ); duke@435: for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) { duke@435: nm->set_data( offsets[idx] ); duke@435: assert(nm->data() == offsets[idx], "check unit test"); duke@435: } duke@435: nm->print(); duke@435: duke@435: VM_Version::revert(); duke@435: #endif // ASSERT duke@435: } duke@435: // End code for unit testing implementation of NativeMovConstRegPatching class duke@435: duke@435: duke@435: //------------------------------------------------------------------- duke@435: duke@435: duke@435: void NativeMovRegMem::copy_instruction_to(address new_instruction_address) { duke@435: Untested("copy_instruction_to"); duke@435: int instruction_size = next_instruction_address() - instruction_address(); duke@435: for (int i = 0; i < instruction_size; i += BytesPerInstWord) { duke@435: *(int*)(new_instruction_address + i) = *(int*)(address(this) + i); duke@435: } duke@435: } duke@435: duke@435: duke@435: void NativeMovRegMem::verify() { duke@435: NativeInstruction::verify(); duke@435: // make sure code pattern is actually a "ld" or "st" of some sort. duke@435: int i0 = long_at(0); duke@435: int op3 = inv_op3(i0); duke@435: duke@435: assert((int)add_offset == NativeMovConstReg::add_offset, "sethi size ok"); duke@435: duke@435: if (!(is_op(i0, Assembler::ldst_op) && duke@435: inv_immed(i0) && duke@435: 0 != (op3 < op3_ldst_int_limit duke@435: ? (1 << op3 ) & (op3_mask_ld | op3_mask_st) duke@435: : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf)))) duke@435: { duke@435: int i1 = long_at(ldst_offset); duke@435: Register rd = inv_rd(i0); duke@435: duke@435: op3 = inv_op3(i1); duke@435: if (!is_op(i1, Assembler::ldst_op) && rd == inv_rs2(i1) && duke@435: 0 != (op3 < op3_ldst_int_limit duke@435: ? (1 << op3 ) & (op3_mask_ld | op3_mask_st) duke@435: : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf))) { duke@435: fatal("not a ld* or st* op"); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void NativeMovRegMem::print() { duke@435: if (is_immediate()) { duke@435: tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + %x]", instruction_address(), offset()); duke@435: } else { duke@435: tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + reg]", instruction_address()); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Code for unit testing implementation of NativeMovRegMem class duke@435: void NativeMovRegMem::test() { duke@435: #ifdef ASSERT duke@435: ResourceMark rm; duke@435: CodeBuffer cb("test", 1000, 1000); duke@435: MacroAssembler* a = new MacroAssembler(&cb); duke@435: NativeMovRegMem* nm; duke@435: uint idx = 0; duke@435: uint idx1; duke@435: int offsets[] = { duke@435: 0x0, duke@435: 0xffffffff, duke@435: 0x7fffffff, duke@435: 0x80000000, duke@435: 4096, duke@435: 4097, duke@435: 0x20, duke@435: 0x4000, duke@435: }; duke@435: duke@435: VM_Version::allow_all(); duke@435: twisti@1162: AddressLiteral al1(0xffffffff, relocInfo::external_word_type); twisti@1162: AddressLiteral al2(0xaaaabbbb, relocInfo::external_word_type); twisti@1162: a->ldsw( G5, al1.low10(), G4 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->ldsw( G5, I3, G4 ); idx++; twisti@1162: a->ldsb( G5, al1.low10(), G4 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->ldsb( G5, I3, G4 ); idx++; twisti@1162: a->ldsh( G5, al1.low10(), G4 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->ldsh( G5, I3, G4 ); idx++; twisti@1162: a->lduw( G5, al1.low10(), G4 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->lduw( G5, I3, G4 ); idx++; twisti@1162: a->ldub( G5, al1.low10(), G4 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->ldub( G5, I3, G4 ); idx++; twisti@1162: a->lduh( G5, al1.low10(), G4 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->lduh( G5, I3, G4 ); idx++; twisti@1162: a->ldx( G5, al1.low10(), G4 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->ldx( G5, I3, G4 ); idx++; twisti@1162: a->ldd( G5, al1.low10(), G4 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->ldd( G5, I3, G4 ); idx++; duke@435: a->ldf( FloatRegisterImpl::D, O2, -1, F14 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->ldf( FloatRegisterImpl::S, O0, I3, F15 ); idx++; duke@435: twisti@1162: a->stw( G5, G4, al1.low10() ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->stw( G5, G4, I3 ); idx++; twisti@1162: a->stb( G5, G4, al1.low10() ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->stb( G5, G4, I3 ); idx++; twisti@1162: a->sth( G5, G4, al1.low10() ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->sth( G5, G4, I3 ); idx++; twisti@1162: a->stx( G5, G4, al1.low10() ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->stx( G5, G4, I3 ); idx++; twisti@1162: a->std( G5, G4, al1.low10() ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->std( G5, G4, I3 ); idx++; duke@435: a->stf( FloatRegisterImpl::S, F18, O2, -1 ); idx++; twisti@1162: a->sethi(al2, I3); a->add(I3, al2.low10(), I3); duke@435: a->stf( FloatRegisterImpl::S, F15, O0, I3 ); idx++; duke@435: twisti@2103: nm = nativeMovRegMem_at( cb.insts_begin() ); duke@435: nm->print(); duke@435: nm->set_offset( low10(0) ); duke@435: nm->print(); duke@435: nm->add_offset_in_bytes( low10(0xbb) * wordSize ); duke@435: nm->print(); duke@435: duke@435: while (--idx) { duke@435: nm = nativeMovRegMem_at( nm->next_instruction_address() ); duke@435: nm->print(); duke@435: for (idx1 = 0; idx1 < ARRAY_SIZE(offsets); idx1++) { duke@435: nm->set_offset( nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1] ); duke@435: assert(nm->offset() == (nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1]), duke@435: "check unit test"); duke@435: nm->print(); duke@435: } duke@435: nm->add_offset_in_bytes( low10(0xbb) * wordSize ); duke@435: nm->print(); duke@435: } duke@435: duke@435: VM_Version::revert(); duke@435: #endif // ASSERT duke@435: } duke@435: duke@435: // End code for unit testing implementation of NativeMovRegMem class duke@435: duke@435: //-------------------------------------------------------------------------------- duke@435: duke@435: duke@435: void NativeMovRegMemPatching::copy_instruction_to(address new_instruction_address) { duke@435: Untested("copy_instruction_to"); duke@435: int instruction_size = next_instruction_address() - instruction_address(); duke@435: for (int i = 0; i < instruction_size; i += wordSize) { duke@435: *(long*)(new_instruction_address + i) = *(long*)(address(this) + i); duke@435: } duke@435: } duke@435: duke@435: duke@435: void NativeMovRegMemPatching::verify() { duke@435: NativeInstruction::verify(); duke@435: // make sure code pattern is actually a "ld" or "st" of some sort. duke@435: int i0 = long_at(0); duke@435: int op3 = inv_op3(i0); duke@435: duke@435: assert((int)nop_offset == (int)NativeMovConstReg::add_offset, "sethi size ok"); duke@435: duke@435: if (!(is_op(i0, Assembler::ldst_op) && duke@435: inv_immed(i0) && duke@435: 0 != (op3 < op3_ldst_int_limit duke@435: ? (1 << op3 ) & (op3_mask_ld | op3_mask_st) duke@435: : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf)))) { duke@435: int i1 = long_at(ldst_offset); duke@435: Register rd = inv_rd(i0); duke@435: duke@435: op3 = inv_op3(i1); duke@435: if (!is_op(i1, Assembler::ldst_op) && rd == inv_rs2(i1) && duke@435: 0 != (op3 < op3_ldst_int_limit duke@435: ? (1 << op3 ) & (op3_mask_ld | op3_mask_st) duke@435: : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf))) { duke@435: fatal("not a ld* or st* op"); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void NativeMovRegMemPatching::print() { duke@435: if (is_immediate()) { duke@435: tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + %x]", instruction_address(), offset()); duke@435: } else { duke@435: tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + reg]", instruction_address()); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Code for unit testing implementation of NativeMovRegMemPatching class duke@435: void NativeMovRegMemPatching::test() { duke@435: #ifdef ASSERT duke@435: ResourceMark rm; duke@435: CodeBuffer cb("test", 1000, 1000); duke@435: MacroAssembler* a = new MacroAssembler(&cb); duke@435: NativeMovRegMemPatching* nm; duke@435: uint idx = 0; duke@435: uint idx1; duke@435: int offsets[] = { duke@435: 0x0, duke@435: 0xffffffff, duke@435: 0x7fffffff, duke@435: 0x80000000, duke@435: 4096, duke@435: 4097, duke@435: 0x20, duke@435: 0x4000, duke@435: }; duke@435: duke@435: VM_Version::allow_all(); duke@435: twisti@1162: AddressLiteral al(0xffffffff, relocInfo::external_word_type); twisti@1162: a->ldsw( G5, al.low10(), G4); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->ldsw( G5, I3, G4 ); idx++; twisti@1162: a->ldsb( G5, al.low10(), G4); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->ldsb( G5, I3, G4 ); idx++; twisti@1162: a->ldsh( G5, al.low10(), G4); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->ldsh( G5, I3, G4 ); idx++; twisti@1162: a->lduw( G5, al.low10(), G4); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->lduw( G5, I3, G4 ); idx++; twisti@1162: a->ldub( G5, al.low10(), G4); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->ldub( G5, I3, G4 ); idx++; twisti@1162: a->lduh( G5, al.low10(), G4); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->lduh( G5, I3, G4 ); idx++; twisti@1162: a->ldx( G5, al.low10(), G4); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); twisti@1162: a->ldx( G5, I3, G4 ); idx++; twisti@1162: a->ldd( G5, al.low10(), G4); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); twisti@1162: a->ldd( G5, I3, G4 ); idx++; twisti@1162: a->ldf( FloatRegisterImpl::D, O2, -1, F14 ); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); twisti@1162: a->ldf( FloatRegisterImpl::S, O0, I3, F15 ); idx++; duke@435: twisti@1162: a->stw( G5, G4, al.low10()); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->stw( G5, G4, I3 ); idx++; twisti@1162: a->stb( G5, G4, al.low10()); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->stb( G5, G4, I3 ); idx++; twisti@1162: a->sth( G5, G4, al.low10()); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->sth( G5, G4, I3 ); idx++; twisti@1162: a->stx( G5, G4, al.low10()); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->stx( G5, G4, I3 ); idx++; twisti@1162: a->std( G5, G4, al.low10()); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->std( G5, G4, I3 ); idx++; duke@435: a->stf( FloatRegisterImpl::S, F18, O2, -1 ); idx++; twisti@1162: a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3); duke@435: a->stf( FloatRegisterImpl::S, F15, O0, I3 ); idx++; duke@435: twisti@2103: nm = nativeMovRegMemPatching_at( cb.insts_begin() ); duke@435: nm->print(); duke@435: nm->set_offset( low10(0) ); duke@435: nm->print(); duke@435: nm->add_offset_in_bytes( low10(0xbb) * wordSize ); duke@435: nm->print(); duke@435: duke@435: while (--idx) { duke@435: nm = nativeMovRegMemPatching_at( nm->next_instruction_address() ); duke@435: nm->print(); duke@435: for (idx1 = 0; idx1 < ARRAY_SIZE(offsets); idx1++) { duke@435: nm->set_offset( nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1] ); duke@435: assert(nm->offset() == (nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1]), duke@435: "check unit test"); duke@435: nm->print(); duke@435: } duke@435: nm->add_offset_in_bytes( low10(0xbb) * wordSize ); duke@435: nm->print(); duke@435: } duke@435: duke@435: VM_Version::revert(); duke@435: #endif // ASSERT duke@435: } duke@435: // End code for unit testing implementation of NativeMovRegMemPatching class duke@435: duke@435: duke@435: //-------------------------------------------------------------------------------- duke@435: duke@435: duke@435: void NativeJump::verify() { duke@435: NativeInstruction::verify(); duke@435: int i0 = long_at(sethi_offset); duke@435: int i1 = long_at(jmpl_offset); duke@435: assert((int)jmpl_offset == (int)NativeMovConstReg::add_offset, "sethi size ok"); duke@435: // verify the pattern "sethi %hi22(imm), treg ; jmpl treg, %lo10(imm), lreg" duke@435: Register rd = inv_rd(i0); duke@435: #ifndef _LP64 duke@435: if (!(is_op2(i0, Assembler::sethi_op2) && rd != G0 && duke@435: (is_op3(i1, Assembler::jmpl_op3, Assembler::arith_op) || duke@435: (TraceJumps && is_op3(i1, Assembler::add_op3, Assembler::arith_op))) && duke@435: inv_immed(i1) && (unsigned)get_simm13(i1) < (1 << 10) && duke@435: rd == inv_rs1(i1))) { duke@435: fatal("not a jump_to instruction"); duke@435: } duke@435: #else duke@435: // In LP64, the jump instruction location varies for non relocatable duke@435: // jumps, for example is could be sethi, xor, jmp instead of the duke@435: // 7 instructions for sethi. So let's check sethi only. duke@435: if (!is_op2(i0, Assembler::sethi_op2) && rd != G0 ) { duke@435: fatal("not a jump_to instruction"); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: duke@435: void NativeJump::print() { duke@435: tty->print_cr(INTPTR_FORMAT ": jmpl reg, " INTPTR_FORMAT, instruction_address(), jump_destination()); duke@435: } duke@435: duke@435: duke@435: // Code for unit testing implementation of NativeJump class duke@435: void NativeJump::test() { duke@435: #ifdef ASSERT duke@435: ResourceMark rm; duke@435: CodeBuffer cb("test", 100, 100); duke@435: MacroAssembler* a = new MacroAssembler(&cb); duke@435: NativeJump* nj; duke@435: uint idx; duke@435: int offsets[] = { duke@435: 0x0, duke@435: 0xffffffff, duke@435: 0x7fffffff, duke@435: 0x80000000, duke@435: 4096, duke@435: 4097, duke@435: 0x20, duke@435: 0x4000, duke@435: }; duke@435: duke@435: VM_Version::allow_all(); duke@435: twisti@1162: AddressLiteral al(0x7fffbbbb, relocInfo::external_word_type); twisti@1162: a->sethi(al, I3); twisti@1162: a->jmpl(I3, al.low10(), G0, RelocationHolder::none); duke@435: a->delayed()->nop(); twisti@1162: a->sethi(al, I3); twisti@1162: a->jmpl(I3, al.low10(), L3, RelocationHolder::none); duke@435: a->delayed()->nop(); duke@435: twisti@2103: nj = nativeJump_at( cb.insts_begin() ); duke@435: nj->print(); duke@435: duke@435: nj = nativeJump_at( nj->next_instruction_address() ); duke@435: for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) { duke@435: nj->set_jump_destination( nj->instruction_address() + offsets[idx] ); duke@435: assert(nj->jump_destination() == (nj->instruction_address() + offsets[idx]), "check unit test"); duke@435: nj->print(); duke@435: } duke@435: duke@435: VM_Version::revert(); duke@435: #endif // ASSERT duke@435: } duke@435: // End code for unit testing implementation of NativeJump class duke@435: duke@435: duke@435: void NativeJump::insert(address code_pos, address entry) { duke@435: Unimplemented(); duke@435: } duke@435: duke@435: // MT safe inserting of a jump over an unknown instruction sequence (used by nmethod::makeZombie) duke@435: // The problem: jump_to is a 3-word instruction (including its delay slot). duke@435: // Atomic write can be only with 1 word. duke@435: void NativeJump::patch_verified_entry(address entry, address verified_entry, address dest) { duke@435: // Here's one way to do it: Pre-allocate a three-word jump sequence somewhere duke@435: // in the header of the nmethod, within a short branch's span of the patch point. duke@435: // Set up the jump sequence using NativeJump::insert, and then use an annulled duke@435: // unconditional branch at the target site (an atomic 1-word update). duke@435: // Limitations: You can only patch nmethods, with any given nmethod patched at duke@435: // most once, and the patch must be in the nmethod's header. duke@435: // It's messy, but you can ask the CodeCache for the nmethod containing the duke@435: // target address. duke@435: duke@435: // %%%%% For now, do something MT-stupid: duke@435: ResourceMark rm; duke@435: int code_size = 1 * BytesPerInstWord; duke@435: CodeBuffer cb(verified_entry, code_size + 1); duke@435: MacroAssembler* a = new MacroAssembler(&cb); morris@5283: a->ldsw(G0, 0, O7); // "ld" must agree with code in the signal handler duke@435: ICache::invalidate_range(verified_entry, code_size); duke@435: } duke@435: duke@435: duke@435: void NativeIllegalInstruction::insert(address code_pos) { duke@435: NativeIllegalInstruction* nii = (NativeIllegalInstruction*) nativeInstruction_at(code_pos); duke@435: nii->set_long_at(0, illegal_instruction()); duke@435: } duke@435: duke@435: static int illegal_instruction_bits = 0; duke@435: duke@435: int NativeInstruction::illegal_instruction() { duke@435: if (illegal_instruction_bits == 0) { duke@435: ResourceMark rm; duke@435: char buf[40]; duke@435: CodeBuffer cbuf((address)&buf[0], 20); duke@435: MacroAssembler* a = new MacroAssembler(&cbuf); duke@435: address ia = a->pc(); duke@435: a->trap(ST_RESERVED_FOR_USER_0 + 1); duke@435: int bits = *(int*)ia; duke@435: assert(is_op3(bits, Assembler::trap_op3, Assembler::arith_op), "bad instruction"); duke@435: illegal_instruction_bits = bits; duke@435: assert(illegal_instruction_bits != 0, "oops"); duke@435: } duke@435: return illegal_instruction_bits; duke@435: } duke@435: duke@435: static int ic_miss_trap_bits = 0; duke@435: duke@435: bool NativeInstruction::is_ic_miss_trap() { duke@435: if (ic_miss_trap_bits == 0) { duke@435: ResourceMark rm; duke@435: char buf[40]; duke@435: CodeBuffer cbuf((address)&buf[0], 20); duke@435: MacroAssembler* a = new MacroAssembler(&cbuf); duke@435: address ia = a->pc(); duke@435: a->trap(Assembler::notEqual, Assembler::ptr_cc, G0, ST_RESERVED_FOR_USER_0 + 2); duke@435: int bits = *(int*)ia; duke@435: assert(is_op3(bits, Assembler::trap_op3, Assembler::arith_op), "bad instruction"); duke@435: ic_miss_trap_bits = bits; duke@435: assert(ic_miss_trap_bits != 0, "oops"); duke@435: } duke@435: return long_at(0) == ic_miss_trap_bits; duke@435: } duke@435: duke@435: duke@435: bool NativeInstruction::is_illegal() { duke@435: if (illegal_instruction_bits == 0) { duke@435: return false; duke@435: } duke@435: return long_at(0) == illegal_instruction_bits; duke@435: } duke@435: duke@435: duke@435: void NativeGeneralJump::verify() { duke@435: assert(((NativeInstruction *)this)->is_jump() || duke@435: ((NativeInstruction *)this)->is_cond_jump(), "not a general jump instruction"); duke@435: } duke@435: duke@435: duke@435: void NativeGeneralJump::insert_unconditional(address code_pos, address entry) { duke@435: Assembler::Condition condition = Assembler::always; duke@435: int x = Assembler::op2(Assembler::br_op2) | Assembler::annul(false) | duke@435: Assembler::cond(condition) | Assembler::wdisp((intptr_t)entry, (intptr_t)code_pos, 22); duke@435: NativeGeneralJump* ni = (NativeGeneralJump*) nativeInstruction_at(code_pos); duke@435: ni->set_long_at(0, x); duke@435: } duke@435: duke@435: duke@435: // MT-safe patching of a jmp instruction (and following word). duke@435: // First patches the second word, and then atomicly replaces duke@435: // the first word with the first new instruction word. duke@435: // Other processors might briefly see the old first word duke@435: // followed by the new second word. This is OK if the old duke@435: // second word is harmless, and the new second word may be duke@435: // harmlessly executed in the delay slot of the call. duke@435: void NativeGeneralJump::replace_mt_safe(address instr_addr, address code_buffer) { duke@435: assert(Patching_lock->is_locked() || duke@435: SafepointSynchronize::is_at_safepoint(), "concurrent code patching"); duke@435: assert (instr_addr != NULL, "illegal address for code patching"); duke@435: NativeGeneralJump* h_jump = nativeGeneralJump_at (instr_addr); // checking that it is a call duke@435: assert(NativeGeneralJump::instruction_size == 8, "wrong instruction size; must be 8"); duke@435: int i0 = ((int*)code_buffer)[0]; duke@435: int i1 = ((int*)code_buffer)[1]; duke@435: int* contention_addr = (int*) h_jump->addr_at(1*BytesPerInstWord); duke@435: assert(inv_op(*contention_addr) == Assembler::arith_op || morris@5283: *contention_addr == nop_instruction(), duke@435: "must not interfere with original call"); duke@435: // The set_long_at calls do the ICacheInvalidate so we just need to do them in reverse order duke@435: h_jump->set_long_at(1*BytesPerInstWord, i1); duke@435: h_jump->set_long_at(0*BytesPerInstWord, i0); duke@435: // NOTE: It is possible that another thread T will execute duke@435: // only the second patched word. duke@435: // In other words, since the original instruction is this duke@435: // jmp patching_stub; nop (NativeGeneralJump) duke@435: // and the new sequence from the buffer is this: duke@435: // sethi %hi(K), %r; add %r, %lo(K), %r (NativeMovConstReg) duke@435: // what T will execute is this: duke@435: // jmp patching_stub; add %r, %lo(K), %r duke@435: // thereby putting garbage into %r before calling the patching stub. duke@435: // This is OK, because the patching stub ignores the value of %r. duke@435: duke@435: // Make sure the first-patched instruction, which may co-exist duke@435: // briefly with the call, will do something harmless. duke@435: assert(inv_op(*contention_addr) == Assembler::arith_op || morris@5283: *contention_addr == nop_instruction(), duke@435: "must not interfere with original call"); duke@435: }