Thu, 14 Apr 2011 13:45:41 -0700
Merge
duke@435 | 1 | /* |
iveresov@2686 | 2 | * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "asm/assembler.inline.hpp" |
stefank@2314 | 27 | #include "assembler_x86.inline.hpp" |
stefank@2314 | 28 | #include "code/relocInfo.hpp" |
stefank@2314 | 29 | #include "nativeInst_x86.hpp" |
stefank@2314 | 30 | #include "oops/oop.inline.hpp" |
stefank@2314 | 31 | #include "runtime/safepoint.hpp" |
duke@435 | 32 | |
duke@435 | 33 | |
never@2657 | 34 | void Relocation::pd_set_data_value(address x, intptr_t o, bool verify_only) { |
duke@435 | 35 | #ifdef AMD64 |
duke@435 | 36 | x += o; |
duke@435 | 37 | typedef Assembler::WhichOperand WhichOperand; |
never@739 | 38 | WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm, call32, narrow oop |
duke@435 | 39 | assert(which == Assembler::disp32_operand || |
kvn@599 | 40 | which == Assembler::narrow_oop_operand || |
never@739 | 41 | which == Assembler::imm_operand, "format unpacks ok"); |
never@739 | 42 | if (which == Assembler::imm_operand) { |
never@2657 | 43 | if (verify_only) { |
never@2657 | 44 | assert(*pd_address_in_code() == x, "instructions must match"); |
never@2657 | 45 | } else { |
never@2657 | 46 | *pd_address_in_code() = x; |
never@2657 | 47 | } |
kvn@599 | 48 | } else if (which == Assembler::narrow_oop_operand) { |
kvn@599 | 49 | address disp = Assembler::locate_operand(addr(), which); |
never@2657 | 50 | if (verify_only) { |
never@2657 | 51 | assert(*(uint32_t*) disp == oopDesc::encode_heap_oop((oop)x), "instructions must match"); |
never@2657 | 52 | } else { |
never@2657 | 53 | *(int32_t*) disp = oopDesc::encode_heap_oop((oop)x); |
never@2657 | 54 | } |
duke@435 | 55 | } else { |
duke@435 | 56 | // Note: Use runtime_call_type relocations for call32_operand. |
duke@435 | 57 | address ip = addr(); |
duke@435 | 58 | address disp = Assembler::locate_operand(ip, which); |
duke@435 | 59 | address next_ip = Assembler::locate_next_instruction(ip); |
never@2657 | 60 | if (verify_only) { |
never@2657 | 61 | assert(*(int32_t*) disp == (x - next_ip), "instructions must match"); |
never@2657 | 62 | } else { |
never@2657 | 63 | *(int32_t*) disp = x - next_ip; |
never@2657 | 64 | } |
duke@435 | 65 | } |
duke@435 | 66 | #else |
never@2657 | 67 | if (verify_only) { |
never@2657 | 68 | assert(*pd_address_in_code() == (x + o), "instructions must match"); |
never@2657 | 69 | } else { |
never@2657 | 70 | *pd_address_in_code() = x + o; |
never@2657 | 71 | } |
duke@435 | 72 | #endif // AMD64 |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | |
duke@435 | 76 | address Relocation::pd_call_destination(address orig_addr) { |
duke@435 | 77 | intptr_t adj = 0; |
duke@435 | 78 | if (orig_addr != NULL) { |
duke@435 | 79 | // We just moved this call instruction from orig_addr to addr(). |
duke@435 | 80 | // This means its target will appear to have grown by addr() - orig_addr. |
duke@435 | 81 | adj = -( addr() - orig_addr ); |
duke@435 | 82 | } |
duke@435 | 83 | NativeInstruction* ni = nativeInstruction_at(addr()); |
duke@435 | 84 | if (ni->is_call()) { |
duke@435 | 85 | return nativeCall_at(addr())->destination() + adj; |
duke@435 | 86 | } else if (ni->is_jump()) { |
duke@435 | 87 | return nativeJump_at(addr())->jump_destination() + adj; |
duke@435 | 88 | } else if (ni->is_cond_jump()) { |
duke@435 | 89 | return nativeGeneralJump_at(addr())->jump_destination() + adj; |
duke@435 | 90 | } else if (ni->is_mov_literal64()) { |
duke@435 | 91 | return (address) ((NativeMovConstReg*)ni)->data(); |
duke@435 | 92 | } else { |
duke@435 | 93 | ShouldNotReachHere(); |
duke@435 | 94 | return NULL; |
duke@435 | 95 | } |
duke@435 | 96 | } |
duke@435 | 97 | |
duke@435 | 98 | |
duke@435 | 99 | void Relocation::pd_set_call_destination(address x) { |
duke@435 | 100 | NativeInstruction* ni = nativeInstruction_at(addr()); |
duke@435 | 101 | if (ni->is_call()) { |
duke@435 | 102 | nativeCall_at(addr())->set_destination(x); |
duke@435 | 103 | } else if (ni->is_jump()) { |
duke@435 | 104 | NativeJump* nj = nativeJump_at(addr()); |
never@739 | 105 | |
never@739 | 106 | // Unresolved jumps are recognized by a destination of -1 |
never@739 | 107 | // However 64bit can't actually produce such an address |
never@739 | 108 | // and encodes a jump to self but jump_destination will |
never@739 | 109 | // return a -1 as the signal. We must not relocate this |
never@739 | 110 | // jmp or the ic code will not see it as unresolved. |
never@739 | 111 | |
duke@435 | 112 | if (nj->jump_destination() == (address) -1) { |
never@739 | 113 | x = addr(); // jump to self |
duke@435 | 114 | } |
duke@435 | 115 | nj->set_jump_destination(x); |
duke@435 | 116 | } else if (ni->is_cond_jump()) { |
duke@435 | 117 | // %%%% kludge this, for now, until we get a jump_destination method |
duke@435 | 118 | address old_dest = nativeGeneralJump_at(addr())->jump_destination(); |
duke@435 | 119 | address disp = Assembler::locate_operand(addr(), Assembler::call32_operand); |
duke@435 | 120 | *(jint*)disp += (x - old_dest); |
duke@435 | 121 | } else if (ni->is_mov_literal64()) { |
duke@435 | 122 | ((NativeMovConstReg*)ni)->set_data((intptr_t)x); |
duke@435 | 123 | } else { |
duke@435 | 124 | ShouldNotReachHere(); |
duke@435 | 125 | } |
duke@435 | 126 | } |
duke@435 | 127 | |
duke@435 | 128 | |
duke@435 | 129 | address* Relocation::pd_address_in_code() { |
duke@435 | 130 | // All embedded Intel addresses are stored in 32-bit words. |
duke@435 | 131 | // Since the addr points at the start of the instruction, |
duke@435 | 132 | // we must parse the instruction a bit to find the embedded word. |
duke@435 | 133 | assert(is_data(), "must be a DataRelocation"); |
duke@435 | 134 | typedef Assembler::WhichOperand WhichOperand; |
never@739 | 135 | WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm/imm32 |
duke@435 | 136 | #ifdef AMD64 |
duke@435 | 137 | assert(which == Assembler::disp32_operand || |
duke@435 | 138 | which == Assembler::call32_operand || |
never@739 | 139 | which == Assembler::imm_operand, "format unpacks ok"); |
never@739 | 140 | if (which != Assembler::imm_operand) { |
duke@435 | 141 | // The "address" in the code is a displacement can't return it as |
duke@435 | 142 | // and address* since it is really a jint* |
duke@435 | 143 | ShouldNotReachHere(); |
duke@435 | 144 | return NULL; |
duke@435 | 145 | } |
duke@435 | 146 | #else |
never@739 | 147 | assert(which == Assembler::disp32_operand || which == Assembler::imm_operand, "format unpacks ok"); |
duke@435 | 148 | #endif // AMD64 |
duke@435 | 149 | return (address*) Assembler::locate_operand(addr(), which); |
duke@435 | 150 | } |
duke@435 | 151 | |
duke@435 | 152 | |
duke@435 | 153 | address Relocation::pd_get_address_from_code() { |
duke@435 | 154 | #ifdef AMD64 |
duke@435 | 155 | // All embedded Intel addresses are stored in 32-bit words. |
duke@435 | 156 | // Since the addr points at the start of the instruction, |
duke@435 | 157 | // we must parse the instruction a bit to find the embedded word. |
duke@435 | 158 | assert(is_data(), "must be a DataRelocation"); |
duke@435 | 159 | typedef Assembler::WhichOperand WhichOperand; |
never@739 | 160 | WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm/imm32 |
duke@435 | 161 | assert(which == Assembler::disp32_operand || |
duke@435 | 162 | which == Assembler::call32_operand || |
never@739 | 163 | which == Assembler::imm_operand, "format unpacks ok"); |
never@739 | 164 | if (which != Assembler::imm_operand) { |
duke@435 | 165 | address ip = addr(); |
duke@435 | 166 | address disp = Assembler::locate_operand(ip, which); |
duke@435 | 167 | address next_ip = Assembler::locate_next_instruction(ip); |
duke@435 | 168 | address a = next_ip + *(int32_t*) disp; |
duke@435 | 169 | return a; |
duke@435 | 170 | } |
duke@435 | 171 | #endif // AMD64 |
duke@435 | 172 | return *pd_address_in_code(); |
duke@435 | 173 | } |
duke@435 | 174 | |
duke@435 | 175 | int Relocation::pd_breakpoint_size() { |
duke@435 | 176 | // minimum breakpoint size, in short words |
duke@435 | 177 | return NativeIllegalInstruction::instruction_size / sizeof(short); |
duke@435 | 178 | } |
duke@435 | 179 | |
duke@435 | 180 | void Relocation::pd_swap_in_breakpoint(address x, short* instrs, int instrlen) { |
duke@435 | 181 | Untested("pd_swap_in_breakpoint"); |
duke@435 | 182 | if (instrs != NULL) { |
duke@435 | 183 | assert(instrlen * sizeof(short) == NativeIllegalInstruction::instruction_size, "enough instrlen in reloc. data"); |
duke@435 | 184 | for (int i = 0; i < instrlen; i++) { |
duke@435 | 185 | instrs[i] = ((short*)x)[i]; |
duke@435 | 186 | } |
duke@435 | 187 | } |
duke@435 | 188 | NativeIllegalInstruction::insert(x); |
duke@435 | 189 | } |
duke@435 | 190 | |
duke@435 | 191 | |
duke@435 | 192 | void Relocation::pd_swap_out_breakpoint(address x, short* instrs, int instrlen) { |
duke@435 | 193 | Untested("pd_swap_out_breakpoint"); |
duke@435 | 194 | assert(NativeIllegalInstruction::instruction_size == sizeof(short), "right address unit for update"); |
duke@435 | 195 | NativeInstruction* ni = nativeInstruction_at(x); |
duke@435 | 196 | *(short*)ni->addr_at(0) = instrs[0]; |
duke@435 | 197 | } |
never@739 | 198 | |
never@739 | 199 | void poll_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { |
never@739 | 200 | #ifdef _LP64 |
iveresov@2686 | 201 | if (!Assembler::is_polling_page_far()) { |
iveresov@2686 | 202 | typedef Assembler::WhichOperand WhichOperand; |
iveresov@2686 | 203 | WhichOperand which = (WhichOperand) format(); |
iveresov@2686 | 204 | // This format is imm but it is really disp32 |
iveresov@2686 | 205 | which = Assembler::disp32_operand; |
iveresov@2686 | 206 | address orig_addr = old_addr_for(addr(), src, dest); |
iveresov@2686 | 207 | NativeInstruction* oni = nativeInstruction_at(orig_addr); |
iveresov@2686 | 208 | int32_t* orig_disp = (int32_t*) Assembler::locate_operand(orig_addr, which); |
iveresov@2686 | 209 | // This poll_addr is incorrect by the size of the instruction it is irrelevant |
iveresov@2686 | 210 | intptr_t poll_addr = (intptr_t)oni + *orig_disp; |
never@739 | 211 | |
iveresov@2686 | 212 | NativeInstruction* ni = nativeInstruction_at(addr()); |
iveresov@2686 | 213 | intptr_t new_disp = poll_addr - (intptr_t) ni; |
never@739 | 214 | |
iveresov@2686 | 215 | int32_t* disp = (int32_t*) Assembler::locate_operand(addr(), which); |
iveresov@2686 | 216 | * disp = (int32_t)new_disp; |
iveresov@2686 | 217 | } |
never@739 | 218 | #endif // _LP64 |
never@739 | 219 | } |
never@739 | 220 | |
never@739 | 221 | void poll_return_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { |
never@739 | 222 | #ifdef _LP64 |
iveresov@2686 | 223 | if (!Assembler::is_polling_page_far()) { |
iveresov@2686 | 224 | typedef Assembler::WhichOperand WhichOperand; |
iveresov@2686 | 225 | WhichOperand which = (WhichOperand) format(); |
iveresov@2686 | 226 | // This format is imm but it is really disp32 |
iveresov@2686 | 227 | which = Assembler::disp32_operand; |
iveresov@2686 | 228 | address orig_addr = old_addr_for(addr(), src, dest); |
iveresov@2686 | 229 | NativeInstruction* oni = nativeInstruction_at(orig_addr); |
iveresov@2686 | 230 | int32_t* orig_disp = (int32_t*) Assembler::locate_operand(orig_addr, which); |
iveresov@2686 | 231 | // This poll_addr is incorrect by the size of the instruction it is irrelevant |
iveresov@2686 | 232 | intptr_t poll_addr = (intptr_t)oni + *orig_disp; |
never@739 | 233 | |
iveresov@2686 | 234 | NativeInstruction* ni = nativeInstruction_at(addr()); |
iveresov@2686 | 235 | intptr_t new_disp = poll_addr - (intptr_t) ni; |
never@739 | 236 | |
iveresov@2686 | 237 | int32_t* disp = (int32_t*) Assembler::locate_operand(addr(), which); |
iveresov@2686 | 238 | * disp = (int32_t)new_disp; |
iveresov@2686 | 239 | } |
never@739 | 240 | #endif // _LP64 |
never@739 | 241 | } |