[turbofan] Fixes for integrating the fast C API
This commit adds a few fixes neccessary for integrating the fast C API into Blink: - added default constructor for CFunction - removed a bogus template specialization allowing void* params - extended the public Isolate class Bug: chromium:1052746 Change-Id: I4f2ba84299920e2cc9d66ec1ed59302313db6c0b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2120587 Commit-Queue: Maya Lekova <mslekova@chromium.org> Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Georg Neis <neis@chromium.org> Cr-Commit-Position: refs/heads/master@{#66986}
This commit is contained in:
parent
6844179837
commit
0d6debcc5f
@ -183,30 +183,32 @@ class CTypeInfo {
|
||||
kUnwrappedApiObject,
|
||||
};
|
||||
|
||||
enum ArgFlags : char {
|
||||
None = 0,
|
||||
IsArrayBit = 1 << 0, // This argument is first in an array of values.
|
||||
enum class ArgFlags : uint8_t {
|
||||
kNone = 0,
|
||||
kIsArrayBit = 1 << 0, // This argument is first in an array of values.
|
||||
};
|
||||
|
||||
static CTypeInfo FromWrapperType(const void* wrapper_type_info,
|
||||
ArgFlags flags = ArgFlags::None) {
|
||||
ArgFlags flags = ArgFlags::kNone) {
|
||||
uintptr_t wrapper_type_info_ptr =
|
||||
reinterpret_cast<uintptr_t>(wrapper_type_info);
|
||||
// Check that the lower kIsWrapperTypeBit bits are 0's.
|
||||
CHECK_EQ(
|
||||
wrapper_type_info_ptr & ~(static_cast<uintptr_t>(~0)
|
||||
<< static_cast<uintptr_t>(kIsWrapperTypeBit)),
|
||||
0);
|
||||
0u);
|
||||
// TODO(mslekova): Refactor the manual bit manipulations to use
|
||||
// PointerWithPayload instead.
|
||||
return CTypeInfo(wrapper_type_info_ptr | flags | kIsWrapperTypeBit);
|
||||
return CTypeInfo(wrapper_type_info_ptr | static_cast<int>(flags) |
|
||||
kIsWrapperTypeBit);
|
||||
}
|
||||
|
||||
static constexpr CTypeInfo FromCType(Type ctype,
|
||||
ArgFlags flags = ArgFlags::None) {
|
||||
ArgFlags flags = ArgFlags::kNone) {
|
||||
// ctype cannot be Type::kUnwrappedApiObject.
|
||||
return CTypeInfo(
|
||||
((static_cast<uintptr_t>(ctype) << kTypeOffset) & kTypeMask) | flags);
|
||||
((static_cast<uintptr_t>(ctype) << kTypeOffset) & kTypeMask) |
|
||||
static_cast<int>(flags));
|
||||
}
|
||||
|
||||
const void* GetWrapperInfo() const;
|
||||
@ -218,7 +220,9 @@ class CTypeInfo {
|
||||
return static_cast<Type>((payload_ & kTypeMask) >> kTypeOffset);
|
||||
}
|
||||
|
||||
constexpr bool IsArray() const { return payload_ & ArgFlags::IsArrayBit; }
|
||||
constexpr bool IsArray() const {
|
||||
return payload_ & static_cast<int>(ArgFlags::kIsArrayBit);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit constexpr CTypeInfo(uintptr_t payload) : payload_(payload) {}
|
||||
@ -283,9 +287,6 @@ SUPPORTED_C_TYPES(SPECIALIZE_GET_C_TYPE_FOR)
|
||||
template <typename T, typename = void>
|
||||
struct EnableIfHasWrapperTypeInfo {};
|
||||
|
||||
template <>
|
||||
struct EnableIfHasWrapperTypeInfo<void> {};
|
||||
|
||||
template <typename T>
|
||||
struct EnableIfHasWrapperTypeInfo<T, decltype(WrapperTraits<T>::GetTypeInfo(),
|
||||
void())> {
|
||||
@ -297,7 +298,7 @@ template <typename T, typename = void>
|
||||
struct GetCTypePointerImpl {
|
||||
static constexpr CTypeInfo Get() {
|
||||
return CTypeInfo::FromCType(GetCType<T>::Get().GetType(),
|
||||
CTypeInfo::IsArrayBit);
|
||||
CTypeInfo::ArgFlags::kIsArrayBit);
|
||||
}
|
||||
};
|
||||
|
||||
@ -321,7 +322,7 @@ struct GetCTypePointerPointerImpl<
|
||||
T, typename EnableIfHasWrapperTypeInfo<T>::type> {
|
||||
static constexpr CTypeInfo Get() {
|
||||
return CTypeInfo::FromWrapperType(WrapperTraits<T>::GetTypeInfo(),
|
||||
CTypeInfo::IsArrayBit);
|
||||
CTypeInfo::ArgFlags::kIsArrayBit);
|
||||
}
|
||||
};
|
||||
|
||||
@ -335,11 +336,12 @@ template <typename R, typename... Args>
|
||||
class CFunctionInfoImpl : public CFunctionInfo {
|
||||
public:
|
||||
CFunctionInfoImpl()
|
||||
: return_info_(i::GetCType<R>::Get()),
|
||||
: return_info_(internal::GetCType<R>::Get()),
|
||||
arg_count_(sizeof...(Args)),
|
||||
arg_info_{i::GetCType<Args>::Get()...} {
|
||||
static_assert(i::GetCType<R>::Get().GetType() == CTypeInfo::Type::kVoid,
|
||||
"Only void return types are currently supported.");
|
||||
arg_info_{internal::GetCType<Args>::Get()...} {
|
||||
static_assert(
|
||||
internal::GetCType<R>::Get().GetType() == CTypeInfo::Type::kVoid,
|
||||
"Only void return types are currently supported.");
|
||||
}
|
||||
|
||||
const CTypeInfo& ReturnInfo() const override { return return_info_; }
|
||||
@ -359,6 +361,8 @@ class CFunctionInfoImpl : public CFunctionInfo {
|
||||
|
||||
class V8_EXPORT CFunction {
|
||||
public:
|
||||
constexpr CFunction() : address_(nullptr), type_info_(nullptr) {}
|
||||
|
||||
const CTypeInfo& ReturnInfo() const { return type_info_->ReturnInfo(); }
|
||||
|
||||
const CTypeInfo& ArgumentInfo(unsigned int index) const {
|
||||
|
12
include/v8.h
12
include/v8.h
@ -8183,7 +8183,9 @@ class V8_EXPORT Isolate {
|
||||
array_buffer_allocator_shared(),
|
||||
external_references(nullptr),
|
||||
allow_atomics_wait(true),
|
||||
only_terminate_in_safe_scope(false) {}
|
||||
only_terminate_in_safe_scope(false),
|
||||
embedder_wrapper_type_index(-1),
|
||||
embedder_wrapper_object_index(-1) {}
|
||||
|
||||
/**
|
||||
* Allows the host application to provide the address of a function that is
|
||||
@ -8247,6 +8249,14 @@ class V8_EXPORT Isolate {
|
||||
* Termination is postponed when there is no active SafeForTerminationScope.
|
||||
*/
|
||||
bool only_terminate_in_safe_scope;
|
||||
|
||||
/**
|
||||
* The following parameters describe the offsets for addressing type info
|
||||
* for wrapped API objects and are used by the fast C API
|
||||
* (for details see v8-fast-api-calls.h).
|
||||
*/
|
||||
int embedder_wrapper_type_index;
|
||||
int embedder_wrapper_object_index;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1582,8 +1582,9 @@ void FunctionTemplate::SetCallHandler(FunctionCallback callback,
|
||||
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
|
||||
}
|
||||
obj->set_data(*Utils::OpenHandle(*data));
|
||||
if (c_function != nullptr) {
|
||||
DCHECK_NOT_NULL(c_function->GetAddress());
|
||||
// Blink passes CFunction's constructed with the default constructor
|
||||
// for non-fast calls, so we should check the address too.
|
||||
if (c_function != nullptr && c_function->GetAddress()) {
|
||||
i::FunctionTemplateInfo::SetCFunction(
|
||||
isolate, info,
|
||||
i::handle(*FromCData(isolate, c_function->GetAddress()), isolate));
|
||||
@ -8333,6 +8334,10 @@ void Isolate::Initialize(Isolate* isolate,
|
||||
}
|
||||
i_isolate->set_only_terminate_in_safe_scope(
|
||||
params.only_terminate_in_safe_scope);
|
||||
i_isolate->set_embedder_wrapper_type_index(
|
||||
params.embedder_wrapper_type_index);
|
||||
i_isolate->set_embedder_wrapper_object_index(
|
||||
params.embedder_wrapper_object_index);
|
||||
|
||||
if (!i::V8::GetCurrentPlatform()
|
||||
->GetForegroundTaskRunner(isolate)
|
||||
|
@ -27064,6 +27064,8 @@ void SetupTest(v8::Local<v8::Value> initial_value, LocalContext* env,
|
||||
v8::Isolate* isolate = CcTest::isolate();
|
||||
|
||||
v8::CFunction c_func = v8::CFunction::Make(ApiNumberChecker<T>::CheckArgFast);
|
||||
CHECK_EQ(c_func.ArgumentInfo(0).GetType(),
|
||||
v8::CTypeInfo::Type::kUnwrappedApiObject);
|
||||
|
||||
Local<v8::FunctionTemplate> checker_templ = v8::FunctionTemplate::New(
|
||||
isolate, ApiNumberChecker<T>::CheckArgSlow, v8::Local<v8::Value>(),
|
||||
|
Loading…
Reference in New Issue
Block a user