Commit 6a088981 authored by Camillo's avatar Camillo Committed by V8 LUCI CQ

[api] Make CanHaveInternalField inlineable

Drive-by-fix: Reduce one branch in the type compairison since
JS_OBJECT_TYPE and JS_FIRST_API_INSTANCE_TYPE are adjacent.

Bug: v8:11476
Change-Id: I621ef2df4da2858cb1652276f800ccedba4e3015
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3695562
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81051}
parent c5f87848
......@@ -333,9 +333,6 @@ V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj);
// mode based on the current context and the closure. This returns true if the
// language mode is strict.
V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate);
V8_EXPORT bool CanHaveInternalField(int instance_type);
/**
* This class exports constants and functionality from within v8 that
* is necessary to implement inline functions in the v8 api. Don't
......@@ -489,6 +486,18 @@ class Internals {
return representation == kExternalTwoByteRepresentationTag;
}
V8_INLINE static constexpr bool CanHaveInternalField(int instance_type) {
static_assert(kJSObjectType + 1 == kFirstJSApiObjectType);
static_assert(kJSObjectType < kLastJSApiObjectType);
static_assert(kFirstJSApiObjectType < kLastJSApiObjectType);
// Check for IsJSObject() || IsJSSpecialApiObject() || IsJSApiObject()
return instance_type == kJSSpecialApiObjectType ||
// inlined version of base::IsInRange
(static_cast<unsigned>(static_cast<unsigned>(instance_type) -
static_cast<unsigned>(kJSObjectType)) <=
static_cast<unsigned>(kLastJSApiObjectType - kJSObjectType));
}
V8_INLINE static uint8_t GetNodeFlag(internal::Address* obj, int shift) {
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
return *addr & static_cast<uint8_t>(1U << shift);
......
......@@ -711,7 +711,7 @@ Local<Value> Object::GetInternalField(int index) {
// Fast path: If the object is a plain JSObject, which is the common case, we
// know where to find the internal fields and can return the value directly.
int instance_type = I::GetInstanceType(obj);
if (v8::internal::CanHaveInternalField(instance_type)) {
if (I::CanHaveInternalField(instance_type)) {
int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
A value = I::ReadRawField<A>(obj, offset);
#ifdef V8_COMPRESS_POINTERS
......@@ -736,7 +736,7 @@ void* Object::GetAlignedPointerFromInternalField(int index) {
// Fast path: If the object is a plain JSObject, which is the common case, we
// know where to find the internal fields and can return the value directly.
auto instance_type = I::GetInstanceType(obj);
if (v8::internal::CanHaveInternalField(instance_type)) {
if (I::CanHaveInternalField(instance_type)) {
int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
offset += I::kEmbedderDataSlotRawPayloadOffset;
......
......@@ -3846,13 +3846,6 @@ bool i::ShouldThrowOnError(i::Isolate* i_isolate) {
i::ShouldThrow::kThrowOnError;
}
bool i::CanHaveInternalField(int instance_type) {
return instance_type == i::Internals::kJSObjectType ||
instance_type == i::Internals::kJSSpecialApiObjectType ||
v8::internal::InstanceTypeChecker::IsJSApiObject(
static_cast<v8::internal::InstanceType>(instance_type));
}
void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(external_isolate);
Utils::ApiCheck(i_isolate != nullptr && !i_isolate->IsDead(),
......
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