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

Unified Diff: src/x64/builtins-x64.cc

Issue 1670143002: Visit the Optimized Code Map on first call rather than closure creation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Removed overly-restrictive assert. Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects-inl.h ('k') | src/x64/macro-assembler-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/x64/builtins-x64.cc
diff --git a/src/x64/builtins-x64.cc b/src/x64/builtins-x64.cc
index dbd13289b7a525658aa545c16687714edab18dfe..38b4440863be77046f849022dccbcf667e3a3e3b 100644
--- a/src/x64/builtins-x64.cc
+++ b/src/x64/builtins-x64.cc
@@ -904,6 +904,134 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- rax : argument count (preserved for callee)
+ // -- rdx : new target (preserved for callee)
+ // -- rdi : target function (preserved for callee)
+ // -----------------------------------
+ // First lookup code, maybe we don't need to compile!
+ Label gotta_call_runtime;
+ Label maybe_call_runtime;
+ Label try_shared;
+ Label loop_top, loop_bottom;
+
+ Register closure = rdi;
+ Register map = r8;
+ Register index = r9;
+ __ movp(map, FieldOperand(closure, JSFunction::kSharedFunctionInfoOffset));
+ __ movp(map, FieldOperand(map, SharedFunctionInfo::kOptimizedCodeMapOffset));
+ __ SmiToInteger32(index, FieldOperand(map, FixedArray::kLengthOffset));
+ __ cmpl(index, Immediate(2));
+ __ j(less, &gotta_call_runtime);
+
+ // Find literals.
+ // r14 : native context
+ // r9 : length / index
+ // r8 : optimized code map
+ // rdx : new target
+ // rdi : closure
+ Register native_context = r14;
+ __ movp(native_context, NativeContextOperand());
+
+ __ bind(&loop_top);
+ // Native context match?
+ Register temp = r11;
+ __ movp(temp, FieldOperand(map, index, times_pointer_size,
+ SharedFunctionInfo::kOffsetToPreviousContext));
+ __ movp(temp, FieldOperand(temp, WeakCell::kValueOffset));
+ __ cmpp(temp, native_context);
+ __ j(not_equal, &loop_bottom);
+ // OSR id set to none?
+ __ movp(temp, FieldOperand(map, index, times_pointer_size,
+ SharedFunctionInfo::kOffsetToPreviousOsrAstId));
+ __ SmiToInteger32(temp, temp);
+ const int bailout_id = BailoutId::None().ToInt();
+ __ cmpl(temp, Immediate(bailout_id));
+ __ j(not_equal, &loop_bottom);
+ // Literals available?
+ __ movp(temp, FieldOperand(map, index, times_pointer_size,
+ SharedFunctionInfo::kOffsetToPreviousLiterals));
+ __ movp(temp, FieldOperand(temp, WeakCell::kValueOffset));
+ __ JumpIfSmi(temp, &gotta_call_runtime);
+
+ // Save the literals in the closure.
+ __ movp(FieldOperand(closure, JSFunction::kLiteralsOffset), temp);
+ __ movp(r15, index);
+ __ RecordWriteField(closure, JSFunction::kLiteralsOffset, temp, r15,
+ kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
+
+ // Code available?
+ Register entry = rcx;
+ __ movp(entry, FieldOperand(map, index, times_pointer_size,
+ SharedFunctionInfo::kOffsetToPreviousCachedCode));
+ __ movp(entry, FieldOperand(entry, WeakCell::kValueOffset));
+ __ JumpIfSmi(entry, &maybe_call_runtime);
+
+ // Found literals and code. Get them into the closure and return.
+ __ leap(entry, FieldOperand(entry, Code::kHeaderSize));
+
+ Label install_optimized_code_and_tailcall;
+ __ bind(&install_optimized_code_and_tailcall);
+ __ movp(FieldOperand(closure, JSFunction::kCodeEntryOffset), entry);
+ __ RecordWriteCodeEntryField(closure, entry, r15);
+
+ // Link the closure into the optimized function list.
+ // rcx : code entry (entry)
+ // r14 : native context
+ // rdx : new target
+ // rdi : closure
+ __ movp(rbx,
+ ContextOperand(native_context, Context::OPTIMIZED_FUNCTIONS_LIST));
+ __ movp(FieldOperand(closure, JSFunction::kNextFunctionLinkOffset), rbx);
+ __ RecordWriteField(closure, JSFunction::kNextFunctionLinkOffset, rbx, r15,
+ kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
+ const int function_list_offset =
+ Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST);
+ __ movp(ContextOperand(native_context, Context::OPTIMIZED_FUNCTIONS_LIST),
+ closure);
+ // Save closure before the write barrier.
+ __ movp(rbx, closure);
+ __ RecordWriteContextSlot(native_context, function_list_offset, closure, r15,
+ kDontSaveFPRegs);
+ __ movp(closure, rbx);
+ __ jmp(entry);
+
+ __ bind(&loop_bottom);
+ __ subl(index, Immediate(SharedFunctionInfo::kEntryLength));
+ __ cmpl(index, Immediate(1));
+ __ j(greater, &loop_top);
+
+ // We found neither literals nor code.
+ __ jmp(&gotta_call_runtime);
+
+ __ bind(&maybe_call_runtime);
+
+ // Last possibility. Check the context free optimized code map entry.
+ __ movp(entry, FieldOperand(map, FixedArray::kHeaderSize +
+ SharedFunctionInfo::kSharedCodeIndex));
+ __ movp(entry, FieldOperand(entry, WeakCell::kValueOffset));
+ __ JumpIfSmi(entry, &try_shared);
+
+ // Store code entry in the closure.
+ __ leap(entry, FieldOperand(entry, Code::kHeaderSize));
+ __ jmp(&install_optimized_code_and_tailcall);
+
+ __ bind(&try_shared);
+ // Is the full code valid?
+ __ movp(entry, FieldOperand(closure, JSFunction::kSharedFunctionInfoOffset));
+ __ movp(entry, FieldOperand(entry, SharedFunctionInfo::kCodeOffset));
+ __ movl(rbx, FieldOperand(entry, Code::kFlagsOffset));
+ __ andl(rbx, Immediate(Code::KindField::kMask));
+ __ shrl(rbx, Immediate(Code::KindField::kShift));
+ __ cmpl(rbx, Immediate(Code::BUILTIN));
+ __ j(equal, &gotta_call_runtime);
+ // Yes, install the full code.
+ __ leap(entry, FieldOperand(entry, Code::kHeaderSize));
+ __ movp(FieldOperand(closure, JSFunction::kCodeEntryOffset), entry);
+ __ RecordWriteCodeEntryField(closure, entry, r15);
+ __ jmp(entry);
+
+ __ bind(&gotta_call_runtime);
GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
}
« no previous file with comments | « src/objects-inl.h ('k') | src/x64/macro-assembler-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698