src/cpu/x86/vm/relocInfo_x86.cpp

Mon, 13 Sep 2010 23:24:30 -0700

author
jrose
date
Mon, 13 Sep 2010 23:24:30 -0700
changeset 2148
d257356e35f0
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
Reviewed-by: never

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

mercurial