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 26 matching lines...) Expand all Loading... | |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 | 39 |
40 #define __ ACCESS_MASM(masm) | 40 #define __ ACCESS_MASM(masm) |
41 | 41 |
42 | 42 |
43 void Builtins::Generate_Adaptor(MacroAssembler* masm, | 43 void Builtins::Generate_Adaptor(MacroAssembler* masm, |
44 CFunctionId id, | 44 CFunctionId id, |
45 BuiltinExtraArguments extra_args) { | 45 BuiltinExtraArguments extra_args) { |
46 // ----------- S t a t e ------------- | 46 // ----------- S t a t e ------------- |
47 // -- rax : number of arguments excluding receiver | 47 // -- rax : number of arguments |
48 // -- rdi : called function (only guaranteed when | 48 // excluding receiver |
49 // extra_args requires it) | 49 // -- rdi : called function (only guaranteed |
50 // -- rsi : context | 50 // when extra_args requires it) |
51 // -- rsp[0] : return address | 51 // -- rsi : context |
52 // -- rsp[8] : last argument | 52 // -- rsp[0] : return address |
53 // -- rsp[8] : last argument | |
53 // -- ... | 54 // -- ... |
54 // -- rsp[8 * argc] : first argument (argc == rax) | 55 // -- rsp[8 * argc] : first argument (argc == rax) |
55 // -- rsp[8 * (argc + 1)] : receiver | 56 // -- rsp[8 * argc + kPCOnStackSize)] : receiver |
56 // ----------------------------------- | 57 // ----------------------------------- |
57 | 58 |
58 // Insert extra arguments. | 59 // Insert extra arguments. |
59 int num_extra_args = 0; | 60 int num_extra_args = 0; |
60 if (extra_args == NEEDS_CALLED_FUNCTION) { | 61 if (extra_args == NEEDS_CALLED_FUNCTION) { |
61 num_extra_args = 1; | 62 num_extra_args = 1; |
62 __ pop(kScratchRegister); // Save return address. | 63 __ pop(kScratchRegister); // Save return address. |
63 __ push(rdi); | 64 __ push(rdi); |
64 __ push(kScratchRegister); // Restore return address. | 65 __ push(kScratchRegister); // Restore return address. |
65 } else { | 66 } else { |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 FrameScope scope(masm, StackFrame::INTERNAL); | 702 FrameScope scope(masm, StackFrame::INTERNAL); |
702 | 703 |
703 // Pass the deoptimization type to the runtime system. | 704 // Pass the deoptimization type to the runtime system. |
704 __ Push(Smi::FromInt(static_cast<int>(type))); | 705 __ Push(Smi::FromInt(static_cast<int>(type))); |
705 | 706 |
706 __ CallRuntime(Runtime::kNotifyDeoptimized, 1); | 707 __ CallRuntime(Runtime::kNotifyDeoptimized, 1); |
707 // Tear down internal frame. | 708 // Tear down internal frame. |
708 } | 709 } |
709 | 710 |
710 // Get the full codegen state from the stack and untag it. | 711 // Get the full codegen state from the stack and untag it. |
711 __ SmiToInteger32(r10, Operand(rsp, 1 * kPointerSize)); | 712 __ SmiToInteger32(r10, Operand(rsp, kPCOnStackSize)); |
712 | 713 |
713 // Switch on the state. | 714 // Switch on the state. |
714 Label not_no_registers, not_tos_rax; | 715 Label not_no_registers, not_tos_rax; |
715 __ cmpq(r10, Immediate(FullCodeGenerator::NO_REGISTERS)); | 716 __ cmpq(r10, Immediate(FullCodeGenerator::NO_REGISTERS)); |
716 __ j(not_equal, ¬_no_registers, Label::kNear); | 717 __ j(not_equal, ¬_no_registers, Label::kNear); |
717 __ ret(1 * kPointerSize); // Remove state. | 718 __ ret(1 * kPointerSize); // Remove state. |
718 | 719 |
719 __ bind(¬_no_registers); | 720 __ bind(¬_no_registers); |
720 __ movq(rax, Operand(rsp, 2 * kPointerSize)); | 721 __ movq(rax, Operand(rsp, kPCOnStackSize + kPointerSize)); |
haitao.feng
2013/07/25 06:31:49
This is not for argument access, so I did not use
| |
721 __ cmpq(r10, Immediate(FullCodeGenerator::TOS_REG)); | 722 __ cmpq(r10, Immediate(FullCodeGenerator::TOS_REG)); |
722 __ j(not_equal, ¬_tos_rax, Label::kNear); | 723 __ j(not_equal, ¬_tos_rax, Label::kNear); |
723 __ ret(2 * kPointerSize); // Remove state, rax. | 724 __ ret(2 * kPointerSize); // Remove state, rax. |
724 | 725 |
725 __ bind(¬_tos_rax); | 726 __ bind(¬_tos_rax); |
726 __ Abort("no cases left"); | 727 __ Abort("no cases left"); |
727 } | 728 } |
728 | 729 |
729 | 730 |
730 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { | 731 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { |
(...skipping 21 matching lines...) Expand all Loading... | |
752 FrameScope scope(masm, StackFrame::INTERNAL); | 753 FrameScope scope(masm, StackFrame::INTERNAL); |
753 __ CallRuntime(Runtime::kNotifyOSR, 0); | 754 __ CallRuntime(Runtime::kNotifyOSR, 0); |
754 } | 755 } |
755 __ Popad(); | 756 __ Popad(); |
756 __ ret(0); | 757 __ ret(0); |
757 } | 758 } |
758 | 759 |
759 | 760 |
760 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { | 761 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { |
761 // Stack Layout: | 762 // Stack Layout: |
762 // rsp[0] : Return address | 763 // rsp[0] : Return address |
763 // rsp[8] : Argument n | 764 // rsp[8] : Argument n |
764 // rsp[16] : Argument n-1 | 765 // rsp[16] : Argument n-1 |
765 // ... | 766 // ... |
766 // rsp[8 * n] : Argument 1 | 767 // rsp[8 * n] : Argument 1 |
767 // rsp[8 * (n + 1)] : Receiver (function to call) | 768 // rsp[8 * n + kPCOnStackSize] : Receiver (function to call) |
768 // | 769 // |
769 // rax contains the number of arguments, n, not counting the receiver. | 770 // rax contains the number of arguments, n, not counting the receiver. |
770 // | 771 // |
771 // 1. Make sure we have at least one argument. | 772 // 1. Make sure we have at least one argument. |
772 { Label done; | 773 { Label done; |
773 __ testq(rax, rax); | 774 __ testq(rax, rax); |
774 __ j(not_zero, &done); | 775 __ j(not_zero, &done); |
775 __ pop(rbx); | 776 __ pop(rbx); |
776 __ Push(masm->isolate()->factory()->undefined_value()); | 777 __ Push(masm->isolate()->factory()->undefined_value()); |
777 __ push(rbx); | 778 __ push(rbx); |
778 __ incq(rax); | 779 __ incq(rax); |
779 __ bind(&done); | 780 __ bind(&done); |
780 } | 781 } |
781 | 782 |
782 // 2. Get the function to call (passed as receiver) from the stack, check | 783 // 2. Get the function to call (passed as receiver) from the stack, check |
783 // if it is a function. | 784 // if it is a function. |
784 Label slow, non_function; | 785 Label slow, non_function; |
785 // The function to call is at position n+1 on the stack. | 786 // The function to call is at position n * kPointerSize + kPCOnStackSize |
786 __ movq(rdi, Operand(rsp, rax, times_pointer_size, 1 * kPointerSize)); | 787 // on the stack. |
788 __ movq(rdi, Operand(rsp, rax, times_pointer_size, kPCOnStackSize)); | |
787 __ JumpIfSmi(rdi, &non_function); | 789 __ JumpIfSmi(rdi, &non_function); |
788 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 790 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
789 __ j(not_equal, &slow); | 791 __ j(not_equal, &slow); |
790 | 792 |
791 // 3a. Patch the first argument if necessary when calling a function. | 793 // 3a. Patch the first argument if necessary when calling a function. |
792 Label shift_arguments; | 794 Label shift_arguments; |
793 __ Set(rdx, 0); // indicate regular JS_FUNCTION | 795 __ Set(rdx, 0); // indicate regular JS_FUNCTION |
794 { Label convert_to_object, use_global_receiver, patch_receiver; | 796 { Label convert_to_object, use_global_receiver, patch_receiver; |
795 // Change context eagerly in case we need the global receiver. | 797 // Change context eagerly in case we need the global receiver. |
796 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 798 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
797 | 799 |
798 // Do not transform the receiver for strict mode functions. | 800 // Do not transform the receiver for strict mode functions. |
799 __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 801 __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
800 __ testb(FieldOperand(rbx, SharedFunctionInfo::kStrictModeByteOffset), | 802 __ testb(FieldOperand(rbx, SharedFunctionInfo::kStrictModeByteOffset), |
801 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); | 803 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); |
802 __ j(not_equal, &shift_arguments); | 804 __ j(not_equal, &shift_arguments); |
803 | 805 |
804 // Do not transform the receiver for natives. | 806 // Do not transform the receiver for natives. |
805 // SharedFunctionInfo is already loaded into rbx. | 807 // SharedFunctionInfo is already loaded into rbx. |
806 __ testb(FieldOperand(rbx, SharedFunctionInfo::kNativeByteOffset), | 808 __ testb(FieldOperand(rbx, SharedFunctionInfo::kNativeByteOffset), |
807 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); | 809 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); |
808 __ j(not_zero, &shift_arguments); | 810 __ j(not_zero, &shift_arguments); |
809 | 811 |
810 // Compute the receiver in non-strict mode. | 812 // Compute the receiver in non-strict mode. |
811 __ movq(rbx, Operand(rsp, rax, times_pointer_size, 0)); | 813 __ movq(rbx, Operand(rsp, rax, times_pointer_size, |
814 kPCOnStackSize - kPointerSize)); | |
812 __ JumpIfSmi(rbx, &convert_to_object, Label::kNear); | 815 __ JumpIfSmi(rbx, &convert_to_object, Label::kNear); |
813 | 816 |
814 __ CompareRoot(rbx, Heap::kNullValueRootIndex); | 817 __ CompareRoot(rbx, Heap::kNullValueRootIndex); |
815 __ j(equal, &use_global_receiver); | 818 __ j(equal, &use_global_receiver); |
816 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); | 819 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); |
817 __ j(equal, &use_global_receiver); | 820 __ j(equal, &use_global_receiver); |
818 | 821 |
819 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); | 822 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
820 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); | 823 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); |
821 __ j(above_equal, &shift_arguments); | 824 __ j(above_equal, &shift_arguments); |
822 | 825 |
823 __ bind(&convert_to_object); | 826 __ bind(&convert_to_object); |
824 { | 827 { |
825 // Enter an internal frame in order to preserve argument count. | 828 // Enter an internal frame in order to preserve argument count. |
826 FrameScope scope(masm, StackFrame::INTERNAL); | 829 FrameScope scope(masm, StackFrame::INTERNAL); |
827 __ Integer32ToSmi(rax, rax); | 830 __ Integer32ToSmi(rax, rax); |
828 __ push(rax); | 831 __ push(rax); |
829 | 832 |
830 __ push(rbx); | 833 __ push(rbx); |
831 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | 834 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
832 __ movq(rbx, rax); | 835 __ movq(rbx, rax); |
833 __ Set(rdx, 0); // indicate regular JS_FUNCTION | 836 __ Set(rdx, 0); // indicate regular JS_FUNCTION |
834 | 837 |
835 __ pop(rax); | 838 __ pop(rax); |
836 __ SmiToInteger32(rax, rax); | 839 __ SmiToInteger32(rax, rax); |
837 } | 840 } |
838 | 841 |
839 // Restore the function to rdi. | 842 // Restore the function to rdi. |
840 __ movq(rdi, Operand(rsp, rax, times_pointer_size, 1 * kPointerSize)); | 843 __ movq(rdi, Operand(rsp, rax, times_pointer_size, kPCOnStackSize)); |
841 __ jmp(&patch_receiver, Label::kNear); | 844 __ jmp(&patch_receiver, Label::kNear); |
842 | 845 |
843 // Use the global receiver object from the called function as the | 846 // Use the global receiver object from the called function as the |
844 // receiver. | 847 // receiver. |
845 __ bind(&use_global_receiver); | 848 __ bind(&use_global_receiver); |
846 const int kGlobalIndex = | 849 const int kGlobalIndex = |
847 Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize; | 850 Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize; |
848 __ movq(rbx, FieldOperand(rsi, kGlobalIndex)); | 851 __ movq(rbx, FieldOperand(rsi, kGlobalIndex)); |
849 __ movq(rbx, FieldOperand(rbx, GlobalObject::kNativeContextOffset)); | 852 __ movq(rbx, FieldOperand(rbx, GlobalObject::kNativeContextOffset)); |
850 __ movq(rbx, FieldOperand(rbx, kGlobalIndex)); | 853 __ movq(rbx, FieldOperand(rbx, kGlobalIndex)); |
851 __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); | 854 __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); |
852 | 855 |
853 __ bind(&patch_receiver); | 856 __ bind(&patch_receiver); |
854 __ movq(Operand(rsp, rax, times_pointer_size, 0), rbx); | 857 __ movq(Operand(rsp, rax, times_pointer_size, |
858 kPCOnStackSize - kPointerSize), rbx); | |
855 | 859 |
856 __ jmp(&shift_arguments); | 860 __ jmp(&shift_arguments); |
857 } | 861 } |
858 | 862 |
859 // 3b. Check for function proxy. | 863 // 3b. Check for function proxy. |
860 __ bind(&slow); | 864 __ bind(&slow); |
861 __ Set(rdx, 1); // indicate function proxy | 865 __ Set(rdx, 1); // indicate function proxy |
862 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); | 866 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); |
863 __ j(equal, &shift_arguments); | 867 __ j(equal, &shift_arguments); |
864 __ bind(&non_function); | 868 __ bind(&non_function); |
865 __ Set(rdx, 2); // indicate non-function | 869 __ Set(rdx, 2); // indicate non-function |
866 | 870 |
867 // 3c. Patch the first argument when calling a non-function. The | 871 // 3c. Patch the first argument when calling a non-function. The |
868 // CALL_NON_FUNCTION builtin expects the non-function callee as | 872 // CALL_NON_FUNCTION builtin expects the non-function callee as |
869 // receiver, so overwrite the first argument which will ultimately | 873 // receiver, so overwrite the first argument which will ultimately |
870 // become the receiver. | 874 // become the receiver. |
871 __ movq(Operand(rsp, rax, times_pointer_size, 0), rdi); | 875 __ movq(Operand(rsp, rax, times_pointer_size, kPCOnStackSize - kPointerSize), |
876 rdi); | |
872 | 877 |
873 // 4. Shift arguments and return address one slot down on the stack | 878 // 4. Shift arguments and return address one slot down on the stack |
874 // (overwriting the original receiver). Adjust argument count to make | 879 // (overwriting the original receiver). Adjust argument count to make |
875 // the original first argument the new receiver. | 880 // the original first argument the new receiver. |
876 __ bind(&shift_arguments); | 881 __ bind(&shift_arguments); |
877 { Label loop; | 882 { Label loop; |
878 __ movq(rcx, rax); | 883 __ movq(rcx, rax); |
879 __ bind(&loop); | 884 __ bind(&loop); |
880 __ movq(rbx, Operand(rsp, rcx, times_pointer_size, 0)); | 885 __ movq(rbx, Operand(rsp, rcx, times_pointer_size, 0)); |
881 __ movq(Operand(rsp, rcx, times_pointer_size, 1 * kPointerSize), rbx); | 886 __ movq(Operand(rsp, rcx, times_pointer_size, 1 * kPointerSize), rbx); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1154 masm->isolate()->heap()->undefined_value(), | 1159 masm->isolate()->heap()->undefined_value(), |
1155 masm->isolate()); | 1160 masm->isolate()); |
1156 __ Move(rbx, undefined_sentinel); | 1161 __ Move(rbx, undefined_sentinel); |
1157 ArrayConstructorStub stub(masm->isolate()); | 1162 ArrayConstructorStub stub(masm->isolate()); |
1158 __ TailCallStub(&stub); | 1163 __ TailCallStub(&stub); |
1159 } | 1164 } |
1160 | 1165 |
1161 | 1166 |
1162 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { | 1167 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { |
1163 // ----------- S t a t e ------------- | 1168 // ----------- S t a t e ------------- |
1164 // -- rax : number of arguments | 1169 // -- rax : number of arguments |
1165 // -- rdi : constructor function | 1170 // -- rdi : constructor function |
1166 // -- rsp[0] : return address | 1171 // -- rsp[0] : return address |
1167 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) | 1172 // -- rsp[(argc - n - 1) * 8 + kPCOnStackSize] : arg[n] (zero-based) |
1168 // -- rsp[(argc + 1) * 8] : receiver | 1173 // -- rsp[argc * 8 + kPCOnStackSize] : receiver |
1169 // ----------------------------------- | 1174 // ----------------------------------- |
1170 Counters* counters = masm->isolate()->counters(); | 1175 Counters* counters = masm->isolate()->counters(); |
1171 __ IncrementCounter(counters->string_ctor_calls(), 1); | 1176 __ IncrementCounter(counters->string_ctor_calls(), 1); |
1172 | 1177 |
1173 if (FLAG_debug_code) { | 1178 if (FLAG_debug_code) { |
1174 __ LoadGlobalFunction(Context::STRING_FUNCTION_INDEX, rcx); | 1179 __ LoadGlobalFunction(Context::STRING_FUNCTION_INDEX, rcx); |
1175 __ cmpq(rdi, rcx); | 1180 __ cmpq(rdi, rcx); |
1176 __ Assert(equal, "Unexpected String function"); | 1181 __ Assert(equal, "Unexpected String function"); |
1177 } | 1182 } |
1178 | 1183 |
1179 // Load the first argument into rax and get rid of the rest | 1184 // Load the first argument into rax and get rid of the rest |
1180 // (including the receiver). | 1185 // (including the receiver). |
1181 Label no_arguments; | 1186 Label no_arguments; |
1182 __ testq(rax, rax); | 1187 __ testq(rax, rax); |
1183 __ j(zero, &no_arguments); | 1188 __ j(zero, &no_arguments); |
1184 __ movq(rbx, Operand(rsp, rax, times_pointer_size, 0)); | 1189 __ movq(rbx, Operand(rsp, rax, times_pointer_size, |
1190 kPCOnStackSize - kPointerSize)); | |
1185 __ pop(rcx); | 1191 __ pop(rcx); |
1186 __ lea(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize)); | 1192 __ lea(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize)); |
1187 __ push(rcx); | 1193 __ push(rcx); |
1188 __ movq(rax, rbx); | 1194 __ movq(rax, rbx); |
1189 | 1195 |
1190 // Lookup the argument in the number to string cache. | 1196 // Lookup the argument in the number to string cache. |
1191 Label not_cached, argument_is_string; | 1197 Label not_cached, argument_is_string; |
1192 NumberToStringStub::GenerateLookupNumberStringCache( | 1198 NumberToStringStub::GenerateLookupNumberStringCache( |
1193 masm, | 1199 masm, |
1194 rax, // Input. | 1200 rax, // Input. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1434 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); | 1440 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); |
1435 generator.Generate(); | 1441 generator.Generate(); |
1436 } | 1442 } |
1437 | 1443 |
1438 | 1444 |
1439 #undef __ | 1445 #undef __ |
1440 | 1446 |
1441 } } // namespace v8::internal | 1447 } } // namespace v8::internal |
1442 | 1448 |
1443 #endif // V8_TARGET_ARCH_X64 | 1449 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |