5#ifndef V8_OBJECTS_FIXED_ARRAY_H_
6#define V8_OBJECTS_FIXED_ARRAY_H_
27#include "torque-generated/src/objects/fixed-array-tq.inc"
36template <
class Super,
bool kLengthEqualsCapacity>
70template <
class Shape,
class Super,
typename =
void>
74template <
class Shape,
class Super>
76 Shape, Super,
std::void_t<typename Shape::template ExtraFields<Super>>> {
78 using type =
typename Shape::template ExtraFields<BaseHeader>;
79 static_assert(std::is_base_of<BaseHeader, type>::value);
81template <
class Shape,
class Super>
85#define V8_ARRAY_EXTRA_FIELDS(...) \
86 V8_OBJECT template <typename Super> \
87 struct ExtraFields : public Super __VA_ARGS__ V8_OBJECT_END
91V8_OBJECT template <
class Derived,
class ShapeT,
class Super = HeapObjectLayout>
93 static_assert(std::is_base_of<HeapObjectLayout, Super>::value);
102 template <
typename ElementT>
104 std::is_convertible_v<Smi, ElementT>;
116 std::conditional_t<kElementsAreMaybeObject, MaybeObjectSlot, ObjectSlot>;
129 typename = std::enable_if<kSupportsSmiElements<T>>>
134 typename = std::enable_if<kSupportsSmiElements<T>>>
139 typename = std::enable_if<kSupportsSmiElements<T>>>
144 typename = std::enable_if<kSupportsSmiElements<T>>>
158 int src_index,
int len,
162 int src_index,
int len,
170 static inline constexpr int SizeFor(
int capacity) {
196 template <
class IsolateT>
198 IsolateT* isolate,
int capacity,
199 std::optional<DisallowGarbageCollection>* no_gc_out,
224 template <
class IsolateT>
226 IsolateT* isolate,
int capacity,
240 template <
template <
typename>
typename HandleType>
244 Isolate* isolate, HandleType<FixedArray> array,
int index,
251 template <
template <
typename>
typename HandleType>
255 HandleType<FixedArray> array,
301 TrustedObjectLayout> {
306 template <
class IsolateT>
308 IsolateT* isolate,
int capacity,
334 TrustedObjectLayout> {
341 template <
class IsolateT>
385template <
class Derived,
class ShapeT,
class Super = HeapObjectLayout>
387 static_assert(std::is_base_of<HeapObjectLayout, Super>::value);
407 static inline constexpr int SizeFor(
int length) {
440 template <
class IsolateT>
442 IsolateT* isolate,
int length,
443 std::optional<DisallowGarbageCollection>* no_gc_out,
465 template <
class IsolateT>
467 IsolateT* isolate,
int capacity,
475 inline void set(
int index,
double value);
476#ifdef V8_ENABLE_EXPERIMENTAL_UNDEFINED_DOUBLE
477 inline void set_undefined(
int index);
478 inline bool is_undefined(
int index);
514 template <
class IsolateT>
516 IsolateT* isolate,
int capacity,
523 class BodyDescriptor;
531 RootIndex::kTrustedWeakFixedArrayMap;
537 :
public TaggedArrayBase<TrustedWeakFixedArray, TrustedWeakFixedArrayShape,
538 TrustedObjectLayout> {
543 template <
class IsolateT>
558 RootIndex::kProtectedWeakFixedArrayMap;
566 ProtectedWeakFixedArrayShape,
567 TrustedObjectLayout> {
573 template <
class IsolateT>
588 :
public TorqueGeneratedWeakArrayList<WeakArrayList, HeapObject> {
628 return SizeFor(capacity);
632 return length + std::max(length / 2, 2);
646 class BodyDescriptor;
717 template <
class IsolateT>
719 IsolateT* isolate,
int capacity,
722 inline int length()
const;
772 template <
class IsolateT>
774 IsolateT* isolate,
int capacity,
785 return size_in_bytes -
sizeof(
Header);
791 class BodyDescriptor;
806 TrustedObjectLayout> {
813 template <
class IsolateT>
815 IsolateT* isolate,
int capacity,
826 return size_in_bytes -
sizeof(
Header);
832 class BodyDescriptor;
838template <
typename T,
typename Base>
840 static_assert(std::is_integral<T>::value);
844 template <
typename... MoreArgs>
847 MoreArgs&&... more_args);
850 T
get(
int index)
const;
851 void set(
int index, T value);
855 return sizeof(
typename Base::Header) + index *
sizeof(T);
858 inline int length()
const;
877template <
typename Base>
887 template <
typename... MoreArgs>
889 Isolate* isolate,
int length, MoreArgs&&... more_args);
896template <
class T,
class Super>
900 MemCopy(
result, &this->values()[index *
sizeof(T)], length *
sizeof(T));
903 void copy_in(
int index,
const T* buffer,
int length) {
904 MemCopy(&this->values()[index *
sizeof(T)], buffer, length *
sizeof(T));
909 return memcmp(this->begin(), buffer, length *
sizeof(T)) == 0;
915 return memcmp(this->begin() +
sizeof(T) *
offset, buffer,
916 length *
sizeof(T)) == 0;
925 void set(
int index,
const T& value) {
copy_in(index, &value, 1); }
927 inline int length()
const;
934class PodArray :
public PodArrayBase<T, ByteArray> {
940 LocalIsolate* isolate,
int length,
#define DISALLOW_GARBAGE_COLLECTION(name)
static constexpr bool kLengthEqualsCapacity
V8_ARRAY_EXTRA_FIELDS({ TaggedMember< Smi > length_;})
static constexpr RootIndex kMapRootIndex
static V8_EXPORT_PRIVATE DirectHandle< ArrayList > Add(Isolate *isolate, DirectHandle< ArrayList > array, Tagged< Smi > obj, AllocationType allocation=AllocationType::kYoung)
static V8_EXPORT_PRIVATE DirectHandle< FixedArray > ToFixedArray(Isolate *isolate, DirectHandle< ArrayList > array, AllocationType allocation=AllocationType::kYoung)
static DirectHandle< ArrayList > EnsureSpace(Isolate *isolate, DirectHandle< ArrayList > array, int length, AllocationType allocation=AllocationType::kYoung)
void set_length(int value)
void RightTrim(Isolate *isolate, int new_capacity)
static DirectHandle< ArrayList > New(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
static constexpr int kElementSize
static constexpr RootIndex kMapRootIndex
static constexpr bool kLengthEqualsCapacity
static Handle< ByteArray > New(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
uint32_t get_int(int offset) const
static constexpr int LengthFor(int size_in_bytes)
void set_int(int offset, uint32_t value)
void set_sandboxed_pointer(int index, Address value)
static DirectHandle< FixedAddressArrayBase > New(Isolate *isolate, int length, MoreArgs &&... more_args)
Address get_sandboxed_pointer(int index) const
V8_EXPORT_PRIVATE bool IsCowArray() const
static constexpr int kMaxRegularLength
static int GetMaxLengthForNewSpaceAllocation(ElementsKind kind)
static constexpr int kHeaderSize
static constexpr int kMaxLength
static constexpr int kLengthOffset
V8_EXPORT_PRIVATE void RightTrim(Isolate *isolate, int new_capacity)
static constexpr int kMaxLength
static HandleType< FixedArray > RightTrimOrEmpty(Isolate *isolate, HandleType< FixedArray > array, int new_length)
static constexpr int kMaxRegularLength
static Handle< FixedArray > New(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
static V8_EXPORT_PRIVATE HandleType< FixedArray > SetAndGrow(Isolate *isolate, HandleType< FixedArray > array, int index, DirectHandle< Object > value)
void CopyElements(Isolate *isolate, int dst_index, Tagged< FixedArray > src, int src_index, int len, WriteBarrierMode mode)
void FillWithHoles(int from, int to)
static Handle< FixedArray > Resize(Isolate *isolate, DirectHandle< FixedArray > xs, int new_capacity, AllocationType allocation=AllocationType::kYoung, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
void set_the_hole(Isolate *isolate, int index)
void MoveElements(Isolate *isolate, int dst_index, int src_index, int len, WriteBarrierMode mode)
bool is_the_hole(Isolate *isolate, int index)
static constexpr RootIndex kMapRootIndex
void set_the_hole(Isolate *isolate, int index)
bool is_the_hole(Isolate *isolate, int index)
uint64_t get_representation(int index)
void set(int index, double value)
static Handle< Object > get(Tagged< FixedDoubleArray > array, int index, Isolate *isolate)
void MoveElements(Isolate *isolate, int dst_index, int src_index, int len, WriteBarrierMode)
double get_scalar(int index)
static Handle< FixedArrayBase > New(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
void FillWithHoles(int from, int to)
void set(int index, T value)
Address get_element_address(int index) const
static constexpr int OffsetOfElementAt(int index)
static Handle< FixedIntegerArrayBase< T, Base > > New(Isolate *isolate, int length, MoreArgs &&... more_args)
static constexpr int kHeaderSize
static const int kFixedArrayHeaderSize
void copy_in(int index, const T *buffer, int length)
bool matches(int offset, const T *buffer, int length)
bool matches(const T *buffer, int length)
void set(int index, const T &value)
void copy_out(int index, T *result, int length)
static Handle< PodArray< T > > New(Isolate *isolate, int length, AllocationType allocation=AllocationType::kYoung)
int AllocatedSize() const
static constexpr int kMaxLength
static constexpr int kElementSize
static constexpr bool kElementsAreMaybeObject
static Tagged< Derived > FromAddressOfFirstElement(Address address)
static constexpr int kMaxRegularLength
static constexpr int OffsetOfElementAt(int index)
static constexpr int SizeFor(int length)
typename ShapeT::ElementT ElementT
void set(int index, ElementMemberT value)
ElementMemberT get(int index) const
std::conditional_t< std::is_same_v< ElementT, double >, UnalignedDoubleMember, ElementT > ElementMemberT
detail::ArrayHeaderBase< Super, true > Header
static Handle< Derived > Allocate(IsolateT *isolate, int length, std::optional< DisallowGarbageCollection > *no_gc_out, AllocationType allocation=AllocationType::kYoung)
bool IsInBounds(int index) const
FLEXIBLE_ARRAY_MEMBER(ElementMemberT, values)
static constexpr RootIndex kMapRootIndex
static constexpr bool kLengthEqualsCapacity
static constexpr int kMaxRegularLength
static constexpr int kMaxLength
static Handle< ProtectedFixedArray > New(IsolateT *isolate, int capacity)
static constexpr RootIndex kMapRootIndex
static constexpr bool kLengthEqualsCapacity
static Handle< ProtectedWeakFixedArray > New(IsolateT *isolate, int capacity)
static bool constexpr IsValid(T value)
static Handle< Derived > Allocate(IsolateT *isolate, int capacity, std::optional< DisallowGarbageCollection > *no_gc_out, AllocationType allocation=AllocationType::kYoung)
void RightTrim(Isolate *isolate, int new_capacity)
FLEXIBLE_ARRAY_MEMBER(ElementMemberT, objects)
Tagged< ElementT > compare_and_swap(int index, Tagged< ElementT > expected, Tagged< ElementT > value, SeqCstAccessTag, WriteBarrierMode mode=kDefaultMode)
SlotType RawFieldOfElementAt(int index) const
static constexpr bool kSupportsSmiElements
detail::TaggedArrayHeader< ShapeT, Super > Header
static void CopyElements(Isolate *isolate, Tagged< Derived > dst, int dst_index, Tagged< Derived > src, int src_index, int len, WriteBarrierMode mode=kDefaultMode)
Tagged< ElementT > swap(int index, Tagged< ElementT > value, SeqCstAccessTag, WriteBarrierMode mode=kDefaultMode)
int AllocatedSize() const
std::conditional_t< kElementsAreMaybeObject, MaybeObjectSlot, ObjectSlot > SlotType
typename ShapeT::ElementT ElementT
void set(int index, Tagged< ElementT > value, WriteBarrierMode mode=kDefaultMode)
static constexpr int OffsetOfElementAt(int index)
bool IsInBounds(int index) const
static void MoveElements(Isolate *isolate, Tagged< Derived > dst, int dst_index, Tagged< Derived > src, int src_index, int len, WriteBarrierMode mode=kDefaultMode)
static constexpr WriteBarrierMode kDefaultMode
static constexpr int kMaxRegularCapacity
static constexpr bool kElementsAreMaybeObject
static constexpr int kMaxCapacity
SlotType RawFieldOfFirstElement() const
static constexpr int kElementSize
Tagged< ElementT > get(int index) const
static constexpr int NewCapacityForIndex(int index, int old_capacity)
static constexpr int SizeFor(int capacity)
static constexpr RootIndex kMapRootIndex
static constexpr bool kLengthEqualsCapacity
static constexpr bool kLengthEqualsCapacity
static constexpr RootIndex kMapRootIndex
static constexpr bool kLengthEqualsCapacity
static constexpr int kElementSize
static constexpr RootIndex kMapRootIndex
void set_int(int offset, uint32_t value)
uint32_t get_int(int offset) const
static Handle< TrustedByteArray > New(IsolateT *isolate, int capacity, AllocationType allocation_type=AllocationType::kTrusted)
static constexpr int LengthFor(int size_in_bytes)
static Handle< TrustedFixedArray > New(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kTrusted)
static constexpr int kMaxLength
static constexpr int kMaxRegularLength
static DirectHandle< TrustedPodArray< T > > New(Isolate *isolate, int length)
static constexpr RootIndex kMapRootIndex
static constexpr bool kLengthEqualsCapacity
static Handle< TrustedWeakFixedArray > New(IsolateT *isolate, int capacity)
Iterator & operator=(const Iterator &)=delete
Iterator(Tagged< WeakArrayList > array)
Iterator(const Iterator &)=delete
Tagged< HeapObject > Next()
Tagged< WeakArrayList > array_
static int OffsetOfElementAt(int index)
int CountLiveElements() const
V8_EXPORT_PRIVATE bool Contains(Tagged< MaybeObject > value)
static Handle< WeakArrayList > EnsureSpace(Isolate *isolate, Handle< WeakArrayList > array, int length, AllocationType allocation=AllocationType::kYoung)
void CopyElements(Isolate *isolate, int dst_index, Tagged< WeakArrayList > src, int src_index, int len, WriteBarrierMode mode)
V8_EXPORT_PRIVATE bool IsFull() const
static constexpr int SizeForCapacity(int capacity)
V8_EXPORT_PRIVATE bool RemoveOne(MaybeObjectDirectHandle value)
int CountLiveWeakReferences() const
Tagged< MaybeObject > get(int index) const
static V8_WARN_UNUSED_RESULT DirectHandle< WeakArrayList > Append(Isolate *isolate, DirectHandle< WeakArrayList > array, MaybeObjectDirectHandle value, AllocationType allocation=AllocationType::kYoung)
void Set(int index, Tagged< MaybeObject > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
static constexpr int kMaxCapacity
MaybeObjectSlot data_start()
NEVER_READ_ONLY_SPACE static V8_EXPORT_PRIVATE Handle< WeakArrayList > AddToEnd(Isolate *isolate, Handle< WeakArrayList > array, MaybeObjectDirectHandle value)
static constexpr int CapacityForLength(int length)
V8_EXPORT_PRIVATE void Compact(Isolate *isolate)
Tagged< MaybeObject > Get(int index) const
int AllocatedSize() const
static constexpr bool kLengthEqualsCapacity
static constexpr RootIndex kMapRootIndex
static Handle< WeakFixedArray > New(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung, MaybeDirectHandle< Object > initial_value={})
#define OBJECT_POINTER_ALIGN(value)
#define V8_LOWER_LIMITS_MODE_BOOL
DisallowGarbageCollection no_gc_
ZoneVector< RpoNumber > & result
typename TaggedArrayHeaderHelper< Shape, Super >::type TaggedArrayHeader
v8::internal::detail::ArrayHeaderBase< Super, false > V8_OBJECT_END
constexpr int kTaggedSize
constexpr int kMaxRegularHeapObjectSize
static constexpr bool is_maybe_weak_v
static constexpr bool is_subtype_v
v8::internal::LoadHandler V8_OBJECT_END
MaybeWeak< Object > MaybeObject
void MemCopy(void *dest, const void *src, size_t size)
V8HeapCompressionScheme TrustedSpaceCompressionScheme
V8HeapCompressionSchemeImpl< MainCage > V8HeapCompressionScheme
static constexpr int kMaxFixedArrayCapacity
#define DECL_VERIFIER(Name)
#define NEVER_READ_ONLY_SPACE
#define DECL_PRINTER(Name)
#define TQ_OBJECT_CONSTRUCTORS(Type)
#define DCHECK_LE(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define V8_EXPORT_PRIVATE
constexpr bool IsAligned(T value, U alignment)
#define V8_WARN_UNUSED_RESULT