Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: cherry-pick V8 API changes #27013

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.13',
'v8_embedder_string': '-node.16',

##### V8 defaults for Node.js #####

13 changes: 12 additions & 1 deletion deps/v8/include/v8-internal.h
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@

#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <type_traits>

#include "v8-version.h" // NOLINT(build/include)
@@ -164,7 +165,6 @@ class Internals {
static const int kNodeStateMask = 0x7;
static const int kNodeStateIsWeakValue = 2;
static const int kNodeStateIsPendingValue = 3;
static const int kNodeStateIsNearDeathValue = 4;
static const int kNodeIsIndependentShift = 3;
static const int kNodeIsActiveShift = 4;

@@ -275,6 +275,17 @@ class Internals {
V8_INLINE static T ReadRawField(internal::Address heap_object_ptr,
int offset) {
internal::Address addr = heap_object_ptr + offset - kHeapObjectTag;
#ifdef V8_COMPRESS_POINTERS
if (sizeof(T) > kApiTaggedSize) {
// TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
// fields (external pointers, doubles and BigInt data) are only
// kTaggedSize aligned so we have to use unaligned pointer friendly way of
// accessing them in order to avoid undefined behavior in C++ code.
T r;
memcpy(&r, reinterpret_cast<void*>(addr), sizeof(T));
return r;
}
#endif
return *reinterpret_cast<const T*>(addr);
}

2 changes: 1 addition & 1 deletion deps/v8/include/v8-util.h
Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@ class PersistentValueMapBase {
* Call V8::RegisterExternallyReferencedObject with the map value for given
* key.
*/
V8_DEPRECATE_SOON(
V8_DEPRECATED(
"Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference",
inline void RegisterExternallyReferencedObject(K& key));

33 changes: 4 additions & 29 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
@@ -118,6 +118,7 @@ class Arguments;
class DeferredHandles;
class Heap;
class HeapObject;
class ExternalString;
class Isolate;
class LocalEmbedderHeapTracer;
class MicrotaskQueue;
@@ -549,7 +550,7 @@ template <class T> class PersistentBase {
* is alive. Only allowed when the embedder is asked to trace its heap by
* EmbedderHeapTracer.
*/
V8_DEPRECATE_SOON(
V8_DEPRECATED(
"Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference",
V8_INLINE void RegisterExternalReference(Isolate* isolate) const);

@@ -572,14 +573,10 @@ template <class T> class PersistentBase {
*
* This bit is cleared after the each garbage collection pass.
*/
V8_DEPRECATE_SOON("Use TracedGlobal.", V8_INLINE void MarkActive());
V8_DEPRECATED("Use TracedGlobal.", V8_INLINE void MarkActive());

V8_DEPRECATED("See MarkIndependent.", V8_INLINE bool IsIndependent() const);

/** Checks if the handle holds the only reference to an object. */
V8_DEPRECATED("Garbage collection internal state should not be relied on.",
V8_INLINE bool IsNearDeath() const);

/** Returns true if the handle's reference is weak. */
V8_INLINE bool IsWeak() const;

@@ -2801,7 +2798,7 @@ class V8_EXPORT String : public Name {
void operator=(const ExternalStringResourceBase&) = delete;

private:
friend class internal::Heap;
friend class internal::ExternalString;
friend class v8::String;
friend class internal::ScopedExternalStringLock;
};
@@ -8519,17 +8516,6 @@ class V8_EXPORT Isolate {
*/
void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);

/**
* Iterates through all the persistent handles in the current isolate's heap
* that have class_ids and are candidates to be marked as partially dependent
* handles. This will visit handles to young objects created since the last
* garbage collection but is free to visit an arbitrary superset of these
* objects.
*/
V8_DEPRECATED(
"Use VisitHandlesWithClassIds",
void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor));

/**
* Iterates through all the persistent handles in the current isolate's heap
* that have class_ids and are weak to be marked as inactive if there is no
@@ -9783,17 +9769,6 @@ bool PersistentBase<T>::IsIndependent() const {
I::kNodeIsIndependentShift);
}

template <class T>
bool PersistentBase<T>::IsNearDeath() const {
typedef internal::Internals I;
if (this->IsEmpty()) return false;
uint8_t node_state =
I::GetNodeState(reinterpret_cast<internal::Address*>(this->val_));
return node_state == I::kNodeStateIsNearDeathValue ||
node_state == I::kNodeStateIsPendingValue;
}


template <class T>
bool PersistentBase<T>::IsWeak() const {
typedef internal::Internals I;
9 changes: 0 additions & 9 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
@@ -8876,15 +8876,6 @@ void Isolate::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) {
isolate->global_handles()->IterateAllRootsWithClassIds(visitor);
}


void Isolate::VisitHandlesForPartialDependence(
PersistentHandleVisitor* visitor) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::DisallowHeapAllocation no_allocation;
isolate->global_handles()->IterateAllYoungRootsWithClassIds(visitor);
}


void Isolate::VisitWeakHandles(PersistentHandleVisitor* visitor) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::DisallowHeapAllocation no_allocation;
10 changes: 0 additions & 10 deletions deps/v8/src/global-handles.cc
Original file line number Diff line number Diff line change
@@ -379,7 +379,6 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> {
Internals::kNodeStateMask);
STATIC_ASSERT(WEAK == Internals::kNodeStateIsWeakValue);
STATIC_ASSERT(PENDING == Internals::kNodeStateIsPendingValue);
STATIC_ASSERT(NEAR_DEATH == Internals::kNodeStateIsNearDeathValue);
STATIC_ASSERT(static_cast<int>(IsIndependent::kShift) ==
Internals::kNodeIsIndependentShift);
STATIC_ASSERT(static_cast<int>(IsActive::kShift) ==
@@ -427,11 +426,6 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> {
flags_ = NodeWeaknessType::update(flags_, weakness_type);
}

bool IsNearDeath() const {
// Check for PENDING to ensure correct answer when processing callbacks.
return state() == PENDING || state() == NEAR_DEATH;
}

bool IsWeak() const { return state() == WEAK; }

bool IsInUse() const { return state() != FREE; }
@@ -819,10 +813,6 @@ void GlobalHandles::AnnotateStrongRetainer(Address* location,
Node::FromLocation(location)->AnnotateStrongRetainer(label);
}

bool GlobalHandles::IsNearDeath(Address* location) {
return Node::FromLocation(location)->IsNearDeath();
}

bool GlobalHandles::IsWeak(Address* location) {
return Node::FromLocation(location)->IsWeak();
}
3 changes: 0 additions & 3 deletions deps/v8/src/global-handles.h
Original file line number Diff line number Diff line change
@@ -73,9 +73,6 @@ class GlobalHandles final {
// Clear the weakness of a global handle.
static void* ClearWeakness(Address* location);

// Tells whether global handle is near death.
static bool IsNearDeath(Address* location);

// Tells whether global handle is weak.
static bool IsWeak(Address* location);

10 changes: 1 addition & 9 deletions deps/v8/src/heap/heap-inl.h
Original file line number Diff line number Diff line change
@@ -300,15 +300,7 @@ void Heap::FinalizeExternalString(String string) {
ExternalBackingStoreType::kExternalString,
ext_string->ExternalPayloadSize());

v8::String::ExternalStringResourceBase** resource_addr =
reinterpret_cast<v8::String::ExternalStringResourceBase**>(
string->address() + ExternalString::kResourceOffset);

// Dispose of the C++ object if it has not already been disposed.
if (*resource_addr != nullptr) {
(*resource_addr)->Dispose();
*resource_addr = nullptr;
}
ext_string->DisposeResource();
}

Address Heap::NewSpaceTop() { return new_space_->top(); }
3 changes: 1 addition & 2 deletions deps/v8/src/objects/bigint.cc
Original file line number Diff line number Diff line change
@@ -205,8 +205,7 @@ class MutableBigInt : public FreshlyAllocatedBigInt {
}
inline void set_digit(int n, digit_t value) {
SLOW_DCHECK(0 <= n && n < length());
Address address = FIELD_ADDR(*this, kDigitsOffset + n * kDigitSize);
(*reinterpret_cast<digit_t*>(address)) = value;
WRITE_UINTPTR_FIELD(*this, kDigitsOffset + n * kDigitSize, value);
}

void set_64_bits(uint64_t bits);
3 changes: 1 addition & 2 deletions deps/v8/src/objects/bigint.h
Original file line number Diff line number Diff line change
@@ -87,8 +87,7 @@ class BigIntBase : public HeapObject {

inline digit_t digit(int n) const {
SLOW_DCHECK(0 <= n && n < length());
Address address = FIELD_ADDR(*this, kDigitsOffset + n * kDigitSize);
return *reinterpret_cast<digit_t*>(address);
return READ_UINTPTR_FIELD(*this, kDigitsOffset + n * kDigitSize);
}

bool is_zero() const { return length() == 0; }
17 changes: 17 additions & 0 deletions deps/v8/src/objects/embedder-data-slot-inl.h
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
#include "src/objects-inl.h"
#include "src/objects/embedder-data-array.h"
#include "src/objects/js-objects-inl.h"
#include "src/v8memory.h"

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
@@ -71,7 +72,15 @@ bool EmbedderDataSlot::ToAlignedPointer(void** out_pointer) const {
// are accessed this way only from the main thread via API during "mutator"
// phase which is propely synched with GC (concurrent marker may still look
// at the tagged part of the embedder slot but read-only access is ok).
#ifdef V8_COMPRESS_POINTERS
// TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
// fields (external pointers, doubles and BigInt data) are only kTaggedSize
// aligned so we have to use unaligned pointer friendly way of accessing them
// in order to avoid undefined behavior in C++ code.
Address raw_value = ReadUnalignedValue<Address>(address());
#else
Address raw_value = *location();
#endif
*out_pointer = reinterpret_cast<void*>(raw_value);
return HAS_SMI_TAG(raw_value);
}
@@ -89,7 +98,15 @@ EmbedderDataSlot::RawData EmbedderDataSlot::load_raw(
// are accessed this way only by serializer from the main thread when
// GC is not active (concurrent marker may still look at the tagged part
// of the embedder slot but read-only access is ok).
#ifdef V8_COMPRESS_POINTERS
// TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
// fields (external pointers, doubles and BigInt data) are only kTaggedSize
// aligned so we have to use unaligned pointer friendly way of accessing them
// in order to avoid undefined behavior in C++ code.
return ReadUnalignedValue<Address>(address());
#else
return *location();
#endif
}

void EmbedderDataSlot::store_raw(EmbedderDataSlot::RawData data,
23 changes: 21 additions & 2 deletions deps/v8/src/objects/fixed-array-inl.h
Original file line number Diff line number Diff line change
@@ -653,7 +653,17 @@ typename Traits::ElementType FixedTypedArray<Traits>::get_scalar_from_data_ptr(
// JavaScript memory model to have tear-free reads of overlapping accesses,
// and using relaxed atomics may introduce overhead.
TSAN_ANNOTATE_IGNORE_READS_BEGIN;
auto result = ptr[index];
ElementType result;
if (COMPRESS_POINTERS_BOOL && alignof(ElementType) > kTaggedSize) {
// TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
// fields (external pointers, doubles and BigInt data) are only kTaggedSize
// aligned so we have to use unaligned pointer friendly way of accessing
// them in order to avoid undefined behavior in C++ code.
result = ReadUnalignedValue<ElementType>(reinterpret_cast<Address>(ptr) +
index * sizeof(ElementType));
} else {
result = ptr[index];
}
TSAN_ANNOTATE_IGNORE_READS_END;
return result;
}
@@ -664,7 +674,16 @@ void FixedTypedArray<Traits>::set(int index, ElementType value) {
// See the comment in FixedTypedArray<Traits>::get_scalar.
auto* ptr = reinterpret_cast<ElementType*>(DataPtr());
TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
ptr[index] = value;
if (COMPRESS_POINTERS_BOOL && alignof(ElementType) > kTaggedSize) {
// TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
// fields (external pointers, doubles and BigInt data) are only kTaggedSize
// aligned so we have to use unaligned pointer friendly way of accessing
// them in order to avoid undefined behavior in C++ code.
WriteUnalignedValue<ElementType>(
reinterpret_cast<Address>(ptr) + index * sizeof(ElementType), value);
} else {
ptr[index] = value;
}
TSAN_ANNOTATE_IGNORE_WRITES_END;
}

23 changes: 13 additions & 10 deletions deps/v8/src/objects/object-macros-undef.h
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#undef DECL_INT_ACCESSORS
#undef DECL_INT32_ACCESSORS
#undef DECL_UINT16_ACCESSORS
#undef DECL_INT16_ACCESSORS
#undef DECL_UINT8_ACCESSORS
#undef DECL_ACCESSORS
#undef DECL_CAST
@@ -42,6 +43,7 @@
#undef BIT_FIELD_ACCESSORS
#undef INSTANCE_TYPE_CHECKER
#undef TYPE_CHECKER
#undef RELAXED_INT16_ACCESSORS
#undef FIELD_ADDR
#undef READ_FIELD
#undef READ_WEAK_FIELD
@@ -52,6 +54,7 @@
#undef WRITE_WEAK_FIELD
#undef RELEASE_WRITE_FIELD
#undef RELAXED_WRITE_FIELD
#undef RELAXED_WRITE_WEAK_FIELD
#undef WRITE_BARRIER
#undef WEAK_WRITE_BARRIER
#undef CONDITIONAL_WRITE_BARRIER
@@ -60,14 +63,7 @@
#undef WRITE_DOUBLE_FIELD
#undef READ_INT_FIELD
#undef WRITE_INT_FIELD
#undef ACQUIRE_READ_INTPTR_FIELD
#undef RELAXED_READ_INTPTR_FIELD
#undef READ_INTPTR_FIELD
#undef RELEASE_WRITE_INTPTR_FIELD
#undef RELAXED_WRITE_INTPTR_FIELD
#undef WRITE_INTPTR_FIELD
#undef READ_UINTPTR_FIELD
#undef WRITE_UINTPTR_FIELD
#undef ACQUIRE_READ_INT32_FIELD
#undef READ_UINT8_FIELD
#undef WRITE_UINT8_FIELD
#undef RELAXED_WRITE_INT8_FIELD
@@ -78,18 +74,25 @@
#undef WRITE_UINT16_FIELD
#undef READ_INT16_FIELD
#undef WRITE_INT16_FIELD
#undef RELAXED_READ_INT16_FIELD
#undef RELAXED_WRITE_INT16_FIELD
#undef READ_UINT32_FIELD
#undef RELAXED_READ_UINT32_FIELD
#undef WRITE_UINT32_FIELD
#undef RELAXED_WRITE_UINT32_FIELD
#undef READ_INT32_FIELD
#undef RELAXED_READ_INT32_FIELD
#undef WRITE_INT32_FIELD
#undef RELEASE_WRITE_INT32_FIELD
#undef RELAXED_WRITE_INT32_FIELD
#undef READ_FLOAT_FIELD
#undef WRITE_FLOAT_FIELD
#undef READ_INTPTR_FIELD
#undef WRITE_INTPTR_FIELD
#undef READ_UINTPTR_FIELD
#undef WRITE_UINTPTR_FIELD
#undef READ_UINT64_FIELD
#undef WRITE_UINT64_FIELD
#undef READ_INT64_FIELD
#undef WRITE_INT64_FIELD
#undef READ_BYTE_FIELD
#undef RELAXED_READ_BYTE_FIELD
#undef WRITE_BYTE_FIELD
Loading