Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 MaybeObject* result = stub->TryGetCode(); | 320 MaybeObject* result = stub->TryGetCode(); |
| 321 if (!result->IsFailure()) { | 321 if (!result->IsFailure()) { |
| 322 call(Handle<Code>(Code::cast(result->ToObjectUnchecked())), | 322 call(Handle<Code>(Code::cast(result->ToObjectUnchecked())), |
| 323 RelocInfo::CODE_TARGET); | 323 RelocInfo::CODE_TARGET); |
| 324 } | 324 } |
| 325 return result; | 325 return result; |
| 326 } | 326 } |
| 327 | 327 |
| 328 | 328 |
| 329 void MacroAssembler::TailCallStub(CodeStub* stub) { | 329 void MacroAssembler::TailCallStub(CodeStub* stub) { |
| 330 ASSERT(allow_stub_calls()); // calls are not allowed in some stubs | 330 ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
| 331 Jump(stub->GetCode(), RelocInfo::CODE_TARGET); | 331 Jump(stub->GetCode(), RelocInfo::CODE_TARGET); |
| 332 } | 332 } |
| 333 | 333 |
| 334 | 334 |
| 335 MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub) { | 335 MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub) { |
| 336 ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. | 336 ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
| 337 MaybeObject* result = stub->TryGetCode(); | 337 MaybeObject* result = stub->TryGetCode(); |
| 338 if (!result->IsFailure()) { | 338 if (!result->IsFailure()) { |
| 339 jmp(Handle<Code>(Code::cast(result->ToObjectUnchecked())), | 339 jmp(Handle<Code>(Code::cast(result->ToObjectUnchecked())), |
| 340 RelocInfo::CODE_TARGET); | 340 RelocInfo::CODE_TARGET); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 | 449 |
| 450 // TODO(1236192): Most runtime routines don't need the number of | 450 // TODO(1236192): Most runtime routines don't need the number of |
| 451 // arguments passed in because it is constant. At some point we | 451 // arguments passed in because it is constant. At some point we |
| 452 // should remove this need and make the runtime routine entry code | 452 // should remove this need and make the runtime routine entry code |
| 453 // smarter. | 453 // smarter. |
| 454 Set(rax, num_arguments); | 454 Set(rax, num_arguments); |
| 455 JumpToExternalReference(ext, result_size); | 455 JumpToExternalReference(ext, result_size); |
| 456 } | 456 } |
| 457 | 457 |
| 458 | 458 |
| 459 MaybeObject* MacroAssembler::TryTailCallExternalReference( | |
| 460 const ExternalReference& ext, int num_arguments, int result_size) { | |
| 461 // ----------- S t a t e ------------- | |
| 462 // -- rsp[0] : return address | |
| 463 // -- rsp[8] : argument num_arguments - 1 | |
| 464 // ... | |
| 465 // -- rsp[8 * num_arguments] : argument 0 (receiver) | |
| 466 // ----------------------------------- | |
| 467 | |
| 468 // TODO(1236192): Most runtime routines don't need the number of | |
| 469 // arguments passed in because it is constant. At some point we | |
| 470 // should remove this need and make the runtime routine entry code | |
| 471 // smarter. | |
| 472 Set(rax, num_arguments); | |
| 473 return TryJumpToExternalReference(ext, result_size); | |
| 474 } | |
| 475 | |
| 476 | |
| 459 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, | 477 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 460 int num_arguments, | 478 int num_arguments, |
| 461 int result_size) { | 479 int result_size) { |
| 462 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); | 480 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
| 463 } | 481 } |
| 464 | 482 |
| 465 | 483 |
| 484 MaybeObject* MacroAssembler::TryTailCallRuntime(Runtime::FunctionId fid, | |
| 485 int num_arguments, | |
| 486 int result_size) { | |
| 487 return TryTailCallExternalReference(ExternalReference(fid), | |
| 488 num_arguments, | |
| 489 result_size); | |
| 490 } | |
| 491 | |
| 492 | |
| 466 static int Offset(ExternalReference ref0, ExternalReference ref1) { | 493 static int Offset(ExternalReference ref0, ExternalReference ref1) { |
| 467 int64_t offset = (ref0.address() - ref1.address()); | 494 int64_t offset = (ref0.address() - ref1.address()); |
| 468 // Check that fits into int. | 495 // Check that fits into int. |
| 469 ASSERT(static_cast<int>(offset) == offset); | 496 ASSERT(static_cast<int>(offset) == offset); |
| 470 return static_cast<int>(offset); | 497 return static_cast<int>(offset); |
| 471 } | 498 } |
| 472 | 499 |
| 473 | 500 |
| 474 void MacroAssembler::PrepareCallApiFunction(int stack_space) { | 501 void MacroAssembler::PrepareCallApiFunction(int stack_space, int argc) { |
| 475 EnterApiExitFrame(stack_space, 0); | 502 #ifdef _WIN64 |
| 503 // We need to prepare a slot for result handle on stack and put | |
| 504 // a pointer to it into 1st arg register. | |
| 505 int register_based_args = argc > 3 ? 3 : argc; | |
| 506 EnterApiExitFrame(stack_space, argc - register_based_args + 1); | |
| 507 | |
| 508 int return_value_slot = (argc > 3 ? argc - 3 + 1 : 4); | |
| 509 // rcx must be used to pass the pointer to the return value slot. | |
| 510 lea(rcx, Operand(rsp, return_value_slot * kPointerSize)); | |
| 511 #else | |
| 512 EnterApiExitFrame(stack_space, argc); | |
| 513 #endif | |
| 476 } | 514 } |
| 477 | 515 |
| 478 | 516 |
| 479 void MacroAssembler::CallApiFunctionAndReturn(ApiFunction* function) { | 517 MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
| 518 ApiFunction* function) { | |
| 480 Label empty_result; | 519 Label empty_result; |
| 481 Label prologue; | 520 Label prologue; |
| 482 Label promote_scheduled_exception; | 521 Label promote_scheduled_exception; |
| 483 Label delete_allocated_handles; | 522 Label delete_allocated_handles; |
| 484 Label leave_exit_frame; | 523 Label leave_exit_frame; |
| 485 Label write_back; | 524 Label write_back; |
| 486 | 525 |
| 487 ExternalReference next_address = | 526 ExternalReference next_address = |
| 488 ExternalReference::handle_scope_next_address(); | 527 ExternalReference::handle_scope_next_address(); |
| 489 const int kNextOffset = 0; | 528 const int kNextOffset = 0; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 | 571 |
| 533 // Check if the function scheduled an exception. | 572 // Check if the function scheduled an exception. |
| 534 movq(rsi, scheduled_exception_address); | 573 movq(rsi, scheduled_exception_address); |
| 535 Cmp(Operand(rsi, 0), Factory::the_hole_value()); | 574 Cmp(Operand(rsi, 0), Factory::the_hole_value()); |
| 536 j(not_equal, &promote_scheduled_exception); | 575 j(not_equal, &promote_scheduled_exception); |
| 537 | 576 |
| 538 LeaveExitFrame(); | 577 LeaveExitFrame(); |
| 539 ret(0); | 578 ret(0); |
| 540 | 579 |
| 541 bind(&promote_scheduled_exception); | 580 bind(&promote_scheduled_exception); |
| 542 TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1); | 581 MaybeObject* result = TryTailCallRuntime(Runtime::kPromoteScheduledException, |
| 582 0, 1); | |
| 583 if (result->IsFailure()) { | |
| 584 return result; | |
| 585 } | |
| 543 | 586 |
| 544 bind(&empty_result); | 587 bind(&empty_result); |
| 545 // It was zero; the result is undefined. | 588 // It was zero; the result is undefined. |
| 546 Move(rax, Factory::undefined_value()); | 589 Move(rax, Factory::undefined_value()); |
| 547 jmp(&prologue); | 590 jmp(&prologue); |
| 548 | 591 |
| 549 // HandleScope limit has changed. Delete allocated extensions. | 592 // HandleScope limit has changed. Delete allocated extensions. |
| 550 bind(&delete_allocated_handles); | 593 bind(&delete_allocated_handles); |
| 551 movq(Operand(base_reg, kLimitOffset), prev_limit_reg); | 594 movq(Operand(base_reg, kLimitOffset), prev_limit_reg); |
| 552 movq(prev_limit_reg, rax); | 595 movq(prev_limit_reg, rax); |
| 553 movq(rax, ExternalReference::delete_handle_scope_extensions()); | 596 movq(rax, ExternalReference::delete_handle_scope_extensions()); |
| 554 call(rax); | 597 call(rax); |
| 555 movq(rax, prev_limit_reg); | 598 movq(rax, prev_limit_reg); |
| 556 jmp(&leave_exit_frame); | 599 jmp(&leave_exit_frame); |
| 600 | |
| 601 return result; | |
| 557 } | 602 } |
| 558 | 603 |
| 559 | 604 |
| 560 void MacroAssembler::JumpToExternalReference(const ExternalReference& ext, | 605 void MacroAssembler::JumpToExternalReference(const ExternalReference& ext, |
| 561 int result_size) { | 606 int result_size) { |
| 562 // Set the entry point and jump to the C entry runtime stub. | 607 // Set the entry point and jump to the C entry runtime stub. |
| 563 movq(rbx, ext); | 608 movq(rbx, ext); |
| 564 CEntryStub ces(result_size); | 609 CEntryStub ces(result_size); |
| 565 jmp(ces.GetCode(), RelocInfo::CODE_TARGET); | 610 jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 566 } | 611 } |
| 567 | 612 |
| 568 | 613 |
| 614 MaybeObject* MacroAssembler::TryJumpToExternalReference( | |
| 615 const ExternalReference& ext, int result_size) { | |
| 616 // Set the entry point and jump to the C entry runtime stub. | |
| 617 movq(rbx, ext); | |
| 618 CEntryStub ces(result_size); | |
| 619 return TryTailCallStub(&ces); | |
| 620 } | |
| 621 | |
| 622 | |
| 569 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) { | 623 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) { |
| 570 // Calls are not allowed in some stubs. | 624 // Calls are not allowed in some stubs. |
| 571 ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); | 625 ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); |
| 572 | 626 |
| 573 // Rely on the assertion to check that the number of provided | 627 // Rely on the assertion to check that the number of provided |
| 574 // arguments match the expected number of arguments. Fake a | 628 // arguments match the expected number of arguments. Fake a |
| 575 // parameter count to avoid emitting code to do the check. | 629 // parameter count to avoid emitting code to do the check. |
| 576 ParameterCount expected(0); | 630 ParameterCount expected(0); |
| 577 GetBuiltinEntry(rdx, id); | 631 GetBuiltinEntry(rdx, id); |
| 578 InvokeCode(rdx, expected, expected, flag); | 632 InvokeCode(rdx, expected, expected, flag); |
| (...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1735 void MacroAssembler::EnterApiExitFrame(int stack_space, | 1789 void MacroAssembler::EnterApiExitFrame(int stack_space, |
| 1736 int argc, | 1790 int argc, |
| 1737 int result_size) { | 1791 int result_size) { |
| 1738 EnterExitFramePrologue(false); | 1792 EnterExitFramePrologue(false); |
| 1739 | 1793 |
| 1740 // Setup argv in callee-saved register r12. It is reused in LeaveExitFrame, | 1794 // Setup argv in callee-saved register r12. It is reused in LeaveExitFrame, |
| 1741 // so it must be retained across the C-call. | 1795 // so it must be retained across the C-call. |
| 1742 int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; | 1796 int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 1743 lea(r12, Operand(rbp, (stack_space * kPointerSize) + offset)); | 1797 lea(r12, Operand(rbp, (stack_space * kPointerSize) + offset)); |
| 1744 | 1798 |
| 1799 #ifndef _WIN64 | |
| 1800 ASSERT(argc <= 6); // EnterApiExitFrame supports only register based args. | |
|
antonm
2010/11/15 16:22:06
Sorry, I still don't understand what. What will h
SeRya
2010/11/15 16:37:50
Currently it's used only for getters for x64 (yet)
| |
| 1801 #endif | |
| 1802 | |
| 1745 EnterExitFrameEpilogue(result_size, argc); | 1803 EnterExitFrameEpilogue(result_size, argc); |
| 1746 } | 1804 } |
| 1747 | 1805 |
| 1748 | 1806 |
| 1749 void MacroAssembler::LeaveExitFrame(int result_size) { | 1807 void MacroAssembler::LeaveExitFrame(int result_size) { |
| 1750 // Registers: | 1808 // Registers: |
| 1751 // r12 : argv | 1809 // r12 : argv |
| 1752 | 1810 |
| 1753 // Get the return address from the stack and restore the frame pointer. | 1811 // Get the return address from the stack and restore the frame pointer. |
| 1754 movq(rcx, Operand(rbp, 1 * kPointerSize)); | 1812 movq(rcx, Operand(rbp, 1 * kPointerSize)); |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2280 CPU::FlushICache(address_, size_); | 2338 CPU::FlushICache(address_, size_); |
| 2281 | 2339 |
| 2282 // Check that the code was patched as expected. | 2340 // Check that the code was patched as expected. |
| 2283 ASSERT(masm_.pc_ == address_ + size_); | 2341 ASSERT(masm_.pc_ == address_ + size_); |
| 2284 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2342 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2285 } | 2343 } |
| 2286 | 2344 |
| 2287 } } // namespace v8::internal | 2345 } } // namespace v8::internal |
| 2288 | 2346 |
| 2289 #endif // V8_TARGET_ARCH_X64 | 2347 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |