5#ifndef V8_HANDLES_HANDLES_H_
6#define V8_HANDLES_HANDLES_H_
20#ifdef V8_ENABLE_DIRECT_HANDLE
31#ifdef V8_ENABLE_DIRECT_HANDLE
32class DirectHandleBase;
35class DirectHandleUnchecked;
36class HandleScopeImplementer;
44class OrderedNameDictionary;
46class SmallOrderedHashMap;
47class SmallOrderedHashSet;
48class SmallOrderedNameDictionary;
49class SwissNameDictionary;
50class WasmExportedFunctionData;
51class ZoneAllocationPolicy;
61#ifdef V8_ENABLE_DIRECT_HANDLE
85#ifdef V8_ENABLE_DIRECT_HANDLE
96#ifdef V8_ENABLE_DIRECT_HANDLE
97 friend class DirectHandleBase;
107 template <
typename T>
109 template <
typename T>
112 template <
typename T>
115 template <
typename T>
169 template <
typename S>
188 "This handle does not reference a heap object. Use `(*handle).foo`.");
242 template <
typename To,
typename From>
270 void*
operator new(
size_t size,
void* storage) {
271 return ::operator
new(
size, storage);
275 void*
operator new(
size_t size) =
delete;
276 void operator delete(
void*
size_t) =
delete;
291 static Address current_next_address(
Isolate* isolate);
292 static Address current_limit_address(
Isolate* isolate);
293 static Address current_level_address(
Isolate* isolate);
305 template <
typename T,
template <
typename>
typename HandleType>
307 HandleType<T> CloseAndEscape(HandleType<T> handle_value);
314 static const int kCheckHandleThreshold = 30 * 1024;
321#ifdef V8_ENABLE_CHECKS
322 int scope_level_ = 0;
327 Address* prev_limit);
332#if defined(ENABLE_GLOBAL_HANDLE_ZAPPING) || \
333 defined(ENABLE_LOCAL_HANDLE_ZAPPING)
336 uintptr_t value = kHandleZapValue);
348template <
typename V,
class AllocationPolicy>
366 Address* prev_limit_;
367 int prev_sealed_level_;
381 next = limit =
nullptr;
393#ifdef V8_ENABLE_DIRECT_HANDLE
402#ifdef ENABLE_SLOW_DCHECKS
411 V8_INLINE bool is_identical_to(
const DirectHandleBase& that)
const;
420#ifdef ENABLE_SLOW_DCHECKS
424 V8_INLINE static int NumberOfHandles() {
return number_of_handles_; }
429 ResetNumberOfHandlesScope() : saved_number_of_handles_(number_of_handles_) {
430 number_of_handles_ = 0;
432 ~ResetNumberOfHandlesScope() {
433 number_of_handles_ = saved_number_of_handles_;
437 int saved_number_of_handles_;
446#if defined(ENABLE_SLOW_DCHECKS) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
452 DirectHandleBase& operator=(
const DirectHandleBase&)
V8_NOEXCEPT =
default;
456 V8_INLINE explicit DirectHandleBase(Address
object) :
obj_(
object) {
463 V8_INLINE bool IsDereferenceAllowed()
const {
return true; }
466 DirectHandleBase(Address obj, no_checking_tag do_not_check)
467 : StackAllocated(do_not_check),
obj_(obj) {
477#if defined(ENABLE_SLOW_DCHECKS) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
478 ++number_of_handles_;
483#if defined(ENABLE_SLOW_DCHECKS) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
485 --number_of_handles_;
489#ifdef ENABLE_SLOW_DCHECKS
490 inline static thread_local int number_of_handles_ = 0;
509class DirectHandle :
public DirectHandleBase {
537 template <
typename S,
typename = std::enable_if_t<is_subtype_v<S, T>>>
540 template <
typename S,
typename = std::enable_if_t<is_subtype_v<S, T>>>
556 "This handle does not reference a heap object. Use `(*handle).foo`.");
578 return address() == other.address();
586 void SetValue(Tagged<T> new_value) {
588 obj_ = new_value.ptr();
601 friend class DirectHandleUnchecked<T>;
603 template <
typename To,
typename From>
626 HandleBase::indirect_handle(
handle.address(), isolate));
631 LocalIsolate* isolate) {
634 HandleBase::indirect_handle(
handle.address(), isolate));
639 LocalHeap* local_heap) {
642 HandleBase::indirect_handle(
handle.address(), local_heap));
654#ifdef ENABLE_SLOW_DCHECKS
675 :
handle_(object, local_heap) {}
677 template <
typename S>
679 requires(is_subtype_v<S, T>)
682 template <
typename S>
684 requires(is_subtype_v<S, T>)
712 return handle_.equals(other.handle_);
715 template <
typename S>
717 return handle_.is_identical_to(other);
719 template <
typename S>
721 return handle_.is_identical_to(other.handle_);
735 template <
typename To,
typename From>
737 template <
typename U>
739 template <
typename U>
741 template <
typename U>
744 template <
typename U>
748 : StackAllocated(do_not_check),
handle_() {}
750 no_checking_tag do_not_check)
788#if defined(ENABLE_SLOW_DCHECKS) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
793 DirectHandleUnchecked& operator=(
const DirectHandleUnchecked&)
806#if V8_ENABLE_DIRECT_HANDLE
811class StrongRootAllocator<DirectHandleUnchecked<T>>
812 :
public StrongRootAllocatorBase {
815 static_assert(std::is_standard_layout_v<value_type>);
818 template <
typename HeapOrIsolateT>
820 : StrongRootAllocatorBase(heap_or_isolate) {}
821 template <
typename U>
823 : StrongRootAllocatorBase(other) {}
826 return reinterpret_cast<value_type*
>(allocate_impl(n));
828 void deallocate(
value_type* p,
size_t n)
noexcept {
829 return deallocate_impl(
reinterpret_cast<Address*
>(p), n);
840#ifdef V8_ENABLE_DIRECT_HANDLE
843 template <
typename IsolateT>
844 static allocator_type make_allocator(IsolateT* isolate)
noexcept {
845 return allocator_type(isolate);
848 using vector_type = std::vector<element_type, allocator_type>;
865#ifdef V8_ENABLE_DIRECT_HANDLE
866 template <
typename IsolateT>
868 :
backing_(make_allocator(isolate)) {}
869 template <
typename IsolateT>
871 :
backing_(n, make_allocator(isolate)) {}
872 template <
typename IsolateT>
874 :
backing_(make_allocator(isolate)) {
875 if (init.size() == 0)
return;
880 template <
typename IsolateT>
882 template <
typename IsolateT>
884 template <
typename IsolateT>
887 if (init.size() == 0)
return;
923 template <
typename InputIt>
943 template <
typename... Args>
955 return x.backing_ ==
y.backing_;
959 return x.backing_ !=
y.backing_;
963 return x.backing_ <
y.backing_;
967 return x.backing_ >
y.backing_;
971 return x.backing_ <=
y.backing_;
975 return x.backing_ >=
y.backing_;
982template <
typename T,
size_t kSize>
987#ifdef V8_ENABLE_DIRECT_HANDLE
990 template <
typename IsolateT>
991 static allocator_type make_allocator(IsolateT* isolate)
noexcept {
992 return allocator_type(isolate);
1015#ifdef V8_ENABLE_DIRECT_HANDLE
1016 template <
typename IsolateT>
1018 :
backing_(make_allocator(isolate)) {}
1019 template <
typename IsolateT>
1021 :
backing_(n, make_allocator(isolate)) {}
1022 template <
typename IsolateT>
1024 std::initializer_list<value_type> init)
1025 :
backing_(make_allocator(isolate)) {
1026 if (init.size() == 0)
return;
1031 template <
typename IsolateT>
1033 template <
typename IsolateT>
1035 template <
typename IsolateT>
1037 std::initializer_list<value_type> init)
1039 if (init.size() == 0)
return;
1043 template <
typename IsolateT>
1047 if (init.
size() == 0)
return;
1087 template <
typename... Args>
1101 template <
typename InputIt>
1124template <
typename T,
template <
typename>
typename HandleType>
1130template <
typename T>
1133template <
typename T>
1138#if defined(ENABLE_SLOW_DCHECKS) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
1146template <
typename T>
1148 :
public std::true_type {};
DirectHandle< JSObject > obj_
#define SLOW_DCHECK(condition)
static constexpr no_checking_tag do_not_check
void erase(T *erase_start)
void pop_back(size_t count=1)
T * insert(T *pos, const T &value)
void emplace_back(Args &&... args)
Allocator get_allocator() const
void reserve(size_t new_capacity)
void resize(size_t new_size)
constexpr size_t size() const
constexpr T * begin() const
constexpr T * end() const
iterator insert(const_iterator pos, InputIt first, InputIt last)
void push_back(const_reference x)
const_iterator rend() const noexcept
void emplace_back(Args &&... args)
const_iterator rbegin() const noexcept
iterator insert(const_iterator pos, const_reference value)
auto get_allocator() const
void pop_back(size_t count=1)
iterator rbegin() noexcept
iterator insert(const_iterator pos, std::initializer_list< value_type > init)
value_type * data() noexcept
DirectHandleSmallVector(IsolateT *isolate, size_t n)
iterator begin() noexcept
size_t size() const noexcept
internal::WrappedIterator< const element_type *, const value_type > const_iterator
static constexpr size_t kInlineSize
DirectHandleSmallVector(IsolateT *isolate, std::initializer_list< value_type > init)
bool empty() const noexcept
const_reference back() const
reference & operator[](size_t n)
const_reference front() const
void resize(size_t new_size)
void erase(iterator erase_start)
V8_INLINE DirectHandleSmallVector(base::Vector< const value_type > init)
DirectHandleSmallVector(IsolateT *isolate)
const_reference & operator[](size_t n) const
ptrdiff_t difference_type
const value_type * data() const noexcept
internal::WrappedIterator< element_type *, value_type > iterator
void resize(size_t new_size, const_reference initial_value)
iterator insert(const_iterator pos, size_t count, const_reference value)
const_iterator begin() const noexcept
const_reference at(size_t n) const
const_iterator end() const noexcept
::v8::base::SmallVector< element_type, kSize > vector_type
DirectHandleUnchecked(const Handle< T > &other) V8_NOEXCEPT
DirectHandleUnchecked(const DirectHandle< T > &other) V8_NOEXCEPT
DirectHandleVector< T > & operator=(std::initializer_list< value_type > init)
void swap(DirectHandleVector< T > &other)
iterator insert(const_iterator pos, const DirectHandle< T > &value)
friend bool operator!=(const DirectHandleVector< T > &x, const DirectHandleVector< T > &y)
friend bool operator==(const DirectHandleVector< T > &x, const DirectHandleVector< T > &y)
const DirectHandle< T > & front() const
DirectHandle< T > * data() noexcept
const DirectHandle< T > & back() const
std::vector< element_type > vector_type
internal::WrappedIterator< typename vector_type::const_iterator, const value_type > const_iterator
iterator insert(const_iterator pos, std::initializer_list< DirectHandle< T > > init)
bool empty() const noexcept
DirectHandle< T > & at(size_t n)
iterator insert(const_iterator pos, InputIt first, InputIt last)
DirectHandleVector(IsolateT *isolate)
iterator begin() noexcept
const_iterator begin() const noexcept
DirectHandle< T > & front()
void push_back(const DirectHandle< T > &x)
DirectHandle< T > & operator[](size_t n)
ptrdiff_t difference_type
internal::WrappedIterator< typename vector_type::iterator, value_type > iterator
const_iterator end() const noexcept
friend bool operator<=(const DirectHandleVector< T > &x, const DirectHandleVector< T > &y)
size_t size() const noexcept
const DirectHandle< T > & at(size_t n) const
DirectHandle< T > & back()
const DirectHandle< T > & operator[](size_t n) const
friend bool operator>=(const DirectHandleVector< T > &x, const DirectHandleVector< T > &y)
friend bool operator<(const DirectHandleVector< T > &x, const DirectHandleVector< T > &y)
friend bool operator>(const DirectHandleVector< T > &x, const DirectHandleVector< T > &y)
const DirectHandle< T > * data() const noexcept
void resize(size_t n, const value_type &value)
DirectHandleVector(IsolateT *isolate, size_t n)
void emplace_back(Args &&... args)
DirectHandleVector(IsolateT *isolate, std::initializer_list< value_type > init)
V8_INLINE bool is_null() const
static V8_INLINE const DirectHandle null()
V8_INLINE DirectHandle()=default
V8_INLINE bool is_identical_to(Handle< S > other) const
MaybeDirectHandle< T > MaybeType
V8_INLINE Address address() const
friend class DirectHandle
V8_INLINE DirectHandle(Tagged< T > object, LocalHeap *local_heap)
V8_INLINE void SetValue(Tagged< T > new_value)
V8_INLINE bool equals(DirectHandle< T > other) const
friend class MaybeDirectHandle
friend IndirectHandle< U > indirect_handle(DirectHandle< U >, LocalIsolate *)
friend IndirectHandle< U > indirect_handle(DirectHandle< U >, LocalHeap *)
friend IndirectHandle< U > indirect_handle(DirectHandle< U >)
V8_INLINE DirectHandle(IndirectHandle< S > handle)
V8_INLINE DirectHandle(Tagged< T > object, Isolate *isolate)
V8_INLINE DirectHandle(DirectHandle< S > handle)
DirectHandle(no_checking_tag do_not_check)
V8_INLINE IndirectHandle< T > operator->() const
IndirectHandle< T > handle_
V8_INLINE bool is_identical_to(DirectHandle< S > other) const
V8_INLINE DirectHandle(Tagged< T > object, LocalIsolate *isolate)
static V8_INLINE DirectHandle< T > New(Tagged< T > object, Isolate *isolate)
V8_INLINE Tagged< T > operator*() const
DirectHandle(const DirectHandle< T > &other, no_checking_tag do_not_check)
static V8_INLINE DirectHandle FromSlot(Address *slot)
friend DirectHandle< To > UncheckedCast(DirectHandle< From > value)
friend IndirectHandle< U > indirect_handle(DirectHandle< U >, Isolate *)
V8_INLINE ValueHelper::InternalRepresentationType repr() const
V8_INLINE HandleBase(Address *location)
V8_INLINE bool is_null() const
V8_INLINE Address address() const
V8_INLINE bool is_identical_to(const HandleBase &that) const
V8_INLINE bool IsDereferenceAllowed() const
V8_INLINE ValueHelper::InternalRepresentationType repr() const
V8_INLINE bool is_identical_to(const DirectHandle< T > &that) const
V8_INLINE Address * location() const
HandleScope & operator=(const HandleScope &)=delete
HandleScope(const HandleScope &)=delete
V8_INLINE Handle(Address *location)
bool equals(Handle< T > other) const
V8_INLINE Tagged< T > operator*() const
static V8_INLINE Handle< T > New(Tagged< T > object, Isolate *isolate)
static const Handle< T > null()
V8_INLINE Handle(Handle< S > handle)
friend IndirectHandle< To > UncheckedCast(IndirectHandle< From > value)
V8_INLINE Tagged< T > operator->() const
void PatchValue(Tagged< T > new_value)
SealHandleScope(Isolate *isolate)
~SealHandleScope()=default
StrongRootAllocator(HeapOrIsolateT *)
V8_INLINE constexpr StorageType ptr() const
internal::Address * InternalRepresentationType
static constexpr InternalRepresentationType kEmpty
constexpr const Iterator & base() const noexcept
base::Vector< const DirectHandle< Object > > args
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
constexpr Address kTaggedNullAddress
static constexpr bool is_maybe_weak_v
V8_INLINE IndirectHandle< T > indirect_handle(DirectHandle< T > handle)
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
static constexpr bool is_taggable_v
static constexpr bool is_subtype_v
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
Handle< To > UncheckedCast(Handle< From > value)
constexpr int kSystemPointerSize
Handle< T > IndirectHandle
V8_ENABLE_CONSERVATIVE_STACK_SCANNING_BOOL
static constexpr bool is_direct_handle_v
#define V8_EXPORT_PRIVATE
static constexpr uint32_t kSizeInBytes
V8_INLINE bool operator()(Handle< T > lhs, Handle< T > rhs) const
V8_INLINE size_t operator()(Handle< T > const &handle) const
WasmOrphanedGlobalHandle * handle_