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 ASSERT(argc <= 6); // EnterApiExitFrame supports only register based args. | |
|
antonm
2010/11/13 11:34:46
you don't have checks that revert to slow path if
SeRya
2010/11/15 12:09:11
Actually I see the following issue. EnterExitFrame
| |
| 513 EnterApiExitFrame(stack_space, argc); | |
| 514 #endif | |
| 476 } | 515 } |
| 477 | 516 |
| 478 | 517 |
| 479 void MacroAssembler::CallApiFunctionAndReturn(ApiFunction* function) { | 518 MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
| 519 ApiFunction* function) { | |
| 480 Label empty_result; | 520 Label empty_result; |
| 481 Label prologue; | 521 Label prologue; |
| 482 Label promote_scheduled_exception; | 522 Label promote_scheduled_exception; |
| 483 Label delete_allocated_handles; | 523 Label delete_allocated_handles; |
| 484 Label leave_exit_frame; | 524 Label leave_exit_frame; |
| 485 Label write_back; | 525 Label write_back; |
| 486 | 526 |
| 487 ExternalReference next_address = | 527 ExternalReference next_address = |
| 488 ExternalReference::handle_scope_next_address(); | 528 ExternalReference::handle_scope_next_address(); |
| 489 const int kNextOffset = 0; | 529 const int kNextOffset = 0; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 | 572 |
| 533 // Check if the function scheduled an exception. | 573 // Check if the function scheduled an exception. |
| 534 movq(rsi, scheduled_exception_address); | 574 movq(rsi, scheduled_exception_address); |
| 535 Cmp(Operand(rsi, 0), Factory::the_hole_value()); | 575 Cmp(Operand(rsi, 0), Factory::the_hole_value()); |
| 536 j(not_equal, &promote_scheduled_exception); | 576 j(not_equal, &promote_scheduled_exception); |
| 537 | 577 |
| 538 LeaveExitFrame(); | 578 LeaveExitFrame(); |
| 539 ret(0); | 579 ret(0); |
| 540 | 580 |
| 541 bind(&promote_scheduled_exception); | 581 bind(&promote_scheduled_exception); |
| 542 TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1); | 582 MaybeObject* result = TryTailCallRuntime(Runtime::kPromoteScheduledException, |
| 583 0, 1); | |
| 584 if (result->IsFailure()) { | |
| 585 return result; | |
| 586 } | |
| 543 | 587 |
| 544 bind(&empty_result); | 588 bind(&empty_result); |
| 545 // It was zero; the result is undefined. | 589 // It was zero; the result is undefined. |
| 546 Move(rax, Factory::undefined_value()); | 590 Move(rax, Factory::undefined_value()); |
| 547 jmp(&prologue); | 591 jmp(&prologue); |
| 548 | 592 |
| 549 // HandleScope limit has changed. Delete allocated extensions. | 593 // HandleScope limit has changed. Delete allocated extensions. |
| 550 bind(&delete_allocated_handles); | 594 bind(&delete_allocated_handles); |
| 551 movq(Operand(base_reg, kLimitOffset), prev_limit_reg); | 595 movq(Operand(base_reg, kLimitOffset), prev_limit_reg); |
| 552 movq(prev_limit_reg, rax); | 596 movq(prev_limit_reg, rax); |
| 553 movq(rax, ExternalReference::delete_handle_scope_extensions()); | 597 movq(rax, ExternalReference::delete_handle_scope_extensions()); |
| 554 call(rax); | 598 call(rax); |
| 555 movq(rax, prev_limit_reg); | 599 movq(rax, prev_limit_reg); |
| 556 jmp(&leave_exit_frame); | 600 jmp(&leave_exit_frame); |
| 601 | |
| 602 return result; | |
| 557 } | 603 } |
| 558 | 604 |
| 559 | 605 |
| 560 void MacroAssembler::JumpToExternalReference(const ExternalReference& ext, | 606 void MacroAssembler::JumpToExternalReference(const ExternalReference& ext, |
| 561 int result_size) { | 607 int result_size) { |
| 562 // Set the entry point and jump to the C entry runtime stub. | 608 // Set the entry point and jump to the C entry runtime stub. |
| 563 movq(rbx, ext); | 609 movq(rbx, ext); |
| 564 CEntryStub ces(result_size); | 610 CEntryStub ces(result_size); |
| 565 jmp(ces.GetCode(), RelocInfo::CODE_TARGET); | 611 jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 566 } | 612 } |
| 567 | 613 |
| 568 | 614 |
| 615 MaybeObject* MacroAssembler::TryJumpToExternalReference( | |
| 616 const ExternalReference& ext, int result_size) { | |
| 617 // Set the entry point and jump to the C entry runtime stub. | |
| 618 movq(rbx, ext); | |
| 619 CEntryStub ces(result_size); | |
| 620 return TryTailCallStub(&ces); | |
| 621 } | |
| 622 | |
| 623 | |
| 569 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) { | 624 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) { |
| 570 // Calls are not allowed in some stubs. | 625 // Calls are not allowed in some stubs. |
| 571 ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); | 626 ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); |
| 572 | 627 |
| 573 // Rely on the assertion to check that the number of provided | 628 // Rely on the assertion to check that the number of provided |
| 574 // arguments match the expected number of arguments. Fake a | 629 // arguments match the expected number of arguments. Fake a |
| 575 // parameter count to avoid emitting code to do the check. | 630 // parameter count to avoid emitting code to do the check. |
| 576 ParameterCount expected(0); | 631 ParameterCount expected(0); |
| 577 GetBuiltinEntry(rdx, id); | 632 GetBuiltinEntry(rdx, id); |
| 578 InvokeCode(rdx, expected, expected, flag); | 633 InvokeCode(rdx, expected, expected, flag); |
| (...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2280 CPU::FlushICache(address_, size_); | 2335 CPU::FlushICache(address_, size_); |
| 2281 | 2336 |
| 2282 // Check that the code was patched as expected. | 2337 // Check that the code was patched as expected. |
| 2283 ASSERT(masm_.pc_ == address_ + size_); | 2338 ASSERT(masm_.pc_ == address_ + size_); |
| 2284 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2339 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2285 } | 2340 } |
| 2286 | 2341 |
| 2287 } } // namespace v8::internal | 2342 } } // namespace v8::internal |
| 2288 | 2343 |
| 2289 #endif // V8_TARGET_ARCH_X64 | 2344 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |