| 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #if V8_TARGET_ARCH_X64 | 30 #if V8_TARGET_ARCH_X64 |
| 31 | 31 |
| 32 #include "codegen.h" | 32 #include "codegen.h" |
| 33 #include "deoptimizer.h" | 33 #include "deoptimizer.h" |
| 34 #include "full-codegen.h" | 34 #include "full-codegen.h" |
| 35 #include "stub-cache.h" |
| 35 | 36 |
| 36 namespace v8 { | 37 namespace v8 { |
| 37 namespace internal { | 38 namespace internal { |
| 38 | 39 |
| 39 | 40 |
| 40 #define __ ACCESS_MASM(masm) | 41 #define __ ACCESS_MASM(masm) |
| 41 | 42 |
| 42 | 43 |
| 43 void Builtins::Generate_Adaptor(MacroAssembler* masm, | 44 void Builtins::Generate_Adaptor(MacroAssembler* masm, |
| 44 CFunctionId id, | 45 CFunctionId id, |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 __ Set(rdx, 0); // indicate regular JS_FUNCTION | 837 __ Set(rdx, 0); // indicate regular JS_FUNCTION |
| 837 | 838 |
| 838 __ pop(rax); | 839 __ pop(rax); |
| 839 __ SmiToInteger32(rax, rax); | 840 __ SmiToInteger32(rax, rax); |
| 840 } | 841 } |
| 841 | 842 |
| 842 // Restore the function to rdi. | 843 // Restore the function to rdi. |
| 843 __ movq(rdi, args.GetReceiverOperand()); | 844 __ movq(rdi, args.GetReceiverOperand()); |
| 844 __ jmp(&patch_receiver, Label::kNear); | 845 __ jmp(&patch_receiver, Label::kNear); |
| 845 | 846 |
| 846 // Use the global receiver object from the called function as the | |
| 847 // receiver. | |
| 848 __ bind(&use_global_receiver); | 847 __ bind(&use_global_receiver); |
| 849 const int kGlobalIndex = | 848 __ movq(rbx, |
| 850 Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize; | 849 Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 851 __ movq(rbx, FieldOperand(rsi, kGlobalIndex)); | |
| 852 __ movq(rbx, FieldOperand(rbx, GlobalObject::kNativeContextOffset)); | |
| 853 __ movq(rbx, FieldOperand(rbx, kGlobalIndex)); | |
| 854 __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); | 850 __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); |
| 855 | 851 |
| 856 __ bind(&patch_receiver); | 852 __ bind(&patch_receiver); |
| 857 __ movq(args.GetArgumentOperand(1), rbx); | 853 __ movq(args.GetArgumentOperand(1), rbx); |
| 858 | 854 |
| 859 __ jmp(&shift_arguments); | 855 __ jmp(&shift_arguments); |
| 860 } | 856 } |
| 861 | 857 |
| 862 // 3b. Check for function proxy. | 858 // 3b. Check for function proxy. |
| 863 __ bind(&slow); | 859 __ bind(&slow); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 } | 910 } |
| 915 | 911 |
| 916 // 5b. Get the code to call from the function and check that the number of | 912 // 5b. Get the code to call from the function and check that the number of |
| 917 // expected arguments matches what we're providing. If so, jump | 913 // expected arguments matches what we're providing. If so, jump |
| 918 // (tail-call) to the code in register edx without checking arguments. | 914 // (tail-call) to the code in register edx without checking arguments. |
| 919 __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 915 __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 920 __ movsxlq(rbx, | 916 __ movsxlq(rbx, |
| 921 FieldOperand(rdx, | 917 FieldOperand(rdx, |
| 922 SharedFunctionInfo::kFormalParameterCountOffset)); | 918 SharedFunctionInfo::kFormalParameterCountOffset)); |
| 923 __ movq(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); | 919 __ movq(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
| 924 __ SetCallKind(rcx, CALL_AS_METHOD); | 920 __ SetCallKind(rcx, CALL_AS_FUNCTION); |
| 925 __ cmpq(rax, rbx); | 921 __ cmpq(rax, rbx); |
| 926 __ j(not_equal, | 922 __ j(not_equal, |
| 927 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), | 923 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 928 RelocInfo::CODE_TARGET); | 924 RelocInfo::CODE_TARGET); |
| 929 | 925 |
| 930 ParameterCount expected(0); | 926 ParameterCount expected(0); |
| 931 __ InvokeCode(rdx, expected, expected, JUMP_FUNCTION, | 927 __ InvokeCode(rdx, expected, expected, JUMP_FUNCTION, |
| 932 NullCallWrapper(), CALL_AS_METHOD); | 928 NullCallWrapper(), CALL_AS_FUNCTION); |
| 933 } | 929 } |
| 934 | 930 |
| 935 | 931 |
| 936 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { | 932 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { |
| 937 // Stack at entry: | 933 // Stack at entry: |
| 938 // rsp : return address | 934 // rsp : return address |
| 939 // rsp[8] : arguments | 935 // rsp[8] : arguments |
| 940 // rsp[16] : receiver ("this") | 936 // rsp[16] : receiver ("this") |
| 941 // rsp[24] : function | 937 // rsp[24] : function |
| 942 { | 938 { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); | 1018 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); |
| 1023 __ j(above_equal, &push_receiver); | 1019 __ j(above_equal, &push_receiver); |
| 1024 | 1020 |
| 1025 // Convert the receiver to an object. | 1021 // Convert the receiver to an object. |
| 1026 __ bind(&call_to_object); | 1022 __ bind(&call_to_object); |
| 1027 __ push(rbx); | 1023 __ push(rbx); |
| 1028 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | 1024 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1029 __ movq(rbx, rax); | 1025 __ movq(rbx, rax); |
| 1030 __ jmp(&push_receiver, Label::kNear); | 1026 __ jmp(&push_receiver, Label::kNear); |
| 1031 | 1027 |
| 1032 // Use the current global receiver object as the receiver. | |
| 1033 __ bind(&use_global_receiver); | 1028 __ bind(&use_global_receiver); |
| 1034 const int kGlobalOffset = | 1029 __ movq(rbx, |
| 1035 Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize; | 1030 Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1036 __ movq(rbx, FieldOperand(rsi, kGlobalOffset)); | |
| 1037 __ movq(rbx, FieldOperand(rbx, GlobalObject::kNativeContextOffset)); | |
| 1038 __ movq(rbx, FieldOperand(rbx, kGlobalOffset)); | |
| 1039 __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); | 1031 __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); |
| 1040 | 1032 |
| 1041 // Push the receiver. | 1033 // Push the receiver. |
| 1042 __ bind(&push_receiver); | 1034 __ bind(&push_receiver); |
| 1043 __ push(rbx); | 1035 __ push(rbx); |
| 1044 | 1036 |
| 1045 // Copy all arguments from the array to the stack. | 1037 // Copy all arguments from the array to the stack. |
| 1046 Label entry, loop; | 1038 Label entry, loop; |
| 1047 __ movq(rax, Operand(rbp, kIndexOffset)); | 1039 __ movq(rax, Operand(rbp, kIndexOffset)); |
| 1048 __ jmp(&entry); | 1040 __ jmp(&entry); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1063 | 1055 |
| 1064 // Update the index on the stack and in register rax. | 1056 // Update the index on the stack and in register rax. |
| 1065 __ movq(rax, Operand(rbp, kIndexOffset)); | 1057 __ movq(rax, Operand(rbp, kIndexOffset)); |
| 1066 __ SmiAddConstant(rax, rax, Smi::FromInt(1)); | 1058 __ SmiAddConstant(rax, rax, Smi::FromInt(1)); |
| 1067 __ movq(Operand(rbp, kIndexOffset), rax); | 1059 __ movq(Operand(rbp, kIndexOffset), rax); |
| 1068 | 1060 |
| 1069 __ bind(&entry); | 1061 __ bind(&entry); |
| 1070 __ cmpq(rax, Operand(rbp, kLimitOffset)); | 1062 __ cmpq(rax, Operand(rbp, kLimitOffset)); |
| 1071 __ j(not_equal, &loop); | 1063 __ j(not_equal, &loop); |
| 1072 | 1064 |
| 1073 // Invoke the function. | 1065 // Call the function. |
| 1074 Label call_proxy; | 1066 Label call_proxy; |
| 1075 ParameterCount actual(rax); | 1067 ParameterCount actual(rax); |
| 1076 __ SmiToInteger32(rax, rax); | 1068 __ SmiToInteger32(rax, rax); |
| 1077 __ movq(rdi, Operand(rbp, kFunctionOffset)); | 1069 __ movq(rdi, Operand(rbp, kFunctionOffset)); |
| 1078 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 1070 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
| 1079 __ j(not_equal, &call_proxy); | 1071 __ j(not_equal, &call_proxy); |
| 1080 __ InvokeFunction(rdi, actual, CALL_FUNCTION, | 1072 __ InvokeFunction(rdi, actual, CALL_FUNCTION, |
| 1081 NullCallWrapper(), CALL_AS_METHOD); | 1073 NullCallWrapper(), CALL_AS_FUNCTION); |
| 1082 | 1074 |
| 1083 frame_scope.GenerateLeaveFrame(); | 1075 frame_scope.GenerateLeaveFrame(); |
| 1084 __ ret(3 * kPointerSize); // remove this, receiver, and arguments | 1076 __ ret(3 * kPointerSize); // remove this, receiver, and arguments |
| 1085 | 1077 |
| 1086 // Invoke the function proxy. | 1078 // Call the function proxy. |
| 1087 __ bind(&call_proxy); | 1079 __ bind(&call_proxy); |
| 1088 __ push(rdi); // add function proxy as last argument | 1080 __ push(rdi); // add function proxy as last argument |
| 1089 __ incq(rax); | 1081 __ incq(rax); |
| 1090 __ Set(rbx, 0); | 1082 __ Set(rbx, 0); |
| 1091 __ SetCallKind(rcx, CALL_AS_METHOD); | 1083 __ SetCallKind(rcx, CALL_AS_FUNCTION); |
| 1092 __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY); | 1084 __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY); |
| 1093 __ call(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), | 1085 __ call(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 1094 RelocInfo::CODE_TARGET); | 1086 RelocInfo::CODE_TARGET); |
| 1095 | 1087 |
| 1096 // Leave internal frame. | 1088 // Leave internal frame. |
| 1097 } | 1089 } |
| 1098 __ ret(3 * kPointerSize); // remove this, receiver, and arguments | 1090 __ ret(3 * kPointerSize); // remove this, receiver, and arguments |
| 1099 } | 1091 } |
| 1100 | 1092 |
| 1101 | 1093 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 __ bind(&ok); | 1451 __ bind(&ok); |
| 1460 __ ret(0); | 1452 __ ret(0); |
| 1461 } | 1453 } |
| 1462 | 1454 |
| 1463 | 1455 |
| 1464 #undef __ | 1456 #undef __ |
| 1465 | 1457 |
| 1466 } } // namespace v8::internal | 1458 } } // namespace v8::internal |
| 1467 | 1459 |
| 1468 #endif // V8_TARGET_ARCH_X64 | 1460 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |