Commit 5de27c34 authored by mvstanton's avatar mvstanton Committed by Commit bot

Preserve argument count for calls.

Calls use registers for target, new_target and argument count.
We don't always respect argument count. It didn't bite us in the past
because the code paths where we clobbered it never used it, though
in future it could be an issue.

BUG=
R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/1683593003

Cr-Commit-Position: refs/heads/master@{#33865}
parent 35b6ca25
...@@ -463,27 +463,6 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { ...@@ -463,27 +463,6 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
} }
static void CallRuntimePassFunction(
MacroAssembler* masm, Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- r1 : target function (preserved for callee)
// -- r3 : new target (preserved for callee)
// -----------------------------------
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
// Push a copy of the target function and the new target.
__ push(r1);
__ push(r3);
// Push function as parameter to the runtime call.
__ Push(r1);
__ CallRuntime(function_id, 1);
// Restore target function and new target.
__ pop(r3);
__ pop(r1);
}
static void GenerateTailCallToSharedCode(MacroAssembler* masm) { static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
__ ldr(r2, FieldMemOperand(r2, SharedFunctionInfo::kCodeOffset)); __ ldr(r2, FieldMemOperand(r2, SharedFunctionInfo::kCodeOffset));
...@@ -491,10 +470,35 @@ static void GenerateTailCallToSharedCode(MacroAssembler* masm) { ...@@ -491,10 +470,35 @@ static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ Jump(r2); __ Jump(r2);
} }
static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- r0 : argument count (preserved for callee)
// -- r1 : target function (preserved for callee)
// -- r3 : new target (preserved for callee)
// -----------------------------------
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
// Push the number of arguments to the callee.
__ SmiTag(r0);
__ push(r0);
// Push a copy of the target function and the new target.
__ push(r1);
__ push(r3);
// Push function as parameter to the runtime call.
__ Push(r1);
__ CallRuntime(function_id, 1);
__ mov(r2, r0);
static void GenerateTailCallToReturnedCode(MacroAssembler* masm) { // Restore target function and new target.
__ add(r0, r0, Operand(Code::kHeaderSize - kHeapObjectTag)); __ pop(r3);
__ Jump(r0); __ pop(r1);
__ pop(r0);
__ SmiUntag(r0, r0);
}
__ add(r2, r2, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Jump(r2);
} }
...@@ -509,8 +513,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { ...@@ -509,8 +513,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
__ cmp(sp, Operand(ip)); __ cmp(sp, Operand(ip));
__ b(hs, &ok); __ b(hs, &ok);
CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
GenerateTailCallToReturnedCode(masm);
__ bind(&ok); __ bind(&ok);
GenerateTailCallToSharedCode(masm); GenerateTailCallToSharedCode(masm);
...@@ -1245,20 +1248,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { ...@@ -1245,20 +1248,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
void Builtins::Generate_CompileLazy(MacroAssembler* masm) { void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileLazy); GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
GenerateTailCallToReturnedCode(masm);
} }
void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); GenerateTailCallToReturnedCode(masm,
GenerateTailCallToReturnedCode(masm); Runtime::kCompileOptimized_NotConcurrent);
} }
void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_Concurrent); GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
GenerateTailCallToReturnedCode(masm);
} }
......
...@@ -455,40 +455,40 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { ...@@ -455,40 +455,40 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
__ Ret(); __ Ret();
} }
static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
__ Ldr(x2, FieldMemOperand(x2, SharedFunctionInfo::kCodeOffset));
__ Add(x2, x2, Code::kHeaderSize - kHeapObjectTag);
__ Br(x2);
}
static void CallRuntimePassFunction(MacroAssembler* masm, static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
Runtime::FunctionId function_id) { Runtime::FunctionId function_id) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- x0 : argument count (preserved for callee)
// -- x1 : target function (preserved for callee) // -- x1 : target function (preserved for callee)
// -- x3 : new target (preserved for callee) // -- x3 : new target (preserved for callee)
// ----------------------------------- // -----------------------------------
{
FrameScope scope(masm, StackFrame::INTERNAL);
// Push a copy of the target function and the new target.
// Push another copy as a parameter to the runtime call.
__ SmiTag(x0);
__ Push(x0, x1, x3, x1);
FrameScope scope(masm, StackFrame::INTERNAL); __ CallRuntime(function_id, 1);
// Push a copy of the target function and the new target. __ Move(x2, x0);
// Push another copy as a parameter to the runtime call.
__ Push(x1, x3, x1);
__ CallRuntime(function_id, 1);
// Restore target function and new target.
__ Pop(x3, x1);
}
// Restore target function and new target.
__ Pop(x3, x1, x0);
__ SmiUntag(x0);
}
static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
__ Ldr(x2, FieldMemOperand(x2, SharedFunctionInfo::kCodeOffset));
__ Add(x2, x2, Code::kHeaderSize - kHeapObjectTag); __ Add(x2, x2, Code::kHeaderSize - kHeapObjectTag);
__ Br(x2); __ Br(x2);
} }
static void GenerateTailCallToReturnedCode(MacroAssembler* masm) {
__ Add(x0, x0, Code::kHeaderSize - kHeapObjectTag);
__ Br(x0);
}
void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
// Checking whether the queued function is ready for install is optional, // Checking whether the queued function is ready for install is optional,
// since we come across interrupts and stack checks elsewhere. However, not // since we come across interrupts and stack checks elsewhere. However, not
...@@ -499,8 +499,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { ...@@ -499,8 +499,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
__ CompareRoot(masm->StackPointer(), Heap::kStackLimitRootIndex); __ CompareRoot(masm->StackPointer(), Heap::kStackLimitRootIndex);
__ B(hs, &ok); __ B(hs, &ok);
CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
GenerateTailCallToReturnedCode(masm);
__ Bind(&ok); __ Bind(&ok);
GenerateTailCallToSharedCode(masm); GenerateTailCallToSharedCode(masm);
...@@ -1194,20 +1193,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { ...@@ -1194,20 +1193,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
void Builtins::Generate_CompileLazy(MacroAssembler* masm) { void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileLazy); GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
GenerateTailCallToReturnedCode(masm);
} }
void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); GenerateTailCallToReturnedCode(masm,
GenerateTailCallToReturnedCode(masm); Runtime::kCompileOptimized_NotConcurrent);
} }
void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_Concurrent); GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
GenerateTailCallToReturnedCode(masm);
} }
......
...@@ -60,42 +60,45 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, ...@@ -60,42 +60,45 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
__ JumpToExternalReference(ExternalReference(id, masm->isolate())); __ JumpToExternalReference(ExternalReference(id, masm->isolate()));
} }
static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
static void CallRuntimePassFunction( Runtime::FunctionId function_id) {
MacroAssembler* masm, Runtime::FunctionId function_id) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : argument count (preserved for callee)
// -- edx : new target (preserved for callee) // -- edx : new target (preserved for callee)
// -- edi : target function (preserved for callee) // -- edi : target function (preserved for callee)
// ----------------------------------- // -----------------------------------
{
FrameScope scope(masm, StackFrame::INTERNAL);
// Push the number of arguments to the callee.
__ SmiTag(eax);
__ push(eax);
// Push a copy of the target function and the new target.
__ push(edi);
__ push(edx);
// Function is also the parameter to the runtime call.
__ push(edi);
FrameScope scope(masm, StackFrame::INTERNAL); __ CallRuntime(function_id, 1);
// Push a copy of the target function and the new target. __ mov(ebx, eax);
__ push(edi);
__ push(edx);
// Function is also the parameter to the runtime call.
__ push(edi);
__ CallRuntime(function_id, 1);
// Restore target function and new target.
__ pop(edx);
__ pop(edi);
}
// Restore target function and new target.
__ pop(edx);
__ pop(edi);
__ pop(eax);
__ SmiUntag(eax);
}
static void GenerateTailCallToSharedCode(MacroAssembler* masm) { __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize));
__ mov(eax, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); __ jmp(ebx);
__ mov(eax, FieldOperand(eax, SharedFunctionInfo::kCodeOffset));
__ lea(eax, FieldOperand(eax, Code::kHeaderSize));
__ jmp(eax);
} }
static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
static void GenerateTailCallToReturnedCode(MacroAssembler* masm) { __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
__ lea(eax, FieldOperand(eax, Code::kHeaderSize)); __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kCodeOffset));
__ jmp(eax); __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize));
__ jmp(ebx);
} }
void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
// Checking whether the queued function is ready for install is optional, // Checking whether the queued function is ready for install is optional,
// since we come across interrupts and stack checks elsewhere. However, // since we come across interrupts and stack checks elsewhere. However,
...@@ -108,14 +111,12 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { ...@@ -108,14 +111,12 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
__ cmp(esp, Operand::StaticVariable(stack_limit)); __ cmp(esp, Operand::StaticVariable(stack_limit));
__ j(above_equal, &ok, Label::kNear); __ j(above_equal, &ok, Label::kNear);
CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
GenerateTailCallToReturnedCode(masm);
__ bind(&ok); __ bind(&ok);
GenerateTailCallToSharedCode(masm); GenerateTailCallToSharedCode(masm);
} }
static void Generate_JSConstructStubHelper(MacroAssembler* masm, static void Generate_JSConstructStubHelper(MacroAssembler* masm,
bool is_api_function, bool is_api_function,
bool create_implicit_receiver, bool create_implicit_receiver,
...@@ -848,20 +849,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { ...@@ -848,20 +849,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
void Builtins::Generate_CompileLazy(MacroAssembler* masm) { void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileLazy); GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
GenerateTailCallToReturnedCode(masm);
} }
void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); GenerateTailCallToReturnedCode(masm,
GenerateTailCallToReturnedCode(masm); Runtime::kCompileOptimized_NotConcurrent);
} }
void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_Concurrent); GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
GenerateTailCallToReturnedCode(masm);
} }
......
...@@ -469,25 +469,6 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { ...@@ -469,25 +469,6 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
__ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot
} }
static void CallRuntimePassFunction(
MacroAssembler* masm, Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- a1 : target function (preserved for callee)
// -- a3 : new target (preserved for callee)
// -----------------------------------
FrameScope scope(masm, StackFrame::INTERNAL);
// Push a copy of the target function and the new target.
// Push function as parameter to the runtime call.
__ Push(a1, a3, a1);
__ CallRuntime(function_id, 1);
// Restore target function and new target.
__ Pop(a1, a3);
}
static void GenerateTailCallToSharedCode(MacroAssembler* masm) { static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ lw(a2, FieldMemOperand(a2, SharedFunctionInfo::kCodeOffset)); __ lw(a2, FieldMemOperand(a2, SharedFunctionInfo::kCodeOffset));
...@@ -495,8 +476,27 @@ static void GenerateTailCallToSharedCode(MacroAssembler* masm) { ...@@ -495,8 +476,27 @@ static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ Jump(at); __ Jump(at);
} }
static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- a0 : argument count (preserved for callee)
// -- a1 : target function (preserved for callee)
// -- a3 : new target (preserved for callee)
// -----------------------------------
{
FrameScope scope(masm, StackFrame::INTERNAL);
// Push a copy of the target function and the new target.
// Push function as parameter to the runtime call.
__ SmiTag(a0);
__ Push(a0, a1, a3, a1);
__ CallRuntime(function_id, 1);
// Restore target function and new target.
__ Pop(a0, a1, a3);
__ SmiUntag(a0);
}
static void GenerateTailCallToReturnedCode(MacroAssembler* masm) {
__ Addu(at, v0, Operand(Code::kHeaderSize - kHeapObjectTag)); __ Addu(at, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Jump(at); __ Jump(at);
} }
...@@ -512,8 +512,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { ...@@ -512,8 +512,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
__ LoadRoot(t0, Heap::kStackLimitRootIndex); __ LoadRoot(t0, Heap::kStackLimitRootIndex);
__ Branch(&ok, hs, sp, Operand(t0)); __ Branch(&ok, hs, sp, Operand(t0));
CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
GenerateTailCallToReturnedCode(masm);
__ bind(&ok); __ bind(&ok);
GenerateTailCallToSharedCode(masm); GenerateTailCallToSharedCode(masm);
...@@ -1236,20 +1235,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { ...@@ -1236,20 +1235,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
void Builtins::Generate_CompileLazy(MacroAssembler* masm) { void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileLazy); GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
GenerateTailCallToReturnedCode(masm);
} }
void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); GenerateTailCallToReturnedCode(masm,
GenerateTailCallToReturnedCode(masm); Runtime::kCompileOptimized_NotConcurrent);
} }
void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_Concurrent); GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
GenerateTailCallToReturnedCode(masm);
} }
......
...@@ -468,25 +468,6 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { ...@@ -468,25 +468,6 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
__ sd(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot. __ sd(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot.
} }
static void CallRuntimePassFunction(
MacroAssembler* masm, Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- a1 : target function (preserved for callee)
// -- a3 : new target (preserved for callee)
// -----------------------------------
FrameScope scope(masm, StackFrame::INTERNAL);
// Push a copy of the function onto the stack.
// Push a copy of the target function and the new target.
__ Push(a1, a3, a1);
__ CallRuntime(function_id, 1);
// Restore target function and new target.
__ Pop(a1, a3);
}
static void GenerateTailCallToSharedCode(MacroAssembler* masm) { static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ ld(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); __ ld(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ ld(a2, FieldMemOperand(a2, SharedFunctionInfo::kCodeOffset)); __ ld(a2, FieldMemOperand(a2, SharedFunctionInfo::kCodeOffset));
...@@ -494,8 +475,26 @@ static void GenerateTailCallToSharedCode(MacroAssembler* masm) { ...@@ -494,8 +475,26 @@ static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ Jump(at); __ Jump(at);
} }
static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- a0 : argument count (preserved for callee)
// -- a1 : target function (preserved for callee)
// -- a3 : new target (preserved for callee)
// -----------------------------------
{
FrameScope scope(masm, StackFrame::INTERNAL);
// Push a copy of the function onto the stack.
// Push a copy of the target function and the new target.
__ SmiTag(a0);
__ Push(a0, a1, a3, a1);
__ CallRuntime(function_id, 1);
// Restore target function and new target.
__ Pop(a0, a1, a3);
__ SmiUntag(a0);
}
static void GenerateTailCallToReturnedCode(MacroAssembler* masm) {
__ Daddu(at, v0, Operand(Code::kHeaderSize - kHeapObjectTag)); __ Daddu(at, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Jump(at); __ Jump(at);
} }
...@@ -511,8 +510,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { ...@@ -511,8 +510,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
__ LoadRoot(a4, Heap::kStackLimitRootIndex); __ LoadRoot(a4, Heap::kStackLimitRootIndex);
__ Branch(&ok, hs, sp, Operand(a4)); __ Branch(&ok, hs, sp, Operand(a4));
CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
GenerateTailCallToReturnedCode(masm);
__ bind(&ok); __ bind(&ok);
GenerateTailCallToSharedCode(masm); GenerateTailCallToSharedCode(masm);
...@@ -1229,20 +1227,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { ...@@ -1229,20 +1227,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
void Builtins::Generate_CompileLazy(MacroAssembler* masm) { void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileLazy); GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
GenerateTailCallToReturnedCode(masm);
} }
void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); GenerateTailCallToReturnedCode(masm,
GenerateTailCallToReturnedCode(masm); Runtime::kCompileOptimized_NotConcurrent);
} }
void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_Concurrent); GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
GenerateTailCallToReturnedCode(masm);
} }
......
...@@ -60,27 +60,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, ...@@ -60,27 +60,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
} }
static void CallRuntimePassFunction(
MacroAssembler* masm, Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- rdx : new target (preserved for callee)
// -- rdi : target function (preserved for callee)
// -----------------------------------
FrameScope scope(masm, StackFrame::INTERNAL);
// Push a copy of the target function and the new target.
__ Push(rdi);
__ Push(rdx);
// Function is also the parameter to the runtime call.
__ Push(rdi);
__ CallRuntime(function_id, 1);
// Restore target function and new target.
__ Pop(rdx);
__ Pop(rdi);
}
static void GenerateTailCallToSharedCode(MacroAssembler* masm) { static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ movp(kScratchRegister, __ movp(kScratchRegister,
FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
...@@ -90,10 +69,35 @@ static void GenerateTailCallToSharedCode(MacroAssembler* masm) { ...@@ -90,10 +69,35 @@ static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ jmp(kScratchRegister); __ jmp(kScratchRegister);
} }
static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- rax : argument count (preserved for callee)
// -- rdx : new target (preserved for callee)
// -- rdi : target function (preserved for callee)
// -----------------------------------
{
FrameScope scope(masm, StackFrame::INTERNAL);
// Push the number of arguments to the callee.
__ Integer32ToSmi(rax, rax);
__ Push(rax);
// Push a copy of the target function and the new target.
__ Push(rdi);
__ Push(rdx);
// Function is also the parameter to the runtime call.
__ Push(rdi);
static void GenerateTailCallToReturnedCode(MacroAssembler* masm) { __ CallRuntime(function_id, 1);
__ leap(rax, FieldOperand(rax, Code::kHeaderSize)); __ movp(rbx, rax);
__ jmp(rax);
// Restore target function and new target.
__ Pop(rdx);
__ Pop(rdi);
__ Pop(rax);
__ SmiToInteger32(rax, rax);
}
__ leap(rbx, FieldOperand(rbx, Code::kHeaderSize));
__ jmp(rbx);
} }
...@@ -107,8 +111,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { ...@@ -107,8 +111,7 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
__ CompareRoot(rsp, Heap::kStackLimitRootIndex); __ CompareRoot(rsp, Heap::kStackLimitRootIndex);
__ j(above_equal, &ok); __ j(above_equal, &ok);
CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
GenerateTailCallToReturnedCode(masm);
__ bind(&ok); __ bind(&ok);
GenerateTailCallToSharedCode(masm); GenerateTailCallToSharedCode(masm);
...@@ -900,20 +903,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { ...@@ -900,20 +903,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
void Builtins::Generate_CompileLazy(MacroAssembler* masm) { void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileLazy); GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
GenerateTailCallToReturnedCode(masm);
} }
void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent); GenerateTailCallToReturnedCode(masm,
GenerateTailCallToReturnedCode(masm); Runtime::kCompileOptimized_NotConcurrent);
} }
void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_Concurrent); GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
GenerateTailCallToReturnedCode(masm);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment