Revision: 17903
Author: [email protected]
Date: Wed Nov 20 10:11:56 2013 UTC
Log: faster stack frame generation for accessor property ics
this is implemented for intel platforms only, as they are the only ones
which show speed up with this change
[email protected]
BUG=
Review URL: https://codereview.chromium.org/48303002
http://code.google.com/p/v8/source/detail?r=17903
Modified:
/branches/bleeding_edge/src/ia32/stub-cache-ia32.cc
/branches/bleeding_edge/src/x64/stub-cache-x64.cc
=======================================
--- /branches/bleeding_edge/src/ia32/stub-cache-ia32.cc Tue Nov 19 12:04:54
2013 UTC
+++ /branches/bleeding_edge/src/ia32/stub-cache-ia32.cc Wed Nov 20 10:11:56
2013 UTC
@@ -449,24 +449,18 @@
__ add(esp, Immediate(kPointerSize * kFastApiCallArguments));
__ push(scratch);
}
+
+
+static void GenerateFastApiCallBody(MacroAssembler* masm,
+ const CallOptimization& optimization,
+ int argc,
+ bool restore_context);
// Generates call to API function.
static void GenerateFastApiCall(MacroAssembler* masm,
const CallOptimization& optimization,
- int argc,
- bool restore_context) {
- // ----------- S t a t e -------------
- // -- esp[0] : return address
- // -- esp[4] - esp[28] : FunctionCallbackInfo, incl.
- // : object passing the type check
- // (set by CheckPrototypes)
- // -- esp[32] : last argument
- // -- ...
- // -- esp[(argc + 7) * 4] : first argument
- // -- esp[(argc + 8) * 4] : receiver
- // -----------------------------------
-
+ int argc) {
typedef FunctionCallbackArguments FCA;
// Save calling context.
__ mov(Operand(esp, (1 + FCA::kContextSaveIndex) * kPointerSize), esi);
@@ -499,6 +493,110 @@
STATIC_ASSERT(kFastApiCallArguments == 7);
__ lea(eax, Operand(esp, 1 * kPointerSize));
+ GenerateFastApiCallBody(masm, optimization, argc, false);
+}
+
+
+// Generate call to api function.
+// This function uses push() to generate smaller, faster code than
+// the version above. It is an optimization that should will be removed
+// when api call ICs are generated in hydrogen.
+static void GenerateFastApiCall(MacroAssembler* masm,
+ const CallOptimization& optimization,
+ Register receiver,
+ Register scratch1,
+ Register scratch2,
+ Register scratch3,
+ int argc,
+ Register* values) {
+ ASSERT(optimization.is_simple_api_call());
+
+ // Copy return value.
+ __ pop(scratch1);
+
+ // receiver
+ __ push(receiver);
+
+ // Write the arguments to stack frame.
+ for (int i = 0; i < argc; i++) {
+ Register arg = values[argc-1-i];
+ ASSERT(!receiver.is(arg));
+ ASSERT(!scratch1.is(arg));
+ ASSERT(!scratch2.is(arg));
+ ASSERT(!scratch3.is(arg));
+ __ push(arg);
+ }
+
+ 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);
+
+ // context save
+ __ push(esi);
+
+ // Get the function and setup the context.
+ Handle<JSFunction> function = optimization.constant_function();
+ __ LoadHeapObject(scratch2, function);
+ __ mov(esi, FieldOperand(scratch2, JSFunction::kContextOffset));
+ // callee
+ __ push(scratch2);
+
+ Isolate* isolate = masm->isolate();
+ Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
+ Handle<Object> call_data(api_call_info->data(), isolate);
+ // Push data from ExecutableAccessorInfo.
+ if (isolate->heap()->InNewSpace(*call_data)) {
+ __ mov(scratch2, api_call_info);
+ __ mov(scratch3, FieldOperand(scratch2, CallHandlerInfo::kDataOffset));
+ __ push(scratch3);
+ } else {
+ __ push(Immediate(call_data));
+ }
+ // return value
+ __ push(Immediate(isolate->factory()->undefined_value()));
+ // return value default
+ __ push(Immediate(isolate->factory()->undefined_value()));
+ // isolate
+ __ push(Immediate(reinterpret_cast<int>(isolate)));
+ // holder
+ __ push(receiver);
+
+ // store receiver address for GenerateFastApiCallBody
+ ASSERT(!scratch1.is(eax));
+ __ mov(eax, esp);
+
+ // return address
+ __ push(scratch1);
+
+ GenerateFastApiCallBody(masm, optimization, argc, true);
+}
+
+
+static void GenerateFastApiCallBody(MacroAssembler* masm,
+ const CallOptimization& optimization,
+ int argc,
+ bool restore_context) {
+ // ----------- S t a t e -------------
+ // -- esp[0] : return address
+ // -- esp[4] - esp[28] : FunctionCallbackInfo, incl.
+ // : object passing the type check
+ // (set by CheckPrototypes)
+ // -- esp[32] : last argument
+ // -- ...
+ // -- esp[(argc + 7) * 4] : first argument
+ // -- esp[(argc + 8) * 4] : receiver
+ //
+ // -- eax : receiver address
+ // -----------------------------------
+ typedef FunctionCallbackArguments FCA;
+
// API function gets reference to the v8::Arguments. If CPU profiler
// is enabled wrapper function will be called and we need to pass
// address of the callback as additional parameter, always allocate
@@ -509,6 +607,8 @@
// it's not controlled by GC.
const int kApiStackSpace = 4;
+ Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
+
// Function address is a foreign pointer outside V8's heap.
Address function_address =
v8::ToCData<Address>(api_call_info->callback());
__ PrepareCallApiFunction(kApiArgc + kApiStackSpace);
@@ -541,40 +641,6 @@
restore_context ?
&context_restore_operand : NULL);
}
-
-
-// Generate call to api function.
-static void GenerateFastApiCall(MacroAssembler* masm,
- const CallOptimization& optimization,
- Register receiver,
- Register scratch,
- int argc,
- Register* values) {
- ASSERT(optimization.is_simple_api_call());
- ASSERT(!receiver.is(scratch));
-
- const int stack_space = kFastApiCallArguments + argc + 1;
- const int kHolderIndex = FunctionCallbackArguments::kHolderIndex + 1;
- // Copy return value.
- __ mov(scratch, Operand(esp, 0));
- // Assign stack space for the call arguments.
- __ sub(esp, Immediate(stack_space * kPointerSize));
- // Move the return address on top of the stack.
- __ mov(Operand(esp, 0), scratch);
- // Write holder to stack frame.
- __ mov(Operand(esp, kHolderIndex * kPointerSize), receiver);
- // Write receiver to stack frame.
- int index = stack_space;
- __ mov(Operand(esp, index-- * kPointerSize), receiver);
- // Write the arguments to stack frame.
- for (int i = 0; i < argc; i++) {
- ASSERT(!receiver.is(values[i]));
- ASSERT(!scratch.is(values[i]));
- __ mov(Operand(esp, index-- * kPointerSize), values[i]);
- }
-
- GenerateFastApiCall(masm, optimization, argc, true);
-}
class CallInterceptorCompiler BASE_EMBEDDED {
@@ -687,7 +753,7 @@
// Invoke function.
if (can_do_fast_api_call) {
- GenerateFastApiCall(masm, optimization, arguments_.immediate(),
false);
+ GenerateFastApiCall(masm, optimization, arguments_.immediate());
} else {
CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
? CALL_AS_FUNCTION
@@ -1370,7 +1436,8 @@
void LoadStubCompiler::GenerateLoadCallback(
const CallOptimization& call_optimization) {
GenerateFastApiCall(
- masm(), call_optimization, receiver(), scratch3(), 0, NULL);
+ masm(), call_optimization, receiver(), scratch1(),
+ scratch2(), name(), 0, NULL);
}
@@ -2603,7 +2670,7 @@
// esp[2 * kPointerSize] is uninitialized, esp[3 * kPointerSize] contains
// duplicate of return address and will be overwritten.
- GenerateFastApiCall(masm(), optimization, argc, false);
+ GenerateFastApiCall(masm(), optimization, argc);
__ bind(&miss);
__ add(esp, Immediate(kFastApiCallArguments * kPointerSize));
@@ -2920,7 +2987,8 @@
Register values[] = { value() };
GenerateFastApiCall(
- masm(), call_optimization, receiver(), scratch1(), 1, values);
+ masm(), call_optimization, receiver(), scratch1(),
+ scratch2(), this->name(), 1, values);
// Return the generated code.
return GetCode(kind(), Code::FAST, name);
=======================================
--- /branches/bleeding_edge/src/x64/stub-cache-x64.cc Tue Nov 19 12:04:54
2013 UTC
+++ /branches/bleeding_edge/src/x64/stub-cache-x64.cc Wed Nov 20 10:11:56
2013 UTC
@@ -434,23 +434,18 @@
scratch);
__ addq(rsp, Immediate(kPointerSize * kFastApiCallArguments));
}
+
+
+static void GenerateFastApiCallBody(MacroAssembler* masm,
+ const CallOptimization& optimization,
+ int argc,
+ bool restore_context);
// Generates call to API function.
static void GenerateFastApiCall(MacroAssembler* masm,
const CallOptimization& optimization,
- int argc,
- bool restore_context) {
- // ----------- S t a t e -------------
- // -- rsp[0] : return address
- // -- rsp[8] - rsp[56] : FunctionCallbackInfo, incl.
- // : object passing the type check
- // (set by CheckPrototypes)
- // -- rsp[64] : last argument
- // -- ...
- // -- rsp[(argc + 7) * 8] : first argument
- // -- rsp[(argc + 8) * 8] : receiver
- // -----------------------------------
+ int argc) {
typedef FunctionCallbackArguments FCA;
StackArgumentsAccessor args(rsp, argc + kFastApiCallArguments);
@@ -485,8 +480,121 @@
// Prepare arguments.
STATIC_ASSERT(kFastApiCallArguments == 7);
- __ lea(rbx, Operand(rsp, 1 * kPointerSize));
+ __ lea(rax, Operand(rsp, 1 * kPointerSize));
+
+ GenerateFastApiCallBody(masm, optimization, argc, false);
+}
+
+
+// Generate call to api function.
+// This function uses push() to generate smaller, faster code than
+// the version above. It is an optimization that should will be removed
+// when api call ICs are generated in hydrogen.
+static void GenerateFastApiCall(MacroAssembler* masm,
+ const CallOptimization& optimization,
+ Register receiver,
+ Register scratch1,
+ Register scratch2,
+ Register scratch3,
+ int argc,
+ Register* values) {
+ ASSERT(optimization.is_simple_api_call());
+
+ // Copy return value.
+ __ pop(scratch1);
+
+ // receiver
+ __ push(receiver);
+
+ // Write the arguments to stack frame.
+ for (int i = 0; i < argc; i++) {
+ Register arg = values[argc-1-i];
+ ASSERT(!receiver.is(arg));
+ ASSERT(!scratch1.is(arg));
+ ASSERT(!scratch2.is(arg));
+ ASSERT(!scratch3.is(arg));
+ __ push(arg);
+ }
+
+ 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);
+
+ // context save
+ __ push(rsi);
+
+ // Get the function and setup the context.
+ Handle<JSFunction> function = optimization.constant_function();
+ __ Move(scratch2, function);
+ __ push(scratch2);
+
+ Isolate* isolate = masm->isolate();
+ Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
+ Handle<Object> call_data(api_call_info->data(), isolate);
+ // Push data from ExecutableAccessorInfo.
+ bool call_data_undefined = false;
+ if (isolate->heap()->InNewSpace(*call_data)) {
+ __ Move(scratch2, api_call_info);
+ __ movq(scratch3, FieldOperand(scratch2,
CallHandlerInfo::kDataOffset));
+ } else if (call_data->IsUndefined()) {
+ call_data_undefined = true;
+ __ LoadRoot(scratch3, Heap::kUndefinedValueRootIndex);
+ } else {
+ __ Move(scratch3, call_data);
+ }
+ // call data
+ __ push(scratch3);
+ if (!call_data_undefined) {
+ __ LoadRoot(scratch3, Heap::kUndefinedValueRootIndex);
+ }
+ // return value
+ __ push(scratch3);
+ // return value default
+ __ push(scratch3);
+ // isolate
+ __ Move(scratch3,
+ ExternalReference::isolate_address(masm->isolate()));
+ __ push(scratch3);
+ // holder
+ __ push(receiver);
+ ASSERT(!scratch1.is(rax));
+ // store receiver address for GenerateFastApiCallBody
+ __ movq(rax, rsp);
+
+ // return address
+ __ push(scratch1);
+
+ GenerateFastApiCallBody(masm, optimization, argc, true);
+}
+
+
+static void GenerateFastApiCallBody(MacroAssembler* masm,
+ const CallOptimization& optimization,
+ int argc,
+ bool restore_context) {
+ // ----------- S t a t e -------------
+ // -- rsp[0] : return address
+ // -- rsp[8] - rsp[56] : FunctionCallbackInfo, incl.
+ // : object passing the type check
+ // (set by CheckPrototypes)
+ // -- rsp[64] : last argument
+ // -- ...
+ // -- rsp[(argc + 7) * 8] : first argument
+ // -- rsp[(argc + 8) * 8] : receiver
+ //
+ // rax : receiver address
+ // -----------------------------------
+ typedef FunctionCallbackArguments FCA;
+
+ Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
// Function address is a foreign pointer outside V8's heap.
Address function_address =
v8::ToCData<Address>(api_call_info->callback());
@@ -496,9 +604,9 @@
__ PrepareCallApiFunction(kApiStackSpace);
- __ movq(StackSpaceOperand(0), rbx); //
FunctionCallbackInfo::implicit_args_.
- __ addq(rbx, Immediate((argc + kFastApiCallArguments - 1) *
kPointerSize));
- __ movq(StackSpaceOperand(1), rbx); // FunctionCallbackInfo::values_.
+ __ movq(StackSpaceOperand(0), rax); //
FunctionCallbackInfo::implicit_args_.
+ __ addq(rax, Immediate((argc + kFastApiCallArguments - 1) *
kPointerSize));
+ __ movq(StackSpaceOperand(1), rax); // FunctionCallbackInfo::values_.
__ Set(StackSpaceOperand(2), argc); // FunctionCallbackInfo::length_.
// FunctionCallbackInfo::is_construct_call_.
__ Set(StackSpaceOperand(3), 0);
@@ -530,39 +638,6 @@
return_value_operand,
restore_context ? &context_restore_operand : NULL);
}
-
-
-// Generate call to api function.
-static void GenerateFastApiCall(MacroAssembler* masm,
- const CallOptimization& optimization,
- Register receiver,
- Register scratch,
- int argc,
- Register* values) {
- ASSERT(optimization.is_simple_api_call());
- ASSERT(!receiver.is(scratch));
-
- const int fast_api_call_argc = argc + kFastApiCallArguments;
- StackArgumentsAccessor args(rsp, fast_api_call_argc);
- // argc + 1 is the argument number before FastApiCall arguments, 1 ~
receiver
- const int kHolderIndex = argc + 1 +
- kFastApiCallArguments - 1 - FunctionCallbackArguments::kHolderIndex;
- __ movq(scratch, StackOperandForReturnAddress(0));
- // Assign stack space for the call arguments and receiver.
- __ subq(rsp, Immediate((fast_api_call_argc + 1) * kPointerSize));
- __ movq(StackOperandForReturnAddress(0), scratch);
- // Write holder to stack frame.
- __ movq(args.GetArgumentOperand(kHolderIndex), receiver);
- __ movq(args.GetReceiverOperand(), receiver);
- // Write the arguments to stack frame.
- for (int i = 0; i < argc; i++) {
- ASSERT(!receiver.is(values[i]));
- ASSERT(!scratch.is(values[i]));
- __ movq(args.GetArgumentOperand(i + 1), values[i]);
- }
-
- GenerateFastApiCall(masm, optimization, argc, true);
-}
class CallInterceptorCompiler BASE_EMBEDDED {
@@ -675,7 +750,7 @@
// Invoke function.
if (can_do_fast_api_call) {
- GenerateFastApiCall(masm, optimization, arguments_.immediate(),
false);
+ GenerateFastApiCall(masm, optimization, arguments_.immediate());
} else {
CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
? CALL_AS_FUNCTION
@@ -1294,7 +1369,8 @@
void LoadStubCompiler::GenerateLoadCallback(
const CallOptimization& call_optimization) {
GenerateFastApiCall(
- masm(), call_optimization, receiver(), scratch3(), 0, NULL);
+ masm(), call_optimization, receiver(),
+ scratch1(), scratch2(), name(), 0, NULL);
}
@@ -2501,7 +2577,7 @@
StackOperandForReturnAddress(kFastApiCallArguments *
kPointerSize));
__ movq(StackOperandForReturnAddress(0), rax);
- GenerateFastApiCall(masm(), optimization, argc, false);
+ GenerateFastApiCall(masm(), optimization, argc);
__ bind(&miss);
__ addq(rsp, Immediate(kFastApiCallArguments * kPointerSize));
@@ -2821,7 +2897,8 @@
Register values[] = { value() };
GenerateFastApiCall(
- masm(), call_optimization, receiver(), scratch3(), 1, values);
+ masm(), call_optimization, receiver(), scratch1(),
+ scratch2(), this->name(), 1, values);
// Return the generated code.
return GetCode(kind(), Code::FAST, name);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.