OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 pc_ += sizeof(uint64_t); | 63 pc_ += sizeof(uint64_t); |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 void Assembler::emitw(uint16_t x) { | 67 void Assembler::emitw(uint16_t x) { |
68 Memory::uint16_at(pc_) = x; | 68 Memory::uint16_at(pc_) = x; |
69 pc_ += sizeof(uint16_t); | 69 pc_ += sizeof(uint16_t); |
70 } | 70 } |
71 | 71 |
72 | 72 |
| 73 void Assembler::emit_code_target(Handle<Code> target, RelocInfo::Mode rmode) { |
| 74 ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 75 RecordRelocInfo(rmode); |
| 76 int current = code_targets_.length(); |
| 77 if (current > 0 && code_targets_.last().is_identical_to(target)) { |
| 78 // Optimization if we keep jumping to the same code target. |
| 79 emitl(current - 1); |
| 80 } else { |
| 81 code_targets_.Add(target); |
| 82 emitl(current); |
| 83 } |
| 84 } |
| 85 |
| 86 |
73 void Assembler::emit_rex_64(Register reg, Register rm_reg) { | 87 void Assembler::emit_rex_64(Register reg, Register rm_reg) { |
74 emit(0x48 | reg.high_bit() << 2 | rm_reg.high_bit()); | 88 emit(0x48 | reg.high_bit() << 2 | rm_reg.high_bit()); |
75 } | 89 } |
76 | 90 |
77 | 91 |
78 void Assembler::emit_rex_64(XMMRegister reg, Register rm_reg) { | 92 void Assembler::emit_rex_64(XMMRegister reg, Register rm_reg) { |
79 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3); | 93 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3); |
80 } | 94 } |
81 | 95 |
82 | 96 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 if (rm_reg.high_bit()) emit(0x41); | 169 if (rm_reg.high_bit()) emit(0x41); |
156 } | 170 } |
157 | 171 |
158 | 172 |
159 void Assembler::emit_optional_rex_32(const Operand& op) { | 173 void Assembler::emit_optional_rex_32(const Operand& op) { |
160 if (op.rex_ != 0) emit(0x40 | op.rex_); | 174 if (op.rex_ != 0) emit(0x40 | op.rex_); |
161 } | 175 } |
162 | 176 |
163 | 177 |
164 Address Assembler::target_address_at(Address pc) { | 178 Address Assembler::target_address_at(Address pc) { |
165 return Memory::Address_at(pc); | 179 return Memory::int32_at(pc) + pc + 4; |
166 } | 180 } |
167 | 181 |
168 | 182 |
169 void Assembler::set_target_address_at(Address pc, Address target) { | 183 void Assembler::set_target_address_at(Address pc, Address target) { |
170 Memory::Address_at(pc) = target; | 184 Memory::int32_at(pc) = target - pc - 4; |
171 CPU::FlushICache(pc, sizeof(intptr_t)); | 185 CPU::FlushICache(pc, sizeof(int32_t)); |
172 } | 186 } |
173 | 187 |
| 188 Handle<Object> Assembler::code_target_object_handle_at(Address pc) { |
| 189 return code_targets_[Memory::int32_at(pc)]; |
| 190 } |
174 | 191 |
175 // ----------------------------------------------------------------------------- | 192 // ----------------------------------------------------------------------------- |
176 // Implementation of RelocInfo | 193 // Implementation of RelocInfo |
177 | 194 |
178 // The modes possibly affected by apply must be in kApplyMask. | 195 // The modes possibly affected by apply must be in kApplyMask. |
179 void RelocInfo::apply(intptr_t delta) { | 196 void RelocInfo::apply(intptr_t delta) { |
180 if (IsInternalReference(rmode_)) { | 197 if (IsInternalReference(rmode_)) { |
181 // absolute code pointer inside code object moves with the code object. | 198 // absolute code pointer inside code object moves with the code object. |
182 intptr_t* p = reinterpret_cast<intptr_t*>(pc_); | 199 Memory::Address_at(pc_) += delta; |
183 *p += delta; // relocate entry | 200 } else if (IsCodeTarget(rmode_)) { |
| 201 Memory::int32_at(pc_) -= delta; |
| 202 } else if (rmode_ == JS_RETURN && IsCallInstruction()) { |
| 203 // Special handling of js_return when a break point is set (call |
| 204 // instruction has been inserted). |
| 205 Memory::int32_at(pc_ + 1) -= delta; // relocate entry |
184 } | 206 } |
185 } | 207 } |
186 | 208 |
187 | 209 |
188 Address RelocInfo::target_address() { | 210 Address RelocInfo::target_address() { |
189 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); | 211 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); |
190 return Assembler::target_address_at(pc_); | 212 if (IsCodeTarget(rmode_)) { |
| 213 return Assembler::target_address_at(pc_); |
| 214 } else { |
| 215 return Memory::Address_at(pc_); |
| 216 } |
191 } | 217 } |
192 | 218 |
193 | 219 |
194 Address RelocInfo::target_address_address() { | 220 Address RelocInfo::target_address_address() { |
195 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); | 221 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); |
196 return reinterpret_cast<Address>(pc_); | 222 return reinterpret_cast<Address>(pc_); |
197 } | 223 } |
198 | 224 |
199 | 225 |
200 void RelocInfo::set_target_address(Address target) { | 226 void RelocInfo::set_target_address(Address target) { |
201 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); | 227 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); |
202 Assembler::set_target_address_at(pc_, target); | 228 if (IsCodeTarget(rmode_)) { |
| 229 Assembler::set_target_address_at(pc_, target); |
| 230 } else { |
| 231 Memory::Address_at(pc_) = target; |
| 232 } |
203 } | 233 } |
204 | 234 |
205 | 235 |
206 Object* RelocInfo::target_object() { | 236 Object* RelocInfo::target_object() { |
207 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); | 237 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
208 return *reinterpret_cast<Object**>(pc_); | 238 return Memory::Object_at(pc_); |
| 239 } |
| 240 |
| 241 |
| 242 Handle<Object> RelocInfo::target_object_handle(Assembler *origin) { |
| 243 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 244 if (rmode_ == EMBEDDED_OBJECT) { |
| 245 return Memory::Object_Handle_at(pc_); |
| 246 } else { |
| 247 return origin->code_target_object_handle_at(pc_); |
| 248 } |
209 } | 249 } |
210 | 250 |
211 | 251 |
212 Object** RelocInfo::target_object_address() { | 252 Object** RelocInfo::target_object_address() { |
213 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); | 253 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
214 return reinterpret_cast<Object**>(pc_); | 254 return reinterpret_cast<Object**>(pc_); |
215 } | 255 } |
216 | 256 |
217 | 257 |
218 Address* RelocInfo::target_reference_address() { | 258 Address* RelocInfo::target_reference_address() { |
(...skipping 14 matching lines...) Expand all Loading... |
233 // It only needs to be distinguished from a return sequence | 273 // It only needs to be distinguished from a return sequence |
234 // movq(rsp, rbp); pop(rbp); ret(n); int3 *6 | 274 // movq(rsp, rbp); pop(rbp); ret(n); int3 *6 |
235 // The 11th byte is int3 (0xCC) in the return sequence and | 275 // The 11th byte is int3 (0xCC) in the return sequence and |
236 // REX.WB (0x48+register bit) for the call sequence. | 276 // REX.WB (0x48+register bit) for the call sequence. |
237 return pc_[10] != 0xCC; | 277 return pc_[10] != 0xCC; |
238 } | 278 } |
239 | 279 |
240 | 280 |
241 Address RelocInfo::call_address() { | 281 Address RelocInfo::call_address() { |
242 ASSERT(IsCallInstruction()); | 282 ASSERT(IsCallInstruction()); |
243 return Assembler::target_address_at( | 283 return Memory::Address_at( |
244 pc_ + Assembler::kPatchReturnSequenceAddressOffset); | 284 pc_ + Assembler::kRealPatchReturnSequenceAddressOffset); |
245 } | 285 } |
246 | 286 |
247 | 287 |
248 void RelocInfo::set_call_address(Address target) { | 288 void RelocInfo::set_call_address(Address target) { |
249 ASSERT(IsCallInstruction()); | 289 ASSERT(IsCallInstruction()); |
250 Assembler::set_target_address_at( | 290 Memory::Address_at(pc_ + Assembler::kRealPatchReturnSequenceAddressOffset) = |
251 pc_ + Assembler::kPatchReturnSequenceAddressOffset, | 291 target; |
252 target); | |
253 } | 292 } |
254 | 293 |
255 | 294 |
256 Object* RelocInfo::call_object() { | 295 Object* RelocInfo::call_object() { |
257 ASSERT(IsCallInstruction()); | 296 ASSERT(IsCallInstruction()); |
258 return *call_object_address(); | 297 return *call_object_address(); |
259 } | 298 } |
260 | 299 |
261 | 300 |
262 void RelocInfo::set_call_object(Object* target) { | 301 void RelocInfo::set_call_object(Object* target) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 ASSERT(len_ == 1 || len_ == 2); | 344 ASSERT(len_ == 1 || len_ == 2); |
306 int32_t* p = reinterpret_cast<int32_t*>(&buf_[len_]); | 345 int32_t* p = reinterpret_cast<int32_t*>(&buf_[len_]); |
307 *p = disp; | 346 *p = disp; |
308 len_ += sizeof(int32_t); | 347 len_ += sizeof(int32_t); |
309 } | 348 } |
310 | 349 |
311 | 350 |
312 } } // namespace v8::internal | 351 } } // namespace v8::internal |
313 | 352 |
314 #endif // V8_X64_ASSEMBLER_X64_INL_H_ | 353 #endif // V8_X64_ASSEMBLER_X64_INL_H_ |
OLD | NEW |