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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 __ bind(&global); | 555 __ bind(&global); |
556 __ movq(rdx, FieldOperand(rdx, GlobalObject::kGlobalReceiverOffset)); | 556 __ movq(rdx, FieldOperand(rdx, GlobalObject::kGlobalReceiverOffset)); |
557 __ movq(Operand(rsp, (argc + 1) * kPointerSize), rdx); | 557 __ movq(Operand(rsp, (argc + 1) * kPointerSize), rdx); |
558 | 558 |
559 // Invoke the function. | 559 // Invoke the function. |
560 ParameterCount actual(argc); | 560 ParameterCount actual(argc); |
561 __ bind(&invoke); | 561 __ bind(&invoke); |
562 __ InvokeFunction(rdi, actual, JUMP_FUNCTION); | 562 __ InvokeFunction(rdi, actual, JUMP_FUNCTION); |
563 } | 563 } |
564 | 564 |
| 565 |
| 566 // Defined in ic.cc. |
| 567 Object* CallIC_Miss(Arguments args); |
| 568 |
565 void CallIC::GenerateMegamorphic(MacroAssembler* masm, int argc) { | 569 void CallIC::GenerateMegamorphic(MacroAssembler* masm, int argc) { |
| 570 // ----------- S t a t e ------------- |
| 571 // rsp[0] return address |
| 572 // rsp[8] argument argc |
| 573 // rsp[16] argument argc - 1 |
| 574 // ... |
| 575 // rsp[argc * 8] argument 1 |
| 576 // rsp[(argc + 1) * 8] argument 0 = reciever |
| 577 // rsp[(argc + 2) * 8] function name |
| 578 // ----------------------------------- |
| 579 Label number, non_number, non_string, boolean, probe, miss; |
| 580 |
| 581 // Get the receiver of the function from the stack; 1 ~ return address. |
| 582 __ movq(rdx, Operand(rsp, (argc + 1) * kPointerSize)); |
| 583 // Get the name of the function from the stack; 2 ~ return address, receiver |
| 584 __ movq(rcx, Operand(rsp, (argc + 2) * kPointerSize)); |
| 585 |
| 586 // Probe the stub cache. |
| 587 Code::Flags flags = |
| 588 Code::ComputeFlags(Code::CALL_IC, NOT_IN_LOOP, MONOMORPHIC, NORMAL, argc); |
| 589 StubCache::GenerateProbe(masm, flags, rdx, rcx, rbx, rax); |
| 590 |
| 591 // If the stub cache probing failed, the receiver might be a value. |
| 592 // For value objects, we use the map of the prototype objects for |
| 593 // the corresponding JSValue for the cache and that is what we need |
| 594 // to probe. |
| 595 // |
| 596 // Check for number. |
| 597 __ testl(rdx, Immediate(kSmiTagMask)); |
| 598 __ j(zero, &number); |
| 599 __ CmpObjectType(rdx, HEAP_NUMBER_TYPE, rbx); |
| 600 __ j(not_equal, &non_number); |
| 601 __ bind(&number); |
| 602 StubCompiler::GenerateLoadGlobalFunctionPrototype( |
| 603 masm, Context::NUMBER_FUNCTION_INDEX, rdx); |
| 604 __ jmp(&probe); |
| 605 |
| 606 // Check for string. |
| 607 __ bind(&non_number); |
| 608 __ CmpInstanceType(rbx, FIRST_NONSTRING_TYPE); |
| 609 __ j(above_equal, &non_string); |
| 610 StubCompiler::GenerateLoadGlobalFunctionPrototype( |
| 611 masm, Context::STRING_FUNCTION_INDEX, rdx); |
| 612 __ jmp(&probe); |
| 613 |
| 614 // Check for boolean. |
| 615 __ bind(&non_string); |
| 616 __ Cmp(rdx, Factory::true_value()); |
| 617 __ j(equal, &boolean); |
| 618 __ Cmp(rdx, Factory::false_value()); |
| 619 __ j(not_equal, &miss); |
| 620 __ bind(&boolean); |
| 621 StubCompiler::GenerateLoadGlobalFunctionPrototype( |
| 622 masm, Context::BOOLEAN_FUNCTION_INDEX, rdx); |
| 623 |
| 624 // Probe the stub cache for the value object. |
| 625 __ bind(&probe); |
| 626 StubCache::GenerateProbe(masm, flags, rdx, rcx, rbx, no_reg); |
| 627 |
566 // Cache miss: Jump to runtime. | 628 // Cache miss: Jump to runtime. |
| 629 __ bind(&miss); |
567 Generate(masm, argc, ExternalReference(IC_Utility(kCallIC_Miss))); | 630 Generate(masm, argc, ExternalReference(IC_Utility(kCallIC_Miss))); |
568 } | 631 } |
569 | 632 |
| 633 |
| 634 static void GenerateNormalHelper(MacroAssembler* masm, |
| 635 int argc, |
| 636 bool is_global_object, |
| 637 Label* miss) { |
| 638 // Search dictionary - put result in register edx. |
| 639 GenerateDictionaryLoad(masm, miss, rax, rdx, rbx, rcx); |
| 640 |
| 641 // Move the result to register rdi and check that it isn't a smi. |
| 642 __ movq(rdi, rdx); |
| 643 __ testl(rdx, Immediate(kSmiTagMask)); |
| 644 __ j(zero, miss); |
| 645 |
| 646 // Check that the value is a JavaScript function. |
| 647 __ CmpObjectType(rdx, JS_FUNCTION_TYPE, rdx); |
| 648 __ j(not_equal, miss); |
| 649 // Check that the function has been loaded. |
| 650 __ testb(FieldOperand(rdx, Map::kBitField2Offset), |
| 651 Immediate(1 << Map::kNeedsLoading)); |
| 652 __ j(not_zero, miss); |
| 653 |
| 654 // Patch the receiver with the global proxy if necessary. |
| 655 if (is_global_object) { |
| 656 __ movq(rdx, Operand(rsp, (argc + 1) * kPointerSize)); |
| 657 __ movq(rdx, FieldOperand(rdx, GlobalObject::kGlobalReceiverOffset)); |
| 658 __ movq(Operand(rsp, (argc + 1) * kPointerSize), rdx); |
| 659 } |
| 660 |
| 661 // Invoke the function. |
| 662 ParameterCount actual(argc); |
| 663 __ InvokeFunction(rdi, actual, JUMP_FUNCTION); |
| 664 } |
| 665 |
| 666 |
570 void CallIC::GenerateNormal(MacroAssembler* masm, int argc) { | 667 void CallIC::GenerateNormal(MacroAssembler* masm, int argc) { |
| 668 // ----------- S t a t e ------------- |
| 669 // rsp[0] return address |
| 670 // rsp[8] argument argc |
| 671 // rsp[16] argument argc - 1 |
| 672 // ... |
| 673 // rsp[argc * 8] argument 1 |
| 674 // rsp[(argc + 1) * 8] argument 0 = reciever |
| 675 // rsp[(argc + 2) * 8] function name |
| 676 // ----------------------------------- |
| 677 |
| 678 Label miss, global_object, non_global_object; |
| 679 |
| 680 // Get the receiver of the function from the stack. |
| 681 __ movq(rdx, Operand(rsp, (argc + 1) * kPointerSize)); |
| 682 // Get the name of the function from the stack. |
| 683 __ movq(rcx, Operand(rsp, (argc + 2) * kPointerSize)); |
| 684 |
| 685 // Check that the receiver isn't a smi. |
| 686 __ testl(rdx, Immediate(kSmiTagMask)); |
| 687 __ j(zero, &miss); |
| 688 |
| 689 // Check that the receiver is a valid JS object. |
| 690 // Because there are so many map checks and type checks, do not |
| 691 // use CmpObjectType, but load map and type into registers. |
| 692 __ movq(rbx, FieldOperand(rdx, HeapObject::kMapOffset)); |
| 693 __ movb(rax, FieldOperand(rbx, Map::kInstanceTypeOffset)); |
| 694 __ cmpb(rax, Immediate(FIRST_JS_OBJECT_TYPE)); |
| 695 __ j(below, &miss); |
| 696 |
| 697 // If this assert fails, we have to check upper bound too. |
| 698 ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 699 |
| 700 // Check for access to global object. |
| 701 __ cmpb(rax, Immediate(JS_GLOBAL_OBJECT_TYPE)); |
| 702 __ j(equal, &global_object); |
| 703 __ cmpb(rax, Immediate(JS_BUILTINS_OBJECT_TYPE)); |
| 704 __ j(not_equal, &non_global_object); |
| 705 |
| 706 // Accessing global object: Load and invoke. |
| 707 __ bind(&global_object); |
| 708 // Check that the global object does not require access checks. |
| 709 __ movb(rbx, FieldOperand(rbx, Map::kBitFieldOffset)); |
| 710 __ testb(rbx, Immediate(1 << Map::kIsAccessCheckNeeded)); |
| 711 __ j(not_equal, &miss); |
| 712 GenerateNormalHelper(masm, argc, true, &miss); |
| 713 |
| 714 // Accessing non-global object: Check for access to global proxy. |
| 715 Label global_proxy, invoke; |
| 716 __ bind(&non_global_object); |
| 717 __ cmpb(rax, Immediate(JS_GLOBAL_PROXY_TYPE)); |
| 718 __ j(equal, &global_proxy); |
| 719 // Check that the non-global, non-global-proxy object does not |
| 720 // require access checks. |
| 721 __ movb(rbx, FieldOperand(rbx, Map::kBitFieldOffset)); |
| 722 __ testb(rbx, Immediate(1 << Map::kIsAccessCheckNeeded)); |
| 723 __ j(not_equal, &miss); |
| 724 __ bind(&invoke); |
| 725 GenerateNormalHelper(masm, argc, false, &miss); |
| 726 |
| 727 // Global object proxy access: Check access rights. |
| 728 __ bind(&global_proxy); |
| 729 __ CheckAccessGlobalProxy(rdx, rax, &miss); |
| 730 __ jmp(&invoke); |
| 731 |
571 // Cache miss: Jump to runtime. | 732 // Cache miss: Jump to runtime. |
| 733 __ bind(&miss); |
572 Generate(masm, argc, ExternalReference(IC_Utility(kCallIC_Miss))); | 734 Generate(masm, argc, ExternalReference(IC_Utility(kCallIC_Miss))); |
573 } | 735 } |
574 | 736 |
575 | 737 |
576 // The offset from the inlined patch site to the start of the | 738 // The offset from the inlined patch site to the start of the |
577 // inlined load instruction. | 739 // inlined load instruction. |
578 const int LoadIC::kOffsetToLoadInstruction = 20; | 740 const int LoadIC::kOffsetToLoadInstruction = 20; |
579 | 741 |
580 | 742 |
581 void LoadIC::ClearInlinedVersion(Address address) { | 743 void LoadIC::ClearInlinedVersion(Address address) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 | 907 |
746 void StoreIC::GenerateMegamorphic(MacroAssembler* masm) { | 908 void StoreIC::GenerateMegamorphic(MacroAssembler* masm) { |
747 Generate(masm, ExternalReference(IC_Utility(kStoreIC_Miss))); | 909 Generate(masm, ExternalReference(IC_Utility(kStoreIC_Miss))); |
748 } | 910 } |
749 | 911 |
750 | 912 |
751 #undef __ | 913 #undef __ |
752 | 914 |
753 | 915 |
754 } } // namespace v8::internal | 916 } } // namespace v8::internal |
OLD | NEW |