| 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_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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 // This simulates the initial call to bytecode handlers in interpreter entry | 907 // This simulates the initial call to bytecode handlers in interpreter entry |
| 908 // trampoline. The return will never actually be taken, but our stack walker | 908 // trampoline. The return will never actually be taken, but our stack walker |
| 909 // uses this address to determine whether a frame is interpreted. | 909 // uses this address to determine whether a frame is interpreted. |
| 910 __ Push(masm->isolate()->builtins()->InterpreterEntryTrampoline()); | 910 __ Push(masm->isolate()->builtins()->InterpreterEntryTrampoline()); |
| 911 | 911 |
| 912 Generate_EnterBytecodeDispatch(masm); | 912 Generate_EnterBytecodeDispatch(masm); |
| 913 } | 913 } |
| 914 | 914 |
| 915 | 915 |
| 916 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { | 916 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { |
| 917 // ----------- S t a t e ------------- | |
| 918 // -- rdx : new target (preserved for callee) | |
| 919 // -- rdi : target function (preserved for callee) | |
| 920 // ----------------------------------- | |
| 921 // First lookup code, maybe we don't need to compile! | |
| 922 Label gotta_call_runtime; | |
| 923 Label maybe_call_runtime; | |
| 924 Label try_shared; | |
| 925 Label loop_top, loop_bottom; | |
| 926 | |
| 927 Register closure = rdi; | |
| 928 Register map = r8; | |
| 929 Register index = r9; | |
| 930 __ movp(map, FieldOperand(closure, JSFunction::kSharedFunctionInfoOffset)); | |
| 931 __ movp(map, FieldOperand(map, SharedFunctionInfo::kOptimizedCodeMapOffset)); | |
| 932 __ SmiToInteger32(index, FieldOperand(map, FixedArray::kLengthOffset)); | |
| 933 __ cmpl(index, Immediate(2)); | |
| 934 __ j(less, &gotta_call_runtime); | |
| 935 | |
| 936 // Find literals. | |
| 937 // r14 : native context | |
| 938 // r9 : length / index | |
| 939 // r8 : optimized code map | |
| 940 // rdx : new target | |
| 941 // rdi : closure | |
| 942 Register native_context = r14; | |
| 943 __ movp(native_context, NativeContextOperand()); | |
| 944 | |
| 945 __ bind(&loop_top); | |
| 946 // Native context match? | |
| 947 Register temp = r11; | |
| 948 __ movp(temp, FieldOperand(map, index, times_pointer_size, | |
| 949 SharedFunctionInfo::OffsetToPreviousContext())); | |
| 950 __ movp(temp, FieldOperand(temp, WeakCell::kValueOffset)); | |
| 951 __ cmpp(temp, native_context); | |
| 952 __ j(not_equal, &loop_bottom); | |
| 953 // OSR id set to none? | |
| 954 __ movp(temp, FieldOperand(map, index, times_pointer_size, | |
| 955 SharedFunctionInfo::OffsetToPreviousOsrAstId())); | |
| 956 __ SmiToInteger32(temp, temp); | |
| 957 const int bailout_id = BailoutId::None().ToInt(); | |
| 958 __ cmpl(temp, Immediate(bailout_id)); | |
| 959 __ j(not_equal, &loop_bottom); | |
| 960 // Literals available? | |
| 961 __ movp(temp, FieldOperand(map, index, times_pointer_size, | |
| 962 SharedFunctionInfo::OffsetToPreviousLiterals())); | |
| 963 __ movp(temp, FieldOperand(temp, WeakCell::kValueOffset)); | |
| 964 __ JumpIfSmi(temp, &gotta_call_runtime); | |
| 965 | |
| 966 // Save the literals in the closure. | |
| 967 __ movp(FieldOperand(closure, JSFunction::kLiteralsOffset), temp); | |
| 968 __ movp(rax, index); | |
| 969 __ RecordWriteField(closure, JSFunction::kLiteralsOffset, temp, rax, | |
| 970 kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | |
| 971 | |
| 972 // Code available? | |
| 973 Register entry = rcx; | |
| 974 __ movp(entry, | |
| 975 FieldOperand(map, index, times_pointer_size, | |
| 976 SharedFunctionInfo::OffsetToPreviousCachedCode())); | |
| 977 __ movp(entry, FieldOperand(entry, WeakCell::kValueOffset)); | |
| 978 __ JumpIfSmi(entry, &maybe_call_runtime); | |
| 979 | |
| 980 // Found literals and code. Get them into the closure and return. | |
| 981 __ leap(entry, FieldOperand(entry, Code::kHeaderSize)); | |
| 982 | |
| 983 Label install_optimized_code_and_tailcall; | |
| 984 __ bind(&install_optimized_code_and_tailcall); | |
| 985 __ movp(FieldOperand(closure, JSFunction::kCodeEntryOffset), entry); | |
| 986 | |
| 987 // Link the closure into the optimized function list. | |
| 988 // rcx : code entry (entry) | |
| 989 // r14 : native context | |
| 990 // rdx : new target | |
| 991 // rdi : closure | |
| 992 __ movp(rbx, | |
| 993 ContextOperand(native_context, Context::OPTIMIZED_FUNCTIONS_LIST)); | |
| 994 __ movp(FieldOperand(closure, JSFunction::kNextFunctionLinkOffset), rbx); | |
| 995 __ RecordWriteField(closure, JSFunction::kNextFunctionLinkOffset, rbx, rax, | |
| 996 kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | |
| 997 const int function_list_offset = | |
| 998 Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST); | |
| 999 __ movp(ContextOperand(native_context, Context::OPTIMIZED_FUNCTIONS_LIST), | |
| 1000 closure); | |
| 1001 // Save closure before the write barrier. | |
| 1002 __ movp(rbx, closure); | |
| 1003 __ RecordWriteContextSlot(native_context, function_list_offset, closure, rax, | |
| 1004 kDontSaveFPRegs); | |
| 1005 __ movp(closure, rbx); | |
| 1006 __ jmp(entry); | |
| 1007 | |
| 1008 __ bind(&loop_bottom); | |
| 1009 __ subl(index, Immediate(SharedFunctionInfo::kEntryLength)); | |
| 1010 __ cmpl(index, Immediate(1)); | |
| 1011 __ j(greater, &loop_top); | |
| 1012 | |
| 1013 // We found neither literals nor code. | |
| 1014 __ jmp(&gotta_call_runtime); | |
| 1015 | |
| 1016 __ bind(&maybe_call_runtime); | |
| 1017 | |
| 1018 // Last possibility. Check the context free optimized code map entry. | |
| 1019 __ movp(entry, FieldOperand(map, FixedArray::kHeaderSize + | |
| 1020 SharedFunctionInfo::kSharedCodeIndex)); | |
| 1021 __ movp(entry, FieldOperand(entry, WeakCell::kValueOffset)); | |
| 1022 __ JumpIfSmi(entry, &try_shared); | |
| 1023 | |
| 1024 // Store code entry in the closure. | |
| 1025 __ leap(entry, FieldOperand(entry, Code::kHeaderSize)); | |
| 1026 __ jmp(&install_optimized_code_and_tailcall); | |
| 1027 | |
| 1028 __ bind(&try_shared); | |
| 1029 // Is the full code valid? | |
| 1030 __ movp(entry, FieldOperand(closure, JSFunction::kSharedFunctionInfoOffset)); | |
| 1031 __ movp(entry, FieldOperand(entry, SharedFunctionInfo::kCodeOffset)); | |
| 1032 __ movl(rbx, FieldOperand(entry, Code::kFlagsOffset)); | |
| 1033 __ andl(rbx, Immediate(Code::KindField::kMask)); | |
| 1034 __ shrl(rbx, Immediate(Code::KindField::kShift)); | |
| 1035 __ cmpl(rbx, Immediate(Code::BUILTIN)); | |
| 1036 __ j(equal, &gotta_call_runtime); | |
| 1037 // Yes, install the full code. | |
| 1038 __ leap(entry, FieldOperand(entry, Code::kHeaderSize)); | |
| 1039 __ movp(FieldOperand(closure, JSFunction::kCodeEntryOffset), entry); | |
| 1040 __ jmp(entry); | |
| 1041 | |
| 1042 __ bind(&gotta_call_runtime); | |
| 1043 CallRuntimePassFunction(masm, Runtime::kCompileLazy); | 917 CallRuntimePassFunction(masm, Runtime::kCompileLazy); |
| 1044 GenerateTailCallToReturnedCode(masm); | 918 GenerateTailCallToReturnedCode(masm); |
| 1045 } | 919 } |
| 1046 | 920 |
| 1047 | 921 |
| 1048 void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { | 922 void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { |
| 1049 CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); | 923 CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); |
| 1050 GenerateTailCallToReturnedCode(masm); | 924 GenerateTailCallToReturnedCode(masm); |
| 1051 } | 925 } |
| 1052 | 926 |
| (...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2879 __ ret(0); | 2753 __ ret(0); |
| 2880 } | 2754 } |
| 2881 | 2755 |
| 2882 | 2756 |
| 2883 #undef __ | 2757 #undef __ |
| 2884 | 2758 |
| 2885 } // namespace internal | 2759 } // namespace internal |
| 2886 } // namespace v8 | 2760 } // namespace v8 |
| 2887 | 2761 |
| 2888 #endif // V8_TARGET_ARCH_X64 | 2762 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |