| Index: src/x64/code-stubs-x64.cc
|
| diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc
|
| index 2e2b975c79108b6d29705f6662072b2ef7185e1c..a807400bd10a16c157f11dce3a28a62720acb84f 100644
|
| --- a/src/x64/code-stubs-x64.cc
|
| +++ b/src/x64/code-stubs-x64.cc
|
| @@ -2197,14 +2197,77 @@ static void GenerateRecordCallTarget(MacroAssembler* masm) {
|
| }
|
|
|
|
|
| +static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
|
| + // Do not transform the receiver for strict mode functions.
|
| + __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
|
| + __ testb(FieldOperand(rcx, SharedFunctionInfo::kStrictModeByteOffset),
|
| + Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte));
|
| + __ j(not_equal, cont);
|
| +
|
| + // Do not transform the receiver for natives.
|
| + // SharedFunctionInfo is already loaded into rcx.
|
| + __ testb(FieldOperand(rcx, SharedFunctionInfo::kNativeByteOffset),
|
| + Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte));
|
| + __ j(not_equal, cont);
|
| +}
|
| +
|
| +
|
| +static void EmitSlowCase(Isolate* isolate,
|
| + MacroAssembler* masm,
|
| + StackArgumentsAccessor* args,
|
| + int argc,
|
| + Label* non_function) {
|
| + // Check for function proxy.
|
| + __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE);
|
| + __ j(not_equal, non_function);
|
| + __ PopReturnAddressTo(rcx);
|
| + __ Push(rdi); // put proxy as additional argument under return address
|
| + __ PushReturnAddressFrom(rcx);
|
| + __ Set(rax, argc + 1);
|
| + __ Set(rbx, 0);
|
| + __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY);
|
| + {
|
| + Handle<Code> adaptor =
|
| + masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
|
| + __ jmp(adaptor, RelocInfo::CODE_TARGET);
|
| + }
|
| +
|
| + // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
|
| + // of the original receiver from the call site).
|
| + __ bind(non_function);
|
| + __ movp(args->GetReceiverOperand(), rdi);
|
| + __ Set(rax, argc);
|
| + __ Set(rbx, 0);
|
| + __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION);
|
| + Handle<Code> adaptor =
|
| + isolate->builtins()->ArgumentsAdaptorTrampoline();
|
| + __ Jump(adaptor, RelocInfo::CODE_TARGET);
|
| +}
|
| +
|
| +
|
| +static void EmitWrapCase(MacroAssembler* masm,
|
| + StackArgumentsAccessor* args,
|
| + Label* cont) {
|
| + // Wrap the receiver and patch it back onto the stack.
|
| + { FrameScope frame_scope(masm, StackFrame::INTERNAL);
|
| + __ Push(rdi);
|
| + __ Push(rax);
|
| + __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
|
| + __ Pop(rdi);
|
| + }
|
| + __ movp(args->GetReceiverOperand(), rax);
|
| + __ jmp(cont);
|
| +}
|
| +
|
| +
|
| void CallFunctionStub::Generate(MacroAssembler* masm) {
|
| - // rbx : feedback vector
|
| - // rdx : (only if rbx is not the megamorphic symbol) slot in feedback
|
| - // vector (Smi)
|
| // rdi : the function to call
|
| +
|
| + // wrap_and_call can only be true if we are compiling a monomorphic method.
|
| Isolate* isolate = masm->isolate();
|
| Label slow, non_function, wrap, cont;
|
| - StackArgumentsAccessor args(rsp, argc_);
|
| + int argc = argc_;
|
| + StackArgumentsAccessor args(rsp, argc);
|
|
|
| if (NeedsChecks()) {
|
| // Check that the function really is a JavaScript function.
|
| @@ -2213,35 +2276,16 @@ void CallFunctionStub::Generate(MacroAssembler* masm) {
|
| // Goto slow case if we do not have a function.
|
| __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
|
| __ j(not_equal, &slow);
|
| -
|
| - if (RecordCallTarget()) {
|
| - GenerateRecordCallTarget(masm);
|
| - // Type information was updated. Because we may call Array, which
|
| - // expects either undefined or an AllocationSite in rbx we need
|
| - // to set rbx to undefined.
|
| - __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex);
|
| - }
|
| }
|
|
|
| // Fast-case: Just invoke the function.
|
| - ParameterCount actual(argc_);
|
| + ParameterCount actual(argc);
|
|
|
| if (CallAsMethod()) {
|
| if (NeedsChecks()) {
|
| - // Do not transform the receiver for strict mode functions.
|
| - __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
|
| - __ testb(FieldOperand(rcx, SharedFunctionInfo::kStrictModeByteOffset),
|
| - Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte));
|
| - __ j(not_equal, &cont);
|
| -
|
| - // Do not transform the receiver for natives.
|
| - // SharedFunctionInfo is already loaded into rcx.
|
| - __ testb(FieldOperand(rcx, SharedFunctionInfo::kNativeByteOffset),
|
| - Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte));
|
| - __ j(not_equal, &cont);
|
| + EmitContinueIfStrictOrNative(masm, &cont);
|
| }
|
|
|
| -
|
| // Load the receiver from the stack.
|
| __ movp(rax, args.GetReceiverOperand());
|
|
|
| @@ -2256,59 +2300,18 @@ void CallFunctionStub::Generate(MacroAssembler* masm) {
|
|
|
| __ bind(&cont);
|
| }
|
| +
|
| __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper());
|
|
|
| if (NeedsChecks()) {
|
| // Slow-case: Non-function called.
|
| __ bind(&slow);
|
| - if (RecordCallTarget()) {
|
| - // If there is a call target cache, mark it megamorphic in the
|
| - // non-function case. MegamorphicSentinel is an immortal immovable
|
| - // object (megamorphic symbol) so no write barrier is needed.
|
| - __ SmiToInteger32(rdx, rdx);
|
| - __ Move(FieldOperand(rbx, rdx, times_pointer_size,
|
| - FixedArray::kHeaderSize),
|
| - TypeFeedbackInfo::MegamorphicSentinel(isolate));
|
| - __ Integer32ToSmi(rdx, rdx);
|
| - }
|
| - // Check for function proxy.
|
| - __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE);
|
| - __ j(not_equal, &non_function);
|
| - __ PopReturnAddressTo(rcx);
|
| - __ Push(rdi); // put proxy as additional argument under return address
|
| - __ PushReturnAddressFrom(rcx);
|
| - __ Set(rax, argc_ + 1);
|
| - __ Set(rbx, 0);
|
| - __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY);
|
| - {
|
| - Handle<Code> adaptor =
|
| - masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
|
| - __ jmp(adaptor, RelocInfo::CODE_TARGET);
|
| - }
|
| -
|
| - // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
|
| - // of the original receiver from the call site).
|
| - __ bind(&non_function);
|
| - __ movp(args.GetReceiverOperand(), rdi);
|
| - __ Set(rax, argc_);
|
| - __ Set(rbx, 0);
|
| - __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION);
|
| - Handle<Code> adaptor =
|
| - isolate->builtins()->ArgumentsAdaptorTrampoline();
|
| - __ Jump(adaptor, RelocInfo::CODE_TARGET);
|
| + EmitSlowCase(isolate, masm, &args, argc, &non_function);
|
| }
|
|
|
| if (CallAsMethod()) {
|
| __ bind(&wrap);
|
| - // Wrap the receiver and patch it back onto the stack.
|
| - { FrameScope frame_scope(masm, StackFrame::INTERNAL);
|
| - __ Push(rdi);
|
| - __ Push(rax);
|
| - __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
|
| - __ Pop(rdi);
|
| - }
|
| - __ movp(args.GetReceiverOperand(), rax);
|
| - __ jmp(&cont);
|
| + EmitWrapCase(masm, &args, &cont);
|
| }
|
| }
|
|
|
| @@ -2379,6 +2382,120 @@ void CallConstructStub::Generate(MacroAssembler* masm) {
|
| }
|
|
|
|
|
| +static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
|
| + __ movp(vector, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
|
| + __ movp(vector, FieldOperand(vector, JSFunction::kSharedFunctionInfoOffset));
|
| + __ movp(vector, FieldOperand(vector,
|
| + SharedFunctionInfo::kFeedbackVectorOffset));
|
| +}
|
| +
|
| +
|
| +void CallICStub::Generate(MacroAssembler* masm) {
|
| + // rdi - function
|
| + // rbx - vector
|
| + // rdx - slot id
|
| + Isolate* isolate = masm->isolate();
|
| + Label extra_checks_or_miss, slow_start;
|
| + Label slow, non_function, wrap, cont;
|
| + Label have_js_function;
|
| + int argc = state_.arg_count();
|
| + StackArgumentsAccessor args(rsp, argc);
|
| + ParameterCount actual(argc);
|
| +
|
| + EmitLoadTypeFeedbackVector(masm, rbx);
|
| +
|
| + // The checks. First, does rdi match the recorded monomorphic target?
|
| + __ SmiToInteger32(rdx, rdx);
|
| + __ cmpq(rdi, FieldOperand(rbx, rdx, times_pointer_size,
|
| + FixedArray::kHeaderSize));
|
| + __ j(not_equal, &extra_checks_or_miss);
|
| +
|
| + __ bind(&have_js_function);
|
| + if (state_.CallAsMethod()) {
|
| + EmitContinueIfStrictOrNative(masm, &cont);
|
| +
|
| + // Load the receiver from the stack.
|
| + __ movp(rax, args.GetReceiverOperand());
|
| +
|
| + __ JumpIfSmi(rax, &wrap);
|
| +
|
| + __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
|
| + __ j(below, &wrap);
|
| +
|
| + __ bind(&cont);
|
| + }
|
| +
|
| + __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper());
|
| +
|
| + __ bind(&slow);
|
| + EmitSlowCase(isolate, masm, &args, argc, &non_function);
|
| +
|
| + if (state_.CallAsMethod()) {
|
| + __ bind(&wrap);
|
| + EmitWrapCase(masm, &args, &cont);
|
| + }
|
| +
|
| + __ bind(&extra_checks_or_miss);
|
| + Label miss;
|
| +
|
| + __ movp(rcx, FieldOperand(rbx, rdx, times_pointer_size,
|
| + FixedArray::kHeaderSize));
|
| + __ Cmp(rcx, TypeFeedbackInfo::MegamorphicSentinel(isolate));
|
| + __ j(equal, &slow_start);
|
| + __ Cmp(rcx, TypeFeedbackInfo::UninitializedSentinel(isolate));
|
| + __ j(equal, &miss);
|
| +
|
| + if (!FLAG_trace_ic) {
|
| + // We are going megamorphic, and we don't want to visit the runtime.
|
| + __ Move(FieldOperand(rbx, rdx, times_pointer_size,
|
| + FixedArray::kHeaderSize),
|
| + TypeFeedbackInfo::MegamorphicSentinel(isolate));
|
| + __ jmp(&slow_start);
|
| + }
|
| +
|
| + // We are here because tracing is on or we are going monomorphic.
|
| + __ bind(&miss);
|
| + GenerateMiss(masm);
|
| +
|
| + // the slow case
|
| + __ bind(&slow_start);
|
| + // Check that function is not a smi.
|
| + __ JumpIfSmi(rdi, &non_function);
|
| + // Check that function is a JSFunction.
|
| + __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
|
| + __ j(not_equal, &slow);
|
| + __ jmp(&have_js_function);
|
| +
|
| + // Unreachable
|
| + __ int3();
|
| +}
|
| +
|
| +
|
| +void CallICStub::GenerateMiss(MacroAssembler* masm) {
|
| + // Get the receiver of the function from the stack; 1 ~ return address.
|
| + __ movp(rcx, Operand(rsp, (state_.arg_count() + 1) * kPointerSize));
|
| +
|
| + {
|
| + FrameScope scope(masm, StackFrame::INTERNAL);
|
| +
|
| + // Push the receiver and the function and feedback info.
|
| + __ Push(rcx);
|
| + __ Push(rdi);
|
| + __ Push(rbx);
|
| + __ Integer32ToSmi(rdx, rdx);
|
| + __ Push(rdx);
|
| +
|
| + // Call the entry.
|
| + ExternalReference miss = ExternalReference(IC_Utility(IC::kCallIC_Miss),
|
| + masm->isolate());
|
| + __ CallExternalReference(miss, 4);
|
| +
|
| + // Move result to edi and exit the internal frame.
|
| + __ movp(rdi, rax);
|
| + }
|
| +}
|
| +
|
| +
|
| bool CEntryStub::NeedsImmovableCode() {
|
| return false;
|
| }
|
|
|