Mercurial > hg > truffle
annotate src/cpu/x86/vm/relocInfo_x86.cpp @ 15847:9e172511971d
make FixedNodeProbabilityCache behave better in the presence of dead code
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Thu, 22 May 2014 14:04:55 +0200 |
parents | 1302b727b5cd |
children | be896a1983c0 |
rev | line source |
---|---|
0 | 1 /* |
12056
740e263c80c6
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
11041
diff
changeset
|
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
304
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
304
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
304
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
7199
cd3d6a6b95d9
8003240: x86: move MacroAssembler into separate file
twisti
parents:
6725
diff
changeset
|
26 #include "asm/macroAssembler.hpp" |
1972 | 27 #include "code/relocInfo.hpp" |
28 #include "nativeInst_x86.hpp" | |
29 #include "oops/oop.inline.hpp" | |
30 #include "runtime/safepoint.hpp" | |
0 | 31 |
32 | |
2375
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
33 void Relocation::pd_set_data_value(address x, intptr_t o, bool verify_only) { |
0 | 34 #ifdef AMD64 |
35 x += o; | |
36 typedef Assembler::WhichOperand WhichOperand; | |
304 | 37 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm, call32, narrow oop |
0 | 38 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
|
39 which == Assembler::narrow_oop_operand || |
304 | 40 which == Assembler::imm_operand, "format unpacks ok"); |
41 if (which == Assembler::imm_operand) { | |
2375
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
42 if (verify_only) { |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
43 assert(*pd_address_in_code() == x, "instructions must match"); |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
44 } else { |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
45 *pd_address_in_code() = x; |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
46 } |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
0
diff
changeset
|
47 } 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
|
48 address disp = Assembler::locate_operand(addr(), which); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
49 // both compressed oops and compressed classes look the same |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
50 if (Universe::heap()->is_in_reserved((oop)x)) { |
2375
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
51 if (verify_only) { |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
52 assert(*(uint32_t*) disp == oopDesc::encode_heap_oop((oop)x), "instructions must match"); |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
53 } else { |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
54 *(int32_t*) disp = oopDesc::encode_heap_oop((oop)x); |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
55 } |
0 | 56 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
57 if (verify_only) { |
12056
740e263c80c6
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
11041
diff
changeset
|
58 assert(*(uint32_t*) disp == Klass::encode_klass((Klass*)x), "instructions must match"); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
59 } else { |
12056
740e263c80c6
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
11041
diff
changeset
|
60 *(int32_t*) disp = Klass::encode_klass((Klass*)x); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
61 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
62 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
63 } else { |
0 | 64 // Note: Use runtime_call_type relocations for call32_operand. |
65 address ip = addr(); | |
66 address disp = Assembler::locate_operand(ip, which); | |
67 address next_ip = Assembler::locate_next_instruction(ip); | |
2375
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
68 if (verify_only) { |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
69 assert(*(int32_t*) disp == (x - next_ip), "instructions must match"); |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
70 } else { |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
71 *(int32_t*) disp = x - next_ip; |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
72 } |
0 | 73 } |
74 #else | |
2375
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
75 if (verify_only) { |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
76 assert(*pd_address_in_code() == (x + o), "instructions must match"); |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
77 } else { |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
78 *pd_address_in_code() = x + o; |
d673ef06fe96
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
1972
diff
changeset
|
79 } |
0 | 80 #endif // AMD64 |
81 } | |
82 | |
83 | |
84 address Relocation::pd_call_destination(address orig_addr) { | |
85 intptr_t adj = 0; | |
86 if (orig_addr != NULL) { | |
87 // We just moved this call instruction from orig_addr to addr(). | |
88 // This means its target will appear to have grown by addr() - orig_addr. | |
89 adj = -( addr() - orig_addr ); | |
90 } | |
91 NativeInstruction* ni = nativeInstruction_at(addr()); | |
92 if (ni->is_call()) { | |
93 return nativeCall_at(addr())->destination() + adj; | |
94 } else if (ni->is_jump()) { | |
95 return nativeJump_at(addr())->jump_destination() + adj; | |
96 } else if (ni->is_cond_jump()) { | |
97 return nativeGeneralJump_at(addr())->jump_destination() + adj; | |
98 } else if (ni->is_mov_literal64()) { | |
99 return (address) ((NativeMovConstReg*)ni)->data(); | |
100 } else { | |
101 ShouldNotReachHere(); | |
102 return NULL; | |
103 } | |
104 } | |
105 | |
106 | |
107 void Relocation::pd_set_call_destination(address x) { | |
108 NativeInstruction* ni = nativeInstruction_at(addr()); | |
109 if (ni->is_call()) { | |
110 nativeCall_at(addr())->set_destination(x); | |
111 } else if (ni->is_jump()) { | |
112 NativeJump* nj = nativeJump_at(addr()); | |
304 | 113 |
114 // Unresolved jumps are recognized by a destination of -1 | |
115 // However 64bit can't actually produce such an address | |
116 // and encodes a jump to self but jump_destination will | |
117 // return a -1 as the signal. We must not relocate this | |
118 // jmp or the ic code will not see it as unresolved. | |
119 | |
0 | 120 if (nj->jump_destination() == (address) -1) { |
304 | 121 x = addr(); // jump to self |
0 | 122 } |
123 nj->set_jump_destination(x); | |
124 } else if (ni->is_cond_jump()) { | |
125 // %%%% kludge this, for now, until we get a jump_destination method | |
126 address old_dest = nativeGeneralJump_at(addr())->jump_destination(); | |
127 address disp = Assembler::locate_operand(addr(), Assembler::call32_operand); | |
128 *(jint*)disp += (x - old_dest); | |
129 } else if (ni->is_mov_literal64()) { | |
130 ((NativeMovConstReg*)ni)->set_data((intptr_t)x); | |
131 } else { | |
132 ShouldNotReachHere(); | |
133 } | |
134 } | |
135 | |
136 | |
137 address* Relocation::pd_address_in_code() { | |
138 // All embedded Intel addresses are stored in 32-bit words. | |
139 // Since the addr points at the start of the instruction, | |
140 // we must parse the instruction a bit to find the embedded word. | |
141 assert(is_data(), "must be a DataRelocation"); | |
142 typedef Assembler::WhichOperand WhichOperand; | |
304 | 143 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm/imm32 |
0 | 144 #ifdef AMD64 |
145 assert(which == Assembler::disp32_operand || | |
146 which == Assembler::call32_operand || | |
304 | 147 which == Assembler::imm_operand, "format unpacks ok"); |
8781
589aa23334ea
8009584: [parfait] Null pointer deference in hotspot/src/cpu/x86/vm/relocInfo_x86.cpp
morris
parents:
7199
diff
changeset
|
148 // The "address" in the code is a displacement can't return it as |
589aa23334ea
8009584: [parfait] Null pointer deference in hotspot/src/cpu/x86/vm/relocInfo_x86.cpp
morris
parents:
7199
diff
changeset
|
149 // and address* since it is really a jint* |
589aa23334ea
8009584: [parfait] Null pointer deference in hotspot/src/cpu/x86/vm/relocInfo_x86.cpp
morris
parents:
7199
diff
changeset
|
150 guarantee(which == Assembler::imm_operand, "must be immediate operand"); |
0 | 151 #else |
304 | 152 assert(which == Assembler::disp32_operand || which == Assembler::imm_operand, "format unpacks ok"); |
0 | 153 #endif // AMD64 |
154 return (address*) Assembler::locate_operand(addr(), which); | |
155 } | |
156 | |
157 | |
158 address Relocation::pd_get_address_from_code() { | |
159 #ifdef AMD64 | |
160 // All embedded Intel addresses are stored in 32-bit words. | |
161 // Since the addr points at the start of the instruction, | |
162 // we must parse the instruction a bit to find the embedded word. | |
163 assert(is_data(), "must be a DataRelocation"); | |
164 typedef Assembler::WhichOperand WhichOperand; | |
304 | 165 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm/imm32 |
0 | 166 assert(which == Assembler::disp32_operand || |
167 which == Assembler::call32_operand || | |
304 | 168 which == Assembler::imm_operand, "format unpacks ok"); |
169 if (which != Assembler::imm_operand) { | |
0 | 170 address ip = addr(); |
171 address disp = Assembler::locate_operand(ip, which); | |
172 address next_ip = Assembler::locate_next_instruction(ip); | |
173 address a = next_ip + *(int32_t*) disp; | |
174 return a; | |
175 } | |
176 #endif // AMD64 | |
177 return *pd_address_in_code(); | |
178 } | |
179 | |
304 | 180 void poll_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { |
181 #ifdef _LP64 | |
13553
d49f00604347
removed poll_Relocation::pollingForm type and associated data field and rely solely on format field of safepoint relocation entries when deciding whether or not to relocate the operand of a safepoint poll instruction
Doug Simon <doug.simon@oracle.com>
parents:
13515
diff
changeset
|
182 typedef Assembler::WhichOperand WhichOperand; |
d49f00604347
removed poll_Relocation::pollingForm type and associated data field and rely solely on format field of safepoint relocation entries when deciding whether or not to relocate the operand of a safepoint poll instruction
Doug Simon <doug.simon@oracle.com>
parents:
13515
diff
changeset
|
183 WhichOperand which = (WhichOperand) format(); |
13573
1302b727b5cd
added assertion for correct format argument in a safepoint poll reloc info
Doug Simon <doug.simon@oracle.com>
parents:
13553
diff
changeset
|
184 #ifndef GRAAL |
1302b727b5cd
added assertion for correct format argument in a safepoint poll reloc info
Doug Simon <doug.simon@oracle.com>
parents:
13553
diff
changeset
|
185 assert((which == Assembler::disp32_operand) == !Assembler::is_polling_page_far(), "format not set correctly"); |
1302b727b5cd
added assertion for correct format argument in a safepoint poll reloc info
Doug Simon <doug.simon@oracle.com>
parents:
13553
diff
changeset
|
186 #endif |
13553
d49f00604347
removed poll_Relocation::pollingForm type and associated data field and rely solely on format field of safepoint relocation entries when deciding whether or not to relocate the operand of a safepoint poll instruction
Doug Simon <doug.simon@oracle.com>
parents:
13515
diff
changeset
|
187 if (which == Assembler::disp32_operand) { |
2404
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
188 address orig_addr = old_addr_for(addr(), src, dest); |
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
189 NativeInstruction* oni = nativeInstruction_at(orig_addr); |
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
190 int32_t* orig_disp = (int32_t*) Assembler::locate_operand(orig_addr, which); |
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
191 // This poll_addr is incorrect by the size of the instruction it is irrelevant |
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
192 intptr_t poll_addr = (intptr_t)oni + *orig_disp; |
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
193 NativeInstruction* ni = nativeInstruction_at(addr()); |
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
194 intptr_t new_disp = poll_addr - (intptr_t) ni; |
304 | 195 |
2404
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
196 int32_t* disp = (int32_t*) Assembler::locate_operand(addr(), which); |
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
197 * disp = (int32_t)new_disp; |
b40d4fa697bf
6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents:
2375
diff
changeset
|
198 } |
304 | 199 #endif // _LP64 |
200 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
201 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
202 void metadata_Relocation::pd_fix_value(address x) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2404
diff
changeset
|
203 } |