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(
&default_descriptor);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
static PlatformInterfaceDescriptor default_descriptor =
PlatformInterfaceDescriptor(CAN_INLINE_TARGET_ADDRESS);
......
......@@ -403,7 +403,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
&default_descriptor);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
static PlatformInterfaceDescriptor default_descriptor =
PlatformInterfaceDescriptor(CAN_INLINE_TARGET_ADDRESS);
......
......@@ -1822,10 +1822,6 @@ class CallApiCallbackStub : public PlatformCodeStub {
: CallApiCallbackStub(isolate, argc, false, call_data_undefined,
is_lazy) {}
CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
return ApiCallbackDescriptorBase::ForArgs(isolate(), argc());
}
private:
CallApiCallbackStub(Isolate* isolate, int argc, bool is_store,
bool call_data_undefined, bool is_lazy)
......@@ -1849,6 +1845,7 @@ class CallApiCallbackStub : public PlatformCodeStub {
class ArgumentBits : public BitField<int, 2, kArgBits> {};
class IsLazyAccessorBits : public BitField<bool, 3 + kArgBits, 1> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiCallback);
DEFINE_PLATFORM_CODE_STUB(CallApiCallback, PlatformCodeStub);
};
......
......@@ -657,9 +657,11 @@ Node* CodeAssembler::CallStub(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(
isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
isolate(), zone(), descriptor,
descriptor.GetStackParameterCount() + js_parameter_count,
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size);
......@@ -822,10 +824,6 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
Node* function, Node* receiver,
size_t result_size) {
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** args = zone()->NewArray<Node*>(argc + 4);
......@@ -834,17 +832,13 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
args[2] = receiver;
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* function, Node* receiver, Node* arg1,
size_t result_size) {
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** args = zone()->NewArray<Node*>(argc + 4);
......@@ -854,17 +848,13 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
args[3] = arg1;
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* function, Node* receiver, Node* arg1,
Node* arg2, size_t result_size) {
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** args = zone()->NewArray<Node*>(argc + 4);
......@@ -875,7 +865,7 @@ Node* CodeAssembler::CallJS(Callable const& callable, Node* context,
args[4] = arg2;
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,
......
......@@ -379,8 +379,13 @@ class CodeAssembler {
const Arg& arg3, const Arg& arg4, const Arg& arg5,
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** 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,
size_t result_size = 1);
......
......@@ -179,27 +179,35 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::Call(
ExternalReference::DIRECT_API_CALL, isolate());
// Create & call API callback via stub.
CallApiCallbackStub stub(isolate(), 1, true, true);
DCHECK_EQ(5, stub.GetCallInterfaceDescriptor().GetParameterCount());
DCHECK_EQ(1, stub.GetCallInterfaceDescriptor().GetStackParameterCount());
const int kJSParameterCount = 1;
CallApiCallbackStub stub(isolate(), kJSParameterCount, true, true);
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
// parameter for a stub and the implementation details are hidden in
// compiler/*. The context_paramter is computed as:
// Linkage::GetJSCallContextParamIndex(descriptor->JSParameterCount())
const int context_parameter = 3;
Node* call = assembler_->CallStub(
stub.GetCallInterfaceDescriptor(),
assembler_->HeapConstant(stub.GetCode()),
assembler_->Parameter(context_parameter),
// Stub/register parameters:
assembler_->UndefinedConstant(), /* callee (there's no JSFunction) */
assembler_->UndefinedConstant(), /* call_data (undefined) */
assembler_->Parameter(0), /* receiver (same as holder in this case) */
assembler_->ExternalConstant(callback), /* API callback function */
// JS arguments, on stack:
FromId(arg));
const int kContextParameter = 3;
Node* context = assembler_->Parameter(kContextParameter);
Node* target = assembler_->HeapConstant(stub.GetCode());
int param_count = descriptor.GetParameterCount();
Node** args = zone()->NewArray<Node*>(param_count + 1 + kJSParameterCount);
// Stub/register parameters:
args[0] = assembler_->UndefinedConstant(); // callee (there's no JSFunction)
args[1] = assembler_->UndefinedConstant(); // call_data (undefined)
args[2] = assembler_->Parameter(0); // receiver (same as holder in this case)
args[3] = assembler_->ExternalConstant(callback); // API callback function
// JS arguments, on stack:
args[4] = FromId(arg);
// Context.
args[5] = context;
Node* call =
assembler_->CallStubN(descriptor, kJSParameterCount, target, args);
return FromRaw(call);
}
......
......@@ -357,7 +357,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {
edi, // callee
......
......@@ -446,38 +446,13 @@ void ArgumentAdaptorDescriptor::InitializePlatformIndependent(
machine_types);
}
CallInterfaceDescriptor ApiCallbackDescriptorBase::ForArgs(Isolate* isolate,
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(
void ApiCallbackDescriptor::InitializePlatformIndependent(
CallInterfaceDescriptorData* data) {
// kFunction, kCallData, kHolder, kApiFunctionAddress
MachineType machine_types[] = {
MachineType::AnyTagged(), MachineType::AnyTagged(),
MachineType::AnyTagged(), MachineType::Pointer()};
data->InitializePlatformIndependent(arraysize(machine_types), extra_args(),
data->InitializePlatformIndependent(arraysize(machine_types), 0,
machine_types);
}
......
......@@ -84,14 +84,7 @@ class PlatformInterfaceDescriptor;
V(GetProperty) \
V(CallHandler) \
V(ArgumentAdaptor) \
V(ApiCallbackWith0Args) \
V(ApiCallbackWith1Args) \
V(ApiCallbackWith2Args) \
V(ApiCallbackWith3Args) \
V(ApiCallbackWith4Args) \
V(ApiCallbackWith5Args) \
V(ApiCallbackWith6Args) \
V(ApiCallbackWith7Args) \
V(ApiCallback) \
V(ApiGetter) \
V(StoreGlobalViaContext) \
V(MathPowTagged) \
......@@ -751,80 +744,13 @@ class ArgumentAdaptorDescriptor : public CallInterfaceDescriptor {
CallInterfaceDescriptor)
};
// The ApiCallback*Descriptors have a lot of boilerplate. The superclass
// 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 {
class ApiCallbackDescriptor : public CallInterfaceDescriptor {
public:
DEFINE_PARAMETERS(kFunction, kCallData, kHolder, kApiFunctionAddress)
static CallInterfaceDescriptor ForArgs(Isolate* isolate, int argc);
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)
DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(ApiCallbackDescriptor,
CallInterfaceDescriptor)
};
class ApiGetterDescriptor : public CallInterfaceDescriptor {
public:
DEFINE_PARAMETERS(kReceiver, kHolder, kCallback)
......
......@@ -353,7 +353,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {
a0, // callee
......
......@@ -352,7 +352,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {
a0, // callee
......
......@@ -351,7 +351,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {
r3, // callee
......
......@@ -322,7 +322,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {
r2, // callee
......
......@@ -352,7 +352,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {
rdi, // callee
......
......@@ -355,7 +355,7 @@ void ArgumentAdaptorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void ApiCallbackDescriptorBase::InitializePlatformSpecific(
void ApiCallbackDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {
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