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

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

Issue 2307903002: [Interpreter] Collect allocation site feedback in call bytecode handler. (Closed)
Patch Set: Fixed a bug in mips implementation. Created 4 years, 3 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
« no previous file with comments | « src/builtins/builtins.h ('k') | src/builtins/mips/builtins-mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_IA32 5 #if V8_TARGET_ARCH_IA32
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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 tail_call_mode), 754 tail_call_mode),
755 RelocInfo::CODE_TARGET); 755 RelocInfo::CODE_TARGET);
756 } else { 756 } else {
757 DCHECK_EQ(function_type, CallableType::kAny); 757 DCHECK_EQ(function_type, CallableType::kAny);
758 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, 758 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny,
759 tail_call_mode), 759 tail_call_mode),
760 RelocInfo::CODE_TARGET); 760 RelocInfo::CODE_TARGET);
761 } 761 }
762 } 762 }
763 763
764 // static 764 namespace {
765 void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
766 MacroAssembler* masm, CallableType construct_type) {
767 // ----------- S t a t e -------------
768 // -- eax : the number of arguments (not including the receiver)
769 // -- edx : the new target
770 // -- edi : the constructor
771 // -- ebx : allocation site feedback (if available or undefined)
772 // -- ecx : the address of the first argument to be pushed. Subsequent
773 // arguments should be consecutive above this, in the same order as
774 // they are to be pushed onto the stack.
775 // -----------------------------------
776 765
777 // Store edi, edx onto the stack. We need two extra registers 766 // This function modified start_addr, and only reads the contents of num_args
778 // so store edi, edx temporarily on stack. 767 // register. scratch1 and scratch2 are used as temporary registers. Their
779 __ Push(edi); 768 // original values are restored after the use.
780 __ Push(edx); 769 void Generate_InterpreterPushArgsAndReturnAddress(
770 MacroAssembler* masm, Register num_args, Register start_addr,
771 Register scratch1, Register scratch2, bool receiver_in_args) {
772 // Store scratch2, scratch1 onto the stack. We need to restore the original
773 // values
774 // so store scratch2, scratch1 temporarily on stack.
775 __ Push(scratch2);
776 __ Push(scratch1);
781 777
782 // We have to pop return address and the two temporary registers before we 778 // We have to pop return address and the two temporary registers before we
783 // can push arguments onto the stack. we do not have any free registers so 779 // can push arguments onto the stack. we do not have any free registers so
784 // update the stack and copy them into the correct places on the stack. 780 // update the stack and copy them into the correct places on the stack.
785 // current stack =====> required stack layout 781 // current stack =====> required stack layout
786 // | | | edx | (2) <-- esp(1) 782 // | | | scratch1 | (2) <-- esp(1)
787 // | | | edi | (3) 783 // | | | scratch2 | (3)
788 // | | | return addr | (4) 784 // | | | return addr | (4)
789 // | | | arg N | (5) 785 // | | | arg N | (5)
790 // | edx | <-- esp | .... | 786 // | scratch1 | <-- esp | .... |
791 // | edi | | arg 0 | 787 // | scratch2 | | arg 0 |
792 // | return addr | | receiver slot | 788 // | return addr | | receiver slot |
793 789
794 // First increment the stack pointer to the correct location. 790 // First increment the stack pointer to the correct location.
795 // we need additional slots for arguments and the receiver. 791 // we need additional slots for arguments and the receiver.
796 // Step 1 - compute the required increment to the stack. 792 // Step 1 - compute the required increment to the stack.
797 __ mov(edx, eax); 793 __ mov(scratch1, num_args);
798 __ shl(edx, kPointerSizeLog2); 794 __ shl(scratch1, kPointerSizeLog2);
799 __ add(edx, Immediate(kPointerSize)); 795 __ add(scratch1, Immediate(kPointerSize));
800 796
801 #ifdef _MSC_VER 797 #ifdef _MSC_VER
802 // TODO(mythria): Move it to macro assembler. 798 // TODO(mythria): Move it to macro assembler.
803 // In windows, we cannot increment the stack size by more than one page 799 // In windows, we cannot increment the stack size by more than one page
804 // (mimimum page size is 4KB) without accessing at least one byte on the 800 // (mimimum page size is 4KB) without accessing at least one byte on the
805 // page. Check this: 801 // page. Check this:
806 // https://msdn.microsoft.com/en-us/library/aa227153(v=vs.60).aspx. 802 // https://msdn.microsoft.com/en-us/library/aa227153(v=vs.60).aspx.
807 const int page_size = 4 * 1024; 803 const int page_size = 4 * 1024;
808 Label check_offset, update_stack_pointer; 804 Label check_offset, update_stack_pointer;
809 __ bind(&check_offset); 805 __ bind(&check_offset);
810 __ cmp(edx, page_size); 806 __ cmp(scratch1, page_size);
811 __ j(less, &update_stack_pointer); 807 __ j(less, &update_stack_pointer);
812 __ sub(esp, Immediate(page_size)); 808 __ sub(esp, Immediate(page_size));
813 // Just to touch the page, before we increment further. 809 // Just to touch the page, before we increment further.
814 __ mov(Operand(esp, 0), Immediate(0)); 810 __ mov(Operand(esp, 0), Immediate(0));
815 __ sub(edx, Immediate(page_size)); 811 __ sub(scratch1, Immediate(page_size));
816 __ jmp(&check_offset); 812 __ jmp(&check_offset);
817 __ bind(&update_stack_pointer); 813 __ bind(&update_stack_pointer);
818 #endif 814 #endif
819 815
820 // TODO(mythria): Add a stack check before updating the stack pointer. 816 // TODO(mythria): Add a stack check before updating the stack pointer.
821 817
822 // Step 1 - Update the stack pointer. 818 // Step 1 - Update the stack pointer.
823 __ sub(esp, edx); 819 __ sub(esp, scratch1);
824 820
825 // Step 2 move edx to the correct location. Move edx first otherwise 821 // Step 2 move scratch1 to the correct location. Move scratch1 first otherwise
826 // we may overwrite when eax = 0 or 1, basically when the source and 822 // we may overwrite when num_args = 0 or 1, basically when the source and
827 // destination overlap. We at least need one extra slot for receiver, 823 // destination overlap. We at least need one extra slot for receiver,
828 // so no extra checks are required to avoid copy. 824 // so no extra checks are required to avoid copy.
829 __ mov(edi, Operand(esp, eax, times_pointer_size, 1 * kPointerSize)); 825 __ mov(scratch1,
830 __ mov(Operand(esp, 0), edi); 826 Operand(esp, num_args, times_pointer_size, 1 * kPointerSize));
827 __ mov(Operand(esp, 0), scratch1);
831 828
832 // Step 3 move edi to the correct location 829 // Step 3 move scratch2 to the correct location
833 __ mov(edi, Operand(esp, eax, times_pointer_size, 2 * kPointerSize)); 830 __ mov(scratch1,
834 __ mov(Operand(esp, 1 * kPointerSize), edi); 831 Operand(esp, num_args, times_pointer_size, 2 * kPointerSize));
832 __ mov(Operand(esp, 1 * kPointerSize), scratch1);
835 833
836 // Step 4 move return address to the correct location 834 // Step 4 move return address to the correct location
837 __ mov(edi, Operand(esp, eax, times_pointer_size, 3 * kPointerSize)); 835 __ mov(scratch1,
838 __ mov(Operand(esp, 2 * kPointerSize), edi); 836 Operand(esp, num_args, times_pointer_size, 3 * kPointerSize));
839 837 __ mov(Operand(esp, 2 * kPointerSize), scratch1);
840 // Slot meant for receiver contains return address. Reset it so that
841 // we will not incorrectly interpret return address as an object.
842 __ mov(Operand(esp, eax, times_pointer_size, 3 * kPointerSize), Immediate(0));
843 838
844 // Step 5 copy arguments to correct locations. 839 // Step 5 copy arguments to correct locations.
845 __ mov(edx, eax); 840 if (receiver_in_args) {
841 __ mov(scratch1, num_args);
842 __ add(scratch1, Immediate(1));
843 } else {
844 // Slot meant for receiver contains return address. Reset it so that
845 // we will not incorrectly interpret return address as an object.
846 __ mov(Operand(esp, num_args, times_pointer_size, 3 * kPointerSize),
847 Immediate(0));
848 __ mov(scratch1, num_args);
849 }
846 850
847 Label loop_header, loop_check; 851 Label loop_header, loop_check;
848 __ jmp(&loop_check); 852 __ jmp(&loop_check);
849 __ bind(&loop_header); 853 __ bind(&loop_header);
850 __ mov(edi, Operand(ecx, 0)); 854 __ mov(scratch2, Operand(start_addr, 0));
851 __ mov(Operand(esp, edx, times_pointer_size, 2 * kPointerSize), edi); 855 __ mov(Operand(esp, scratch1, times_pointer_size, 2 * kPointerSize),
852 __ sub(ecx, Immediate(kPointerSize)); 856 scratch2);
853 __ sub(edx, Immediate(1)); 857 __ sub(start_addr, Immediate(kPointerSize));
858 __ sub(scratch1, Immediate(1));
854 __ bind(&loop_check); 859 __ bind(&loop_check);
855 __ cmp(edx, Immediate(0)); 860 __ cmp(scratch1, Immediate(0));
856 __ j(greater, &loop_header, Label::kNear); 861 __ j(greater, &loop_header, Label::kNear);
857 862
858 // Restore edi and edx. 863 // Restore scratch1 and scratch2.
859 __ Pop(edx); 864 __ Pop(scratch1);
860 __ Pop(edi); 865 __ Pop(scratch2);
866 }
867
868 } // end anonymous namespace
869
870 // static
871 void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
872 MacroAssembler* masm, CallableType construct_type) {
873 // ----------- S t a t e -------------
874 // -- eax : the number of arguments (not including the receiver)
875 // -- edx : the new target
876 // -- edi : the constructor
877 // -- ebx : allocation site feedback (if available or undefined)
878 // -- ecx : the address of the first argument to be pushed. Subsequent
879 // arguments should be consecutive above this, in the same order as
880 // they are to be pushed onto the stack.
881 // -----------------------------------
882
883 // Push arguments and move return address to the top of stack.
884 // The eax register is readonly. The ecx register will be modified. The edx
885 // and edi registers will be modified but restored to their original values.
886 Generate_InterpreterPushArgsAndReturnAddress(masm, eax, ecx, edx, edi, false);
861 887
862 __ AssertUndefinedOrAllocationSite(ebx); 888 __ AssertUndefinedOrAllocationSite(ebx);
863 if (construct_type == CallableType::kJSFunction) { 889 if (construct_type == CallableType::kJSFunction) {
864 // Tail call to the function-specific construct stub (still in the caller 890 // Tail call to the function-specific construct stub (still in the caller
865 // context at this point). 891 // context at this point).
866 __ AssertFunction(edi); 892 __ AssertFunction(edi);
867 893
868 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); 894 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
869 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); 895 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset));
870 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); 896 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize));
871 __ jmp(ecx); 897 __ jmp(ecx);
872 } else { 898 } else {
873 DCHECK_EQ(construct_type, CallableType::kAny); 899 DCHECK_EQ(construct_type, CallableType::kAny);
874 900
875 // Call the constructor with unmodified eax, edi, edx values. 901 // Call the constructor with unmodified eax, edi, edx values.
876 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); 902 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
877 } 903 }
878 } 904 }
879 905
906 // static
907 void Builtins::Generate_InterpreterPushArgsAndConstructArray(
908 MacroAssembler* masm) {
909 // ----------- S t a t e -------------
910 // -- eax : the number of arguments (not including the receiver)
911 // -- edx : the target to call checked to be Array function.
912 // -- ebx : the allocation site feedback
913 // -- ecx : the address of the first argument to be pushed. Subsequent
914 // arguments should be consecutive above this, in the same order as
915 // they are to be pushed onto the stack.
916 // -----------------------------------
917
918 // Push arguments and move return address to the top of stack.
919 // The eax register is readonly. The ecx register will be modified. The edx
920 // and edi registers will be modified but restored to their original values.
921 Generate_InterpreterPushArgsAndReturnAddress(masm, eax, ecx, edx, ebx, true);
922
923 // Array constructor expects constructor in edi. It is same as edx here.
924 __ Move(edi, edx);
925
926 ArrayConstructorStub stub(masm->isolate());
927 __ TailCallStub(&stub);
928 }
929
880 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { 930 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
881 // Set the return address to the correct point in the interpreter entry 931 // Set the return address to the correct point in the interpreter entry
882 // trampoline. 932 // trampoline.
883 Smi* interpreter_entry_return_pc_offset( 933 Smi* interpreter_entry_return_pc_offset(
884 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); 934 masm->isolate()->heap()->interpreter_entry_return_pc_offset());
885 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); 935 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0));
886 __ LoadHeapObject(ebx, 936 __ LoadHeapObject(ebx,
887 masm->isolate()->builtins()->InterpreterEntryTrampoline()); 937 masm->isolate()->builtins()->InterpreterEntryTrampoline());
888 __ add(ebx, Immediate(interpreter_entry_return_pc_offset->value() + 938 __ add(ebx, Immediate(interpreter_entry_return_pc_offset->value() +
889 Code::kHeaderSize - kHeapObjectTag)); 939 Code::kHeaderSize - kHeapObjectTag));
(...skipping 2231 matching lines...) Expand 10 before | Expand all | Expand 10 after
3121 3171
3122 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { 3172 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) {
3123 Generate_OnStackReplacementHelper(masm, true); 3173 Generate_OnStackReplacementHelper(masm, true);
3124 } 3174 }
3125 3175
3126 #undef __ 3176 #undef __
3127 } // namespace internal 3177 } // namespace internal
3128 } // namespace v8 3178 } // namespace v8
3129 3179
3130 #endif // V8_TARGET_ARCH_IA32 3180 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/builtins/mips/builtins-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698