src/cpu/x86/vm/relocInfo_x86.cpp

Wed, 07 May 2008 08:06:46 -0700

author
rasbold
date
Wed, 07 May 2008 08:06:46 -0700
changeset 580
f3de1255b035
parent 435
a61af66fc99e
child 599
c436414a719e
permissions
-rw-r--r--

6603011: RFE: Optimize long division
Summary: Transform long division by constant into multiply
Reviewed-by: never, kvn

duke@435 1 /*
duke@435 2 * Copyright 1998-2005 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/_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;
duke@435 33 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64, call32
duke@435 34 assert(which == Assembler::disp32_operand ||
duke@435 35 which == Assembler::imm64_operand, "format unpacks ok");
duke@435 36 if (which == Assembler::imm64_operand) {
duke@435 37 *pd_address_in_code() = x;
duke@435 38 } else {
duke@435 39 // Note: Use runtime_call_type relocations for call32_operand.
duke@435 40 address ip = addr();
duke@435 41 address disp = Assembler::locate_operand(ip, which);
duke@435 42 address next_ip = Assembler::locate_next_instruction(ip);
duke@435 43 *(int32_t*) disp = x - next_ip;
duke@435 44 }
duke@435 45 #else
duke@435 46 *pd_address_in_code() = x + o;
duke@435 47 #endif // AMD64
duke@435 48 }
duke@435 49
duke@435 50
duke@435 51 address Relocation::pd_call_destination(address orig_addr) {
duke@435 52 intptr_t adj = 0;
duke@435 53 if (orig_addr != NULL) {
duke@435 54 // We just moved this call instruction from orig_addr to addr().
duke@435 55 // This means its target will appear to have grown by addr() - orig_addr.
duke@435 56 adj = -( addr() - orig_addr );
duke@435 57 }
duke@435 58 NativeInstruction* ni = nativeInstruction_at(addr());
duke@435 59 if (ni->is_call()) {
duke@435 60 return nativeCall_at(addr())->destination() + adj;
duke@435 61 } else if (ni->is_jump()) {
duke@435 62 return nativeJump_at(addr())->jump_destination() + adj;
duke@435 63 } else if (ni->is_cond_jump()) {
duke@435 64 return nativeGeneralJump_at(addr())->jump_destination() + adj;
duke@435 65 } else if (ni->is_mov_literal64()) {
duke@435 66 return (address) ((NativeMovConstReg*)ni)->data();
duke@435 67 } else {
duke@435 68 ShouldNotReachHere();
duke@435 69 return NULL;
duke@435 70 }
duke@435 71 }
duke@435 72
duke@435 73
duke@435 74 void Relocation::pd_set_call_destination(address x) {
duke@435 75 NativeInstruction* ni = nativeInstruction_at(addr());
duke@435 76 if (ni->is_call()) {
duke@435 77 nativeCall_at(addr())->set_destination(x);
duke@435 78 } else if (ni->is_jump()) {
duke@435 79 NativeJump* nj = nativeJump_at(addr());
duke@435 80 #ifdef AMD64
duke@435 81 if (nj->jump_destination() == (address) -1) {
duke@435 82 x = (address) -1; // retain jump to self
duke@435 83 }
duke@435 84 #endif // AMD64
duke@435 85 nj->set_jump_destination(x);
duke@435 86 } else if (ni->is_cond_jump()) {
duke@435 87 // %%%% kludge this, for now, until we get a jump_destination method
duke@435 88 address old_dest = nativeGeneralJump_at(addr())->jump_destination();
duke@435 89 address disp = Assembler::locate_operand(addr(), Assembler::call32_operand);
duke@435 90 *(jint*)disp += (x - old_dest);
duke@435 91 } else if (ni->is_mov_literal64()) {
duke@435 92 ((NativeMovConstReg*)ni)->set_data((intptr_t)x);
duke@435 93 } else {
duke@435 94 ShouldNotReachHere();
duke@435 95 }
duke@435 96 }
duke@435 97
duke@435 98
duke@435 99 address* Relocation::pd_address_in_code() {
duke@435 100 // All embedded Intel addresses are stored in 32-bit words.
duke@435 101 // Since the addr points at the start of the instruction,
duke@435 102 // we must parse the instruction a bit to find the embedded word.
duke@435 103 assert(is_data(), "must be a DataRelocation");
duke@435 104 typedef Assembler::WhichOperand WhichOperand;
duke@435 105 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64/imm32
duke@435 106 #ifdef AMD64
duke@435 107 assert(which == Assembler::disp32_operand ||
duke@435 108 which == Assembler::call32_operand ||
duke@435 109 which == Assembler::imm64_operand, "format unpacks ok");
duke@435 110 if (which != Assembler::imm64_operand) {
duke@435 111 // The "address" in the code is a displacement can't return it as
duke@435 112 // and address* since it is really a jint*
duke@435 113 ShouldNotReachHere();
duke@435 114 return NULL;
duke@435 115 }
duke@435 116 #else
duke@435 117 assert(which == Assembler::disp32_operand || which == Assembler::imm32_operand, "format unpacks ok");
duke@435 118 #endif // AMD64
duke@435 119 return (address*) Assembler::locate_operand(addr(), which);
duke@435 120 }
duke@435 121
duke@435 122
duke@435 123 address Relocation::pd_get_address_from_code() {
duke@435 124 #ifdef AMD64
duke@435 125 // All embedded Intel addresses are stored in 32-bit words.
duke@435 126 // Since the addr points at the start of the instruction,
duke@435 127 // we must parse the instruction a bit to find the embedded word.
duke@435 128 assert(is_data(), "must be a DataRelocation");
duke@435 129 typedef Assembler::WhichOperand WhichOperand;
duke@435 130 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64/imm32
duke@435 131 assert(which == Assembler::disp32_operand ||
duke@435 132 which == Assembler::call32_operand ||
duke@435 133 which == Assembler::imm64_operand, "format unpacks ok");
duke@435 134 if (which != Assembler::imm64_operand) {
duke@435 135 address ip = addr();
duke@435 136 address disp = Assembler::locate_operand(ip, which);
duke@435 137 address next_ip = Assembler::locate_next_instruction(ip);
duke@435 138 address a = next_ip + *(int32_t*) disp;
duke@435 139 return a;
duke@435 140 }
duke@435 141 #endif // AMD64
duke@435 142 return *pd_address_in_code();
duke@435 143 }
duke@435 144
duke@435 145 int Relocation::pd_breakpoint_size() {
duke@435 146 // minimum breakpoint size, in short words
duke@435 147 return NativeIllegalInstruction::instruction_size / sizeof(short);
duke@435 148 }
duke@435 149
duke@435 150 void Relocation::pd_swap_in_breakpoint(address x, short* instrs, int instrlen) {
duke@435 151 Untested("pd_swap_in_breakpoint");
duke@435 152 if (instrs != NULL) {
duke@435 153 assert(instrlen * sizeof(short) == NativeIllegalInstruction::instruction_size, "enough instrlen in reloc. data");
duke@435 154 for (int i = 0; i < instrlen; i++) {
duke@435 155 instrs[i] = ((short*)x)[i];
duke@435 156 }
duke@435 157 }
duke@435 158 NativeIllegalInstruction::insert(x);
duke@435 159 }
duke@435 160
duke@435 161
duke@435 162 void Relocation::pd_swap_out_breakpoint(address x, short* instrs, int instrlen) {
duke@435 163 Untested("pd_swap_out_breakpoint");
duke@435 164 assert(NativeIllegalInstruction::instruction_size == sizeof(short), "right address unit for update");
duke@435 165 NativeInstruction* ni = nativeInstruction_at(x);
duke@435 166 *(short*)ni->addr_at(0) = instrs[0];
duke@435 167 }

mercurial