Index: src/arm/builtins-arm.cc |
diff --git a/src/arm/builtins-arm.cc b/src/arm/builtins-arm.cc |
index 74fd005d0cd793c4ff11025e30cc37957cf55ca4..cd3a9260ccd79a67c3f5e52f24f5370115b1bb77 100644 |
--- a/src/arm/builtins-arm.cc |
+++ b/src/arm/builtins-arm.cc |
@@ -1228,6 +1228,159 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { |
void Builtins::Generate_CompileLazy(MacroAssembler* masm) { |
+ // ----------- S t a t e ------------- |
+ // -- r0 : argument count (preserved for callee) |
+ // -- r3 : new target (preserved for callee) |
+ // -- r1 : target function (preserved for callee) |
+ // ----------------------------------- |
+ // First lookup code, maybe we don't need to compile! |
+ Label gotta_call_runtime, gotta_call_runtime_no_stack; |
+ Label maybe_call_runtime; |
+ Label try_shared; |
+ Label loop_top, loop_bottom; |
+ |
+ Register argument_count = r0; |
+ Register closure = r1; |
+ Register new_target = r3; |
+ __ push(argument_count); |
+ __ push(new_target); |
+ __ push(closure); |
+ |
+ Register map = argument_count; |
+ Register index = r2; |
+ __ ldr(map, FieldMemOperand(closure, JSFunction::kSharedFunctionInfoOffset)); |
+ __ ldr(map, |
+ FieldMemOperand(map, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
+ __ ldr(index, FieldMemOperand(map, FixedArray::kLengthOffset)); |
+ __ cmp(index, Operand(Smi::FromInt(2))); |
+ __ b(lt, &gotta_call_runtime); |
+ |
+ // Find literals. |
+ // r3 : native context |
+ // r2 : length / index |
+ // r0 : optimized code map |
+ // stack[0] : new target |
+ // stack[4] : closure |
+ Register native_context = r3; |
+ __ ldr(native_context, NativeContextMemOperand()); |
+ |
+ __ bind(&loop_top); |
+ Register temp = r1; |
+ Register array_pointer = r5; |
+ |
+ // Does the native context match? |
+ __ add(array_pointer, map, Operand::PointerOffsetFromSmiKey(index)); |
+ __ ldr(temp, FieldMemOperand(array_pointer, |
+ SharedFunctionInfo::kOffsetToPreviousContext)); |
+ __ ldr(temp, FieldMemOperand(temp, WeakCell::kValueOffset)); |
+ __ cmp(temp, native_context); |
+ __ b(ne, &loop_bottom); |
+ // OSR id set to none? |
+ __ ldr(temp, FieldMemOperand(array_pointer, |
+ SharedFunctionInfo::kOffsetToPreviousOsrAstId)); |
+ const int bailout_id = BailoutId::None().ToInt(); |
+ __ cmp(temp, Operand(Smi::FromInt(bailout_id))); |
+ __ b(ne, &loop_bottom); |
+ // Literals available? |
+ __ ldr(temp, FieldMemOperand(array_pointer, |
+ SharedFunctionInfo::kOffsetToPreviousLiterals)); |
+ __ ldr(temp, FieldMemOperand(temp, WeakCell::kValueOffset)); |
+ __ JumpIfSmi(temp, &gotta_call_runtime); |
+ |
+ // Save the literals in the closure. |
+ __ ldr(r4, MemOperand(sp, 0)); |
+ __ str(temp, FieldMemOperand(r4, JSFunction::kLiteralsOffset)); |
+ __ push(index); |
+ __ RecordWriteField(r4, JSFunction::kLiteralsOffset, temp, index, |
+ kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
+ OMIT_SMI_CHECK); |
+ __ pop(index); |
+ |
+ // Code available? |
+ Register entry = r4; |
+ __ ldr(entry, |
+ FieldMemOperand(array_pointer, |
+ SharedFunctionInfo::kOffsetToPreviousCachedCode)); |
+ __ ldr(entry, FieldMemOperand(entry, WeakCell::kValueOffset)); |
+ __ JumpIfSmi(entry, &maybe_call_runtime); |
+ |
+ // Found literals and code. Get them into the closure and return. |
+ __ pop(closure); |
+ // Store code entry in the closure. |
+ __ add(entry, entry, Operand(Code::kHeaderSize - kHeapObjectTag)); |
+ |
+ Label install_optimized_code_and_tailcall; |
+ __ bind(&install_optimized_code_and_tailcall); |
+ __ str(entry, FieldMemOperand(closure, JSFunction::kCodeEntryOffset)); |
+ __ RecordWriteCodeEntryField(closure, entry, r5); |
+ |
+ // Link the closure into the optimized function list. |
+ // r4 : code entry |
+ // r3 : native context |
+ // r1 : closure |
+ __ ldr(r5, |
+ ContextMemOperand(native_context, Context::OPTIMIZED_FUNCTIONS_LIST)); |
+ __ str(r5, FieldMemOperand(closure, JSFunction::kNextFunctionLinkOffset)); |
+ __ RecordWriteField(closure, JSFunction::kNextFunctionLinkOffset, r5, r0, |
+ kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
+ OMIT_SMI_CHECK); |
+ const int function_list_offset = |
+ Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST); |
+ __ str(closure, |
+ ContextMemOperand(native_context, Context::OPTIMIZED_FUNCTIONS_LIST)); |
+ // Save closure before the write barrier. |
+ __ mov(r5, closure); |
+ __ RecordWriteContextSlot(native_context, function_list_offset, closure, r0, |
+ kLRHasNotBeenSaved, kDontSaveFPRegs); |
+ __ mov(closure, r5); |
+ __ pop(new_target); |
+ __ pop(argument_count); |
+ __ Jump(entry); |
+ |
+ __ bind(&loop_bottom); |
+ __ sub(index, index, Operand(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
+ __ cmp(index, Operand(Smi::FromInt(1))); |
+ __ b(gt, &loop_top); |
+ |
+ // We found neither literals nor code. |
+ __ jmp(&gotta_call_runtime); |
+ |
+ __ bind(&maybe_call_runtime); |
+ __ pop(closure); |
+ |
+ // Last possibility. Check the context free optimized code map entry. |
+ __ ldr(entry, FieldMemOperand(map, FixedArray::kHeaderSize + |
+ SharedFunctionInfo::kSharedCodeIndex)); |
+ __ ldr(entry, FieldMemOperand(entry, WeakCell::kValueOffset)); |
+ __ JumpIfSmi(entry, &try_shared); |
+ |
+ // Store code entry in the closure. |
+ __ add(entry, entry, Operand(Code::kHeaderSize - kHeapObjectTag)); |
+ __ jmp(&install_optimized_code_and_tailcall); |
+ |
+ __ bind(&try_shared); |
+ __ pop(new_target); |
+ __ pop(argument_count); |
+ // Is the full code valid? |
+ __ ldr(entry, |
+ FieldMemOperand(closure, JSFunction::kSharedFunctionInfoOffset)); |
+ __ ldr(entry, FieldMemOperand(entry, SharedFunctionInfo::kCodeOffset)); |
+ __ ldr(r5, FieldMemOperand(entry, Code::kFlagsOffset)); |
+ __ and_(r5, r5, Operand(Code::KindField::kMask)); |
+ __ mov(r5, Operand(r5, LSR, Code::KindField::kShift)); |
+ __ cmp(r5, Operand(Code::BUILTIN)); |
+ __ b(eq, &gotta_call_runtime_no_stack); |
+ // Yes, install the full code. |
+ __ add(entry, entry, Operand(Code::kHeaderSize - kHeapObjectTag)); |
+ __ str(entry, FieldMemOperand(closure, JSFunction::kCodeEntryOffset)); |
+ __ RecordWriteCodeEntryField(closure, entry, r5); |
+ __ Jump(entry); |
+ |
+ __ bind(&gotta_call_runtime); |
+ __ pop(closure); |
+ __ pop(new_target); |
+ __ pop(argument_count); |
+ __ bind(&gotta_call_runtime_no_stack); |
GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy); |
} |