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 4660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4671 void StackCheckStub::Generate(MacroAssembler* masm) { | 4671 void StackCheckStub::Generate(MacroAssembler* masm) { |
4672 __ TailCallRuntime(Runtime::kStackGuard, 0, 1); | 4672 __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
4673 } | 4673 } |
4674 | 4674 |
4675 | 4675 |
4676 void InterruptStub::Generate(MacroAssembler* masm) { | 4676 void InterruptStub::Generate(MacroAssembler* masm) { |
4677 __ TailCallRuntime(Runtime::kInterrupt, 0, 1); | 4677 __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
4678 } | 4678 } |
4679 | 4679 |
4680 | 4680 |
4681 static void GenerateRecordCallTargetNoArray(MacroAssembler* masm) { | |
4682 // Cache the called function in a global property cell. Cache states | |
4683 // are uninitialized, monomorphic (indicated by a JSFunction), and | |
4684 // megamorphic. | |
4685 // ebx : cache cell for call target | |
4686 // edi : the function to call | |
4687 Isolate* isolate = masm->isolate(); | |
4688 Label initialize, done; | |
4689 | |
4690 // Load the cache state into ecx. | |
4691 __ mov(ecx, FieldOperand(ebx, PropertyCell::kValueOffset)); | |
4692 | |
4693 // A monomorphic cache hit or an already megamorphic state: invoke the | |
4694 // function without changing the state. | |
4695 __ cmp(ecx, edi); | |
4696 __ j(equal, &done, Label::kNear); | |
4697 __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); | |
4698 __ j(equal, &done, Label::kNear); | |
4699 | |
4700 // A monomorphic miss (i.e, here the cache is not uninitialized) goes | |
4701 // megamorphic. | |
4702 __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); | |
4703 __ j(equal, &initialize, Label::kNear); | |
4704 // MegamorphicSentinel is an immortal immovable object (undefined) so no | |
4705 // write-barrier is needed. | |
4706 __ mov(FieldOperand(ebx, Cell::kValueOffset), | |
4707 Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); | |
4708 __ jmp(&done, Label::kNear); | |
4709 | |
4710 // An uninitialized cache is patched with the function. | |
4711 __ bind(&initialize); | |
4712 __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); | |
4713 // No need for a write barrier here - cells are rescanned. | |
4714 | |
4715 __ bind(&done); | |
4716 } | |
4717 | |
4718 | |
4719 static void GenerateRecordCallTarget(MacroAssembler* masm) { | 4681 static void GenerateRecordCallTarget(MacroAssembler* masm) { |
4720 // Cache the called function in a global property cell. Cache states | 4682 // Cache the called function in a global property cell. Cache states |
4721 // are uninitialized, monomorphic (indicated by a JSFunction), and | 4683 // are uninitialized, monomorphic (indicated by a JSFunction), and |
4722 // megamorphic. | 4684 // megamorphic. |
4723 // ebx : cache cell for call target | 4685 // ebx : cache cell for call target |
4724 // edi : the function to call | 4686 // edi : the function to call |
4725 ASSERT(FLAG_optimize_constructed_arrays); | |
4726 Isolate* isolate = masm->isolate(); | 4687 Isolate* isolate = masm->isolate(); |
4727 Label initialize, done, miss, megamorphic, not_array_function; | 4688 Label initialize, done, miss, megamorphic, not_array_function; |
4728 | 4689 |
4729 // Load the cache state into ecx. | 4690 // Load the cache state into ecx. |
4730 __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); | 4691 __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
4731 | 4692 |
4732 // A monomorphic cache hit or an already megamorphic state: invoke the | 4693 // A monomorphic cache hit or an already megamorphic state: invoke the |
4733 // function without changing the state. | 4694 // function without changing the state. |
4734 __ cmp(ecx, edi); | 4695 __ cmp(ecx, edi); |
4735 __ j(equal, &done); | 4696 __ j(equal, &done); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4817 __ bind(&receiver_ok); | 4778 __ bind(&receiver_ok); |
4818 } | 4779 } |
4819 | 4780 |
4820 // Check that the function really is a JavaScript function. | 4781 // Check that the function really is a JavaScript function. |
4821 __ JumpIfSmi(edi, &non_function); | 4782 __ JumpIfSmi(edi, &non_function); |
4822 // Goto slow case if we do not have a function. | 4783 // Goto slow case if we do not have a function. |
4823 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); | 4784 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
4824 __ j(not_equal, &slow); | 4785 __ j(not_equal, &slow); |
4825 | 4786 |
4826 if (RecordCallTarget()) { | 4787 if (RecordCallTarget()) { |
4827 if (FLAG_optimize_constructed_arrays) { | 4788 GenerateRecordCallTarget(masm); |
4828 GenerateRecordCallTarget(masm); | |
4829 } else { | |
4830 GenerateRecordCallTargetNoArray(masm); | |
4831 } | |
4832 } | 4789 } |
4833 | 4790 |
4834 // Fast-case: Just invoke the function. | 4791 // Fast-case: Just invoke the function. |
4835 ParameterCount actual(argc_); | 4792 ParameterCount actual(argc_); |
4836 | 4793 |
4837 if (ReceiverMightBeImplicit()) { | 4794 if (ReceiverMightBeImplicit()) { |
4838 Label call_as_function; | 4795 Label call_as_function; |
4839 __ cmp(eax, isolate->factory()->the_hole_value()); | 4796 __ cmp(eax, isolate->factory()->the_hole_value()); |
4840 __ j(equal, &call_as_function); | 4797 __ j(equal, &call_as_function); |
4841 __ InvokeFunction(edi, | 4798 __ InvokeFunction(edi, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4894 // edi : constructor function | 4851 // edi : constructor function |
4895 Label slow, non_function_call; | 4852 Label slow, non_function_call; |
4896 | 4853 |
4897 // Check that function is not a smi. | 4854 // Check that function is not a smi. |
4898 __ JumpIfSmi(edi, &non_function_call); | 4855 __ JumpIfSmi(edi, &non_function_call); |
4899 // Check that function is a JSFunction. | 4856 // Check that function is a JSFunction. |
4900 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); | 4857 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
4901 __ j(not_equal, &slow); | 4858 __ j(not_equal, &slow); |
4902 | 4859 |
4903 if (RecordCallTarget()) { | 4860 if (RecordCallTarget()) { |
4904 if (FLAG_optimize_constructed_arrays) { | 4861 GenerateRecordCallTarget(masm); |
4905 GenerateRecordCallTarget(masm); | |
4906 } else { | |
4907 GenerateRecordCallTargetNoArray(masm); | |
4908 } | |
4909 } | 4862 } |
4910 | 4863 |
4911 // Jump to the function-specific construct stub. | 4864 // Jump to the function-specific construct stub. |
4912 Register jmp_reg = FLAG_optimize_constructed_arrays ? ecx : ebx; | 4865 Register jmp_reg = ecx; |
4913 __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 4866 __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
4914 __ mov(jmp_reg, FieldOperand(jmp_reg, | 4867 __ mov(jmp_reg, FieldOperand(jmp_reg, |
4915 SharedFunctionInfo::kConstructStubOffset)); | 4868 SharedFunctionInfo::kConstructStubOffset)); |
4916 __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); | 4869 __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
4917 __ jmp(jmp_reg); | 4870 __ jmp(jmp_reg); |
4918 | 4871 |
4919 // edi: called object | 4872 // edi: called object |
4920 // eax: number of arguments | 4873 // eax: number of arguments |
4921 // ecx: object map | 4874 // ecx: object map |
4922 Label do_call; | 4875 Label do_call; |
(...skipping 25 matching lines...) Expand all Loading... |
4948 result_size_ == 1; | 4901 result_size_ == 1; |
4949 } | 4902 } |
4950 | 4903 |
4951 | 4904 |
4952 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { | 4905 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
4953 CEntryStub::GenerateAheadOfTime(isolate); | 4906 CEntryStub::GenerateAheadOfTime(isolate); |
4954 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); | 4907 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
4955 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); | 4908 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
4956 // It is important that the store buffer overflow stubs are generated first. | 4909 // It is important that the store buffer overflow stubs are generated first. |
4957 RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); | 4910 RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
4958 if (FLAG_optimize_constructed_arrays) { | 4911 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
4959 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); | |
4960 } | |
4961 } | 4912 } |
4962 | 4913 |
4963 | 4914 |
4964 void CodeStub::GenerateFPStubs(Isolate* isolate) { | 4915 void CodeStub::GenerateFPStubs(Isolate* isolate) { |
4965 if (CpuFeatures::IsSupported(SSE2)) { | 4916 if (CpuFeatures::IsSupported(SSE2)) { |
4966 CEntryStub save_doubles(1, kSaveFPRegs); | 4917 CEntryStub save_doubles(1, kSaveFPRegs); |
4967 // Stubs might already be in the snapshot, detect that and don't regenerate, | 4918 // Stubs might already be in the snapshot, detect that and don't regenerate, |
4968 // which would lead to code stub initialization state being messed up. | 4919 // which would lead to code stub initialization state being messed up. |
4969 Code* save_doubles_code; | 4920 Code* save_doubles_code; |
4970 if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { | 4921 if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
(...skipping 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7933 // We should either have undefined in ebx or a valid cell | 7884 // We should either have undefined in ebx or a valid cell |
7934 Label okay_here; | 7885 Label okay_here; |
7935 Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); | 7886 Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
7936 __ cmp(ebx, Immediate(undefined_sentinel)); | 7887 __ cmp(ebx, Immediate(undefined_sentinel)); |
7937 __ j(equal, &okay_here); | 7888 __ j(equal, &okay_here); |
7938 __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); | 7889 __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
7939 __ Assert(equal, "Expected property cell in register ebx"); | 7890 __ Assert(equal, "Expected property cell in register ebx"); |
7940 __ bind(&okay_here); | 7891 __ bind(&okay_here); |
7941 } | 7892 } |
7942 | 7893 |
7943 if (FLAG_optimize_constructed_arrays) { | 7894 Label no_info, switch_ready; |
7944 Label no_info, switch_ready; | 7895 // Get the elements kind and case on that. |
7945 // Get the elements kind and case on that. | 7896 __ cmp(ebx, Immediate(undefined_sentinel)); |
7946 __ cmp(ebx, Immediate(undefined_sentinel)); | 7897 __ j(equal, &no_info); |
7947 __ j(equal, &no_info); | 7898 __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
7948 __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); | 7899 __ JumpIfNotSmi(edx, &no_info); |
7949 __ JumpIfNotSmi(edx, &no_info); | 7900 __ SmiUntag(edx); |
7950 __ SmiUntag(edx); | 7901 __ jmp(&switch_ready); |
7951 __ jmp(&switch_ready); | 7902 __ bind(&no_info); |
7952 __ bind(&no_info); | 7903 __ mov(edx, Immediate(GetInitialFastElementsKind())); |
7953 __ mov(edx, Immediate(GetInitialFastElementsKind())); | 7904 __ bind(&switch_ready); |
7954 __ bind(&switch_ready); | |
7955 | 7905 |
7956 if (argument_count_ == ANY) { | 7906 if (argument_count_ == ANY) { |
7957 Label not_zero_case, not_one_case; | 7907 Label not_zero_case, not_one_case; |
7958 __ test(eax, eax); | 7908 __ test(eax, eax); |
7959 __ j(not_zero, ¬_zero_case); | 7909 __ j(not_zero, ¬_zero_case); |
7960 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); | 7910 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
7961 | 7911 |
7962 __ bind(¬_zero_case); | 7912 __ bind(¬_zero_case); |
7963 __ cmp(eax, 1); | 7913 __ cmp(eax, 1); |
7964 __ j(greater, ¬_one_case); | 7914 __ j(greater, ¬_one_case); |
7965 CreateArrayDispatchOneArgument(masm); | 7915 CreateArrayDispatchOneArgument(masm); |
7966 | 7916 |
7967 __ bind(¬_one_case); | 7917 __ bind(¬_one_case); |
7968 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); | 7918 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
7969 } else if (argument_count_ == NONE) { | 7919 } else if (argument_count_ == NONE) { |
7970 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); | 7920 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
7971 } else if (argument_count_ == ONE) { | 7921 } else if (argument_count_ == ONE) { |
7972 CreateArrayDispatchOneArgument(masm); | 7922 CreateArrayDispatchOneArgument(masm); |
7973 } else if (argument_count_ == MORE_THAN_ONE) { | 7923 } else if (argument_count_ == MORE_THAN_ONE) { |
7974 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); | 7924 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
7975 } else { | |
7976 UNREACHABLE(); | |
7977 } | |
7978 } else { | 7925 } else { |
7979 Label generic_constructor; | 7926 UNREACHABLE(); |
7980 // Run the native code for the Array function called as constructor. | |
7981 ArrayNativeCode(masm, true, &generic_constructor); | |
7982 | |
7983 // Jump to the generic construct code in case the specialized code cannot | |
7984 // handle the construction. | |
7985 __ bind(&generic_constructor); | |
7986 Handle<Code> generic_construct_stub = | |
7987 masm->isolate()->builtins()->JSConstructStubGeneric(); | |
7988 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); | |
7989 } | 7927 } |
7990 } | 7928 } |
7991 | 7929 |
7992 | 7930 |
7993 void InternalArrayConstructorStub::GenerateCase( | 7931 void InternalArrayConstructorStub::GenerateCase( |
7994 MacroAssembler* masm, ElementsKind kind) { | 7932 MacroAssembler* masm, ElementsKind kind) { |
7995 Label not_zero_case, not_one_case; | 7933 Label not_zero_case, not_one_case; |
7996 Label normal_sequence; | 7934 Label normal_sequence; |
7997 | 7935 |
7998 __ test(eax, eax); | 7936 __ test(eax, eax); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8041 | 7979 |
8042 // Initial map for the builtin Array function should be a map. | 7980 // Initial map for the builtin Array function should be a map. |
8043 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); | 7981 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
8044 // Will both indicate a NULL and a Smi. | 7982 // Will both indicate a NULL and a Smi. |
8045 __ test(ecx, Immediate(kSmiTagMask)); | 7983 __ test(ecx, Immediate(kSmiTagMask)); |
8046 __ Assert(not_zero, "Unexpected initial map for Array function"); | 7984 __ Assert(not_zero, "Unexpected initial map for Array function"); |
8047 __ CmpObjectType(ecx, MAP_TYPE, ecx); | 7985 __ CmpObjectType(ecx, MAP_TYPE, ecx); |
8048 __ Assert(equal, "Unexpected initial map for Array function"); | 7986 __ Assert(equal, "Unexpected initial map for Array function"); |
8049 } | 7987 } |
8050 | 7988 |
8051 if (FLAG_optimize_constructed_arrays) { | 7989 // Figure out the right elements kind |
8052 // Figure out the right elements kind | 7990 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
8053 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); | |
8054 | 7991 |
8055 // Load the map's "bit field 2" into |result|. We only need the first byte, | 7992 // Load the map's "bit field 2" into |result|. We only need the first byte, |
8056 // but the following masking takes care of that anyway. | 7993 // but the following masking takes care of that anyway. |
8057 __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); | 7994 __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
8058 // Retrieve elements_kind from bit field 2. | 7995 // Retrieve elements_kind from bit field 2. |
8059 __ and_(ecx, Map::kElementsKindMask); | 7996 __ and_(ecx, Map::kElementsKindMask); |
8060 __ shr(ecx, Map::kElementsKindShift); | 7997 __ shr(ecx, Map::kElementsKindShift); |
8061 | 7998 |
8062 if (FLAG_debug_code) { | 7999 if (FLAG_debug_code) { |
8063 Label done; | 8000 Label done; |
8064 __ cmp(ecx, Immediate(FAST_ELEMENTS)); | 8001 __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
8065 __ j(equal, &done); | 8002 __ j(equal, &done); |
8066 __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); | 8003 __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
8067 __ Assert(equal, | 8004 __ Assert(equal, |
8068 "Invalid ElementsKind for InternalArray or InternalPackedArray"); | 8005 "Invalid ElementsKind for InternalArray or InternalPackedArray"); |
8069 __ bind(&done); | 8006 __ bind(&done); |
8070 } | 8007 } |
8071 | 8008 |
8072 Label fast_elements_case; | 8009 Label fast_elements_case; |
8073 __ cmp(ecx, Immediate(FAST_ELEMENTS)); | 8010 __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
8074 __ j(equal, &fast_elements_case); | 8011 __ j(equal, &fast_elements_case); |
8075 GenerateCase(masm, FAST_HOLEY_ELEMENTS); | 8012 GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
8076 | 8013 |
8077 __ bind(&fast_elements_case); | 8014 __ bind(&fast_elements_case); |
8078 GenerateCase(masm, FAST_ELEMENTS); | 8015 GenerateCase(masm, FAST_ELEMENTS); |
8079 } else { | |
8080 Label generic_constructor; | |
8081 // Run the native code for the Array function called as constructor. | |
8082 ArrayNativeCode(masm, true, &generic_constructor); | |
8083 | |
8084 // Jump to the generic construct code in case the specialized code cannot | |
8085 // handle the construction. | |
8086 __ bind(&generic_constructor); | |
8087 Handle<Code> generic_construct_stub = | |
8088 masm->isolate()->builtins()->JSConstructStubGeneric(); | |
8089 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); | |
8090 } | |
8091 } | 8016 } |
8092 | 8017 |
8093 | 8018 |
8094 #undef __ | 8019 #undef __ |
8095 | 8020 |
8096 } } // namespace v8::internal | 8021 } } // namespace v8::internal |
8097 | 8022 |
8098 #endif // V8_TARGET_ARCH_IA32 | 8023 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |