annotate src/cpu/x86/vm/relocInfo_x86.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents c436414a719e
children dc7f315e41f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 164
diff changeset
2 * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_relocInfo_x86.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 void Relocation::pd_set_data_value(address x, intptr_t o) {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
31 x += o;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 typedef Assembler::WhichOperand WhichOperand;
164
c436414a719e 6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents: 0
diff changeset
33 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64, call32, narrow oop
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34 assert(which == Assembler::disp32_operand ||
164
c436414a719e 6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents: 0
diff changeset
35 which == Assembler::narrow_oop_operand ||
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36 which == Assembler::imm64_operand, "format unpacks ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
37 if (which == Assembler::imm64_operand) {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 *pd_address_in_code() = x;
164
c436414a719e 6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents: 0
diff changeset
39 } else if (which == Assembler::narrow_oop_operand) {
c436414a719e 6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents: 0
diff changeset
40 address disp = Assembler::locate_operand(addr(), which);
c436414a719e 6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents: 0
diff changeset
41 *(int32_t*) disp = oopDesc::encode_heap_oop((oop)x);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
42 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Note: Use runtime_call_type relocations for call32_operand.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 address ip = addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
45 address disp = Assembler::locate_operand(ip, which);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 address next_ip = Assembler::locate_next_instruction(ip);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 *(int32_t*) disp = x - next_ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
50 *pd_address_in_code() = x + o;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 address Relocation::pd_call_destination(address orig_addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 intptr_t adj = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (orig_addr != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // We just moved this call instruction from orig_addr to addr().
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // This means its target will appear to have grown by addr() - orig_addr.
a61af66fc99e Initial load
duke
parents:
diff changeset
60 adj = -( addr() - orig_addr );
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 NativeInstruction* ni = nativeInstruction_at(addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
63 if (ni->is_call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return nativeCall_at(addr())->destination() + adj;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 } else if (ni->is_jump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return nativeJump_at(addr())->jump_destination() + adj;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 } else if (ni->is_cond_jump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return nativeGeneralJump_at(addr())->jump_destination() + adj;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 } else if (ni->is_mov_literal64()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return (address) ((NativeMovConstReg*)ni)->data();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 void Relocation::pd_set_call_destination(address x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 NativeInstruction* ni = nativeInstruction_at(addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (ni->is_call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 nativeCall_at(addr())->set_destination(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 } else if (ni->is_jump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 NativeJump* nj = nativeJump_at(addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (nj->jump_destination() == (address) -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 x = (address) -1; // retain jump to self
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
89 nj->set_jump_destination(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 } else if (ni->is_cond_jump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // %%%% kludge this, for now, until we get a jump_destination method
a61af66fc99e Initial load
duke
parents:
diff changeset
92 address old_dest = nativeGeneralJump_at(addr())->jump_destination();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 address disp = Assembler::locate_operand(addr(), Assembler::call32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 *(jint*)disp += (x - old_dest);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 } else if (ni->is_mov_literal64()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 ((NativeMovConstReg*)ni)->set_data((intptr_t)x);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 address* Relocation::pd_address_in_code() {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // All embedded Intel addresses are stored in 32-bit words.
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Since the addr points at the start of the instruction,
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // we must parse the instruction a bit to find the embedded word.
a61af66fc99e Initial load
duke
parents:
diff changeset
107 assert(is_data(), "must be a DataRelocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 typedef Assembler::WhichOperand WhichOperand;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64/imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
110 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
111 assert(which == Assembler::disp32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
112 which == Assembler::call32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
113 which == Assembler::imm64_operand, "format unpacks ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (which != Assembler::imm64_operand) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // The "address" in the code is a displacement can't return it as
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // and address* since it is really a jint*
a61af66fc99e Initial load
duke
parents:
diff changeset
117 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
121 assert(which == Assembler::disp32_operand || which == Assembler::imm32_operand, "format unpacks ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
122 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return (address*) Assembler::locate_operand(addr(), which);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 address Relocation::pd_get_address_from_code() {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // All embedded Intel addresses are stored in 32-bit words.
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Since the addr points at the start of the instruction,
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // we must parse the instruction a bit to find the embedded word.
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert(is_data(), "must be a DataRelocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 typedef Assembler::WhichOperand WhichOperand;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64/imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
135 assert(which == Assembler::disp32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
136 which == Assembler::call32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
137 which == Assembler::imm64_operand, "format unpacks ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (which != Assembler::imm64_operand) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 address ip = addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 address disp = Assembler::locate_operand(ip, which);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 address next_ip = Assembler::locate_next_instruction(ip);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 address a = next_ip + *(int32_t*) disp;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return a;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return *pd_address_in_code();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 int Relocation::pd_breakpoint_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // minimum breakpoint size, in short words
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return NativeIllegalInstruction::instruction_size / sizeof(short);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 void Relocation::pd_swap_in_breakpoint(address x, short* instrs, int instrlen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 Untested("pd_swap_in_breakpoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (instrs != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 assert(instrlen * sizeof(short) == NativeIllegalInstruction::instruction_size, "enough instrlen in reloc. data");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 for (int i = 0; i < instrlen; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 instrs[i] = ((short*)x)[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 NativeIllegalInstruction::insert(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 void Relocation::pd_swap_out_breakpoint(address x, short* instrs, int instrlen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 Untested("pd_swap_out_breakpoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 assert(NativeIllegalInstruction::instruction_size == sizeof(short), "right address unit for update");
a61af66fc99e Initial load
duke
parents:
diff changeset
169 NativeInstruction* ni = nativeInstruction_at(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 *(short*)ni->addr_at(0) = instrs[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }