OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
8 | 8 |
9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 Label slow, non_function; | 821 Label slow, non_function; |
822 StackArgumentsAccessor args(rsp, rax); | 822 StackArgumentsAccessor args(rsp, rax); |
823 __ movp(rdi, args.GetReceiverOperand()); | 823 __ movp(rdi, args.GetReceiverOperand()); |
824 __ JumpIfSmi(rdi, &non_function); | 824 __ JumpIfSmi(rdi, &non_function); |
825 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 825 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
826 __ j(not_equal, &slow); | 826 __ j(not_equal, &slow); |
827 | 827 |
828 // 3a. Patch the first argument if necessary when calling a function. | 828 // 3a. Patch the first argument if necessary when calling a function. |
829 Label shift_arguments; | 829 Label shift_arguments; |
830 __ Set(rdx, 0); // indicate regular JS_FUNCTION | 830 __ Set(rdx, 0); // indicate regular JS_FUNCTION |
831 { Label convert_to_object, use_global_receiver, patch_receiver; | 831 { Label convert_to_object, use_global_proxy, patch_receiver; |
832 // Change context eagerly in case we need the global receiver. | 832 // Change context eagerly in case we need the global receiver. |
833 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 833 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
834 | 834 |
835 // Do not transform the receiver for strict mode functions. | 835 // Do not transform the receiver for strict mode functions. |
836 __ movp(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 836 __ movp(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
837 __ testb(FieldOperand(rbx, SharedFunctionInfo::kStrictModeByteOffset), | 837 __ testb(FieldOperand(rbx, SharedFunctionInfo::kStrictModeByteOffset), |
838 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); | 838 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); |
839 __ j(not_equal, &shift_arguments); | 839 __ j(not_equal, &shift_arguments); |
840 | 840 |
841 // Do not transform the receiver for natives. | 841 // Do not transform the receiver for natives. |
842 // SharedFunctionInfo is already loaded into rbx. | 842 // SharedFunctionInfo is already loaded into rbx. |
843 __ testb(FieldOperand(rbx, SharedFunctionInfo::kNativeByteOffset), | 843 __ testb(FieldOperand(rbx, SharedFunctionInfo::kNativeByteOffset), |
844 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); | 844 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); |
845 __ j(not_zero, &shift_arguments); | 845 __ j(not_zero, &shift_arguments); |
846 | 846 |
847 // Compute the receiver in sloppy mode. | 847 // Compute the receiver in sloppy mode. |
848 __ movp(rbx, args.GetArgumentOperand(1)); | 848 __ movp(rbx, args.GetArgumentOperand(1)); |
849 __ JumpIfSmi(rbx, &convert_to_object, Label::kNear); | 849 __ JumpIfSmi(rbx, &convert_to_object, Label::kNear); |
850 | 850 |
851 __ CompareRoot(rbx, Heap::kNullValueRootIndex); | 851 __ CompareRoot(rbx, Heap::kNullValueRootIndex); |
852 __ j(equal, &use_global_receiver); | 852 __ j(equal, &use_global_proxy); |
853 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); | 853 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); |
854 __ j(equal, &use_global_receiver); | 854 __ j(equal, &use_global_proxy); |
855 | 855 |
856 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); | 856 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
857 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); | 857 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); |
858 __ j(above_equal, &shift_arguments); | 858 __ j(above_equal, &shift_arguments); |
859 | 859 |
860 __ bind(&convert_to_object); | 860 __ bind(&convert_to_object); |
861 { | 861 { |
862 // Enter an internal frame in order to preserve argument count. | 862 // Enter an internal frame in order to preserve argument count. |
863 FrameScope scope(masm, StackFrame::INTERNAL); | 863 FrameScope scope(masm, StackFrame::INTERNAL); |
864 __ Integer32ToSmi(rax, rax); | 864 __ Integer32ToSmi(rax, rax); |
865 __ Push(rax); | 865 __ Push(rax); |
866 | 866 |
867 __ Push(rbx); | 867 __ Push(rbx); |
868 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | 868 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
869 __ movp(rbx, rax); | 869 __ movp(rbx, rax); |
870 __ Set(rdx, 0); // indicate regular JS_FUNCTION | 870 __ Set(rdx, 0); // indicate regular JS_FUNCTION |
871 | 871 |
872 __ Pop(rax); | 872 __ Pop(rax); |
873 __ SmiToInteger32(rax, rax); | 873 __ SmiToInteger32(rax, rax); |
874 } | 874 } |
875 | 875 |
876 // Restore the function to rdi. | 876 // Restore the function to rdi. |
877 __ movp(rdi, args.GetReceiverOperand()); | 877 __ movp(rdi, args.GetReceiverOperand()); |
878 __ jmp(&patch_receiver, Label::kNear); | 878 __ jmp(&patch_receiver, Label::kNear); |
879 | 879 |
880 __ bind(&use_global_receiver); | 880 __ bind(&use_global_proxy); |
881 __ movp(rbx, | 881 __ movp(rbx, |
882 Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); | 882 Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
883 __ movp(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); | 883 __ movp(rbx, FieldOperand(rbx, GlobalObject::kGlobalProxyOffset)); |
884 | 884 |
885 __ bind(&patch_receiver); | 885 __ bind(&patch_receiver); |
886 __ movp(args.GetArgumentOperand(1), rbx); | 886 __ movp(args.GetArgumentOperand(1), rbx); |
887 | 887 |
888 __ jmp(&shift_arguments); | 888 __ jmp(&shift_arguments); |
889 } | 889 } |
890 | 890 |
891 // 3b. Check for function proxy. | 891 // 3b. Check for function proxy. |
892 __ bind(&slow); | 892 __ bind(&slow); |
893 __ Set(rdx, 1); // indicate function proxy | 893 __ Set(rdx, 1); // indicate function proxy |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 // Check that the function is a JS function (otherwise it must be a proxy). | 1017 // Check that the function is a JS function (otherwise it must be a proxy). |
1018 Label push_receiver; | 1018 Label push_receiver; |
1019 __ movp(rdi, Operand(rbp, kFunctionOffset)); | 1019 __ movp(rdi, Operand(rbp, kFunctionOffset)); |
1020 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 1020 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
1021 __ j(not_equal, &push_receiver); | 1021 __ j(not_equal, &push_receiver); |
1022 | 1022 |
1023 // Change context eagerly to get the right global object if necessary. | 1023 // Change context eagerly to get the right global object if necessary. |
1024 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 1024 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
1025 | 1025 |
1026 // Do not transform the receiver for strict mode functions. | 1026 // Do not transform the receiver for strict mode functions. |
1027 Label call_to_object, use_global_receiver; | 1027 Label call_to_object, use_global_proxy; |
1028 __ movp(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 1028 __ movp(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
1029 __ testb(FieldOperand(rdx, SharedFunctionInfo::kStrictModeByteOffset), | 1029 __ testb(FieldOperand(rdx, SharedFunctionInfo::kStrictModeByteOffset), |
1030 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); | 1030 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); |
1031 __ j(not_equal, &push_receiver); | 1031 __ j(not_equal, &push_receiver); |
1032 | 1032 |
1033 // Do not transform the receiver for natives. | 1033 // Do not transform the receiver for natives. |
1034 __ testb(FieldOperand(rdx, SharedFunctionInfo::kNativeByteOffset), | 1034 __ testb(FieldOperand(rdx, SharedFunctionInfo::kNativeByteOffset), |
1035 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); | 1035 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); |
1036 __ j(not_equal, &push_receiver); | 1036 __ j(not_equal, &push_receiver); |
1037 | 1037 |
1038 // Compute the receiver in sloppy mode. | 1038 // Compute the receiver in sloppy mode. |
1039 __ JumpIfSmi(rbx, &call_to_object, Label::kNear); | 1039 __ JumpIfSmi(rbx, &call_to_object, Label::kNear); |
1040 __ CompareRoot(rbx, Heap::kNullValueRootIndex); | 1040 __ CompareRoot(rbx, Heap::kNullValueRootIndex); |
1041 __ j(equal, &use_global_receiver); | 1041 __ j(equal, &use_global_proxy); |
1042 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); | 1042 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); |
1043 __ j(equal, &use_global_receiver); | 1043 __ j(equal, &use_global_proxy); |
1044 | 1044 |
1045 // If given receiver is already a JavaScript object then there's no | 1045 // If given receiver is already a JavaScript object then there's no |
1046 // reason for converting it. | 1046 // reason for converting it. |
1047 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); | 1047 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
1048 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); | 1048 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); |
1049 __ j(above_equal, &push_receiver); | 1049 __ j(above_equal, &push_receiver); |
1050 | 1050 |
1051 // Convert the receiver to an object. | 1051 // Convert the receiver to an object. |
1052 __ bind(&call_to_object); | 1052 __ bind(&call_to_object); |
1053 __ Push(rbx); | 1053 __ Push(rbx); |
1054 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | 1054 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
1055 __ movp(rbx, rax); | 1055 __ movp(rbx, rax); |
1056 __ jmp(&push_receiver, Label::kNear); | 1056 __ jmp(&push_receiver, Label::kNear); |
1057 | 1057 |
1058 __ bind(&use_global_receiver); | 1058 __ bind(&use_global_proxy); |
1059 __ movp(rbx, | 1059 __ movp(rbx, |
1060 Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); | 1060 Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
1061 __ movp(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); | 1061 __ movp(rbx, FieldOperand(rbx, GlobalObject::kGlobalProxyOffset)); |
1062 | 1062 |
1063 // Push the receiver. | 1063 // Push the receiver. |
1064 __ bind(&push_receiver); | 1064 __ bind(&push_receiver); |
1065 __ Push(rbx); | 1065 __ Push(rbx); |
1066 | 1066 |
1067 // Copy all arguments from the array to the stack. | 1067 // Copy all arguments from the array to the stack. |
1068 Label entry, loop; | 1068 Label entry, loop; |
1069 __ movp(rax, Operand(rbp, kIndexOffset)); | 1069 __ movp(rax, Operand(rbp, kIndexOffset)); |
1070 __ jmp(&entry); | 1070 __ jmp(&entry); |
1071 __ bind(&loop); | 1071 __ bind(&loop); |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 __ bind(&ok); | 1513 __ bind(&ok); |
1514 __ ret(0); | 1514 __ ret(0); |
1515 } | 1515 } |
1516 | 1516 |
1517 | 1517 |
1518 #undef __ | 1518 #undef __ |
1519 | 1519 |
1520 } } // namespace v8::internal | 1520 } } // namespace v8::internal |
1521 | 1521 |
1522 #endif // V8_TARGET_ARCH_X64 | 1522 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |