Commit 12d4dc32 authored by ishell's avatar ishell Committed by Commit bot

[stubs] ApiCallbackDescriptor cleanup - make it independent on the number of JS parameters.

This cleanup is necessary to make HCallWithDescriptor support passing arguments on the stack.

BUG=v8:5407

Review-Url: https://codereview.chromium.org/2352163004
Cr-Commit-Position: refs/heads/master@{#39590}
parent 031a04c6
...@@ -371,7 +371,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -371,7 +371,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
&default_descriptor); &default_descriptor);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
static PlatformInterfaceDescriptor default_descriptor = static PlatformInterfaceDescriptor default_descriptor =
PlatformInterfaceDescriptor(CAN_INLINE_TARGET_ADDRESS); PlatformInterfaceDescriptor(CAN_INLINE_TARGET_ADDRESS);
......
...@@ -403,7 +403,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -403,7 +403,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
&default_descriptor); &default_descriptor);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
static PlatformInterfaceDescriptor default_descriptor = static PlatformInterfaceDescriptor default_descriptor =
PlatformInterfaceDescriptor(CAN_INLINE_TARGET_ADDRESS); PlatformInterfaceDescriptor(CAN_INLINE_TARGET_ADDRESS);
......
...@@ -1822,10 +1822,6 @@ class CallApiCallbackStub : public PlatformCodeStub { ...@@ -1822,10 +1822,6 @@ class CallApiCallbackStub : public PlatformCodeStub {
: CallApiCallbackStub(isolate, argc, false, call_data_undefined, : CallApiCallbackStub(isolate, argc, false, call_data_undefined,
is_lazy) {} is_lazy) {}
CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
return ApiCallbackDescriptorBase::ForArgs(isolate(), argc());
}
private: private:
CallApiCallbackStub(Isolate* isolate, int argc, bool is_store, CallApiCallbackStub(Isolate* isolate, int argc, bool is_store,
bool call_data_undefined, bool is_lazy) bool call_data_undefined, bool is_lazy)
...@@ -1849,6 +1845,7 @@ class CallApiCallbackStub : public PlatformCodeStub { ...@@ -1849,6 +1845,7 @@ class CallApiCallbackStub : public PlatformCodeStub {
class ArgumentBits : public BitField<int, 2, kArgBits> {}; class ArgumentBits : public BitField<int, 2, kArgBits> {};
class IsLazyAccessorBits : public BitField<bool, 3 + kArgBits, 1> {}; class IsLazyAccessorBits : public BitField<bool, 3 + kArgBits, 1> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiCallback);
DEFINE_PLATFORM_CODE_STUB(CallApiCallback, PlatformCodeStub); DEFINE_PLATFORM_CODE_STUB(CallApiCallback, PlatformCodeStub);
}; };
......
...@@ -657,9 +657,11 @@ Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, ...@@ -657,9 +657,11 @@ Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
} }
Node* CodeAssembler::CallStubN(const CallInterfaceDescriptor& descriptor, Node* CodeAssembler::CallStubN(const CallInterfaceDescriptor& descriptor,
Node* target, Node** args, size_t result_size) { int js_parameter_count, Node* target,
Node** args, size_t result_size) {
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), isolate(), zone(), descriptor,
descriptor.GetStackParameterCount() + js_parameter_count,
CallDescriptor::kNoFlags, Operator::kNoProperties, CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size); MachineType::AnyTagged(), result_size);
...@@ -822,10 +824,6 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context, ...@@ -822,10 +824,6 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
Node* function, Node* receiver, Node* function, Node* receiver,
size_t result_size) { size_t result_size) {
const int argc = 0; const int argc = 0;
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), zone(), callable.descriptor(), argc + 1,
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size);
Node* target = HeapConstant(callable.code()); Node* target = HeapConstant(callable.code());
Node** args = zone()->NewArray<Node*>(argc + 4); Node** args = zone()->NewArray<Node*>(argc + 4);
...@@ -834,17 +832,13 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context, ...@@ -834,17 +832,13 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
args[2] = receiver; args[2] = receiver;
args[3] = context; args[3] = context;
return CallN(call_descriptor, target, args); return CallStubN(callable.descriptor(), argc + 1, target, args, result_size);
} }
Node* CodeAssembler::CallJS(Callable const& callable, Node* context, Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
Node* function, Node* receiver, Node* arg1, Node* function, Node* receiver, Node* arg1,
size_t result_size) { size_t result_size) {
const int argc = 1; const int argc = 1;
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), zone(), callable.descriptor(), argc + 1,
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size);
Node* target = HeapConstant(callable.code()); Node* target = HeapConstant(callable.code());
Node** args = zone()->NewArray<Node*>(argc + 4); Node** args = zone()->NewArray<Node*>(argc + 4);
...@@ -854,17 +848,13 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context, ...@@ -854,17 +848,13 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
args[3] = arg1; args[3] = arg1;
args[4] = context; args[4] = context;
return CallN(call_descriptor, target, args); return CallStubN(callable.descriptor(), argc + 1, target, args, result_size);
} }
Node* CodeAssembler::CallJS(Callable const& callable, Node* context, Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
Node* function, Node* receiver, Node* arg1, Node* function, Node* receiver, Node* arg1,
Node* arg2, size_t result_size) { Node* arg2, size_t result_size) {
const int argc = 2; const int argc = 2;
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), zone(), callable.descriptor(), argc + 1,
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size);
Node* target = HeapConstant(callable.code()); Node* target = HeapConstant(callable.code());
Node** args = zone()->NewArray<Node*>(argc + 4); Node** args = zone()->NewArray<Node*>(argc + 4);
...@@ -875,7 +865,7 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context, ...@@ -875,7 +865,7 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
args[4] = arg2; args[4] = arg2;
args[5] = context; args[5] = context;
return CallN(call_descriptor, target, args); return CallStubN(callable.descriptor(), argc + 1, target, args, result_size);
} }
Node* CodeAssembler::CallCFunction2(MachineType return_type, Node* CodeAssembler::CallCFunction2(MachineType return_type,
......
...@@ -379,8 +379,13 @@ class CodeAssembler { ...@@ -379,8 +379,13 @@ class CodeAssembler {
const Arg& arg3, const Arg& arg4, const Arg& arg5, const Arg& arg3, const Arg& arg4, const Arg& arg5,
size_t result_size = 1); size_t result_size = 1);
Node* CallStubN(const CallInterfaceDescriptor& descriptor,
int js_parameter_count, Node* target, Node** args,
size_t result_size = 1);
Node* CallStubN(const CallInterfaceDescriptor& descriptor, Node* target, Node* CallStubN(const CallInterfaceDescriptor& descriptor, Node* target,
Node** args, size_t result_size = 1); Node** args, size_t result_size = 1) {
return CallStubN(descriptor, 0, target, args, result_size);
}
Node* TailCallStub(Callable const& callable, Node* context, Node* arg1, Node* TailCallStub(Callable const& callable, Node* context, Node* arg1,
size_t result_size = 1); size_t result_size = 1);
......
...@@ -179,27 +179,35 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::Call( ...@@ -179,27 +179,35 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::Call(
ExternalReference::DIRECT_API_CALL, isolate()); ExternalReference::DIRECT_API_CALL, isolate());
// Create & call API callback via stub. // Create & call API callback via stub.
CallApiCallbackStub stub(isolate(), 1, true, true); const int kJSParameterCount = 1;
DCHECK_EQ(5, stub.GetCallInterfaceDescriptor().GetParameterCount()); CallApiCallbackStub stub(isolate(), kJSParameterCount, true, true);
DCHECK_EQ(1, stub.GetCallInterfaceDescriptor().GetStackParameterCount()); CallInterfaceDescriptor descriptor = stub.GetCallInterfaceDescriptor();
DCHECK_EQ(4, descriptor.GetParameterCount());
DCHECK_EQ(0, descriptor.GetStackParameterCount());
// TODO(vogelheim): There is currently no clean way to retrieve the context // TODO(vogelheim): There is currently no clean way to retrieve the context
// parameter for a stub and the implementation details are hidden in // parameter for a stub and the implementation details are hidden in
// compiler/*. The context_paramter is computed as: // compiler/*. The context_paramter is computed as:
// Linkage::GetJSCallContextParamIndex(descriptor->JSParameterCount()) // Linkage::GetJSCallContextParamIndex(descriptor->JSParameterCount())
const int context_parameter = 3; const int kContextParameter = 3;
Node* call = assembler_->CallStub( Node* context = assembler_->Parameter(kContextParameter);
stub.GetCallInterfaceDescriptor(), Node* target = assembler_->HeapConstant(stub.GetCode());
assembler_->HeapConstant(stub.GetCode()),
assembler_->Parameter(context_parameter), int param_count = descriptor.GetParameterCount();
Node** args = zone()->NewArray<Node*>(param_count + 1 + kJSParameterCount);
// Stub/register parameters: // Stub/register parameters:
assembler_->UndefinedConstant(), /* callee (there's no JSFunction) */ args[0] = assembler_->UndefinedConstant(); // callee (there's no JSFunction)
assembler_->UndefinedConstant(), /* call_data (undefined) */ args[1] = assembler_->UndefinedConstant(); // call_data (undefined)
assembler_->Parameter(0), /* receiver (same as holder in this case) */ args[2] = assembler_->Parameter(0); // receiver (same as holder in this case)
assembler_->ExternalConstant(callback), /* API callback function */ args[3] = assembler_->ExternalConstant(callback); // API callback function
// JS arguments, on stack: // JS arguments, on stack:
FromId(arg)); args[4] = FromId(arg);
// Context.
args[5] = context;
Node* call =
assembler_->CallStubN(descriptor, kJSParameterCount, target, args);
return FromRaw(call); return FromRaw(call);
} }
......
...@@ -357,7 +357,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -357,7 +357,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers); data->InitializePlatformSpecific(arraysize(registers), registers);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
Register registers[] = { Register registers[] = {
edi, // callee edi, // callee
......
...@@ -446,38 +446,13 @@ void ArgumentAdaptorDescriptor::InitializePlatformIndependent( ...@@ -446,38 +446,13 @@ void ArgumentAdaptorDescriptor::InitializePlatformIndependent(
machine_types); machine_types);
} }
CallInterfaceDescriptor ApiCallbackDescriptorBase::ForArgs(Isolate* isolate, void ApiCallbackDescriptor::InitializePlatformIndependent(
int argc) {
switch (argc) {
case 0:
return ApiCallbackWith0ArgsDescriptor(isolate);
case 1:
return ApiCallbackWith1ArgsDescriptor(isolate);
case 2:
return ApiCallbackWith2ArgsDescriptor(isolate);
case 3:
return ApiCallbackWith3ArgsDescriptor(isolate);
case 4:
return ApiCallbackWith4ArgsDescriptor(isolate);
case 5:
return ApiCallbackWith5ArgsDescriptor(isolate);
case 6:
return ApiCallbackWith6ArgsDescriptor(isolate);
case 7:
return ApiCallbackWith7ArgsDescriptor(isolate);
default:
UNREACHABLE();
return VoidDescriptor(isolate);
}
}
void ApiCallbackDescriptorBase::InitializePlatformIndependent(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
// kFunction, kCallData, kHolder, kApiFunctionAddress // kFunction, kCallData, kHolder, kApiFunctionAddress
MachineType machine_types[] = { MachineType machine_types[] = {
MachineType::AnyTagged(), MachineType::AnyTagged(), MachineType::AnyTagged(), MachineType::AnyTagged(),
MachineType::AnyTagged(), MachineType::Pointer()}; MachineType::AnyTagged(), MachineType::Pointer()};
data->InitializePlatformIndependent(arraysize(machine_types), extra_args(), data->InitializePlatformIndependent(arraysize(machine_types), 0,
machine_types); machine_types);
} }
......
...@@ -84,14 +84,7 @@ class PlatformInterfaceDescriptor; ...@@ -84,14 +84,7 @@ class PlatformInterfaceDescriptor;
V(GetProperty) \ V(GetProperty) \
V(CallHandler) \ V(CallHandler) \
V(ArgumentAdaptor) \ V(ArgumentAdaptor) \
V(ApiCallbackWith0Args) \ V(ApiCallback) \
V(ApiCallbackWith1Args) \
V(ApiCallbackWith2Args) \
V(ApiCallbackWith3Args) \
V(ApiCallbackWith4Args) \
V(ApiCallbackWith5Args) \
V(ApiCallbackWith6Args) \
V(ApiCallbackWith7Args) \
V(ApiGetter) \ V(ApiGetter) \
V(StoreGlobalViaContext) \ V(StoreGlobalViaContext) \
V(MathPowTagged) \ V(MathPowTagged) \
...@@ -751,80 +744,13 @@ class ArgumentAdaptorDescriptor : public CallInterfaceDescriptor { ...@@ -751,80 +744,13 @@ class ArgumentAdaptorDescriptor : public CallInterfaceDescriptor {
CallInterfaceDescriptor) CallInterfaceDescriptor)
}; };
// The ApiCallback*Descriptors have a lot of boilerplate. The superclass class ApiCallbackDescriptor : public CallInterfaceDescriptor {
// ApiCallbackDescriptorBase contains all the logic, and the
// ApiCallbackWith*ArgsDescriptor merely instantiate these with a
// parameter for the number of args.
//
// The base class is not meant to be instantiated directly and has no
// public constructors to ensure this is so.
//
// The simplest usage for all the ApiCallback*Descriptors is probably
// ApiCallbackDescriptorBase::ForArgs(isolate, argc)
//
class ApiCallbackDescriptorBase : public CallInterfaceDescriptor {
public: public:
DEFINE_PARAMETERS(kFunction, kCallData, kHolder, kApiFunctionAddress) DEFINE_PARAMETERS(kFunction, kCallData, kHolder, kApiFunctionAddress)
static CallInterfaceDescriptor ForArgs(Isolate* isolate, int argc); DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(ApiCallbackDescriptor,
CallInterfaceDescriptor)
protected:
virtual int extra_args() const { return 0; }
ApiCallbackDescriptorBase(Isolate* isolate, CallDescriptors::Key key)
: CallInterfaceDescriptor(isolate, key) {}
void InitializePlatformSpecific(CallInterfaceDescriptorData* data) override;
void InitializePlatformIndependent(
CallInterfaceDescriptorData* data) override;
};
class ApiCallbackWith0ArgsDescriptor : public ApiCallbackDescriptorBase {
public:
DECLARE_DESCRIPTOR_WITH_BASE_AND_FUNCTION_TYPE_ARG(
ApiCallbackWith0ArgsDescriptor, ApiCallbackDescriptorBase, 0)
};
class ApiCallbackWith1ArgsDescriptor : public ApiCallbackDescriptorBase {
public:
DECLARE_DESCRIPTOR_WITH_BASE_AND_FUNCTION_TYPE_ARG(
ApiCallbackWith1ArgsDescriptor, ApiCallbackDescriptorBase, 1)
};
class ApiCallbackWith2ArgsDescriptor : public ApiCallbackDescriptorBase {
public:
DECLARE_DESCRIPTOR_WITH_BASE_AND_FUNCTION_TYPE_ARG(
ApiCallbackWith2ArgsDescriptor, ApiCallbackDescriptorBase, 2)
};
class ApiCallbackWith3ArgsDescriptor : public ApiCallbackDescriptorBase {
public:
DECLARE_DESCRIPTOR_WITH_BASE_AND_FUNCTION_TYPE_ARG(
ApiCallbackWith3ArgsDescriptor, ApiCallbackDescriptorBase, 3)
};
class ApiCallbackWith4ArgsDescriptor : public ApiCallbackDescriptorBase {
public:
DECLARE_DESCRIPTOR_WITH_BASE_AND_FUNCTION_TYPE_ARG(
ApiCallbackWith4ArgsDescriptor, ApiCallbackDescriptorBase, 4)
};
class ApiCallbackWith5ArgsDescriptor : public ApiCallbackDescriptorBase {
public:
DECLARE_DESCRIPTOR_WITH_BASE_AND_FUNCTION_TYPE_ARG(
ApiCallbackWith5ArgsDescriptor, ApiCallbackDescriptorBase, 5)
};
class ApiCallbackWith6ArgsDescriptor : public ApiCallbackDescriptorBase {
public:
DECLARE_DESCRIPTOR_WITH_BASE_AND_FUNCTION_TYPE_ARG(
ApiCallbackWith6ArgsDescriptor, ApiCallbackDescriptorBase, 6)
};
class ApiCallbackWith7ArgsDescriptor : public ApiCallbackDescriptorBase {
public:
DECLARE_DESCRIPTOR_WITH_BASE_AND_FUNCTION_TYPE_ARG(
ApiCallbackWith7ArgsDescriptor, ApiCallbackDescriptorBase, 7)
}; };
class ApiGetterDescriptor : public CallInterfaceDescriptor { class ApiGetterDescriptor : public CallInterfaceDescriptor {
public: public:
DEFINE_PARAMETERS(kReceiver, kHolder, kCallback) DEFINE_PARAMETERS(kReceiver, kHolder, kCallback)
......
...@@ -353,7 +353,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -353,7 +353,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers); data->InitializePlatformSpecific(arraysize(registers), registers);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
Register registers[] = { Register registers[] = {
a0, // callee a0, // callee
......
...@@ -352,7 +352,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -352,7 +352,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers); data->InitializePlatformSpecific(arraysize(registers), registers);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
Register registers[] = { Register registers[] = {
a0, // callee a0, // callee
......
...@@ -351,7 +351,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -351,7 +351,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers); data->InitializePlatformSpecific(arraysize(registers), registers);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
Register registers[] = { Register registers[] = {
r3, // callee r3, // callee
......
...@@ -322,7 +322,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -322,7 +322,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers); data->InitializePlatformSpecific(arraysize(registers), registers);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
Register registers[] = { Register registers[] = {
r2, // callee r2, // callee
......
...@@ -352,7 +352,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -352,7 +352,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers); data->InitializePlatformSpecific(arraysize(registers), registers);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
Register registers[] = { Register registers[] = {
rdi, // callee rdi, // callee
......
...@@ -355,7 +355,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific( ...@@ -355,7 +355,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers); data->InitializePlatformSpecific(arraysize(registers), registers);
} }
void ApiCallbackDescriptorBase::InitializePlatformSpecific( void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) { CallInterfaceDescriptorData* data) {
Register registers[] = { Register registers[] = {
edi, // callee edi, // callee
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment