11cb0ef41Sopenharmony_ci// Copyright 2017 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_FIXED_ARRAY_H_
61cb0ef41Sopenharmony_ci#define V8_OBJECTS_FIXED_ARRAY_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/handles/maybe-handles.h"
91cb0ef41Sopenharmony_ci#include "src/objects/instance-type.h"
101cb0ef41Sopenharmony_ci#include "src/objects/objects.h"
111cb0ef41Sopenharmony_ci#include "src/objects/smi.h"
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards):
141cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cinamespace v8 {
171cb0ef41Sopenharmony_cinamespace internal {
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci#define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V)    \
201cb0ef41Sopenharmony_ci  V(BYTECODE_ARRAY_CONSTANT_POOL_SUB_TYPE)       \
211cb0ef41Sopenharmony_ci  V(BYTECODE_ARRAY_HANDLER_TABLE_SUB_TYPE)       \
221cb0ef41Sopenharmony_ci  V(CODE_STUBS_TABLE_SUB_TYPE)                   \
231cb0ef41Sopenharmony_ci  V(COMPILATION_CACHE_TABLE_SUB_TYPE)            \
241cb0ef41Sopenharmony_ci  V(CONTEXT_SUB_TYPE)                            \
251cb0ef41Sopenharmony_ci  V(COPY_ON_WRITE_SUB_TYPE)                      \
261cb0ef41Sopenharmony_ci  V(DEOPTIMIZATION_DATA_SUB_TYPE)                \
271cb0ef41Sopenharmony_ci  V(DESCRIPTOR_ARRAY_SUB_TYPE)                   \
281cb0ef41Sopenharmony_ci  V(EMBEDDED_OBJECT_SUB_TYPE)                    \
291cb0ef41Sopenharmony_ci  V(ENUM_CACHE_SUB_TYPE)                         \
301cb0ef41Sopenharmony_ci  V(ENUM_INDICES_CACHE_SUB_TYPE)                 \
311cb0ef41Sopenharmony_ci  V(DEPENDENT_CODE_SUB_TYPE)                     \
321cb0ef41Sopenharmony_ci  V(DICTIONARY_ELEMENTS_SUB_TYPE)                \
331cb0ef41Sopenharmony_ci  V(DICTIONARY_PROPERTIES_SUB_TYPE)              \
341cb0ef41Sopenharmony_ci  V(EMPTY_PROPERTIES_DICTIONARY_SUB_TYPE)        \
351cb0ef41Sopenharmony_ci  V(PACKED_ELEMENTS_SUB_TYPE)                    \
361cb0ef41Sopenharmony_ci  V(FAST_PROPERTIES_SUB_TYPE)                    \
371cb0ef41Sopenharmony_ci  V(FAST_TEMPLATE_INSTANTIATIONS_CACHE_SUB_TYPE) \
381cb0ef41Sopenharmony_ci  V(HANDLER_TABLE_SUB_TYPE)                      \
391cb0ef41Sopenharmony_ci  V(JS_COLLECTION_SUB_TYPE)                      \
401cb0ef41Sopenharmony_ci  V(JS_WEAK_COLLECTION_SUB_TYPE)                 \
411cb0ef41Sopenharmony_ci  V(NOSCRIPT_SHARED_FUNCTION_INFOS_SUB_TYPE)     \
421cb0ef41Sopenharmony_ci  V(NUMBER_STRING_CACHE_SUB_TYPE)                \
431cb0ef41Sopenharmony_ci  V(OBJECT_TO_CODE_SUB_TYPE)                     \
441cb0ef41Sopenharmony_ci  V(OPTIMIZED_CODE_LITERALS_SUB_TYPE)            \
451cb0ef41Sopenharmony_ci  V(OPTIMIZED_CODE_MAP_SUB_TYPE)                 \
461cb0ef41Sopenharmony_ci  V(PROTOTYPE_USERS_SUB_TYPE)                    \
471cb0ef41Sopenharmony_ci  V(REGEXP_MULTIPLE_CACHE_SUB_TYPE)              \
481cb0ef41Sopenharmony_ci  V(RETAINED_MAPS_SUB_TYPE)                      \
491cb0ef41Sopenharmony_ci  V(SCOPE_INFO_SUB_TYPE)                         \
501cb0ef41Sopenharmony_ci  V(SCRIPT_LIST_SUB_TYPE)                        \
511cb0ef41Sopenharmony_ci  V(SERIALIZED_OBJECTS_SUB_TYPE)                 \
521cb0ef41Sopenharmony_ci  V(SHARED_FUNCTION_INFOS_SUB_TYPE)              \
531cb0ef41Sopenharmony_ci  V(SINGLE_CHARACTER_STRING_CACHE_SUB_TYPE)      \
541cb0ef41Sopenharmony_ci  V(SLOW_TEMPLATE_INSTANTIATIONS_CACHE_SUB_TYPE) \
551cb0ef41Sopenharmony_ci  V(STRING_SPLIT_CACHE_SUB_TYPE)                 \
561cb0ef41Sopenharmony_ci  V(TEMPLATE_INFO_SUB_TYPE)                      \
571cb0ef41Sopenharmony_ci  V(FEEDBACK_METADATA_SUB_TYPE)                  \
581cb0ef41Sopenharmony_ci  V(WEAK_NEW_SPACE_OBJECT_TO_CODE_SUB_TYPE)
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_cienum FixedArraySubInstanceType {
611cb0ef41Sopenharmony_ci#define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name,
621cb0ef41Sopenharmony_ci  FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE)
631cb0ef41Sopenharmony_ci#undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE
641cb0ef41Sopenharmony_ci      LAST_FIXED_ARRAY_SUB_TYPE = WEAK_NEW_SPACE_OBJECT_TO_CODE_SUB_TYPE
651cb0ef41Sopenharmony_ci};
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/fixed-array-tq.inc"
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci// Common superclass for FixedArrays that allow implementations to share
701cb0ef41Sopenharmony_ci// common accessors and some code paths.
711cb0ef41Sopenharmony_ciclass FixedArrayBase
721cb0ef41Sopenharmony_ci    : public TorqueGeneratedFixedArrayBase<FixedArrayBase, HeapObject> {
731cb0ef41Sopenharmony_ci public:
741cb0ef41Sopenharmony_ci  // Forward declare the non-atomic (set_)length defined in torque.
751cb0ef41Sopenharmony_ci  using TorqueGeneratedFixedArrayBase::length;
761cb0ef41Sopenharmony_ci  using TorqueGeneratedFixedArrayBase::set_length;
771cb0ef41Sopenharmony_ci  DECL_RELEASE_ACQUIRE_INT_ACCESSORS(length)
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci  inline Object unchecked_length(AcquireLoadTag) const;
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci  static int GetMaxLengthForNewSpaceAllocation(ElementsKind kind);
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE bool IsCowArray() const;
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci  // Maximal allowed size, in bytes, of a single FixedArrayBase.
861cb0ef41Sopenharmony_ci  // Prevents overflowing size computations, as well as extreme memory
871cb0ef41Sopenharmony_ci  // consumption. It's either (512Mb - kTaggedSize) or (1024Mb - kTaggedSize).
881cb0ef41Sopenharmony_ci  // -kTaggedSize is here to ensure that this max size always fits into Smi
891cb0ef41Sopenharmony_ci  // which is necessary for being able to create a free space filler for the
901cb0ef41Sopenharmony_ci  // whole array of kMaxSize.
911cb0ef41Sopenharmony_ci  static const int kMaxSize = 128 * kTaggedSize * MB - kTaggedSize;
921cb0ef41Sopenharmony_ci  STATIC_ASSERT(Smi::IsValid(kMaxSize));
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci protected:
951cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(FixedArrayBase)
961cb0ef41Sopenharmony_ci  inline FixedArrayBase(Address ptr,
971cb0ef41Sopenharmony_ci                        HeapObject::AllowInlineSmiStorage allow_smi);
981cb0ef41Sopenharmony_ci};
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci// FixedArray describes fixed-sized arrays with element type Object.
1011cb0ef41Sopenharmony_ciclass FixedArray
1021cb0ef41Sopenharmony_ci    : public TorqueGeneratedFixedArray<FixedArray, FixedArrayBase> {
1031cb0ef41Sopenharmony_ci public:
1041cb0ef41Sopenharmony_ci  // Setter and getter for elements.
1051cb0ef41Sopenharmony_ci  inline Object get(int index) const;
1061cb0ef41Sopenharmony_ci  inline Object get(PtrComprCageBase cage_base, int index) const;
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci  static inline Handle<Object> get(FixedArray array, int index,
1091cb0ef41Sopenharmony_ci                                   Isolate* isolate);
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ci  // Return a grown copy if the index is bigger than the array's length.
1121cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static Handle<FixedArray> SetAndGrow(
1131cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<FixedArray> array, int index,
1141cb0ef41Sopenharmony_ci      Handle<Object> value);
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_ci  // Relaxed accessors.
1171cb0ef41Sopenharmony_ci  inline Object get(int index, RelaxedLoadTag) const;
1181cb0ef41Sopenharmony_ci  inline Object get(PtrComprCageBase cage_base, int index,
1191cb0ef41Sopenharmony_ci                    RelaxedLoadTag) const;
1201cb0ef41Sopenharmony_ci  inline void set(int index, Object value, RelaxedStoreTag,
1211cb0ef41Sopenharmony_ci                  WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
1221cb0ef41Sopenharmony_ci  inline void set(int index, Smi value, RelaxedStoreTag);
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci  // Acquire/release accessors.
1251cb0ef41Sopenharmony_ci  inline Object get(int index, AcquireLoadTag) const;
1261cb0ef41Sopenharmony_ci  inline Object get(PtrComprCageBase cage_base, int index,
1271cb0ef41Sopenharmony_ci                    AcquireLoadTag) const;
1281cb0ef41Sopenharmony_ci  inline void set(int index, Object value, ReleaseStoreTag,
1291cb0ef41Sopenharmony_ci                  WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
1301cb0ef41Sopenharmony_ci  inline void set(int index, Smi value, ReleaseStoreTag);
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ci  // Setter that uses write barrier.
1331cb0ef41Sopenharmony_ci  inline void set(int index, Object value);
1341cb0ef41Sopenharmony_ci  inline bool is_the_hole(Isolate* isolate, int index);
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci  // Setter that doesn't need write barrier.
1371cb0ef41Sopenharmony_ci#if !defined(_WIN32) || (defined(_WIN64) && _MSC_VER < 1930 && __cplusplus < 201703L)
1381cb0ef41Sopenharmony_ci  inline void set(int index, Smi value);
1391cb0ef41Sopenharmony_ci#else
1401cb0ef41Sopenharmony_ci  inline void set(int index, Smi value) {
1411cb0ef41Sopenharmony_ci#if !defined(_WIN32)
1421cb0ef41Sopenharmony_ci    DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
1431cb0ef41Sopenharmony_ci#endif
1441cb0ef41Sopenharmony_ci    DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
1451cb0ef41Sopenharmony_ci    DCHECK(Object(value).IsSmi());
1461cb0ef41Sopenharmony_ci    int offset = OffsetOfElementAt(index);
1471cb0ef41Sopenharmony_ci    RELAXED_WRITE_FIELD(*this, offset, value);
1481cb0ef41Sopenharmony_ci  }
1491cb0ef41Sopenharmony_ci#endif
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci  // Setter with explicit barrier mode.
1521cb0ef41Sopenharmony_ci  inline void set(int index, Object value, WriteBarrierMode mode);
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ci  // Setters for frequently used oddballs located in old space.
1551cb0ef41Sopenharmony_ci  inline void set_undefined(int index);
1561cb0ef41Sopenharmony_ci  inline void set_undefined(Isolate* isolate, int index);
1571cb0ef41Sopenharmony_ci  inline void set_undefined(ReadOnlyRoots ro_roots, int index);
1581cb0ef41Sopenharmony_ci  inline void set_null(int index);
1591cb0ef41Sopenharmony_ci  inline void set_null(Isolate* isolate, int index);
1601cb0ef41Sopenharmony_ci  inline void set_null(ReadOnlyRoots ro_roots, int index);
1611cb0ef41Sopenharmony_ci  inline void set_the_hole(int index);
1621cb0ef41Sopenharmony_ci  inline void set_the_hole(Isolate* isolate, int index);
1631cb0ef41Sopenharmony_ci  inline void set_the_hole(ReadOnlyRoots ro_roots, int index);
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci  inline ObjectSlot GetFirstElementAddress();
1661cb0ef41Sopenharmony_ci  inline bool ContainsOnlySmisOrHoles();
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_ci  // Gives access to raw memory which stores the array's data.
1691cb0ef41Sopenharmony_ci  inline ObjectSlot data_start();
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci  inline void MoveElements(Isolate* isolate, int dst_index, int src_index,
1721cb0ef41Sopenharmony_ci                           int len, WriteBarrierMode mode);
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_ci  inline void CopyElements(Isolate* isolate, int dst_index, FixedArray src,
1751cb0ef41Sopenharmony_ci                           int src_index, int len, WriteBarrierMode mode);
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_ci  inline void FillWithHoles(int from, int to);
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_ci  // Shrink the array and insert filler objects. {new_length} must be > 0.
1801cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE void Shrink(Isolate* isolate, int new_length);
1811cb0ef41Sopenharmony_ci  // If {new_length} is 0, return the canonical empty FixedArray. Otherwise
1821cb0ef41Sopenharmony_ci  // like above.
1831cb0ef41Sopenharmony_ci  static Handle<FixedArray> ShrinkOrEmpty(Isolate* isolate,
1841cb0ef41Sopenharmony_ci                                          Handle<FixedArray> array,
1851cb0ef41Sopenharmony_ci                                          int new_length);
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci  // Copy a sub array from the receiver to dest.
1881cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE void CopyTo(int pos, FixedArray dest, int dest_pos,
1891cb0ef41Sopenharmony_ci                                int len) const;
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ci  // Garbage collection support.
1921cb0ef41Sopenharmony_ci  static constexpr int SizeFor(int length) {
1931cb0ef41Sopenharmony_ci    return kHeaderSize + length * kTaggedSize;
1941cb0ef41Sopenharmony_ci  }
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ci  // Code Generation support.
1971cb0ef41Sopenharmony_ci  static constexpr int OffsetOfElementAt(int index) {
1981cb0ef41Sopenharmony_ci    STATIC_ASSERT(kObjectsOffset == SizeFor(0));
1991cb0ef41Sopenharmony_ci    return SizeFor(index);
2001cb0ef41Sopenharmony_ci  }
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ci  // Garbage collection support.
2031cb0ef41Sopenharmony_ci  inline ObjectSlot RawFieldOfElementAt(int index);
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci  // Maximally allowed length of a FixedArray.
2061cb0ef41Sopenharmony_ci  static const int kMaxLength = (kMaxSize - kHeaderSize) / kTaggedSize;
2071cb0ef41Sopenharmony_ci  static_assert(Internals::IsValidSmi(kMaxLength),
2081cb0ef41Sopenharmony_ci                "FixedArray maxLength not a Smi");
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ci  // Maximally allowed length for regular (non large object space) object.
2111cb0ef41Sopenharmony_ci  STATIC_ASSERT(kMaxRegularHeapObjectSize < kMaxSize);
2121cb0ef41Sopenharmony_ci  static const int kMaxRegularLength =
2131cb0ef41Sopenharmony_ci      (kMaxRegularHeapObjectSize - kHeaderSize) / kTaggedSize;
2141cb0ef41Sopenharmony_ci
2151cb0ef41Sopenharmony_ci  // Dispatched behavior.
2161cb0ef41Sopenharmony_ci  DECL_PRINTER(FixedArray)
2171cb0ef41Sopenharmony_ci  DECL_VERIFIER(FixedArray)
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci  int AllocatedSize();
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_ci  class BodyDescriptor;
2221cb0ef41Sopenharmony_ci
2231cb0ef41Sopenharmony_ci  static constexpr int kObjectsOffset = kHeaderSize;
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ci protected:
2261cb0ef41Sopenharmony_ci  // Set operation on FixedArray without using write barriers. Can
2271cb0ef41Sopenharmony_ci  // only be used for storing old space objects or smis.
2281cb0ef41Sopenharmony_ci  static inline void NoWriteBarrierSet(FixedArray array, int index,
2291cb0ef41Sopenharmony_ci                                       Object value);
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ci private:
2321cb0ef41Sopenharmony_ci  STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize);
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(FixedArray)
2351cb0ef41Sopenharmony_ci};
2361cb0ef41Sopenharmony_ci
2371cb0ef41Sopenharmony_ci// FixedArray alias added only because of IsFixedArrayExact() predicate, which
2381cb0ef41Sopenharmony_ci// checks for the exact instance type FIXED_ARRAY_TYPE instead of a range
2391cb0ef41Sopenharmony_ci// check: [FIRST_FIXED_ARRAY_TYPE, LAST_FIXED_ARRAY_TYPE].
2401cb0ef41Sopenharmony_ciclass FixedArrayExact final : public FixedArray {};
2411cb0ef41Sopenharmony_ci
2421cb0ef41Sopenharmony_ci// FixedDoubleArray describes fixed-sized arrays with element type double.
2431cb0ef41Sopenharmony_ciclass FixedDoubleArray
2441cb0ef41Sopenharmony_ci    : public TorqueGeneratedFixedDoubleArray<FixedDoubleArray, FixedArrayBase> {
2451cb0ef41Sopenharmony_ci public:
2461cb0ef41Sopenharmony_ci  // Setter and getter for elements.
2471cb0ef41Sopenharmony_ci  inline double get_scalar(int index);
2481cb0ef41Sopenharmony_ci  inline uint64_t get_representation(int index);
2491cb0ef41Sopenharmony_ci  static inline Handle<Object> get(FixedDoubleArray array, int index,
2501cb0ef41Sopenharmony_ci                                   Isolate* isolate);
2511cb0ef41Sopenharmony_ci  inline void set(int index, double value);
2521cb0ef41Sopenharmony_ci  inline void set_the_hole(Isolate* isolate, int index);
2531cb0ef41Sopenharmony_ci  inline void set_the_hole(int index);
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_ci  // Checking for the hole.
2561cb0ef41Sopenharmony_ci  inline bool is_the_hole(Isolate* isolate, int index);
2571cb0ef41Sopenharmony_ci  inline bool is_the_hole(int index);
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci  // Garbage collection support.
2601cb0ef41Sopenharmony_ci  inline static int SizeFor(int length) {
2611cb0ef41Sopenharmony_ci    return kHeaderSize + length * kDoubleSize;
2621cb0ef41Sopenharmony_ci  }
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci  inline void MoveElements(Isolate* isolate, int dst_index, int src_index,
2651cb0ef41Sopenharmony_ci                           int len, WriteBarrierMode mode);
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ci  inline void FillWithHoles(int from, int to);
2681cb0ef41Sopenharmony_ci
2691cb0ef41Sopenharmony_ci  // Code Generation support.
2701cb0ef41Sopenharmony_ci  static int OffsetOfElementAt(int index) { return SizeFor(index); }
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ci  // Start offset of elements.
2731cb0ef41Sopenharmony_ci  static constexpr int kFloatsOffset = kHeaderSize;
2741cb0ef41Sopenharmony_ci
2751cb0ef41Sopenharmony_ci  // Maximally allowed length of a FixedDoubleArray.
2761cb0ef41Sopenharmony_ci  static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
2771cb0ef41Sopenharmony_ci  static_assert(Internals::IsValidSmi(kMaxLength),
2781cb0ef41Sopenharmony_ci                "FixedDoubleArray maxLength not a Smi");
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci  // Dispatched behavior.
2811cb0ef41Sopenharmony_ci  DECL_PRINTER(FixedDoubleArray)
2821cb0ef41Sopenharmony_ci  DECL_VERIFIER(FixedDoubleArray)
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ci  class BodyDescriptor;
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(FixedDoubleArray)
2871cb0ef41Sopenharmony_ci};
2881cb0ef41Sopenharmony_ci
2891cb0ef41Sopenharmony_ci// WeakFixedArray describes fixed-sized arrays with element type
2901cb0ef41Sopenharmony_ci// MaybeObject.
2911cb0ef41Sopenharmony_ciclass WeakFixedArray
2921cb0ef41Sopenharmony_ci    : public TorqueGeneratedWeakFixedArray<WeakFixedArray, HeapObject> {
2931cb0ef41Sopenharmony_ci public:
2941cb0ef41Sopenharmony_ci  inline MaybeObject Get(int index) const;
2951cb0ef41Sopenharmony_ci  inline MaybeObject Get(PtrComprCageBase cage_base, int index) const;
2961cb0ef41Sopenharmony_ci
2971cb0ef41Sopenharmony_ci  inline void Set(
2981cb0ef41Sopenharmony_ci      int index, MaybeObject value,
2991cb0ef41Sopenharmony_ci      WriteBarrierMode mode = WriteBarrierMode::UPDATE_WRITE_BARRIER);
3001cb0ef41Sopenharmony_ci
3011cb0ef41Sopenharmony_ci  static inline Handle<WeakFixedArray> EnsureSpace(Isolate* isolate,
3021cb0ef41Sopenharmony_ci                                                   Handle<WeakFixedArray> array,
3031cb0ef41Sopenharmony_ci                                                   int length);
3041cb0ef41Sopenharmony_ci
3051cb0ef41Sopenharmony_ci  // Forward declare the non-atomic (set_)length defined in torque.
3061cb0ef41Sopenharmony_ci  using TorqueGeneratedWeakFixedArray::length;
3071cb0ef41Sopenharmony_ci  using TorqueGeneratedWeakFixedArray::set_length;
3081cb0ef41Sopenharmony_ci  DECL_RELEASE_ACQUIRE_INT_ACCESSORS(length)
3091cb0ef41Sopenharmony_ci
3101cb0ef41Sopenharmony_ci  // Gives access to raw memory which stores the array's data.
3111cb0ef41Sopenharmony_ci  inline MaybeObjectSlot data_start();
3121cb0ef41Sopenharmony_ci
3131cb0ef41Sopenharmony_ci  inline MaybeObjectSlot RawFieldOfElementAt(int index);
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_ci  inline void CopyElements(Isolate* isolate, int dst_index, WeakFixedArray src,
3161cb0ef41Sopenharmony_ci                           int src_index, int len, WriteBarrierMode mode);
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_ci  DECL_PRINTER(WeakFixedArray)
3191cb0ef41Sopenharmony_ci  DECL_VERIFIER(WeakFixedArray)
3201cb0ef41Sopenharmony_ci
3211cb0ef41Sopenharmony_ci  class BodyDescriptor;
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_ci  static const int kMaxLength =
3241cb0ef41Sopenharmony_ci      (FixedArray::kMaxSize - kHeaderSize) / kTaggedSize;
3251cb0ef41Sopenharmony_ci  static_assert(Internals::IsValidSmi(kMaxLength),
3261cb0ef41Sopenharmony_ci                "WeakFixedArray maxLength not a Smi");
3271cb0ef41Sopenharmony_ci
3281cb0ef41Sopenharmony_ci  int AllocatedSize();
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ci  static int OffsetOfElementAt(int index) {
3311cb0ef41Sopenharmony_ci    STATIC_ASSERT(kObjectsOffset == SizeFor(0));
3321cb0ef41Sopenharmony_ci    return SizeFor(index);
3331cb0ef41Sopenharmony_ci  }
3341cb0ef41Sopenharmony_ci
3351cb0ef41Sopenharmony_ci private:
3361cb0ef41Sopenharmony_ci  friend class Heap;
3371cb0ef41Sopenharmony_ci
3381cb0ef41Sopenharmony_ci  static const int kFirstIndex = 1;
3391cb0ef41Sopenharmony_ci
3401cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(WeakFixedArray)
3411cb0ef41Sopenharmony_ci};
3421cb0ef41Sopenharmony_ci
3431cb0ef41Sopenharmony_ci// WeakArrayList is like a WeakFixedArray with static convenience methods for
3441cb0ef41Sopenharmony_ci// adding more elements. length() returns the number of elements in the list and
3451cb0ef41Sopenharmony_ci// capacity() returns the allocated size. The number of elements is stored at
3461cb0ef41Sopenharmony_ci// kLengthOffset and is updated with every insertion. The array grows
3471cb0ef41Sopenharmony_ci// dynamically with O(1) amortized insertion.
3481cb0ef41Sopenharmony_ciclass WeakArrayList
3491cb0ef41Sopenharmony_ci    : public TorqueGeneratedWeakArrayList<WeakArrayList, HeapObject> {
3501cb0ef41Sopenharmony_ci public:
3511cb0ef41Sopenharmony_ci  NEVER_READ_ONLY_SPACE
3521cb0ef41Sopenharmony_ci  DECL_PRINTER(WeakArrayList)
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static Handle<WeakArrayList> AddToEnd(
3551cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<WeakArrayList> array,
3561cb0ef41Sopenharmony_ci      const MaybeObjectHandle& value);
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_ci  // A version that adds to elements. This ensures that the elements are
3591cb0ef41Sopenharmony_ci  // inserted atomically w.r.t GC.
3601cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static Handle<WeakArrayList> AddToEnd(
3611cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<WeakArrayList> array,
3621cb0ef41Sopenharmony_ci      const MaybeObjectHandle& value1, const MaybeObjectHandle& value2);
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_ci  // Appends an element to the array and possibly compacts and shrinks live weak
3651cb0ef41Sopenharmony_ci  // references to the start of the collection. Only use this method when
3661cb0ef41Sopenharmony_ci  // indices to elements can change.
3671cb0ef41Sopenharmony_ci  static Handle<WeakArrayList> Append(
3681cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<WeakArrayList> array,
3691cb0ef41Sopenharmony_ci      const MaybeObjectHandle& value,
3701cb0ef41Sopenharmony_ci      AllocationType allocation = AllocationType::kYoung);
3711cb0ef41Sopenharmony_ci
3721cb0ef41Sopenharmony_ci  // Compact weak references to the beginning of the array.
3731cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE void Compact(Isolate* isolate);
3741cb0ef41Sopenharmony_ci
3751cb0ef41Sopenharmony_ci  inline MaybeObject Get(int index) const;
3761cb0ef41Sopenharmony_ci  inline MaybeObject Get(PtrComprCageBase cage_base, int index) const;
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ci  // Set the element at index to obj. The underlying array must be large enough.
3791cb0ef41Sopenharmony_ci  // If you need to grow the WeakArrayList, use the static AddToEnd() method
3801cb0ef41Sopenharmony_ci  // instead.
3811cb0ef41Sopenharmony_ci  inline void Set(int index, MaybeObject value,
3821cb0ef41Sopenharmony_ci                  WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
3831cb0ef41Sopenharmony_ci  inline void Set(int index, Smi value);
3841cb0ef41Sopenharmony_ci
3851cb0ef41Sopenharmony_ci  static constexpr int SizeForCapacity(int capacity) {
3861cb0ef41Sopenharmony_ci    return SizeFor(capacity);
3871cb0ef41Sopenharmony_ci  }
3881cb0ef41Sopenharmony_ci
3891cb0ef41Sopenharmony_ci  static constexpr int CapacityForLength(int length) {
3901cb0ef41Sopenharmony_ci    return length + std::max(length / 2, 2);
3911cb0ef41Sopenharmony_ci  }
3921cb0ef41Sopenharmony_ci
3931cb0ef41Sopenharmony_ci  // Gives access to raw memory which stores the array's data.
3941cb0ef41Sopenharmony_ci  inline MaybeObjectSlot data_start();
3951cb0ef41Sopenharmony_ci
3961cb0ef41Sopenharmony_ci  inline void CopyElements(Isolate* isolate, int dst_index, WeakArrayList src,
3971cb0ef41Sopenharmony_ci                           int src_index, int len, WriteBarrierMode mode);
3981cb0ef41Sopenharmony_ci
3991cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE bool IsFull() const;
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_ci  int AllocatedSize();
4021cb0ef41Sopenharmony_ci
4031cb0ef41Sopenharmony_ci  class BodyDescriptor;
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci  static const int kMaxCapacity =
4061cb0ef41Sopenharmony_ci      (FixedArray::kMaxSize - kHeaderSize) / kTaggedSize;
4071cb0ef41Sopenharmony_ci
4081cb0ef41Sopenharmony_ci  static Handle<WeakArrayList> EnsureSpace(
4091cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<WeakArrayList> array, int length,
4101cb0ef41Sopenharmony_ci      AllocationType allocation = AllocationType::kYoung);
4111cb0ef41Sopenharmony_ci
4121cb0ef41Sopenharmony_ci  // Returns the number of non-cleaned weak references in the array.
4131cb0ef41Sopenharmony_ci  int CountLiveWeakReferences() const;
4141cb0ef41Sopenharmony_ci
4151cb0ef41Sopenharmony_ci  // Returns the number of non-cleaned elements in the array.
4161cb0ef41Sopenharmony_ci  int CountLiveElements() const;
4171cb0ef41Sopenharmony_ci
4181cb0ef41Sopenharmony_ci  // Returns whether an entry was found and removed. Will move the elements
4191cb0ef41Sopenharmony_ci  // around in the array - this method can only be used in cases where the user
4201cb0ef41Sopenharmony_ci  // doesn't care about the indices! Users should make sure there are no
4211cb0ef41Sopenharmony_ci  // duplicates.
4221cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE bool RemoveOne(const MaybeObjectHandle& value);
4231cb0ef41Sopenharmony_ci
4241cb0ef41Sopenharmony_ci  class Iterator;
4251cb0ef41Sopenharmony_ci
4261cb0ef41Sopenharmony_ci private:
4271cb0ef41Sopenharmony_ci  static int OffsetOfElementAt(int index) {
4281cb0ef41Sopenharmony_ci    return kHeaderSize + index * kTaggedSize;
4291cb0ef41Sopenharmony_ci  }
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(WeakArrayList)
4321cb0ef41Sopenharmony_ci};
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_ciclass WeakArrayList::Iterator {
4351cb0ef41Sopenharmony_ci public:
4361cb0ef41Sopenharmony_ci  explicit Iterator(WeakArrayList array) : index_(0), array_(array) {}
4371cb0ef41Sopenharmony_ci  Iterator(const Iterator&) = delete;
4381cb0ef41Sopenharmony_ci  Iterator& operator=(const Iterator&) = delete;
4391cb0ef41Sopenharmony_ci
4401cb0ef41Sopenharmony_ci  inline HeapObject Next();
4411cb0ef41Sopenharmony_ci
4421cb0ef41Sopenharmony_ci private:
4431cb0ef41Sopenharmony_ci  int index_;
4441cb0ef41Sopenharmony_ci  WeakArrayList array_;
4451cb0ef41Sopenharmony_ci  DISALLOW_GARBAGE_COLLECTION(no_gc_)
4461cb0ef41Sopenharmony_ci};
4471cb0ef41Sopenharmony_ci
4481cb0ef41Sopenharmony_ci// Generic array grows dynamically with O(1) amortized insertion.
4491cb0ef41Sopenharmony_ci//
4501cb0ef41Sopenharmony_ci// ArrayList is a FixedArray with static convenience methods for adding more
4511cb0ef41Sopenharmony_ci// elements. The Length() method returns the number of elements in the list, not
4521cb0ef41Sopenharmony_ci// the allocated size. The number of elements is stored at kLengthIndex and is
4531cb0ef41Sopenharmony_ci// updated with every insertion. The elements of the ArrayList are stored in the
4541cb0ef41Sopenharmony_ci// underlying FixedArray starting at kFirstIndex.
4551cb0ef41Sopenharmony_ciclass ArrayList : public TorqueGeneratedArrayList<ArrayList, FixedArray> {
4561cb0ef41Sopenharmony_ci public:
4571cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static Handle<ArrayList> Add(Isolate* isolate,
4581cb0ef41Sopenharmony_ci                                                 Handle<ArrayList> array,
4591cb0ef41Sopenharmony_ci                                                 Handle<Object> obj);
4601cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static Handle<ArrayList> Add(Isolate* isolate,
4611cb0ef41Sopenharmony_ci                                                 Handle<ArrayList> array,
4621cb0ef41Sopenharmony_ci                                                 Handle<Object> obj1,
4631cb0ef41Sopenharmony_ci                                                 Handle<Object> obj2);
4641cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static Handle<ArrayList> Add(Isolate* isolate,
4651cb0ef41Sopenharmony_ci                                                 Handle<ArrayList> array,
4661cb0ef41Sopenharmony_ci                                                 Handle<Object> obj1, Smi obj2,
4671cb0ef41Sopenharmony_ci                                                 Smi obj3, Smi obj4);
4681cb0ef41Sopenharmony_ci  static Handle<ArrayList> New(Isolate* isolate, int size);
4691cb0ef41Sopenharmony_ci
4701cb0ef41Sopenharmony_ci  // Returns the number of elements in the list, not the allocated size, which
4711cb0ef41Sopenharmony_ci  // is length(). Lower and upper case length() return different results!
4721cb0ef41Sopenharmony_ci  inline int Length() const;
4731cb0ef41Sopenharmony_ci
4741cb0ef41Sopenharmony_ci  // Sets the Length() as used by Elements(). Does not change the underlying
4751cb0ef41Sopenharmony_ci  // storage capacity, i.e., length().
4761cb0ef41Sopenharmony_ci  inline void SetLength(int length);
4771cb0ef41Sopenharmony_ci  inline Object Get(int index) const;
4781cb0ef41Sopenharmony_ci  inline Object Get(PtrComprCageBase cage_base, int index) const;
4791cb0ef41Sopenharmony_ci  inline ObjectSlot Slot(int index);
4801cb0ef41Sopenharmony_ci
4811cb0ef41Sopenharmony_ci  // Set the element at index to obj. The underlying array must be large enough.
4821cb0ef41Sopenharmony_ci  // If you need to grow the ArrayList, use the static Add() methods instead.
4831cb0ef41Sopenharmony_ci  inline void Set(int index, Object obj,
4841cb0ef41Sopenharmony_ci                  WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
4851cb0ef41Sopenharmony_ci
4861cb0ef41Sopenharmony_ci  inline void Set(int index, Smi obj);
4871cb0ef41Sopenharmony_ci
4881cb0ef41Sopenharmony_ci  // Set the element at index to undefined. This does not change the Length().
4891cb0ef41Sopenharmony_ci  inline void Clear(int index, Object undefined);
4901cb0ef41Sopenharmony_ci
4911cb0ef41Sopenharmony_ci  // Return a copy of the list of size Length() without the first entry. The
4921cb0ef41Sopenharmony_ci  // number returned by Length() is stored in the first entry.
4931cb0ef41Sopenharmony_ci  static Handle<FixedArray> Elements(Isolate* isolate, Handle<ArrayList> array);
4941cb0ef41Sopenharmony_ci
4951cb0ef41Sopenharmony_ci  static const int kHeaderFields = 1;
4961cb0ef41Sopenharmony_ci
4971cb0ef41Sopenharmony_ci  static const int kLengthIndex = 0;
4981cb0ef41Sopenharmony_ci  static const int kFirstIndex = 1;
4991cb0ef41Sopenharmony_ci  STATIC_ASSERT(kHeaderFields == kFirstIndex);
5001cb0ef41Sopenharmony_ci
5011cb0ef41Sopenharmony_ci  DECL_VERIFIER(ArrayList)
5021cb0ef41Sopenharmony_ci
5031cb0ef41Sopenharmony_ci private:
5041cb0ef41Sopenharmony_ci  static Handle<ArrayList> EnsureSpace(Isolate* isolate,
5051cb0ef41Sopenharmony_ci                                       Handle<ArrayList> array, int length);
5061cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(ArrayList)
5071cb0ef41Sopenharmony_ci};
5081cb0ef41Sopenharmony_ci
5091cb0ef41Sopenharmony_cienum SearchMode { ALL_ENTRIES, VALID_ENTRIES };
5101cb0ef41Sopenharmony_ci
5111cb0ef41Sopenharmony_citemplate <SearchMode search_mode, typename T>
5121cb0ef41Sopenharmony_ciinline int Search(T* array, Name name, int valid_entries = 0,
5131cb0ef41Sopenharmony_ci                  int* out_insertion_index = nullptr,
5141cb0ef41Sopenharmony_ci                  bool concurrent_search = false);
5151cb0ef41Sopenharmony_ci
5161cb0ef41Sopenharmony_ci// ByteArray represents fixed sized byte arrays.  Used for the relocation info
5171cb0ef41Sopenharmony_ci// that is attached to code objects.
5181cb0ef41Sopenharmony_ciclass ByteArray : public TorqueGeneratedByteArray<ByteArray, FixedArrayBase> {
5191cb0ef41Sopenharmony_ci public:
5201cb0ef41Sopenharmony_ci  inline int Size();
5211cb0ef41Sopenharmony_ci
5221cb0ef41Sopenharmony_ci  // Setter and getter.
5231cb0ef41Sopenharmony_ci  inline byte get(int index) const;
5241cb0ef41Sopenharmony_ci  inline void set(int index, byte value);
5251cb0ef41Sopenharmony_ci
5261cb0ef41Sopenharmony_ci  // Copy in / copy out whole byte slices.
5271cb0ef41Sopenharmony_ci  inline void copy_out(int index, byte* buffer, int slice_length);
5281cb0ef41Sopenharmony_ci  inline void copy_in(int index, const byte* buffer, int slice_length);
5291cb0ef41Sopenharmony_ci
5301cb0ef41Sopenharmony_ci  // Treat contents as an int array.
5311cb0ef41Sopenharmony_ci  inline int get_int(int index) const;
5321cb0ef41Sopenharmony_ci  inline void set_int(int index, int value);
5331cb0ef41Sopenharmony_ci
5341cb0ef41Sopenharmony_ci  inline uint32_t get_uint32(int index) const;
5351cb0ef41Sopenharmony_ci  inline void set_uint32(int index, uint32_t value);
5361cb0ef41Sopenharmony_ci
5371cb0ef41Sopenharmony_ci  inline uint32_t get_uint32_relaxed(int index) const;
5381cb0ef41Sopenharmony_ci  inline void set_uint32_relaxed(int index, uint32_t value);
5391cb0ef41Sopenharmony_ci
5401cb0ef41Sopenharmony_ci  inline uint16_t get_uint16(int index) const;
5411cb0ef41Sopenharmony_ci  inline void set_uint16(int index, uint16_t value);
5421cb0ef41Sopenharmony_ci
5431cb0ef41Sopenharmony_ci  // Clear uninitialized padding space. This ensures that the snapshot content
5441cb0ef41Sopenharmony_ci  // is deterministic.
5451cb0ef41Sopenharmony_ci  inline void clear_padding();
5461cb0ef41Sopenharmony_ci
5471cb0ef41Sopenharmony_ci  static int SizeFor(int length) {
5481cb0ef41Sopenharmony_ci    return OBJECT_POINTER_ALIGN(kHeaderSize + length);
5491cb0ef41Sopenharmony_ci  }
5501cb0ef41Sopenharmony_ci  // We use byte arrays for free blocks in the heap.  Given a desired size in
5511cb0ef41Sopenharmony_ci  // bytes that is a multiple of the word size and big enough to hold a byte
5521cb0ef41Sopenharmony_ci  // array, this function returns the number of elements a byte array should
5531cb0ef41Sopenharmony_ci  // have.
5541cb0ef41Sopenharmony_ci  static int LengthFor(int size_in_bytes) {
5551cb0ef41Sopenharmony_ci    DCHECK(IsAligned(size_in_bytes, kTaggedSize));
5561cb0ef41Sopenharmony_ci    DCHECK_GE(size_in_bytes, kHeaderSize);
5571cb0ef41Sopenharmony_ci    return size_in_bytes - kHeaderSize;
5581cb0ef41Sopenharmony_ci  }
5591cb0ef41Sopenharmony_ci
5601cb0ef41Sopenharmony_ci  // Returns data start address.
5611cb0ef41Sopenharmony_ci  inline byte* GetDataStartAddress();
5621cb0ef41Sopenharmony_ci  // Returns address of the past-the-end element.
5631cb0ef41Sopenharmony_ci  inline byte* GetDataEndAddress();
5641cb0ef41Sopenharmony_ci
5651cb0ef41Sopenharmony_ci  inline int DataSize() const;
5661cb0ef41Sopenharmony_ci
5671cb0ef41Sopenharmony_ci  // Returns a pointer to the ByteArray object for a given data start address.
5681cb0ef41Sopenharmony_ci  static inline ByteArray FromDataStartAddress(Address address);
5691cb0ef41Sopenharmony_ci
5701cb0ef41Sopenharmony_ci  // Dispatched behavior.
5711cb0ef41Sopenharmony_ci  inline int ByteArraySize();
5721cb0ef41Sopenharmony_ci  DECL_PRINTER(ByteArray)
5731cb0ef41Sopenharmony_ci
5741cb0ef41Sopenharmony_ci  // Layout description.
5751cb0ef41Sopenharmony_ci  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
5761cb0ef41Sopenharmony_ci
5771cb0ef41Sopenharmony_ci  // Maximal length of a single ByteArray.
5781cb0ef41Sopenharmony_ci  static const int kMaxLength = kMaxSize - kHeaderSize;
5791cb0ef41Sopenharmony_ci  static_assert(Internals::IsValidSmi(kMaxLength),
5801cb0ef41Sopenharmony_ci                "ByteArray maxLength not a Smi");
5811cb0ef41Sopenharmony_ci
5821cb0ef41Sopenharmony_ci  class BodyDescriptor;
5831cb0ef41Sopenharmony_ci
5841cb0ef41Sopenharmony_ci protected:
5851cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(ByteArray)
5861cb0ef41Sopenharmony_ci  inline ByteArray(Address ptr, HeapObject::AllowInlineSmiStorage allow_smi);
5871cb0ef41Sopenharmony_ci};
5881cb0ef41Sopenharmony_ci
5891cb0ef41Sopenharmony_ci// Wrapper class for ByteArray which can store arbitrary C++ classes, as long
5901cb0ef41Sopenharmony_ci// as they can be copied with memcpy.
5911cb0ef41Sopenharmony_citemplate <class T>
5921cb0ef41Sopenharmony_ciclass PodArray : public ByteArray {
5931cb0ef41Sopenharmony_ci public:
5941cb0ef41Sopenharmony_ci  static Handle<PodArray<T>> New(
5951cb0ef41Sopenharmony_ci      Isolate* isolate, int length,
5961cb0ef41Sopenharmony_ci      AllocationType allocation = AllocationType::kYoung);
5971cb0ef41Sopenharmony_ci  void copy_out(int index, T* result, int length) {
5981cb0ef41Sopenharmony_ci    ByteArray::copy_out(index * sizeof(T), reinterpret_cast<byte*>(result),
5991cb0ef41Sopenharmony_ci                        length * sizeof(T));
6001cb0ef41Sopenharmony_ci  }
6011cb0ef41Sopenharmony_ci
6021cb0ef41Sopenharmony_ci  void copy_in(int index, const T* buffer, int length) {
6031cb0ef41Sopenharmony_ci    ByteArray::copy_in(index * sizeof(T), reinterpret_cast<const byte*>(buffer),
6041cb0ef41Sopenharmony_ci                       length * sizeof(T));
6051cb0ef41Sopenharmony_ci  }
6061cb0ef41Sopenharmony_ci
6071cb0ef41Sopenharmony_ci  bool matches(const T* buffer, int length) {
6081cb0ef41Sopenharmony_ci    DCHECK_LE(length, this->length());
6091cb0ef41Sopenharmony_ci    return memcmp(GetDataStartAddress(), buffer, length * sizeof(T)) == 0;
6101cb0ef41Sopenharmony_ci  }
6111cb0ef41Sopenharmony_ci
6121cb0ef41Sopenharmony_ci  bool matches(int offset, const T* buffer, int length) {
6131cb0ef41Sopenharmony_ci    DCHECK_LE(offset, this->length());
6141cb0ef41Sopenharmony_ci    DCHECK_LE(offset + length, this->length());
6151cb0ef41Sopenharmony_ci    return memcmp(GetDataStartAddress() + sizeof(T) * offset, buffer,
6161cb0ef41Sopenharmony_ci                  length * sizeof(T)) == 0;
6171cb0ef41Sopenharmony_ci  }
6181cb0ef41Sopenharmony_ci
6191cb0ef41Sopenharmony_ci  T get(int index) {
6201cb0ef41Sopenharmony_ci    T result;
6211cb0ef41Sopenharmony_ci    copy_out(index, &result, 1);
6221cb0ef41Sopenharmony_ci    return result;
6231cb0ef41Sopenharmony_ci  }
6241cb0ef41Sopenharmony_ci
6251cb0ef41Sopenharmony_ci  void set(int index, const T& value) { copy_in(index, &value, 1); }
6261cb0ef41Sopenharmony_ci
6271cb0ef41Sopenharmony_ci  inline int length() const;
6281cb0ef41Sopenharmony_ci  DECL_CAST(PodArray<T>)
6291cb0ef41Sopenharmony_ci
6301cb0ef41Sopenharmony_ci  OBJECT_CONSTRUCTORS(PodArray<T>, ByteArray);
6311cb0ef41Sopenharmony_ci};
6321cb0ef41Sopenharmony_ci
6331cb0ef41Sopenharmony_ciclass TemplateList
6341cb0ef41Sopenharmony_ci    : public TorqueGeneratedTemplateList<TemplateList, FixedArray> {
6351cb0ef41Sopenharmony_ci public:
6361cb0ef41Sopenharmony_ci  static Handle<TemplateList> New(Isolate* isolate, int size);
6371cb0ef41Sopenharmony_ci  inline int length() const;
6381cb0ef41Sopenharmony_ci  inline Object get(int index) const;
6391cb0ef41Sopenharmony_ci  inline Object get(PtrComprCageBase cage_base, int index) const;
6401cb0ef41Sopenharmony_ci  inline void set(int index, Object value);
6411cb0ef41Sopenharmony_ci  static Handle<TemplateList> Add(Isolate* isolate, Handle<TemplateList> list,
6421cb0ef41Sopenharmony_ci                                  Handle<Object> value);
6431cb0ef41Sopenharmony_ci private:
6441cb0ef41Sopenharmony_ci  static const int kLengthIndex = 0;
6451cb0ef41Sopenharmony_ci  static const int kFirstElementIndex = kLengthIndex + 1;
6461cb0ef41Sopenharmony_ci
6471cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(TemplateList)
6481cb0ef41Sopenharmony_ci};
6491cb0ef41Sopenharmony_ci
6501cb0ef41Sopenharmony_ci}  // namespace internal
6511cb0ef41Sopenharmony_ci}  // namespace v8
6521cb0ef41Sopenharmony_ci
6531cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h"
6541cb0ef41Sopenharmony_ci
6551cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_FIXED_ARRAY_H_
656