X87: Preserve argument count for calls.

port 5de27c343bbf898ca87246caa1e83e533ec44561(r33865)

  original commit message:
  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=

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

Cr-Commit-Position: refs/heads/master@{#33984}
This commit is contained in:
zhengxing.li 2016-02-15 01:45:48 -08:00 committed by Commit bot
parent 125ac66bf6
commit 63a59fa341

View File

@ -60,39 +60,43 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
}
static void CallRuntimePassFunction(
MacroAssembler* masm, Runtime::FunctionId function_id) {
static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- eax : argument count (preserved for callee)
// -- edx : new target (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);
// 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);
__ CallRuntime(function_id, 1);
__ mov(ebx, eax);
__ 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);
}
__ lea(ebx, FieldOperand(ebx, Code::kHeaderSize));
__ jmp(ebx);
}
static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
__ mov(eax, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
__ mov(eax, FieldOperand(eax, SharedFunctionInfo::kCodeOffset));
__ lea(eax, FieldOperand(eax, Code::kHeaderSize));
__ jmp(eax);
}
static void GenerateTailCallToReturnedCode(MacroAssembler* masm) {
__ lea(eax, FieldOperand(eax, Code::kHeaderSize));
__ jmp(eax);
__ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
__ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kCodeOffset));
__ lea(ebx, FieldOperand(ebx, Code::kHeaderSize));
__ jmp(ebx);
}
@ -108,14 +112,12 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
__ cmp(esp, Operand::StaticVariable(stack_limit));
__ j(above_equal, &ok, Label::kNear);
CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode);
GenerateTailCallToReturnedCode(masm);
GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
__ bind(&ok);
GenerateTailCallToSharedCode(masm);
}
static void Generate_JSConstructStubHelper(MacroAssembler* masm,
bool is_api_function,
bool create_implicit_receiver,
@ -852,20 +854,18 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileLazy);
GenerateTailCallToReturnedCode(masm);
GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
}
void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_NotConcurrent);
GenerateTailCallToReturnedCode(masm);
GenerateTailCallToReturnedCode(masm,
Runtime::kCompileOptimized_NotConcurrent);
}
void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
CallRuntimePassFunction(masm, Runtime::kCompileOptimized_Concurrent);
GenerateTailCallToReturnedCode(masm);
GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
}