OLD | NEW |
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 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 // This simulates the initial call to bytecode handlers in interpreter entry | 859 // This simulates the initial call to bytecode handlers in interpreter entry |
860 // trampoline. The return will never actually be taken, but our stack walker | 860 // trampoline. The return will never actually be taken, but our stack walker |
861 // uses this address to determine whether a frame is interpreted. | 861 // uses this address to determine whether a frame is interpreted. |
862 __ Push(masm->isolate()->builtins()->InterpreterEntryTrampoline()); | 862 __ Push(masm->isolate()->builtins()->InterpreterEntryTrampoline()); |
863 | 863 |
864 Generate_EnterBytecodeDispatch(masm); | 864 Generate_EnterBytecodeDispatch(masm); |
865 } | 865 } |
866 | 866 |
867 | 867 |
868 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { | 868 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { |
| 869 // ----------- S t a t e ------------- |
| 870 // -- edx : new target (preserved for callee) |
| 871 // -- edi : target function (preserved for callee) |
| 872 // ----------------------------------- |
| 873 // First lookup code, maybe we don't need to compile! |
| 874 Label gotta_call_runtime, gotta_call_runtime_no_stack; |
| 875 Label maybe_call_runtime; |
| 876 Label try_shared; |
| 877 Label loop_top, loop_bottom; |
| 878 |
| 879 Register closure = edi; |
| 880 Register new_target = edx; |
| 881 __ push(new_target); |
| 882 __ push(closure); |
| 883 |
| 884 Register map = eax; |
| 885 Register index = ebx; |
| 886 __ mov(map, FieldOperand(closure, JSFunction::kSharedFunctionInfoOffset)); |
| 887 __ mov(map, FieldOperand(map, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 888 __ mov(index, FieldOperand(map, FixedArray::kLengthOffset)); |
| 889 __ cmp(index, Immediate(Smi::FromInt(2))); |
| 890 __ j(less, &gotta_call_runtime); |
| 891 |
| 892 // Find literals. |
| 893 // edx : native context |
| 894 // ebx : length / index |
| 895 // eax : optimized code map |
| 896 // stack[0] : new target |
| 897 // stack[4] : closure |
| 898 Register native_context = edx; |
| 899 __ mov(native_context, NativeContextOperand()); |
| 900 |
| 901 __ bind(&loop_top); |
| 902 Register temp = edi; |
| 903 |
| 904 // Does the native context match? |
| 905 __ mov(temp, FieldOperand(map, index, times_half_pointer_size, |
| 906 SharedFunctionInfo::OffsetToPreviousContext())); |
| 907 __ mov(temp, FieldOperand(temp, WeakCell::kValueOffset)); |
| 908 __ cmp(temp, native_context); |
| 909 __ j(not_equal, &loop_bottom); |
| 910 // OSR id set to none? |
| 911 __ mov(temp, FieldOperand(map, index, times_half_pointer_size, |
| 912 SharedFunctionInfo::OffsetToPreviousOsrAstId())); |
| 913 const int bailout_id = BailoutId::None().ToInt(); |
| 914 __ cmp(temp, Immediate(Smi::FromInt(bailout_id))); |
| 915 __ j(not_equal, &loop_bottom); |
| 916 // Literals available? |
| 917 __ mov(temp, FieldOperand(map, index, times_half_pointer_size, |
| 918 SharedFunctionInfo::OffsetToPreviousLiterals())); |
| 919 __ mov(temp, FieldOperand(temp, WeakCell::kValueOffset)); |
| 920 __ JumpIfSmi(temp, &gotta_call_runtime); |
| 921 |
| 922 // Save the literals in the closure. |
| 923 __ mov(ecx, Operand(esp, 0)); |
| 924 __ mov(FieldOperand(ecx, JSFunction::kLiteralsOffset), temp); |
| 925 __ push(index); |
| 926 __ RecordWriteField(ecx, JSFunction::kLiteralsOffset, temp, index, |
| 927 kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 928 __ pop(index); |
| 929 |
| 930 // Code available? |
| 931 Register entry = ecx; |
| 932 __ mov(entry, FieldOperand(map, index, times_half_pointer_size, |
| 933 SharedFunctionInfo::OffsetToPreviousCachedCode())); |
| 934 __ mov(entry, FieldOperand(entry, WeakCell::kValueOffset)); |
| 935 __ JumpIfSmi(entry, &maybe_call_runtime); |
| 936 |
| 937 // Found literals and code. Get them into the closure and return. |
| 938 __ pop(closure); |
| 939 // Store code entry in the closure. |
| 940 __ lea(entry, FieldOperand(entry, Code::kHeaderSize)); |
| 941 |
| 942 Label install_optimized_code_and_tailcall; |
| 943 __ bind(&install_optimized_code_and_tailcall); |
| 944 __ mov(FieldOperand(closure, JSFunction::kCodeEntryOffset), entry); |
| 945 |
| 946 // Link the closure into the optimized function list. |
| 947 // ecx : code entry |
| 948 // edx : native context |
| 949 // edi : closure |
| 950 __ mov(ebx, |
| 951 ContextOperand(native_context, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 952 __ mov(FieldOperand(closure, JSFunction::kNextFunctionLinkOffset), ebx); |
| 953 __ RecordWriteField(closure, JSFunction::kNextFunctionLinkOffset, ebx, eax, |
| 954 kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 955 const int function_list_offset = |
| 956 Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST); |
| 957 __ mov(ContextOperand(native_context, Context::OPTIMIZED_FUNCTIONS_LIST), |
| 958 closure); |
| 959 // Save closure before the write barrier. |
| 960 __ mov(ebx, closure); |
| 961 __ RecordWriteContextSlot(native_context, function_list_offset, closure, eax, |
| 962 kDontSaveFPRegs); |
| 963 __ mov(closure, ebx); |
| 964 __ pop(new_target); |
| 965 __ jmp(entry); |
| 966 |
| 967 __ bind(&loop_bottom); |
| 968 __ sub(index, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 969 __ cmp(index, Immediate(Smi::FromInt(1))); |
| 970 __ j(greater, &loop_top); |
| 971 |
| 972 // We found neither literals nor code. |
| 973 __ jmp(&gotta_call_runtime); |
| 974 |
| 975 __ bind(&maybe_call_runtime); |
| 976 __ pop(closure); |
| 977 |
| 978 // Last possibility. Check the context free optimized code map entry. |
| 979 __ mov(entry, FieldOperand(map, FixedArray::kHeaderSize + |
| 980 SharedFunctionInfo::kSharedCodeIndex)); |
| 981 __ mov(entry, FieldOperand(entry, WeakCell::kValueOffset)); |
| 982 __ JumpIfSmi(entry, &try_shared); |
| 983 |
| 984 // Store code entry in the closure. |
| 985 __ lea(entry, FieldOperand(entry, Code::kHeaderSize)); |
| 986 __ jmp(&install_optimized_code_and_tailcall); |
| 987 |
| 988 __ bind(&try_shared); |
| 989 __ pop(new_target); |
| 990 // Is the full code valid? |
| 991 __ mov(entry, FieldOperand(closure, JSFunction::kSharedFunctionInfoOffset)); |
| 992 __ mov(entry, FieldOperand(entry, SharedFunctionInfo::kCodeOffset)); |
| 993 __ mov(ebx, FieldOperand(entry, Code::kFlagsOffset)); |
| 994 __ and_(ebx, Code::KindField::kMask); |
| 995 __ shr(ebx, Code::KindField::kShift); |
| 996 __ cmp(ebx, Immediate(Code::BUILTIN)); |
| 997 __ j(equal, &gotta_call_runtime_no_stack); |
| 998 // Yes, install the full code. |
| 999 __ lea(entry, FieldOperand(entry, Code::kHeaderSize)); |
| 1000 __ mov(FieldOperand(closure, JSFunction::kCodeEntryOffset), entry); |
| 1001 __ jmp(entry); |
| 1002 |
| 1003 __ bind(&gotta_call_runtime); |
| 1004 __ pop(closure); |
| 1005 __ pop(new_target); |
| 1006 __ bind(&gotta_call_runtime_no_stack); |
869 CallRuntimePassFunction(masm, Runtime::kCompileLazy); | 1007 CallRuntimePassFunction(masm, Runtime::kCompileLazy); |
870 GenerateTailCallToReturnedCode(masm); | 1008 GenerateTailCallToReturnedCode(masm); |
871 } | 1009 } |
872 | 1010 |
873 | 1011 |
874 void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { | 1012 void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { |
875 CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); | 1013 CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); |
876 GenerateTailCallToReturnedCode(masm); | 1014 GenerateTailCallToReturnedCode(masm); |
877 } | 1015 } |
878 | 1016 |
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2676 | 2814 |
2677 __ bind(&ok); | 2815 __ bind(&ok); |
2678 __ ret(0); | 2816 __ ret(0); |
2679 } | 2817 } |
2680 | 2818 |
2681 #undef __ | 2819 #undef __ |
2682 } // namespace internal | 2820 } // namespace internal |
2683 } // namespace v8 | 2821 } // namespace v8 |
2684 | 2822 |
2685 #endif // V8_TARGET_ARCH_IA32 | 2823 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |