From ec2f11c577c6e804a822f5af7a1e2e9837340068 Mon Sep 17 00:00:00 2001 From: "chunyang.dai" Date: Tue, 15 Sep 2015 04:26:51 -0700 Subject: [PATCH] X87: [stubs] Simplify the non-function case of CallConstructStub. port 622fa0ea21b3517b1feaed447c87e580bafac865 (r30691). original commit message: Currently we do this dance between the CallConstructStub, the CALL_* builtins and the %GetConstructorDelegate, %GetProxyTrap, and %Apply runtime functions for every [[Construct]] operation on non-function callables. This is complexity is unnecessary, and can be simplified to work without any JS builtin. This will also make it a lot easier to implement ES6 compliant [[Construct]] for proxies. Also sanitize the invariant for CallConstructStub, which up until now always restored the context itself, but that force us to always create another copy of all arguments in case of proxies and other callables, so we can relax that constraint by making the caller restore the context (this only affects fullcodegen, since the optimizing compilers already properly restore the context anyway). BUG= Review URL: https://codereview.chromium.org/1341233002 Cr-Commit-Position: refs/heads/master@{#30740} --- src/full-codegen/x87/full-codegen-x87.cc | 9 +++++-- src/x87/code-stubs-x87.cc | 42 ++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/full-codegen/x87/full-codegen-x87.cc b/src/full-codegen/x87/full-codegen-x87.cc index 8f287da..f5d2adc 100644 --- a/src/full-codegen/x87/full-codegen-x87.cc +++ b/src/full-codegen/x87/full-codegen-x87.cc @@ -3083,6 +3083,8 @@ void FullCodeGenerator::VisitCallNew(CallNew* expr) { CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET); __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); PrepareForBailoutForId(expr->ReturnId(), TOS_REG); + // Restore context register. + __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); context()->Plug(eax); } @@ -3132,6 +3134,8 @@ void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) { RecordJSReturnSite(expr); + // Restore context register. + __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); context()->Plug(eax); } @@ -3955,9 +3959,10 @@ void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) { CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL); __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); - __ Drop(1); + // Restore context register. + __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); - context()->Plug(eax); + context()->DropAndPlug(1, eax); } diff --git a/src/x87/code-stubs-x87.cc b/src/x87/code-stubs-x87.cc index daab993..c763401 100644 --- a/src/x87/code-stubs-x87.cc +++ b/src/x87/code-stubs-x87.cc @@ -1885,26 +1885,32 @@ void CallConstructStub::Generate(MacroAssembler* masm) { // eax: number of arguments // ecx: object map // esp[0]: original receiver (for IsSuperConstructorCall) - Label do_call; __ bind(&slow); - __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); - __ j(not_equal, &non_function_call); - __ GetBuiltinEntry(edx, - Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX); - __ jmp(&do_call); - - __ bind(&non_function_call); - __ GetBuiltinEntry(edx, - Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX); - __ bind(&do_call); - if (IsSuperConstructorCall()) { - __ Drop(1); + { + __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); + __ j(not_equal, &non_function_call, Label::kNear); + if (IsSuperConstructorCall()) __ Drop(1); + // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. + __ mov(edi, FieldOperand(edi, JSFunctionProxy::kConstructTrapOffset)); + __ Jump(isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); + + __ bind(&non_function_call); + if (IsSuperConstructorCall()) __ Drop(1); + { + // Determine the delegate for the target (if any). + FrameScope scope(masm, StackFrame::INTERNAL); + __ SmiTag(eax); + __ Push(eax); + __ Push(edi); + __ CallRuntime(Runtime::kGetConstructorDelegate, 1); + __ mov(edi, eax); + __ Pop(eax); + __ SmiUntag(eax); + } + // The delegate is always a regular function. + __ AssertFunction(edi); + __ Jump(isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); } - // Set expected number of arguments to zero (not changing eax). - __ Move(ebx, Immediate(0)); - Handle arguments_adaptor = - isolate()->builtins()->ArgumentsAdaptorTrampoline(); - __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); } -- 2.7.4