| Index: src/arm/stub-cache-arm.cc
|
| diff --git a/src/arm/stub-cache-arm.cc b/src/arm/stub-cache-arm.cc
|
| index 8625ed6f35c33c51f191b57567ccae2fa83c2597..987437bbd7bd60163f17c9d828fad46951f0c6fc 100644
|
| --- a/src/arm/stub-cache-arm.cc
|
| +++ b/src/arm/stub-cache-arm.cc
|
| @@ -779,64 +779,72 @@ static void CompileCallLoadPropertyWithInterceptor(
|
|
|
| static const int kFastApiCallArguments = FunctionCallbackArguments::kArgsLength;
|
|
|
| -// Reserves space for the extra arguments to API function in the
|
| -// caller's frame.
|
| -//
|
| -// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
|
| -static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
|
| - Register scratch) {
|
| - __ mov(scratch, Operand(Smi::FromInt(0)));
|
| - for (int i = 0; i < kFastApiCallArguments; i++) {
|
| - __ push(scratch);
|
| - }
|
| -}
|
| -
|
|
|
| -// Undoes the effects of ReserveSpaceForFastApiCall.
|
| -static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
|
| - __ Drop(kFastApiCallArguments);
|
| -}
|
| -
|
| -
|
| -static void GenerateFastApiDirectCall(MacroAssembler* masm,
|
| - const CallOptimization& optimization,
|
| - int argc,
|
| - bool restore_context) {
|
| +static void GenerateFastApiCallBody(MacroAssembler* masm,
|
| + const CallOptimization& optimization,
|
| + int argc,
|
| + Register holder,
|
| + Register scratch1,
|
| + Register scratch2,
|
| + Register scratch3,
|
| + bool restore_context) {
|
| // ----------- S t a t e -------------
|
| - // -- sp[0] - sp[24] : FunctionCallbackInfo, incl.
|
| - // : holder (set by CheckPrototypes)
|
| - // -- sp[28] : last JS argument
|
| + // -- sp[0] : last JS argument
|
| // -- ...
|
| - // -- sp[(argc + 6) * 4] : first JS argument
|
| - // -- sp[(argc + 7) * 4] : receiver
|
| + // -- sp[(argc - 1) * 4] : first JS argument
|
| + // -- sp[argc * 4] : receiver
|
| // -----------------------------------
|
| + ASSERT(optimization.is_simple_api_call());
|
| +
|
| typedef FunctionCallbackArguments FCA;
|
| +
|
| + STATIC_ASSERT(FCA::kHolderIndex == 0);
|
| + STATIC_ASSERT(FCA::kIsolateIndex == 1);
|
| + STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
|
| + STATIC_ASSERT(FCA::kReturnValueOffset == 3);
|
| + STATIC_ASSERT(FCA::kDataIndex == 4);
|
| + STATIC_ASSERT(FCA::kCalleeIndex == 5);
|
| + STATIC_ASSERT(FCA::kContextSaveIndex == 6);
|
| + STATIC_ASSERT(FCA::kArgsLength == 7);
|
| +
|
| + ASSERT(!holder.is(cp));
|
| +
|
| // Save calling context.
|
| - __ str(cp, MemOperand(sp, FCA::kContextSaveIndex * kPointerSize));
|
| + __ push(cp);
|
| // Get the function and setup the context.
|
| Handle<JSFunction> function = optimization.constant_function();
|
| - __ Move(r5, function);
|
| - __ ldr(cp, FieldMemOperand(r5, JSFunction::kContextOffset));
|
| - __ str(r5, MemOperand(sp, FCA::kCalleeIndex * kPointerSize));
|
| + __ Move(scratch1, function);
|
| + __ ldr(cp, FieldMemOperand(scratch1, JSFunction::kContextOffset));
|
| + __ push(scratch1);
|
|
|
| // Construct the FunctionCallbackInfo.
|
| Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
| Handle<Object> call_data(api_call_info->data(), masm->isolate());
|
| + bool call_data_undefined = false;
|
| if (masm->isolate()->heap()->InNewSpace(*call_data)) {
|
| - __ Move(r0, api_call_info);
|
| - __ ldr(r6, FieldMemOperand(r0, CallHandlerInfo::kDataOffset));
|
| + __ Move(scratch1, api_call_info);
|
| + __ ldr(scratch1, FieldMemOperand(scratch1, CallHandlerInfo::kDataOffset));
|
| + } else if (call_data->IsUndefined()) {
|
| + call_data_undefined = true;
|
| + __ LoadRoot(scratch3, Heap::kUndefinedValueRootIndex);
|
| } else {
|
| - __ Move(r6, call_data);
|
| + __ Move(scratch1, call_data);
|
| }
|
| // Store call data.
|
| - __ str(r6, MemOperand(sp, FCA::kDataIndex * kPointerSize));
|
| - // Store isolate.
|
| - __ mov(r5, Operand(ExternalReference::isolate_address(masm->isolate())));
|
| - __ str(r5, MemOperand(sp, FCA::kIsolateIndex * kPointerSize));
|
| + __ push(scratch1);
|
| + if (!call_data_undefined) {
|
| + __ LoadRoot(scratch1, Heap::kUndefinedValueRootIndex);
|
| + }
|
| // Store ReturnValue default and ReturnValue.
|
| - __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
|
| - __ str(r5, MemOperand(sp, FCA::kReturnValueOffset * kPointerSize));
|
| - __ str(r5, MemOperand(sp, FCA::kReturnValueDefaultValueIndex * kPointerSize));
|
| + __ LoadRoot(scratch1, Heap::kUndefinedValueRootIndex);
|
| + __ push(scratch1);
|
| + __ push(scratch1);
|
| + // Store isolate.
|
| + __ mov(scratch1,
|
| + Operand(ExternalReference::isolate_address(masm->isolate())));
|
| + __ push(scratch1);
|
| + // holder
|
| + __ push(holder);
|
|
|
| // Prepare arguments.
|
| __ mov(r2, sp);
|
| @@ -893,6 +901,50 @@ static void GenerateFastApiDirectCall(MacroAssembler* masm,
|
| }
|
|
|
|
|
| +// Generates call to API function.
|
| +static void GenerateFastApiCall(MacroAssembler* masm,
|
| + const CallOptimization& optimization,
|
| + int argc,
|
| + Handle<Map> map_to_holder,
|
| + CallOptimization::HolderLookup holder_lookup) {
|
| + Counters* counters = masm->isolate()->counters();
|
| + __ IncrementCounter(counters->call_const_fast_api(), 1, r0, r1);
|
| +
|
| + // Move holder to a register
|
| + Register holder_reg = r0;
|
| + switch (holder_lookup) {
|
| + case CallOptimization::kHolderIsReceiver:
|
| + {
|
| + ASSERT(map_to_holder.is_null());
|
| + __ ldr(holder_reg, MemOperand(sp, argc * kPointerSize));
|
| + }
|
| + break;
|
| + case CallOptimization::kHolderIsPrototypeOfMap:
|
| + {
|
| + Handle<JSObject> holder(JSObject::cast(map_to_holder->prototype()));
|
| + if (!masm->isolate()->heap()->InNewSpace(*holder)) {
|
| + __ Move(holder_reg, holder);
|
| + } else {
|
| + __ Move(holder_reg, map_to_holder);
|
| + __ ldr(holder_reg,
|
| + FieldMemOperand(holder_reg, Map::kPrototypeOffset));
|
| + }
|
| + }
|
| + break;
|
| + case CallOptimization::kHolderNotFound:
|
| + UNREACHABLE();
|
| + }
|
| + GenerateFastApiCallBody(masm,
|
| + optimization,
|
| + argc,
|
| + holder_reg,
|
| + r1,
|
| + r2,
|
| + r3,
|
| + false);
|
| +}
|
| +
|
| +
|
| // Generate call to api function.
|
| static void GenerateFastApiCall(MacroAssembler* masm,
|
| const CallOptimization& optimization,
|
| @@ -900,26 +952,31 @@ static void GenerateFastApiCall(MacroAssembler* masm,
|
| Register scratch,
|
| int argc,
|
| Register* values) {
|
| - ASSERT(optimization.is_simple_api_call());
|
| ASSERT(!receiver.is(scratch));
|
| -
|
| - typedef FunctionCallbackArguments FCA;
|
| - const int stack_space = kFastApiCallArguments + argc + 1;
|
| - // Assign stack space for the call arguments.
|
| - __ sub(sp, sp, Operand(stack_space * kPointerSize));
|
| - // Write holder to stack frame.
|
| - __ str(receiver, MemOperand(sp, FCA::kHolderIndex * kPointerSize));
|
| - // Write receiver to stack frame.
|
| - int index = stack_space - 1;
|
| - __ str(receiver, MemOperand(sp, index-- * kPointerSize));
|
| + __ push(receiver);
|
| // Write the arguments to stack frame.
|
| for (int i = 0; i < argc; i++) {
|
| - ASSERT(!receiver.is(values[i]));
|
| - ASSERT(!scratch.is(values[i]));
|
| - __ str(values[i], MemOperand(sp, index-- * kPointerSize));
|
| + Register arg = values[argc-1-i];
|
| + ASSERT(!receiver.is(arg));
|
| + ASSERT(!scratch.is(arg));
|
| + __ push(arg);
|
| }
|
| -
|
| - GenerateFastApiDirectCall(masm, optimization, argc, true);
|
| + Register scratch1 = r0;
|
| + Register scratch2 = r1;
|
| + Register scratch3 = r2;
|
| + if (!r3.is(receiver)) {
|
| + __ mov(r3, receiver);
|
| + receiver = r3;
|
| + }
|
| + // Stack now matches JSFunction abi.
|
| + GenerateFastApiCallBody(masm,
|
| + optimization,
|
| + argc,
|
| + receiver,
|
| + scratch1,
|
| + scratch2,
|
| + scratch3,
|
| + true);
|
| }
|
|
|
|
|
| @@ -972,39 +1029,17 @@ class CallInterceptorCompiler BASE_EMBEDDED {
|
| ASSERT(optimization.is_constant_call());
|
| ASSERT(!lookup->holder()->IsGlobalObject());
|
| Counters* counters = masm->isolate()->counters();
|
| - int depth1 = kInvalidProtoDepth;
|
| - int depth2 = kInvalidProtoDepth;
|
| - bool can_do_fast_api_call = false;
|
| - if (optimization.is_simple_api_call() &&
|
| - !lookup->holder()->IsGlobalObject()) {
|
| - depth1 = optimization.GetPrototypeDepthOfExpectedType(
|
| - object, interceptor_holder);
|
| - if (depth1 == kInvalidProtoDepth) {
|
| - depth2 = optimization.GetPrototypeDepthOfExpectedType(
|
| - interceptor_holder, Handle<JSObject>(lookup->holder()));
|
| - }
|
| - can_do_fast_api_call =
|
| - depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
|
| - }
|
| -
|
| __ IncrementCounter(counters->call_const_interceptor(), 1,
|
| scratch1, scratch2);
|
|
|
| - if (can_do_fast_api_call) {
|
| - __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
|
| - scratch1, scratch2);
|
| - ReserveSpaceForFastApiCall(masm, scratch1);
|
| - }
|
| -
|
| // Check that the maps from receiver to interceptor's holder
|
| // haven't changed and thus we can invoke interceptor.
|
| Label miss_cleanup;
|
| - Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
|
| Register holder =
|
| stub_compiler_->CheckPrototypes(
|
| IC::CurrentTypeOf(object, masm->isolate()), receiver,
|
| interceptor_holder, scratch1, scratch2, scratch3,
|
| - name, depth1, miss);
|
| + name, miss_label);
|
|
|
| // Invoke an interceptor and if it provides a value,
|
| // branch to |regular_invoke|.
|
| @@ -1021,37 +1056,42 @@ class CallInterceptorCompiler BASE_EMBEDDED {
|
| stub_compiler_->CheckPrototypes(
|
| IC::CurrentTypeOf(interceptor_holder, masm->isolate()), holder,
|
| handle(lookup->holder()), scratch1, scratch2, scratch3,
|
| - name, depth2, miss);
|
| - } else {
|
| - // CheckPrototypes has a side effect of fetching a 'holder'
|
| - // for API (object which is instanceof for the signature). It's
|
| - // safe to omit it here, as if present, it should be fetched
|
| - // by the previous CheckPrototypes.
|
| - ASSERT(depth2 == kInvalidProtoDepth);
|
| + name, miss_label);
|
| + }
|
| +
|
| + Handle<Map> lookup_map;
|
| + CallOptimization::HolderLookup holder_lookup =
|
| + CallOptimization::kHolderNotFound;
|
| + if (optimization.is_simple_api_call() &&
|
| + !lookup->holder()->IsGlobalObject()) {
|
| + lookup_map = optimization.LookupHolderOfExpectedType(
|
| + object, object, interceptor_holder, &holder_lookup);
|
| + if (holder_lookup == CallOptimization::kHolderNotFound) {
|
| + lookup_map =
|
| + optimization.LookupHolderOfExpectedType(
|
| + object,
|
| + interceptor_holder,
|
| + Handle<JSObject>(lookup->holder()),
|
| + &holder_lookup);
|
| + }
|
| }
|
|
|
| // Invoke function.
|
| - if (can_do_fast_api_call) {
|
| - GenerateFastApiDirectCall(
|
| - masm, optimization, arguments_.immediate(), false);
|
| + if (holder_lookup != CallOptimization::kHolderNotFound) {
|
| + int argc = arguments_.immediate();
|
| + GenerateFastApiCall(masm,
|
| + optimization,
|
| + argc,
|
| + lookup_map,
|
| + holder_lookup);
|
| } else {
|
| Handle<JSFunction> function = optimization.constant_function();
|
| __ Move(r0, receiver);
|
| stub_compiler_->GenerateJumpFunction(object, function);
|
| }
|
|
|
| - // Deferred code for fast API call case---clean preallocated space.
|
| - if (can_do_fast_api_call) {
|
| - __ bind(&miss_cleanup);
|
| - FreeSpaceForFastApiCall(masm);
|
| - __ b(miss_label);
|
| - }
|
| -
|
| // Invoke a regular function.
|
| __ bind(®ular_invoke);
|
| - if (can_do_fast_api_call) {
|
| - FreeSpaceForFastApiCall(masm);
|
| - }
|
| }
|
|
|
| void CompileRegular(MacroAssembler* masm,
|
| @@ -1127,7 +1167,6 @@ Register StubCompiler::CheckPrototypes(Handle<HeapType> type,
|
| Register scratch1,
|
| Register scratch2,
|
| Handle<Name> name,
|
| - int save_at_depth,
|
| Label* miss,
|
| PrototypeCheckType check) {
|
| Handle<Map> receiver_map(IC::TypeToMap(*type, isolate()));
|
| @@ -1144,11 +1183,6 @@ Register StubCompiler::CheckPrototypes(Handle<HeapType> type,
|
| Register reg = object_reg;
|
| int depth = 0;
|
|
|
| - typedef FunctionCallbackArguments FCA;
|
| - if (save_at_depth == depth) {
|
| - __ str(reg, MemOperand(sp, FCA::kHolderIndex * kPointerSize));
|
| - }
|
| -
|
| Handle<JSObject> current = Handle<JSObject>::null();
|
| if (type->IsConstant()) current = Handle<JSObject>::cast(type->AsConstant());
|
| Handle<JSObject> prototype = Handle<JSObject>::null();
|
| @@ -1214,10 +1248,6 @@ Register StubCompiler::CheckPrototypes(Handle<HeapType> type,
|
| }
|
| }
|
|
|
| - if (save_at_depth == depth) {
|
| - __ str(reg, MemOperand(sp, FCA::kHolderIndex * kPointerSize));
|
| - }
|
| -
|
| // Go to the next object in the prototype chain.
|
| current = prototype;
|
| current_map = handle(current->map());
|
| @@ -1586,36 +1616,36 @@ Handle<Code> CallStubCompiler::CompileFastApiCall(
|
| if (object->IsGlobalObject()) return Handle<Code>::null();
|
| if (!cell.is_null()) return Handle<Code>::null();
|
| if (!object->IsJSObject()) return Handle<Code>::null();
|
| - int depth = optimization.GetPrototypeDepthOfExpectedType(
|
| - Handle<JSObject>::cast(object), holder);
|
| - if (depth == kInvalidProtoDepth) return Handle<Code>::null();
|
| + Handle<JSObject> receiver = Handle<JSObject>::cast(object);
|
| + CallOptimization::HolderLookup holder_lookup =
|
| + CallOptimization::kHolderNotFound;
|
| + Handle<Map> lookup_map = optimization.LookupHolderOfExpectedType(
|
| + receiver, receiver, holder, &holder_lookup);
|
| + if (holder_lookup == CallOptimization::kHolderNotFound) {
|
| + return Handle<Code>::null();
|
| + }
|
|
|
| - Label miss, miss_before_stack_reserved;
|
| - GenerateNameCheck(name, &miss_before_stack_reserved);
|
| + Label miss;
|
| + GenerateNameCheck(name, &miss);
|
|
|
| // Get the receiver from the stack.
|
| const int argc = arguments().immediate();
|
| __ ldr(r1, MemOperand(sp, argc * kPointerSize));
|
|
|
| // Check that the receiver isn't a smi.
|
| - __ JumpIfSmi(r1, &miss_before_stack_reserved);
|
| + __ JumpIfSmi(r1, &miss);
|
|
|
| __ IncrementCounter(counters->call_const(), 1, r0, r3);
|
| - __ IncrementCounter(counters->call_const_fast_api(), 1, r0, r3);
|
| -
|
| - ReserveSpaceForFastApiCall(masm(), r0);
|
|
|
| // Check that the maps haven't changed and find a Holder as a side effect.
|
| CheckPrototypes(
|
| IC::CurrentTypeOf(object, isolate()),
|
| - r1, holder, r0, r3, r4, name, depth, &miss);
|
| -
|
| - GenerateFastApiDirectCall(masm(), optimization, argc, false);
|
| + r1, holder, r0, r3, r4, name, &miss);
|
|
|
| - __ bind(&miss);
|
| - FreeSpaceForFastApiCall(masm());
|
| + GenerateFastApiCall(
|
| + masm(), optimization, argc, lookup_map, holder_lookup);
|
|
|
| - HandlerFrontendFooter(&miss_before_stack_reserved);
|
| + HandlerFrontendFooter(&miss);
|
|
|
| // Return the generated code.
|
| return GetCode(function);
|
|
|