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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 Register name, | 770 Register name, |
771 Handle<JSObject> holder_obj, | 771 Handle<JSObject> holder_obj, |
772 IC::UtilityId id) { | 772 IC::UtilityId id) { |
773 PushInterceptorArguments(masm, receiver, holder, name, holder_obj); | 773 PushInterceptorArguments(masm, receiver, holder, name, holder_obj); |
774 __ CallExternalReference( | 774 __ CallExternalReference( |
775 ExternalReference(IC_Utility(id), masm->isolate()), | 775 ExternalReference(IC_Utility(id), masm->isolate()), |
776 StubCache::kInterceptorArgsLength); | 776 StubCache::kInterceptorArgsLength); |
777 } | 777 } |
778 | 778 |
779 | 779 |
780 static const int kFastApiCallArguments = FunctionCallbackArguments::kArgsLength; | |
781 | |
782 | |
783 static void GenerateFastApiCallBody(MacroAssembler* masm, | 780 static void GenerateFastApiCallBody(MacroAssembler* masm, |
784 const CallOptimization& optimization, | 781 const CallOptimization& optimization, |
785 int argc, | 782 int argc, |
786 Register holder, | 783 Register holder_in, |
787 Register scratch1, | |
788 Register scratch2, | |
789 Register scratch3, | |
790 bool restore_context) { | 784 bool restore_context) { |
791 // ----------- S t a t e ------------- | |
792 // -- sp[0] : last JS argument | |
793 // -- ... | |
794 // -- sp[(argc - 1) * 4] : first JS argument | |
795 // -- sp[argc * 4] : receiver | |
796 // ----------------------------------- | |
797 ASSERT(optimization.is_simple_api_call()); | 785 ASSERT(optimization.is_simple_api_call()); |
798 | 786 |
799 typedef FunctionCallbackArguments FCA; | 787 // Abi for CallApiFunctionStub. |
| 788 Register callee = r0; |
| 789 Register call_data = r4; |
| 790 Register holder = r2; |
| 791 Register api_function_address = r3; |
| 792 Register thunk_arg = r1; |
800 | 793 |
801 STATIC_ASSERT(FCA::kHolderIndex == 0); | 794 // Put holder in place. |
802 STATIC_ASSERT(FCA::kIsolateIndex == 1); | 795 __ Move(holder, holder_in); |
803 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); | |
804 STATIC_ASSERT(FCA::kReturnValueOffset == 3); | |
805 STATIC_ASSERT(FCA::kDataIndex == 4); | |
806 STATIC_ASSERT(FCA::kCalleeIndex == 5); | |
807 STATIC_ASSERT(FCA::kContextSaveIndex == 6); | |
808 STATIC_ASSERT(FCA::kArgsLength == 7); | |
809 | 796 |
810 ASSERT(!holder.is(cp)); | 797 Isolate* isolate = masm->isolate(); |
| 798 Handle<JSFunction> function = optimization.constant_function(); |
| 799 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 800 Handle<Object> call_data_obj(api_call_info->data(), isolate); |
811 | 801 |
812 // Save calling context. | 802 // Put callee in place. |
813 __ push(cp); | 803 __ Move(callee, function); |
814 // Get the function and setup the context. | |
815 Handle<JSFunction> function = optimization.constant_function(); | |
816 __ Move(scratch1, function); | |
817 __ ldr(cp, FieldMemOperand(scratch1, JSFunction::kContextOffset)); | |
818 __ push(scratch1); | |
819 | 804 |
820 // Construct the FunctionCallbackInfo. | |
821 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); | |
822 Handle<Object> call_data(api_call_info->data(), masm->isolate()); | |
823 bool call_data_undefined = false; | 805 bool call_data_undefined = false; |
824 if (masm->isolate()->heap()->InNewSpace(*call_data)) { | 806 // Put call_data in place. |
825 __ Move(scratch1, api_call_info); | 807 if (isolate->heap()->InNewSpace(*call_data_obj)) { |
826 __ ldr(scratch1, FieldMemOperand(scratch1, CallHandlerInfo::kDataOffset)); | 808 __ Move(call_data, api_call_info); |
827 } else if (call_data->IsUndefined()) { | 809 __ ldr(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset)); |
| 810 } else if (call_data_obj->IsUndefined()) { |
828 call_data_undefined = true; | 811 call_data_undefined = true; |
829 __ LoadRoot(scratch3, Heap::kUndefinedValueRootIndex); | 812 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex); |
830 } else { | 813 } else { |
831 __ Move(scratch1, call_data); | 814 __ Move(call_data, call_data_obj); |
832 } | 815 } |
833 // Store call data. | |
834 __ push(scratch1); | |
835 if (!call_data_undefined) { | |
836 __ LoadRoot(scratch1, Heap::kUndefinedValueRootIndex); | |
837 } | |
838 // Store ReturnValue default and ReturnValue. | |
839 __ LoadRoot(scratch1, Heap::kUndefinedValueRootIndex); | |
840 __ push(scratch1); | |
841 __ push(scratch1); | |
842 // Store isolate. | |
843 __ mov(scratch1, | |
844 Operand(ExternalReference::isolate_address(masm->isolate()))); | |
845 __ push(scratch1); | |
846 // holder | |
847 __ push(holder); | |
848 | 816 |
849 // Prepare arguments. | 817 // Put api_function_address in place. |
850 __ mov(r2, sp); | |
851 | |
852 // Allocate the v8::Arguments structure in the arguments' space since | |
853 // it's not controlled by GC. | |
854 const int kApiStackSpace = 4; | |
855 | |
856 FrameScope frame_scope(masm, StackFrame::MANUAL); | |
857 __ EnterExitFrame(false, kApiStackSpace); | |
858 | |
859 // r0 = FunctionCallbackInfo& | |
860 // Arguments is after the return address. | |
861 __ add(r0, sp, Operand(1 * kPointerSize)); | |
862 // FunctionCallbackInfo::implicit_args_ | |
863 __ str(r2, MemOperand(r0, 0 * kPointerSize)); | |
864 // FunctionCallbackInfo::values_ | |
865 __ add(ip, r2, Operand((kFastApiCallArguments - 1 + argc) * kPointerSize)); | |
866 __ str(ip, MemOperand(r0, 1 * kPointerSize)); | |
867 // FunctionCallbackInfo::length_ = argc | |
868 __ mov(ip, Operand(argc)); | |
869 __ str(ip, MemOperand(r0, 2 * kPointerSize)); | |
870 // FunctionCallbackInfo::is_construct_call = 0 | |
871 __ mov(ip, Operand::Zero()); | |
872 __ str(ip, MemOperand(r0, 3 * kPointerSize)); | |
873 | |
874 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1; | |
875 Address function_address = v8::ToCData<Address>(api_call_info->callback()); | 818 Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
876 ApiFunction fun(function_address); | 819 ApiFunction fun(function_address); |
877 ExternalReference::Type type = ExternalReference::DIRECT_API_CALL; | 820 ExternalReference::Type type = ExternalReference::DIRECT_API_CALL; |
878 ExternalReference ref = ExternalReference(&fun, | 821 ExternalReference ref = ExternalReference(&fun, |
879 type, | 822 type, |
880 masm->isolate()); | 823 masm->isolate()); |
881 Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback); | 824 __ mov(api_function_address, Operand(ref)); |
882 ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL; | 825 __ mov(thunk_arg, Operand(reinterpret_cast<int32_t>(function_address))); |
883 ApiFunction thunk_fun(thunk_address); | |
884 ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type, | |
885 masm->isolate()); | |
886 | 826 |
887 AllowExternalCallThatCantCauseGC scope(masm); | 827 // Jump to stub. |
888 MemOperand context_restore_operand( | 828 CallApiFunctionStub stub(restore_context, call_data_undefined, argc); |
889 fp, (2 + FCA::kContextSaveIndex) * kPointerSize); | 829 __ TailCallStub(&stub); |
890 MemOperand return_value_operand(fp, | |
891 (2 + FCA::kReturnValueOffset) * kPointerSize); | |
892 | |
893 __ CallApiFunctionAndReturn(ref, | |
894 function_address, | |
895 thunk_ref, | |
896 r1, | |
897 kStackUnwindSpace, | |
898 return_value_operand, | |
899 restore_context ? | |
900 &context_restore_operand : NULL); | |
901 } | 830 } |
902 | 831 |
903 | 832 |
904 // Generates call to API function. | 833 // Generates call to API function. |
905 static void GenerateFastApiCall(MacroAssembler* masm, | 834 static void GenerateFastApiCall(MacroAssembler* masm, |
906 const CallOptimization& optimization, | 835 const CallOptimization& optimization, |
907 int argc, | 836 int argc, |
908 Handle<Map> map_to_holder, | 837 Handle<Map> map_to_holder, |
909 CallOptimization::HolderLookup holder_lookup) { | 838 CallOptimization::HolderLookup holder_lookup) { |
910 Counters* counters = masm->isolate()->counters(); | 839 Counters* counters = masm->isolate()->counters(); |
911 __ IncrementCounter(counters->call_const_fast_api(), 1, r0, r1); | 840 __ IncrementCounter(counters->call_const_fast_api(), 1, r0, r1); |
912 | 841 |
913 // Move holder to a register | 842 // Move holder to a register |
914 Register holder_reg = r0; | 843 Register holder_reg = r2; |
915 switch (holder_lookup) { | 844 switch (holder_lookup) { |
916 case CallOptimization::kHolderIsReceiver: | 845 case CallOptimization::kHolderIsReceiver: |
917 { | 846 { |
918 ASSERT(map_to_holder.is_null()); | 847 ASSERT(map_to_holder.is_null()); |
919 __ ldr(holder_reg, MemOperand(sp, argc * kPointerSize)); | 848 __ ldr(holder_reg, MemOperand(sp, argc * kPointerSize)); |
920 } | 849 } |
921 break; | 850 break; |
922 case CallOptimization::kHolderIsPrototypeOfMap: | 851 case CallOptimization::kHolderIsPrototypeOfMap: |
923 { | 852 { |
924 Handle<JSObject> holder(JSObject::cast(map_to_holder->prototype())); | 853 Handle<JSObject> holder(JSObject::cast(map_to_holder->prototype())); |
925 if (!masm->isolate()->heap()->InNewSpace(*holder)) { | 854 if (!masm->isolate()->heap()->InNewSpace(*holder)) { |
926 __ Move(holder_reg, holder); | 855 __ Move(holder_reg, holder); |
927 } else { | 856 } else { |
928 __ Move(holder_reg, map_to_holder); | 857 __ Move(holder_reg, map_to_holder); |
929 __ ldr(holder_reg, | 858 __ ldr(holder_reg, |
930 FieldMemOperand(holder_reg, Map::kPrototypeOffset)); | 859 FieldMemOperand(holder_reg, Map::kPrototypeOffset)); |
931 } | 860 } |
932 } | 861 } |
933 break; | 862 break; |
934 case CallOptimization::kHolderNotFound: | 863 case CallOptimization::kHolderNotFound: |
935 UNREACHABLE(); | 864 UNREACHABLE(); |
936 } | 865 } |
937 GenerateFastApiCallBody(masm, | 866 GenerateFastApiCallBody(masm, |
938 optimization, | 867 optimization, |
939 argc, | 868 argc, |
940 holder_reg, | 869 holder_reg, |
941 r1, | |
942 r2, | |
943 r3, | |
944 false); | 870 false); |
945 } | 871 } |
946 | 872 |
947 | 873 |
948 // Generate call to api function. | 874 // Generate call to api function. |
949 static void GenerateFastApiCall(MacroAssembler* masm, | 875 static void GenerateFastApiCall(MacroAssembler* masm, |
950 const CallOptimization& optimization, | 876 const CallOptimization& optimization, |
951 Register receiver, | 877 Register receiver, |
952 Register scratch, | 878 Register scratch, |
953 int argc, | 879 int argc, |
954 Register* values) { | 880 Register* values) { |
955 ASSERT(!receiver.is(scratch)); | 881 ASSERT(!receiver.is(scratch)); |
956 __ push(receiver); | 882 __ push(receiver); |
957 // Write the arguments to stack frame. | 883 // Write the arguments to stack frame. |
958 for (int i = 0; i < argc; i++) { | 884 for (int i = 0; i < argc; i++) { |
959 Register arg = values[argc-1-i]; | 885 Register arg = values[argc-1-i]; |
960 ASSERT(!receiver.is(arg)); | 886 ASSERT(!receiver.is(arg)); |
961 ASSERT(!scratch.is(arg)); | 887 ASSERT(!scratch.is(arg)); |
962 __ push(arg); | 888 __ push(arg); |
963 } | 889 } |
964 Register scratch1 = r0; | |
965 Register scratch2 = r1; | |
966 Register scratch3 = r2; | |
967 if (!r3.is(receiver)) { | |
968 __ mov(r3, receiver); | |
969 receiver = r3; | |
970 } | |
971 // Stack now matches JSFunction abi. | 890 // Stack now matches JSFunction abi. |
972 GenerateFastApiCallBody(masm, | 891 GenerateFastApiCallBody(masm, |
973 optimization, | 892 optimization, |
974 argc, | 893 argc, |
975 receiver, | 894 receiver, |
976 scratch1, | |
977 scratch2, | |
978 scratch3, | |
979 true); | 895 true); |
980 } | 896 } |
981 | 897 |
982 | 898 |
983 class CallInterceptorCompiler BASE_EMBEDDED { | 899 class CallInterceptorCompiler BASE_EMBEDDED { |
984 public: | 900 public: |
985 CallInterceptorCompiler(CallStubCompiler* stub_compiler, | 901 CallInterceptorCompiler(CallStubCompiler* stub_compiler, |
986 const ParameterCount& arguments, | 902 const ParameterCount& arguments, |
987 Register name) | 903 Register name) |
988 : stub_compiler_(stub_compiler), | 904 : stub_compiler_(stub_compiler), |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 // scratch2 (internal::Object** args_) as the data. | 1332 // scratch2 (internal::Object** args_) as the data. |
1417 __ str(scratch2(), MemOperand(sp, 1 * kPointerSize)); | 1333 __ str(scratch2(), MemOperand(sp, 1 * kPointerSize)); |
1418 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo& | 1334 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo& |
1419 | 1335 |
1420 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1; | 1336 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1; |
1421 Address getter_address = v8::ToCData<Address>(callback->getter()); | 1337 Address getter_address = v8::ToCData<Address>(callback->getter()); |
1422 | 1338 |
1423 ApiFunction fun(getter_address); | 1339 ApiFunction fun(getter_address); |
1424 ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL; | 1340 ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL; |
1425 ExternalReference ref = ExternalReference(&fun, type, isolate()); | 1341 ExternalReference ref = ExternalReference(&fun, type, isolate()); |
| 1342 Register getter_address_reg = r3; |
| 1343 Register thunk_last_arg = r2; |
| 1344 __ mov(getter_address_reg, Operand(ref)); |
| 1345 __ mov(thunk_last_arg, Operand(reinterpret_cast<int32_t>(getter_address))); |
1426 | 1346 |
1427 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback); | 1347 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback); |
1428 ExternalReference::Type thunk_type = | 1348 ExternalReference::Type thunk_type = |
1429 ExternalReference::PROFILING_GETTER_CALL; | 1349 ExternalReference::PROFILING_GETTER_CALL; |
1430 ApiFunction thunk_fun(thunk_address); | 1350 ApiFunction thunk_fun(thunk_address); |
1431 ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type, | 1351 ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type, |
1432 isolate()); | 1352 isolate()); |
1433 __ CallApiFunctionAndReturn(ref, | 1353 __ CallApiFunctionAndReturn(getter_address_reg, |
1434 getter_address, | |
1435 thunk_ref, | 1354 thunk_ref, |
1436 r2, | 1355 thunk_last_arg, |
1437 kStackUnwindSpace, | 1356 kStackUnwindSpace, |
1438 MemOperand(fp, 6 * kPointerSize), | 1357 MemOperand(fp, 6 * kPointerSize), |
1439 NULL); | 1358 NULL); |
1440 } | 1359 } |
1441 | 1360 |
1442 | 1361 |
1443 void LoadStubCompiler::GenerateLoadInterceptor( | 1362 void LoadStubCompiler::GenerateLoadInterceptor( |
1444 Register holder_reg, | 1363 Register holder_reg, |
1445 Handle<Object> object, | 1364 Handle<Object> object, |
1446 Handle<JSObject> interceptor_holder, | 1365 Handle<JSObject> interceptor_holder, |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 // ----------------------------------- | 2120 // ----------------------------------- |
2202 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); | 2121 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); |
2203 } | 2122 } |
2204 | 2123 |
2205 | 2124 |
2206 #undef __ | 2125 #undef __ |
2207 | 2126 |
2208 } } // namespace v8::internal | 2127 } } // namespace v8::internal |
2209 | 2128 |
2210 #endif // V8_TARGET_ARCH_ARM | 2129 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |