Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: src/x64/builtins-x64.cc

Issue 1362383002: [Interpreter] Add CallRuntime support to the interpreter. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/codegen.h" 8 #include "src/codegen.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 // Drop receiver + arguments and return. 764 // Drop receiver + arguments and return.
765 __ movl(rbx, FieldOperand(kInterpreterBytecodeArrayRegister, 765 __ movl(rbx, FieldOperand(kInterpreterBytecodeArrayRegister,
766 BytecodeArray::kParameterSizeOffset)); 766 BytecodeArray::kParameterSizeOffset));
767 __ PopReturnAddressTo(rcx); 767 __ PopReturnAddressTo(rcx);
768 __ addp(rsp, rbx); 768 __ addp(rsp, rbx);
769 __ PushReturnAddressFrom(rcx); 769 __ PushReturnAddressFrom(rcx);
770 __ ret(0); 770 __ ret(0);
771 } 771 }
772 772
773 773
774 // static
775 void Builtins::Generate_InterpreterPushArgsAndCall(MacroAssembler* masm) {
776 // ----------- S t a t e -------------
777 // -- rax : the number of arguments (not including the receiver)
778 // -- rbx : the address of the first argument to be pushed. Subsequent
779 // arguments should be consecutive above this, in the same order as
780 // they are to be pushed onto the stack.
781 // -- rdi : the target to call (can be any Object).
782
783 // Pop return address to allow tail-call after pushing arguments.
784 __ Pop(rdx);
785
786 // Find the address of the last argument.
787 __ movp(rcx, rax);
788 __ addp(rcx, Immediate(1)); // Add one for receiver.
789 __ shlp(rcx, Immediate(kPointerSizeLog2));
790 __ negp(rcx);
791 __ addp(rcx, rbx);
792
793 // Push the arguments.
794 Label loop_header, loop_check;
795 __ j(always, &loop_check);
796 __ bind(&loop_header);
797 __ Push(Operand(rbx, 0));
798 __ subp(rbx, Immediate(kPointerSize));
799 __ bind(&loop_check);
800 __ cmpp(rbx, rcx);
801 __ j(greater, &loop_header, Label::kNear);
802
803 // Call the target.
804 __ Push(rdx); // Re-push return address.
805 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
806 }
807
808
809 void Builtins::Generate_InterpreterCEntry(MacroAssembler* masm) {
810 // ----------- S t a t e -------------
811 // -- r14 : the number of arguments (argc).
812 // -- r15 : the address of the first argument (argv).
813 // -- rbx : the FunctionId of the runtime function to call.
814 // -- rsi : current context.
815
816 // TODO(rmcilroy): Things that still need to be done:
817 // - Call ProfileEntryHookStub when isolate has a function_entry_hook.
818 // - Deal with more than one return value.
819 // - Deal with saving fpregs if necessary.
820 // - Handle pending exceptions.
821
822 // Get the function entry address for the FunctionID.
823 const int kFunctionSizeLog2 = 2 + kPointerSizeLog2;
Michael Starzinger 2015/09/25 11:23:26 Hmm, I am not all too excited to have lookup in th
rmcilroy 2015/09/28 16:20:47 Acknowledged. I can't think of a better way either
824 STATIC_ASSERT(sizeof(Runtime::Function) == 1 << kFunctionSizeLog2);
825 __ shlp(rbx, Immediate(kFunctionSizeLog2));
826 __ LoadAddress(rax, ExternalReference::runtime_function_table_address());
827 __ addp(rbx, rax);
828 __ movp(rbx, Operand(rbx, offsetof(Runtime::Function, entry)));
829
830 // Enter the exit frame that transitions from JavaScript to C++.
831 #ifdef _WIN64
832 int arg_stack_space = 2;
833 #else // _WIN64
834 int arg_stack_space = 0;
835 #endif // _WIN64
836 // TODO(rmcilroy): save fpregs if required.
837 __ EnterApiExitFrame(arg_stack_space);
838
839 // Check stack alignment.
840 if (FLAG_debug_code) {
841 __ CheckStackAlignment();
842 }
843
844 // Call C function.
845 //
846 // Pass argv and argc as two parameters. The arguments object will
847 // be created by stubs declared by DECLARE_RUNTIME_FUNCTION().
848 #ifdef _WIN64
849 // Windows 64-bit ABI passes arguments in rcx, rdx, r8, r9.
850 __ movp(rcx, r14); // argc.
851 __ movp(rdx, r15); // argv.
852 __ Move(r8, ExternalReference::isolate_address(masm->isolate()));
853 #else // _WIN64
854 // GCC passes arguments in rdi, rsi, rdx, rcx, r8, r9.
855 __ movp(rdi, r14); // argc.
856 __ movp(rsi, r15); // argv.
857 __ Move(rdx, ExternalReference::isolate_address(masm->isolate()));
858 #endif // _WIN64
859 __ call(rbx);
860 // Result is in rax - do not destroy this register!
861
862 // Check result for exception sentinel.
863 Label exception_returned;
864 __ CompareRoot(rax, Heap::kExceptionRootIndex);
865 __ j(equal, &exception_returned);
866
867 // Check that there is no pending exception, otherwise we
868 // should have returned the exception sentinel.
869 if (FLAG_debug_code) {
870 Label okay;
871 __ LoadRoot(r14, Heap::kTheHoleValueRootIndex);
872 ExternalReference pending_exception_address(
873 Isolate::kPendingExceptionAddress, masm->isolate());
874 Operand pending_exception_operand =
875 masm->ExternalOperand(pending_exception_address);
876 __ cmpp(r14, pending_exception_operand);
877 __ j(equal, &okay, Label::kNear);
878 __ int3();
879 __ bind(&okay);
880 }
881
882 // Exit the JavaScript to C++ exit frame.
883 // TODO(rmcilroy): restore fpregs if required.
884 __ LeaveExitFrame(false);
885 __ ret(0);
886
887 // TODO(rmcilroy): Handle exceptions.
888 __ bind(&exception_returned);
Michael Starzinger 2015/09/25 11:23:26 I am not too happy about duplicating the CEntryStu
rmcilroy 2015/09/28 16:20:47 Very good point. The missing thing in CEntryStub w
889 __ int3();
890 }
891
892
774 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { 893 void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
775 CallRuntimePassFunction(masm, Runtime::kCompileLazy); 894 CallRuntimePassFunction(masm, Runtime::kCompileLazy);
776 GenerateTailCallToReturnedCode(masm); 895 GenerateTailCallToReturnedCode(masm);
777 } 896 }
778 897
779 898
780 static void CallCompileOptimized(MacroAssembler* masm, 899 static void CallCompileOptimized(MacroAssembler* masm,
781 bool concurrent) { 900 bool concurrent) {
782 FrameScope scope(masm, StackFrame::INTERNAL); 901 FrameScope scope(masm, StackFrame::INTERNAL);
783 // Push a copy of the function onto the stack. 902 // Push a copy of the function onto the stack.
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 // method. 1944 // method.
1826 __ bind(&non_constructor); 1945 __ bind(&non_constructor);
1827 { 1946 {
1828 FrameScope scope(masm, StackFrame::INTERNAL); 1947 FrameScope scope(masm, StackFrame::INTERNAL);
1829 __ Push(rdi); 1948 __ Push(rdi);
1830 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); 1949 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1);
1831 } 1950 }
1832 } 1951 }
1833 1952
1834 1953
1835 // static
1836 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) {
1837 // ----------- S t a t e -------------
1838 // -- rax : the number of arguments (not including the receiver)
1839 // -- rbx : the address of the first argument to be pushed. Subsequent
1840 // arguments should be consecutive above this, in the same order as
1841 // they are to be pushed onto the stack.
1842 // -- rdi : the target to call (can be any Object).
1843
1844 // Pop return address to allow tail-call after pushing arguments.
1845 __ Pop(rdx);
1846
1847 // Find the address of the last argument.
1848 __ movp(rcx, rax);
1849 __ addp(rcx, Immediate(1)); // Add one for receiver.
1850 __ shlp(rcx, Immediate(kPointerSizeLog2));
1851 __ negp(rcx);
1852 __ addp(rcx, rbx);
1853
1854 // Push the arguments.
1855 Label loop_header, loop_check;
1856 __ j(always, &loop_check);
1857 __ bind(&loop_header);
1858 __ Push(Operand(rbx, 0));
1859 __ subp(rbx, Immediate(kPointerSize));
1860 __ bind(&loop_check);
1861 __ cmpp(rbx, rcx);
1862 __ j(greater, &loop_header, Label::kNear);
1863
1864 // Call the target.
1865 __ Push(rdx); // Re-push return address.
1866 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1867 }
1868
1869
1870 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { 1954 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
1871 // Lookup the function in the JavaScript frame. 1955 // Lookup the function in the JavaScript frame.
1872 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1956 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1873 { 1957 {
1874 FrameScope scope(masm, StackFrame::INTERNAL); 1958 FrameScope scope(masm, StackFrame::INTERNAL);
1875 // Pass function as argument. 1959 // Pass function as argument.
1876 __ Push(rax); 1960 __ Push(rax);
1877 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); 1961 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1);
1878 } 1962 }
1879 1963
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 __ ret(0); 2003 __ ret(0);
1920 } 2004 }
1921 2005
1922 2006
1923 #undef __ 2007 #undef __
1924 2008
1925 } // namespace internal 2009 } // namespace internal
1926 } // namespace v8 2010 } // namespace v8
1927 2011
1928 #endif // V8_TARGET_ARCH_X64 2012 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698