OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (current > 0 && code_targets_.last().is_identical_to(target)) { | 79 if (current > 0 && code_targets_.last().is_identical_to(target)) { |
80 // Optimization if we keep jumping to the same code target. | 80 // Optimization if we keep jumping to the same code target. |
81 emitl(current - 1); | 81 emitl(current - 1); |
82 } else { | 82 } else { |
83 code_targets_.Add(target); | 83 code_targets_.Add(target); |
84 emitl(current); | 84 emitl(current); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 | 88 |
89 void Assembler::emit_runtime_entry(Address entry, RelocInfo::Mode rmode) { | |
90 ASSERT(RelocInfo::IsRuntimeEntry(rmode)); | |
91 ASSERT(isolate()->code_range()->exists()); | |
92 RecordRelocInfo(rmode); | |
93 emitl(static_cast<uint32_t>(entry - isolate()->code_range()->start())); | |
94 } | |
95 | |
96 | |
97 void Assembler::emit_rex_64(Register reg, Register rm_reg) { | 89 void Assembler::emit_rex_64(Register reg, Register rm_reg) { |
98 emit(0x48 | reg.high_bit() << 2 | rm_reg.high_bit()); | 90 emit(0x48 | reg.high_bit() << 2 | rm_reg.high_bit()); |
99 } | 91 } |
100 | 92 |
101 | 93 |
102 void Assembler::emit_rex_64(XMMRegister reg, Register rm_reg) { | 94 void Assembler::emit_rex_64(XMMRegister reg, Register rm_reg) { |
103 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3); | 95 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3); |
104 } | 96 } |
105 | 97 |
106 | 98 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 201 |
210 Address Assembler::target_address_from_return_address(Address pc) { | 202 Address Assembler::target_address_from_return_address(Address pc) { |
211 return pc - kCallTargetAddressOffset; | 203 return pc - kCallTargetAddressOffset; |
212 } | 204 } |
213 | 205 |
214 | 206 |
215 Handle<Object> Assembler::code_target_object_handle_at(Address pc) { | 207 Handle<Object> Assembler::code_target_object_handle_at(Address pc) { |
216 return code_targets_[Memory::int32_at(pc)]; | 208 return code_targets_[Memory::int32_at(pc)]; |
217 } | 209 } |
218 | 210 |
219 | |
220 Address Assembler::runtime_entry_at(Address pc) { | |
221 ASSERT(isolate()->code_range()->exists()); | |
222 return Memory::int32_at(pc) + isolate()->code_range()->start(); | |
223 } | |
224 | |
225 // ----------------------------------------------------------------------------- | 211 // ----------------------------------------------------------------------------- |
226 // Implementation of RelocInfo | 212 // Implementation of RelocInfo |
227 | 213 |
228 // The modes possibly affected by apply must be in kApplyMask. | 214 // The modes possibly affected by apply must be in kApplyMask. |
229 void RelocInfo::apply(intptr_t delta) { | 215 void RelocInfo::apply(intptr_t delta) { |
230 if (IsInternalReference(rmode_)) { | 216 if (IsInternalReference(rmode_)) { |
231 // absolute code pointer inside code object moves with the code object. | 217 // absolute code pointer inside code object moves with the code object. |
232 Memory::Address_at(pc_) += static_cast<int32_t>(delta); | 218 Memory::Address_at(pc_) += static_cast<int32_t>(delta); |
233 CPU::FlushICache(pc_, sizeof(Address)); | 219 CPU::FlushICache(pc_, sizeof(Address)); |
234 } else if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)) { | 220 } else if (IsCodeTarget(rmode_)) { |
235 Memory::int32_at(pc_) -= static_cast<int32_t>(delta); | 221 Memory::int32_at(pc_) -= static_cast<int32_t>(delta); |
236 CPU::FlushICache(pc_, sizeof(int32_t)); | 222 CPU::FlushICache(pc_, sizeof(int32_t)); |
237 } else if (rmode_ == CODE_AGE_SEQUENCE) { | 223 } else if (rmode_ == CODE_AGE_SEQUENCE) { |
238 if (*pc_ == kCallOpcode) { | 224 if (*pc_ == kCallOpcode) { |
239 int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1); | 225 int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1); |
240 *p -= static_cast<int32_t>(delta); // Relocate entry. | 226 *p -= static_cast<int32_t>(delta); // Relocate entry. |
241 CPU::FlushICache(p, sizeof(uint32_t)); | 227 CPU::FlushICache(p, sizeof(uint32_t)); |
242 } | 228 } |
243 } | 229 } |
244 } | 230 } |
245 | 231 |
246 | 232 |
247 Address RelocInfo::target_address() { | 233 Address RelocInfo::target_address() { |
248 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); | 234 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); |
249 return Assembler::target_address_at(pc_); | 235 if (IsCodeTarget(rmode_)) { |
| 236 return Assembler::target_address_at(pc_); |
| 237 } else { |
| 238 return Memory::Address_at(pc_); |
| 239 } |
250 } | 240 } |
251 | 241 |
252 | 242 |
253 Address RelocInfo::target_address_address() { | 243 Address RelocInfo::target_address_address() { |
254 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) | 244 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY |
255 || rmode_ == EMBEDDED_OBJECT | 245 || rmode_ == EMBEDDED_OBJECT |
256 || rmode_ == EXTERNAL_REFERENCE); | 246 || rmode_ == EXTERNAL_REFERENCE); |
257 return reinterpret_cast<Address>(pc_); | 247 return reinterpret_cast<Address>(pc_); |
258 } | 248 } |
259 | 249 |
260 | 250 |
261 int RelocInfo::target_address_size() { | 251 int RelocInfo::target_address_size() { |
262 if (IsCodedSpecially()) { | 252 if (IsCodedSpecially()) { |
263 return Assembler::kSpecialTargetSize; | 253 return Assembler::kSpecialTargetSize; |
264 } else { | 254 } else { |
265 return kPointerSize; | 255 return kPointerSize; |
266 } | 256 } |
267 } | 257 } |
268 | 258 |
269 | 259 |
270 void RelocInfo::set_target_address(Address target, WriteBarrierMode mode) { | 260 void RelocInfo::set_target_address(Address target, WriteBarrierMode mode) { |
271 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); | 261 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); |
272 Assembler::set_target_address_at(pc_, target); | 262 if (IsCodeTarget(rmode_)) { |
273 if (mode == UPDATE_WRITE_BARRIER && host() != NULL && IsCodeTarget(rmode_)) { | 263 Assembler::set_target_address_at(pc_, target); |
274 Object* target_code = Code::GetCodeFromTargetAddress(target); | 264 Object* target_code = Code::GetCodeFromTargetAddress(target); |
275 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( | 265 if (mode == UPDATE_WRITE_BARRIER && host() != NULL) { |
276 host(), this, HeapObject::cast(target_code)); | 266 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 267 host(), this, HeapObject::cast(target_code)); |
| 268 } |
| 269 } else { |
| 270 Memory::Address_at(pc_) = target; |
| 271 CPU::FlushICache(pc_, sizeof(Address)); |
277 } | 272 } |
278 } | 273 } |
279 | 274 |
280 | 275 |
281 Object* RelocInfo::target_object() { | 276 Object* RelocInfo::target_object() { |
282 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); | 277 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
283 return Memory::Object_at(pc_); | 278 return Memory::Object_at(pc_); |
284 } | 279 } |
285 | 280 |
286 | 281 |
(...skipping 25 matching lines...) Expand all Loading... |
312 CPU::FlushICache(pc_, sizeof(Address)); | 307 CPU::FlushICache(pc_, sizeof(Address)); |
313 if (mode == UPDATE_WRITE_BARRIER && | 308 if (mode == UPDATE_WRITE_BARRIER && |
314 host() != NULL && | 309 host() != NULL && |
315 target->IsHeapObject()) { | 310 target->IsHeapObject()) { |
316 host()->GetHeap()->incremental_marking()->RecordWrite( | 311 host()->GetHeap()->incremental_marking()->RecordWrite( |
317 host(), &Memory::Object_at(pc_), HeapObject::cast(target)); | 312 host(), &Memory::Object_at(pc_), HeapObject::cast(target)); |
318 } | 313 } |
319 } | 314 } |
320 | 315 |
321 | 316 |
322 Address RelocInfo::target_runtime_entry(Assembler* origin) { | |
323 ASSERT(IsRuntimeEntry(rmode_)); | |
324 return origin->runtime_entry_at(pc_); | |
325 } | |
326 | |
327 | |
328 void RelocInfo::set_target_runtime_entry(Address target, | |
329 WriteBarrierMode mode) { | |
330 ASSERT(IsRuntimeEntry(rmode_)); | |
331 if (target_address() != target) set_target_address(target, mode); | |
332 } | |
333 | |
334 | |
335 Handle<JSGlobalPropertyCell> RelocInfo::target_cell_handle() { | 317 Handle<JSGlobalPropertyCell> RelocInfo::target_cell_handle() { |
336 ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL); | 318 ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL); |
337 Address address = Memory::Address_at(pc_); | 319 Address address = Memory::Address_at(pc_); |
338 return Handle<JSGlobalPropertyCell>( | 320 return Handle<JSGlobalPropertyCell>( |
339 reinterpret_cast<JSGlobalPropertyCell**>(address)); | 321 reinterpret_cast<JSGlobalPropertyCell**>(address)); |
340 } | 322 } |
341 | 323 |
342 | 324 |
343 JSGlobalPropertyCell* RelocInfo::target_cell() { | 325 JSGlobalPropertyCell* RelocInfo::target_cell() { |
344 ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL); | 326 ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 visitor->VisitCodeAgeSequence(this); | 436 visitor->VisitCodeAgeSequence(this); |
455 #ifdef ENABLE_DEBUGGER_SUPPORT | 437 #ifdef ENABLE_DEBUGGER_SUPPORT |
456 // TODO(isolates): Get a cached isolate below. | 438 // TODO(isolates): Get a cached isolate below. |
457 } else if (((RelocInfo::IsJSReturn(mode) && | 439 } else if (((RelocInfo::IsJSReturn(mode) && |
458 IsPatchedReturnSequence()) || | 440 IsPatchedReturnSequence()) || |
459 (RelocInfo::IsDebugBreakSlot(mode) && | 441 (RelocInfo::IsDebugBreakSlot(mode) && |
460 IsPatchedDebugBreakSlotSequence())) && | 442 IsPatchedDebugBreakSlotSequence())) && |
461 Isolate::Current()->debug()->has_break_points()) { | 443 Isolate::Current()->debug()->has_break_points()) { |
462 visitor->VisitDebugTarget(this); | 444 visitor->VisitDebugTarget(this); |
463 #endif | 445 #endif |
464 } else if (RelocInfo::IsRuntimeEntry(mode)) { | 446 } else if (mode == RelocInfo::RUNTIME_ENTRY) { |
465 visitor->VisitRuntimeEntry(this); | 447 visitor->VisitRuntimeEntry(this); |
466 } | 448 } |
467 } | 449 } |
468 | 450 |
469 | 451 |
470 template<typename StaticVisitor> | 452 template<typename StaticVisitor> |
471 void RelocInfo::Visit(Heap* heap) { | 453 void RelocInfo::Visit(Heap* heap) { |
472 RelocInfo::Mode mode = rmode(); | 454 RelocInfo::Mode mode = rmode(); |
473 if (mode == RelocInfo::EMBEDDED_OBJECT) { | 455 if (mode == RelocInfo::EMBEDDED_OBJECT) { |
474 StaticVisitor::VisitEmbeddedPointer(heap, this); | 456 StaticVisitor::VisitEmbeddedPointer(heap, this); |
475 CPU::FlushICache(pc_, sizeof(Address)); | 457 CPU::FlushICache(pc_, sizeof(Address)); |
476 } else if (RelocInfo::IsCodeTarget(mode)) { | 458 } else if (RelocInfo::IsCodeTarget(mode)) { |
477 StaticVisitor::VisitCodeTarget(heap, this); | 459 StaticVisitor::VisitCodeTarget(heap, this); |
478 } else if (mode == RelocInfo::GLOBAL_PROPERTY_CELL) { | 460 } else if (mode == RelocInfo::GLOBAL_PROPERTY_CELL) { |
479 StaticVisitor::VisitGlobalPropertyCell(heap, this); | 461 StaticVisitor::VisitGlobalPropertyCell(heap, this); |
480 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) { | 462 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) { |
481 StaticVisitor::VisitExternalReference(this); | 463 StaticVisitor::VisitExternalReference(this); |
482 CPU::FlushICache(pc_, sizeof(Address)); | 464 CPU::FlushICache(pc_, sizeof(Address)); |
483 } else if (RelocInfo::IsCodeAgeSequence(mode)) { | 465 } else if (RelocInfo::IsCodeAgeSequence(mode)) { |
484 StaticVisitor::VisitCodeAgeSequence(heap, this); | 466 StaticVisitor::VisitCodeAgeSequence(heap, this); |
485 #ifdef ENABLE_DEBUGGER_SUPPORT | 467 #ifdef ENABLE_DEBUGGER_SUPPORT |
486 } else if (heap->isolate()->debug()->has_break_points() && | 468 } else if (heap->isolate()->debug()->has_break_points() && |
487 ((RelocInfo::IsJSReturn(mode) && | 469 ((RelocInfo::IsJSReturn(mode) && |
488 IsPatchedReturnSequence()) || | 470 IsPatchedReturnSequence()) || |
489 (RelocInfo::IsDebugBreakSlot(mode) && | 471 (RelocInfo::IsDebugBreakSlot(mode) && |
490 IsPatchedDebugBreakSlotSequence()))) { | 472 IsPatchedDebugBreakSlotSequence()))) { |
491 StaticVisitor::VisitDebugTarget(heap, this); | 473 StaticVisitor::VisitDebugTarget(heap, this); |
492 #endif | 474 #endif |
493 } else if (RelocInfo::IsRuntimeEntry(mode)) { | 475 } else if (mode == RelocInfo::RUNTIME_ENTRY) { |
494 StaticVisitor::VisitRuntimeEntry(this); | 476 StaticVisitor::VisitRuntimeEntry(this); |
495 } | 477 } |
496 } | 478 } |
497 | 479 |
498 | 480 |
499 // ----------------------------------------------------------------------------- | 481 // ----------------------------------------------------------------------------- |
500 // Implementation of Operand | 482 // Implementation of Operand |
501 | 483 |
502 void Operand::set_modrm(int mod, Register rm_reg) { | 484 void Operand::set_modrm(int mod, Register rm_reg) { |
503 ASSERT(is_uint2(mod)); | 485 ASSERT(is_uint2(mod)); |
(...skipping 26 matching lines...) Expand all Loading... |
530 ASSERT(len_ == 1 || len_ == 2); | 512 ASSERT(len_ == 1 || len_ == 2); |
531 int32_t* p = reinterpret_cast<int32_t*>(&buf_[len_]); | 513 int32_t* p = reinterpret_cast<int32_t*>(&buf_[len_]); |
532 *p = disp; | 514 *p = disp; |
533 len_ += sizeof(int32_t); | 515 len_ += sizeof(int32_t); |
534 } | 516 } |
535 | 517 |
536 | 518 |
537 } } // namespace v8::internal | 519 } } // namespace v8::internal |
538 | 520 |
539 #endif // V8_X64_ASSEMBLER_X64_INL_H_ | 521 #endif // V8_X64_ASSEMBLER_X64_INL_H_ |
OLD | NEW |