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_INL_H_
61cb0ef41Sopenharmony_ci#define V8_OBJECTS_FIXED_ARRAY_INL_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/handles/handles-inl.h"
91cb0ef41Sopenharmony_ci#include "src/heap/heap-write-barrier-inl.h"
101cb0ef41Sopenharmony_ci#include "src/numbers/conversions.h"
111cb0ef41Sopenharmony_ci#include "src/objects/bigint.h"
121cb0ef41Sopenharmony_ci#include "src/objects/compressed-slots.h"
131cb0ef41Sopenharmony_ci#include "src/objects/fixed-array.h"
141cb0ef41Sopenharmony_ci#include "src/objects/map.h"
151cb0ef41Sopenharmony_ci#include "src/objects/maybe-object-inl.h"
161cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h"
171cb0ef41Sopenharmony_ci#include "src/objects/oddball.h"
181cb0ef41Sopenharmony_ci#include "src/objects/slots.h"
191cb0ef41Sopenharmony_ci#include "src/roots/roots-inl.h"
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards):
221cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cinamespace v8 {
251cb0ef41Sopenharmony_cinamespace internal {
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/fixed-array-tq-inl.inc"
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(FixedArrayBase)
301cb0ef41Sopenharmony_ciFixedArrayBase::FixedArrayBase(Address ptr,
311cb0ef41Sopenharmony_ci                               HeapObject::AllowInlineSmiStorage allow_smi)
321cb0ef41Sopenharmony_ci    : TorqueGeneratedFixedArrayBase(ptr, allow_smi) {}
331cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(FixedArray)
341cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(FixedDoubleArray)
351cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(ArrayList)
361cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(ByteArray)
371cb0ef41Sopenharmony_ciByteArray::ByteArray(Address ptr, HeapObject::AllowInlineSmiStorage allow_smi)
381cb0ef41Sopenharmony_ci    : TorqueGeneratedByteArray(ptr, allow_smi) {}
391cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(TemplateList)
401cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(WeakFixedArray)
411cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(WeakArrayList)
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciNEVER_READ_ONLY_SPACE_IMPL(WeakArrayList)
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciRELEASE_ACQUIRE_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ciRELEASE_ACQUIRE_SMI_ACCESSORS(WeakFixedArray, length, kLengthOffset)
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ciObject FixedArrayBase::unchecked_length(AcquireLoadTag) const {
501cb0ef41Sopenharmony_ci  return ACQUIRE_READ_FIELD(*this, kLengthOffset);
511cb0ef41Sopenharmony_ci}
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciObjectSlot FixedArray::GetFirstElementAddress() {
541cb0ef41Sopenharmony_ci  return RawField(OffsetOfElementAt(0));
551cb0ef41Sopenharmony_ci}
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_cibool FixedArray::ContainsOnlySmisOrHoles() {
581cb0ef41Sopenharmony_ci  Object the_hole = GetReadOnlyRoots().the_hole_value();
591cb0ef41Sopenharmony_ci  ObjectSlot current = GetFirstElementAddress();
601cb0ef41Sopenharmony_ci  for (int i = 0; i < length(); ++i, ++current) {
611cb0ef41Sopenharmony_ci    Object candidate = *current;
621cb0ef41Sopenharmony_ci    if (!candidate.IsSmi() && candidate != the_hole) return false;
631cb0ef41Sopenharmony_ci  }
641cb0ef41Sopenharmony_ci  return true;
651cb0ef41Sopenharmony_ci}
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ciObject FixedArray::get(int index) const {
681cb0ef41Sopenharmony_ci  PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
691cb0ef41Sopenharmony_ci  return get(cage_base, index);
701cb0ef41Sopenharmony_ci}
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ciObject FixedArray::get(PtrComprCageBase cage_base, int index) const {
731cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
741cb0ef41Sopenharmony_ci  return TaggedField<Object>::Relaxed_Load(cage_base, *this,
751cb0ef41Sopenharmony_ci                                           OffsetOfElementAt(index));
761cb0ef41Sopenharmony_ci}
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ciHandle<Object> FixedArray::get(FixedArray array, int index, Isolate* isolate) {
791cb0ef41Sopenharmony_ci  return handle(array.get(isolate, index), isolate);
801cb0ef41Sopenharmony_ci}
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_cibool FixedArray::is_the_hole(Isolate* isolate, int index) {
831cb0ef41Sopenharmony_ci  return get(isolate, index).IsTheHole(isolate);
841cb0ef41Sopenharmony_ci}
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci#if !defined(_WIN32) || (defined(_WIN64) && _MSC_VER < 1930 && __cplusplus < 201703L)
871cb0ef41Sopenharmony_civoid FixedArray::set(int index, Smi value) {
881cb0ef41Sopenharmony_ci  DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
891cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
901cb0ef41Sopenharmony_ci  DCHECK(Object(value).IsSmi());
911cb0ef41Sopenharmony_ci  int offset = OffsetOfElementAt(index);
921cb0ef41Sopenharmony_ci  RELAXED_WRITE_FIELD(*this, offset, value);
931cb0ef41Sopenharmony_ci}
941cb0ef41Sopenharmony_ci#endif
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_civoid FixedArray::set(int index, Object value) {
971cb0ef41Sopenharmony_ci  DCHECK_NE(GetReadOnlyRoots().fixed_cow_array_map(), map());
981cb0ef41Sopenharmony_ci  DCHECK(IsFixedArray());
991cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
1001cb0ef41Sopenharmony_ci  int offset = OffsetOfElementAt(index);
1011cb0ef41Sopenharmony_ci  RELAXED_WRITE_FIELD(*this, offset, value);
1021cb0ef41Sopenharmony_ci  WRITE_BARRIER(*this, offset, value);
1031cb0ef41Sopenharmony_ci}
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_civoid FixedArray::set(int index, Object value, WriteBarrierMode mode) {
1061cb0ef41Sopenharmony_ci  DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
1071cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
1081cb0ef41Sopenharmony_ci  int offset = OffsetOfElementAt(index);
1091cb0ef41Sopenharmony_ci  RELAXED_WRITE_FIELD(*this, offset, value);
1101cb0ef41Sopenharmony_ci  CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode);
1111cb0ef41Sopenharmony_ci}
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ci// static
1141cb0ef41Sopenharmony_civoid FixedArray::NoWriteBarrierSet(FixedArray array, int index, Object value) {
1151cb0ef41Sopenharmony_ci  DCHECK_NE(array.map(), array.GetReadOnlyRoots().fixed_cow_array_map());
1161cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index),
1171cb0ef41Sopenharmony_ci            static_cast<unsigned>(array.length()));
1181cb0ef41Sopenharmony_ci  DCHECK(!ObjectInYoungGeneration(value));
1191cb0ef41Sopenharmony_ci  int offset = OffsetOfElementAt(index);
1201cb0ef41Sopenharmony_ci  RELAXED_WRITE_FIELD(array, offset, value);
1211cb0ef41Sopenharmony_ci}
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ciObject FixedArray::get(int index, RelaxedLoadTag) const {
1241cb0ef41Sopenharmony_ci  PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
1251cb0ef41Sopenharmony_ci  return get(cage_base, index);
1261cb0ef41Sopenharmony_ci}
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ciObject FixedArray::get(PtrComprCageBase cage_base, int index,
1291cb0ef41Sopenharmony_ci                       RelaxedLoadTag) const {
1301cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
1311cb0ef41Sopenharmony_ci  return RELAXED_READ_FIELD(*this, OffsetOfElementAt(index));
1321cb0ef41Sopenharmony_ci}
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_civoid FixedArray::set(int index, Object value, RelaxedStoreTag,
1351cb0ef41Sopenharmony_ci                     WriteBarrierMode mode) {
1361cb0ef41Sopenharmony_ci  DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
1371cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
1381cb0ef41Sopenharmony_ci  RELAXED_WRITE_FIELD(*this, OffsetOfElementAt(index), value);
1391cb0ef41Sopenharmony_ci  CONDITIONAL_WRITE_BARRIER(*this, OffsetOfElementAt(index), value, mode);
1401cb0ef41Sopenharmony_ci}
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_civoid FixedArray::set(int index, Smi value, RelaxedStoreTag tag) {
1431cb0ef41Sopenharmony_ci  DCHECK(Object(value).IsSmi());
1441cb0ef41Sopenharmony_ci  set(index, value, tag, SKIP_WRITE_BARRIER);
1451cb0ef41Sopenharmony_ci}
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ciObject FixedArray::get(int index, AcquireLoadTag) const {
1481cb0ef41Sopenharmony_ci  PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
1491cb0ef41Sopenharmony_ci  return get(cage_base, index);
1501cb0ef41Sopenharmony_ci}
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ciObject FixedArray::get(PtrComprCageBase cage_base, int index,
1531cb0ef41Sopenharmony_ci                       AcquireLoadTag) const {
1541cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
1551cb0ef41Sopenharmony_ci  return ACQUIRE_READ_FIELD(*this, OffsetOfElementAt(index));
1561cb0ef41Sopenharmony_ci}
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_civoid FixedArray::set(int index, Object value, ReleaseStoreTag,
1591cb0ef41Sopenharmony_ci                     WriteBarrierMode mode) {
1601cb0ef41Sopenharmony_ci  DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
1611cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
1621cb0ef41Sopenharmony_ci  RELEASE_WRITE_FIELD(*this, OffsetOfElementAt(index), value);
1631cb0ef41Sopenharmony_ci  CONDITIONAL_WRITE_BARRIER(*this, OffsetOfElementAt(index), value, mode);
1641cb0ef41Sopenharmony_ci}
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_civoid FixedArray::set(int index, Smi value, ReleaseStoreTag tag) {
1671cb0ef41Sopenharmony_ci  DCHECK(Object(value).IsSmi());
1681cb0ef41Sopenharmony_ci  set(index, value, tag, SKIP_WRITE_BARRIER);
1691cb0ef41Sopenharmony_ci}
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_civoid FixedArray::set_undefined(int index) {
1721cb0ef41Sopenharmony_ci  set_undefined(GetReadOnlyRoots(), index);
1731cb0ef41Sopenharmony_ci}
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_civoid FixedArray::set_undefined(Isolate* isolate, int index) {
1761cb0ef41Sopenharmony_ci  set_undefined(ReadOnlyRoots(isolate), index);
1771cb0ef41Sopenharmony_ci}
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_civoid FixedArray::set_undefined(ReadOnlyRoots ro_roots, int index) {
1801cb0ef41Sopenharmony_ci  FixedArray::NoWriteBarrierSet(*this, index, ro_roots.undefined_value());
1811cb0ef41Sopenharmony_ci}
1821cb0ef41Sopenharmony_ci
1831cb0ef41Sopenharmony_civoid FixedArray::set_null(int index) { set_null(GetReadOnlyRoots(), index); }
1841cb0ef41Sopenharmony_ci
1851cb0ef41Sopenharmony_civoid FixedArray::set_null(Isolate* isolate, int index) {
1861cb0ef41Sopenharmony_ci  set_null(ReadOnlyRoots(isolate), index);
1871cb0ef41Sopenharmony_ci}
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_civoid FixedArray::set_null(ReadOnlyRoots ro_roots, int index) {
1901cb0ef41Sopenharmony_ci  FixedArray::NoWriteBarrierSet(*this, index, ro_roots.null_value());
1911cb0ef41Sopenharmony_ci}
1921cb0ef41Sopenharmony_ci
1931cb0ef41Sopenharmony_civoid FixedArray::set_the_hole(int index) {
1941cb0ef41Sopenharmony_ci  set_the_hole(GetReadOnlyRoots(), index);
1951cb0ef41Sopenharmony_ci}
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_civoid FixedArray::set_the_hole(Isolate* isolate, int index) {
1981cb0ef41Sopenharmony_ci  set_the_hole(ReadOnlyRoots(isolate), index);
1991cb0ef41Sopenharmony_ci}
2001cb0ef41Sopenharmony_ci
2011cb0ef41Sopenharmony_civoid FixedArray::set_the_hole(ReadOnlyRoots ro_roots, int index) {
2021cb0ef41Sopenharmony_ci  FixedArray::NoWriteBarrierSet(*this, index, ro_roots.the_hole_value());
2031cb0ef41Sopenharmony_ci}
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_civoid FixedArray::FillWithHoles(int from, int to) {
2061cb0ef41Sopenharmony_ci  for (int i = from; i < to; i++) {
2071cb0ef41Sopenharmony_ci    set_the_hole(i);
2081cb0ef41Sopenharmony_ci  }
2091cb0ef41Sopenharmony_ci}
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ciObjectSlot FixedArray::data_start() { return RawField(OffsetOfElementAt(0)); }
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ciObjectSlot FixedArray::RawFieldOfElementAt(int index) {
2141cb0ef41Sopenharmony_ci  return RawField(OffsetOfElementAt(index));
2151cb0ef41Sopenharmony_ci}
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_civoid FixedArray::MoveElements(Isolate* isolate, int dst_index, int src_index,
2181cb0ef41Sopenharmony_ci                              int len, WriteBarrierMode mode) {
2191cb0ef41Sopenharmony_ci  if (len == 0) return;
2201cb0ef41Sopenharmony_ci  DCHECK_LE(dst_index + len, length());
2211cb0ef41Sopenharmony_ci  DCHECK_LE(src_index + len, length());
2221cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
2231cb0ef41Sopenharmony_ci  ObjectSlot dst_slot(RawFieldOfElementAt(dst_index));
2241cb0ef41Sopenharmony_ci  ObjectSlot src_slot(RawFieldOfElementAt(src_index));
2251cb0ef41Sopenharmony_ci  isolate->heap()->MoveRange(*this, dst_slot, src_slot, len, mode);
2261cb0ef41Sopenharmony_ci}
2271cb0ef41Sopenharmony_ci
2281cb0ef41Sopenharmony_civoid FixedArray::CopyElements(Isolate* isolate, int dst_index, FixedArray src,
2291cb0ef41Sopenharmony_ci                              int src_index, int len, WriteBarrierMode mode) {
2301cb0ef41Sopenharmony_ci  if (len == 0) return;
2311cb0ef41Sopenharmony_ci  DCHECK_LE(dst_index + len, length());
2321cb0ef41Sopenharmony_ci  DCHECK_LE(src_index + len, src.length());
2331cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
2341cb0ef41Sopenharmony_ci
2351cb0ef41Sopenharmony_ci  ObjectSlot dst_slot(RawFieldOfElementAt(dst_index));
2361cb0ef41Sopenharmony_ci  ObjectSlot src_slot(src.RawFieldOfElementAt(src_index));
2371cb0ef41Sopenharmony_ci  isolate->heap()->CopyRange(*this, dst_slot, src_slot, len, mode);
2381cb0ef41Sopenharmony_ci}
2391cb0ef41Sopenharmony_ci
2401cb0ef41Sopenharmony_ci// Due to left- and right-trimming, concurrent visitors need to read the length
2411cb0ef41Sopenharmony_ci// with acquire semantics.
2421cb0ef41Sopenharmony_ci// TODO(ulan): Acquire should not be needed anymore.
2431cb0ef41Sopenharmony_ciinline int FixedArray::AllocatedSize() { return SizeFor(length(kAcquireLoad)); }
2441cb0ef41Sopenharmony_ciinline int WeakFixedArray::AllocatedSize() {
2451cb0ef41Sopenharmony_ci  return SizeFor(length(kAcquireLoad));
2461cb0ef41Sopenharmony_ci}
2471cb0ef41Sopenharmony_ciinline int WeakArrayList::AllocatedSize() { return SizeFor(capacity()); }
2481cb0ef41Sopenharmony_ci
2491cb0ef41Sopenharmony_ci// Perform a binary search in a fixed array.
2501cb0ef41Sopenharmony_citemplate <SearchMode search_mode, typename T>
2511cb0ef41Sopenharmony_ciint BinarySearch(T* array, Name name, int valid_entries,
2521cb0ef41Sopenharmony_ci                 int* out_insertion_index) {
2531cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(search_mode == VALID_ENTRIES, out_insertion_index == nullptr);
2541cb0ef41Sopenharmony_ci  int low = 0;
2551cb0ef41Sopenharmony_ci  // We have to search on all entries, even when search_mode == VALID_ENTRIES.
2561cb0ef41Sopenharmony_ci  // This is because the InternalIndex might be different from the SortedIndex
2571cb0ef41Sopenharmony_ci  // (i.e the first added item in {array} could be the last in the sorted
2581cb0ef41Sopenharmony_ci  // index). After doing the binary search and getting the correct internal
2591cb0ef41Sopenharmony_ci  // index we check to have the index lower than valid_entries, if needed.
2601cb0ef41Sopenharmony_ci  int high = array->number_of_entries() - 1;
2611cb0ef41Sopenharmony_ci  uint32_t hash = name.hash();
2621cb0ef41Sopenharmony_ci  int limit = high;
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci  DCHECK(low <= high);
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci  while (low != high) {
2671cb0ef41Sopenharmony_ci    int mid = low + (high - low) / 2;
2681cb0ef41Sopenharmony_ci    Name mid_name = array->GetSortedKey(mid);
2691cb0ef41Sopenharmony_ci    uint32_t mid_hash = mid_name.hash();
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_ci    if (mid_hash >= hash) {
2721cb0ef41Sopenharmony_ci      high = mid;
2731cb0ef41Sopenharmony_ci    } else {
2741cb0ef41Sopenharmony_ci      low = mid + 1;
2751cb0ef41Sopenharmony_ci    }
2761cb0ef41Sopenharmony_ci  }
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_ci  for (; low <= limit; ++low) {
2791cb0ef41Sopenharmony_ci    int sort_index = array->GetSortedKeyIndex(low);
2801cb0ef41Sopenharmony_ci    Name entry = array->GetKey(InternalIndex(sort_index));
2811cb0ef41Sopenharmony_ci    uint32_t current_hash = entry.hash();
2821cb0ef41Sopenharmony_ci    if (current_hash != hash) {
2831cb0ef41Sopenharmony_ci      // 'search_mode == ALL_ENTRIES' here and below is not needed since
2841cb0ef41Sopenharmony_ci      // 'out_insertion_index != nullptr' implies 'search_mode == ALL_ENTRIES'.
2851cb0ef41Sopenharmony_ci      // Having said that, when creating the template for <VALID_ENTRIES> these
2861cb0ef41Sopenharmony_ci      // ifs can be elided by the C++ compiler if we add 'search_mode ==
2871cb0ef41Sopenharmony_ci      // ALL_ENTRIES'.
2881cb0ef41Sopenharmony_ci      if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
2891cb0ef41Sopenharmony_ci        *out_insertion_index = sort_index + (current_hash > hash ? 0 : 1);
2901cb0ef41Sopenharmony_ci      }
2911cb0ef41Sopenharmony_ci      return T::kNotFound;
2921cb0ef41Sopenharmony_ci    }
2931cb0ef41Sopenharmony_ci    if (entry == name) {
2941cb0ef41Sopenharmony_ci      if (search_mode == ALL_ENTRIES || sort_index < valid_entries) {
2951cb0ef41Sopenharmony_ci        return sort_index;
2961cb0ef41Sopenharmony_ci      }
2971cb0ef41Sopenharmony_ci      return T::kNotFound;
2981cb0ef41Sopenharmony_ci    }
2991cb0ef41Sopenharmony_ci  }
3001cb0ef41Sopenharmony_ci
3011cb0ef41Sopenharmony_ci  if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
3021cb0ef41Sopenharmony_ci    *out_insertion_index = limit + 1;
3031cb0ef41Sopenharmony_ci  }
3041cb0ef41Sopenharmony_ci  return T::kNotFound;
3051cb0ef41Sopenharmony_ci}
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci// Perform a linear search in this fixed array. len is the number of entry
3081cb0ef41Sopenharmony_ci// indices that are valid.
3091cb0ef41Sopenharmony_citemplate <SearchMode search_mode, typename T>
3101cb0ef41Sopenharmony_ciint LinearSearch(T* array, Name name, int valid_entries,
3111cb0ef41Sopenharmony_ci                 int* out_insertion_index) {
3121cb0ef41Sopenharmony_ci  if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
3131cb0ef41Sopenharmony_ci    uint32_t hash = name.hash();
3141cb0ef41Sopenharmony_ci    int len = array->number_of_entries();
3151cb0ef41Sopenharmony_ci    for (int number = 0; number < len; number++) {
3161cb0ef41Sopenharmony_ci      int sorted_index = array->GetSortedKeyIndex(number);
3171cb0ef41Sopenharmony_ci      Name entry = array->GetKey(InternalIndex(sorted_index));
3181cb0ef41Sopenharmony_ci      uint32_t current_hash = entry.hash();
3191cb0ef41Sopenharmony_ci      if (current_hash > hash) {
3201cb0ef41Sopenharmony_ci        *out_insertion_index = sorted_index;
3211cb0ef41Sopenharmony_ci        return T::kNotFound;
3221cb0ef41Sopenharmony_ci      }
3231cb0ef41Sopenharmony_ci      if (entry == name) return sorted_index;
3241cb0ef41Sopenharmony_ci    }
3251cb0ef41Sopenharmony_ci    *out_insertion_index = len;
3261cb0ef41Sopenharmony_ci    return T::kNotFound;
3271cb0ef41Sopenharmony_ci  } else {
3281cb0ef41Sopenharmony_ci    DCHECK_LE(valid_entries, array->number_of_entries());
3291cb0ef41Sopenharmony_ci    DCHECK_NULL(out_insertion_index);  // Not supported here.
3301cb0ef41Sopenharmony_ci    for (int number = 0; number < valid_entries; number++) {
3311cb0ef41Sopenharmony_ci      if (array->GetKey(InternalIndex(number)) == name) return number;
3321cb0ef41Sopenharmony_ci    }
3331cb0ef41Sopenharmony_ci    return T::kNotFound;
3341cb0ef41Sopenharmony_ci  }
3351cb0ef41Sopenharmony_ci}
3361cb0ef41Sopenharmony_ci
3371cb0ef41Sopenharmony_citemplate <SearchMode search_mode, typename T>
3381cb0ef41Sopenharmony_ciint Search(T* array, Name name, int valid_entries, int* out_insertion_index,
3391cb0ef41Sopenharmony_ci           bool concurrent_search) {
3401cb0ef41Sopenharmony_ci  SLOW_DCHECK_IMPLIES(!concurrent_search, array->IsSortedNoDuplicates());
3411cb0ef41Sopenharmony_ci
3421cb0ef41Sopenharmony_ci  if (valid_entries == 0) {
3431cb0ef41Sopenharmony_ci    if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
3441cb0ef41Sopenharmony_ci      *out_insertion_index = 0;
3451cb0ef41Sopenharmony_ci    }
3461cb0ef41Sopenharmony_ci    return T::kNotFound;
3471cb0ef41Sopenharmony_ci  }
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_ci  // Do linear search for small arrays, and for searches in the background
3501cb0ef41Sopenharmony_ci  // thread.
3511cb0ef41Sopenharmony_ci  const int kMaxElementsForLinearSearch = 8;
3521cb0ef41Sopenharmony_ci  if (valid_entries <= kMaxElementsForLinearSearch || concurrent_search) {
3531cb0ef41Sopenharmony_ci    return LinearSearch<search_mode>(array, name, valid_entries,
3541cb0ef41Sopenharmony_ci                                     out_insertion_index);
3551cb0ef41Sopenharmony_ci  }
3561cb0ef41Sopenharmony_ci
3571cb0ef41Sopenharmony_ci  return BinarySearch<search_mode>(array, name, valid_entries,
3581cb0ef41Sopenharmony_ci                                   out_insertion_index);
3591cb0ef41Sopenharmony_ci}
3601cb0ef41Sopenharmony_ci
3611cb0ef41Sopenharmony_cidouble FixedDoubleArray::get_scalar(int index) {
3621cb0ef41Sopenharmony_ci  DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
3631cb0ef41Sopenharmony_ci         map() != GetReadOnlyRoots().fixed_array_map());
3641cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
3651cb0ef41Sopenharmony_ci  DCHECK(!is_the_hole(index));
3661cb0ef41Sopenharmony_ci  return ReadField<double>(kHeaderSize + index * kDoubleSize);
3671cb0ef41Sopenharmony_ci}
3681cb0ef41Sopenharmony_ci
3691cb0ef41Sopenharmony_ciuint64_t FixedDoubleArray::get_representation(int index) {
3701cb0ef41Sopenharmony_ci  DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
3711cb0ef41Sopenharmony_ci         map() != GetReadOnlyRoots().fixed_array_map());
3721cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
3731cb0ef41Sopenharmony_ci  int offset = kHeaderSize + index * kDoubleSize;
3741cb0ef41Sopenharmony_ci  // Bug(v8:8875): Doubles may be unaligned.
3751cb0ef41Sopenharmony_ci  return base::ReadUnalignedValue<uint64_t>(field_address(offset));
3761cb0ef41Sopenharmony_ci}
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ciHandle<Object> FixedDoubleArray::get(FixedDoubleArray array, int index,
3791cb0ef41Sopenharmony_ci                                     Isolate* isolate) {
3801cb0ef41Sopenharmony_ci  if (array.is_the_hole(index)) {
3811cb0ef41Sopenharmony_ci    return ReadOnlyRoots(isolate).the_hole_value_handle();
3821cb0ef41Sopenharmony_ci  } else {
3831cb0ef41Sopenharmony_ci    return isolate->factory()->NewNumber(array.get_scalar(index));
3841cb0ef41Sopenharmony_ci  }
3851cb0ef41Sopenharmony_ci}
3861cb0ef41Sopenharmony_ci
3871cb0ef41Sopenharmony_civoid FixedDoubleArray::set(int index, double value) {
3881cb0ef41Sopenharmony_ci  DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
3891cb0ef41Sopenharmony_ci         map() != GetReadOnlyRoots().fixed_array_map());
3901cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
3911cb0ef41Sopenharmony_ci  int offset = kHeaderSize + index * kDoubleSize;
3921cb0ef41Sopenharmony_ci  if (std::isnan(value)) {
3931cb0ef41Sopenharmony_ci    WriteField<double>(offset, std::numeric_limits<double>::quiet_NaN());
3941cb0ef41Sopenharmony_ci  } else {
3951cb0ef41Sopenharmony_ci    WriteField<double>(offset, value);
3961cb0ef41Sopenharmony_ci  }
3971cb0ef41Sopenharmony_ci  DCHECK(!is_the_hole(index));
3981cb0ef41Sopenharmony_ci}
3991cb0ef41Sopenharmony_ci
4001cb0ef41Sopenharmony_civoid FixedDoubleArray::set_the_hole(Isolate* isolate, int index) {
4011cb0ef41Sopenharmony_ci  set_the_hole(index);
4021cb0ef41Sopenharmony_ci}
4031cb0ef41Sopenharmony_ci
4041cb0ef41Sopenharmony_civoid FixedDoubleArray::set_the_hole(int index) {
4051cb0ef41Sopenharmony_ci  DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
4061cb0ef41Sopenharmony_ci         map() != GetReadOnlyRoots().fixed_array_map());
4071cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
4081cb0ef41Sopenharmony_ci  int offset = kHeaderSize + index * kDoubleSize;
4091cb0ef41Sopenharmony_ci  base::WriteUnalignedValue<uint64_t>(field_address(offset), kHoleNanInt64);
4101cb0ef41Sopenharmony_ci}
4111cb0ef41Sopenharmony_ci
4121cb0ef41Sopenharmony_cibool FixedDoubleArray::is_the_hole(Isolate* isolate, int index) {
4131cb0ef41Sopenharmony_ci  return is_the_hole(index);
4141cb0ef41Sopenharmony_ci}
4151cb0ef41Sopenharmony_ci
4161cb0ef41Sopenharmony_cibool FixedDoubleArray::is_the_hole(int index) {
4171cb0ef41Sopenharmony_ci  return get_representation(index) == kHoleNanInt64;
4181cb0ef41Sopenharmony_ci}
4191cb0ef41Sopenharmony_ci
4201cb0ef41Sopenharmony_civoid FixedDoubleArray::MoveElements(Isolate* isolate, int dst_index,
4211cb0ef41Sopenharmony_ci                                    int src_index, int len,
4221cb0ef41Sopenharmony_ci                                    WriteBarrierMode mode) {
4231cb0ef41Sopenharmony_ci  DCHECK_EQ(SKIP_WRITE_BARRIER, mode);
4241cb0ef41Sopenharmony_ci  double* data_start = reinterpret_cast<double*>(field_address(kHeaderSize));
4251cb0ef41Sopenharmony_ci  MemMove(data_start + dst_index, data_start + src_index, len * kDoubleSize);
4261cb0ef41Sopenharmony_ci}
4271cb0ef41Sopenharmony_ci
4281cb0ef41Sopenharmony_civoid FixedDoubleArray::FillWithHoles(int from, int to) {
4291cb0ef41Sopenharmony_ci  for (int i = from; i < to; i++) {
4301cb0ef41Sopenharmony_ci    set_the_hole(i);
4311cb0ef41Sopenharmony_ci  }
4321cb0ef41Sopenharmony_ci}
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_ciMaybeObject WeakFixedArray::Get(int index) const {
4351cb0ef41Sopenharmony_ci  PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
4361cb0ef41Sopenharmony_ci  return Get(cage_base, index);
4371cb0ef41Sopenharmony_ci}
4381cb0ef41Sopenharmony_ci
4391cb0ef41Sopenharmony_ciMaybeObject WeakFixedArray::Get(PtrComprCageBase cage_base, int index) const {
4401cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
4411cb0ef41Sopenharmony_ci  return objects(cage_base, index, kRelaxedLoad);
4421cb0ef41Sopenharmony_ci}
4431cb0ef41Sopenharmony_ci
4441cb0ef41Sopenharmony_civoid WeakFixedArray::Set(int index, MaybeObject value, WriteBarrierMode mode) {
4451cb0ef41Sopenharmony_ci  set_objects(index, value, mode);
4461cb0ef41Sopenharmony_ci}
4471cb0ef41Sopenharmony_ci
4481cb0ef41Sopenharmony_ciHandle<WeakFixedArray> WeakFixedArray::EnsureSpace(Isolate* isolate,
4491cb0ef41Sopenharmony_ci                                                   Handle<WeakFixedArray> array,
4501cb0ef41Sopenharmony_ci                                                   int length) {
4511cb0ef41Sopenharmony_ci  if (array->length() < length) {
4521cb0ef41Sopenharmony_ci    int grow_by = length - array->length();
4531cb0ef41Sopenharmony_ci    array = isolate->factory()->CopyWeakFixedArrayAndGrow(array, grow_by);
4541cb0ef41Sopenharmony_ci  }
4551cb0ef41Sopenharmony_ci  return array;
4561cb0ef41Sopenharmony_ci}
4571cb0ef41Sopenharmony_ci
4581cb0ef41Sopenharmony_ciMaybeObjectSlot WeakFixedArray::data_start() {
4591cb0ef41Sopenharmony_ci  return RawMaybeWeakField(kObjectsOffset);
4601cb0ef41Sopenharmony_ci}
4611cb0ef41Sopenharmony_ci
4621cb0ef41Sopenharmony_ciMaybeObjectSlot WeakFixedArray::RawFieldOfElementAt(int index) {
4631cb0ef41Sopenharmony_ci  return RawMaybeWeakField(OffsetOfElementAt(index));
4641cb0ef41Sopenharmony_ci}
4651cb0ef41Sopenharmony_ci
4661cb0ef41Sopenharmony_civoid WeakFixedArray::CopyElements(Isolate* isolate, int dst_index,
4671cb0ef41Sopenharmony_ci                                  WeakFixedArray src, int src_index, int len,
4681cb0ef41Sopenharmony_ci                                  WriteBarrierMode mode) {
4691cb0ef41Sopenharmony_ci  if (len == 0) return;
4701cb0ef41Sopenharmony_ci  DCHECK_LE(dst_index + len, length());
4711cb0ef41Sopenharmony_ci  DCHECK_LE(src_index + len, src.length());
4721cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
4731cb0ef41Sopenharmony_ci
4741cb0ef41Sopenharmony_ci  MaybeObjectSlot dst_slot(data_start() + dst_index);
4751cb0ef41Sopenharmony_ci  MaybeObjectSlot src_slot(src.data_start() + src_index);
4761cb0ef41Sopenharmony_ci  isolate->heap()->CopyRange(*this, dst_slot, src_slot, len, mode);
4771cb0ef41Sopenharmony_ci}
4781cb0ef41Sopenharmony_ci
4791cb0ef41Sopenharmony_ciMaybeObject WeakArrayList::Get(int index) const {
4801cb0ef41Sopenharmony_ci  PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
4811cb0ef41Sopenharmony_ci  return Get(cage_base, index);
4821cb0ef41Sopenharmony_ci}
4831cb0ef41Sopenharmony_ci
4841cb0ef41Sopenharmony_ciMaybeObject WeakArrayList::Get(PtrComprCageBase cage_base, int index) const {
4851cb0ef41Sopenharmony_ci  DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(capacity()));
4861cb0ef41Sopenharmony_ci  return objects(cage_base, index, kRelaxedLoad);
4871cb0ef41Sopenharmony_ci}
4881cb0ef41Sopenharmony_ci
4891cb0ef41Sopenharmony_civoid WeakArrayList::Set(int index, MaybeObject value, WriteBarrierMode mode) {
4901cb0ef41Sopenharmony_ci  set_objects(index, value, mode);
4911cb0ef41Sopenharmony_ci}
4921cb0ef41Sopenharmony_ci
4931cb0ef41Sopenharmony_civoid WeakArrayList::Set(int index, Smi value) {
4941cb0ef41Sopenharmony_ci  Set(index, MaybeObject::FromSmi(value), SKIP_WRITE_BARRIER);
4951cb0ef41Sopenharmony_ci}
4961cb0ef41Sopenharmony_ci
4971cb0ef41Sopenharmony_ciMaybeObjectSlot WeakArrayList::data_start() {
4981cb0ef41Sopenharmony_ci  return RawMaybeWeakField(kObjectsOffset);
4991cb0ef41Sopenharmony_ci}
5001cb0ef41Sopenharmony_ci
5011cb0ef41Sopenharmony_civoid WeakArrayList::CopyElements(Isolate* isolate, int dst_index,
5021cb0ef41Sopenharmony_ci                                 WeakArrayList src, int src_index, int len,
5031cb0ef41Sopenharmony_ci                                 WriteBarrierMode mode) {
5041cb0ef41Sopenharmony_ci  if (len == 0) return;
5051cb0ef41Sopenharmony_ci  DCHECK_LE(dst_index + len, capacity());
5061cb0ef41Sopenharmony_ci  DCHECK_LE(src_index + len, src.capacity());
5071cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
5081cb0ef41Sopenharmony_ci
5091cb0ef41Sopenharmony_ci  MaybeObjectSlot dst_slot(data_start() + dst_index);
5101cb0ef41Sopenharmony_ci  MaybeObjectSlot src_slot(src.data_start() + src_index);
5111cb0ef41Sopenharmony_ci  isolate->heap()->CopyRange(*this, dst_slot, src_slot, len, mode);
5121cb0ef41Sopenharmony_ci}
5131cb0ef41Sopenharmony_ci
5141cb0ef41Sopenharmony_ciHeapObject WeakArrayList::Iterator::Next() {
5151cb0ef41Sopenharmony_ci  if (!array_.is_null()) {
5161cb0ef41Sopenharmony_ci    while (index_ < array_.length()) {
5171cb0ef41Sopenharmony_ci      MaybeObject item = array_.Get(index_++);
5181cb0ef41Sopenharmony_ci      DCHECK(item->IsWeakOrCleared());
5191cb0ef41Sopenharmony_ci      if (!item->IsCleared()) return item->GetHeapObjectAssumeWeak();
5201cb0ef41Sopenharmony_ci    }
5211cb0ef41Sopenharmony_ci    array_ = WeakArrayList();
5221cb0ef41Sopenharmony_ci  }
5231cb0ef41Sopenharmony_ci  return HeapObject();
5241cb0ef41Sopenharmony_ci}
5251cb0ef41Sopenharmony_ci
5261cb0ef41Sopenharmony_ciint ArrayList::Length() const {
5271cb0ef41Sopenharmony_ci  if (FixedArray::cast(*this).length() == 0) return 0;
5281cb0ef41Sopenharmony_ci  return Smi::ToInt(FixedArray::cast(*this).get(kLengthIndex));
5291cb0ef41Sopenharmony_ci}
5301cb0ef41Sopenharmony_ci
5311cb0ef41Sopenharmony_civoid ArrayList::SetLength(int length) {
5321cb0ef41Sopenharmony_ci  return FixedArray::cast(*this).set(kLengthIndex, Smi::FromInt(length));
5331cb0ef41Sopenharmony_ci}
5341cb0ef41Sopenharmony_ci
5351cb0ef41Sopenharmony_ciObject ArrayList::Get(int index) const {
5361cb0ef41Sopenharmony_ci  return FixedArray::cast(*this).get(kFirstIndex + index);
5371cb0ef41Sopenharmony_ci}
5381cb0ef41Sopenharmony_ci
5391cb0ef41Sopenharmony_ciObject ArrayList::Get(PtrComprCageBase cage_base, int index) const {
5401cb0ef41Sopenharmony_ci  return FixedArray::cast(*this).get(cage_base, kFirstIndex + index);
5411cb0ef41Sopenharmony_ci}
5421cb0ef41Sopenharmony_ci
5431cb0ef41Sopenharmony_ciObjectSlot ArrayList::Slot(int index) {
5441cb0ef41Sopenharmony_ci  return RawField(OffsetOfElementAt(kFirstIndex + index));
5451cb0ef41Sopenharmony_ci}
5461cb0ef41Sopenharmony_ci
5471cb0ef41Sopenharmony_civoid ArrayList::Set(int index, Object obj, WriteBarrierMode mode) {
5481cb0ef41Sopenharmony_ci  FixedArray::cast(*this).set(kFirstIndex + index, obj, mode);
5491cb0ef41Sopenharmony_ci}
5501cb0ef41Sopenharmony_ci
5511cb0ef41Sopenharmony_civoid ArrayList::Set(int index, Smi value) {
5521cb0ef41Sopenharmony_ci  DCHECK(Object(value).IsSmi());
5531cb0ef41Sopenharmony_ci  Set(index, value, SKIP_WRITE_BARRIER);
5541cb0ef41Sopenharmony_ci}
5551cb0ef41Sopenharmony_civoid ArrayList::Clear(int index, Object undefined) {
5561cb0ef41Sopenharmony_ci  DCHECK(undefined.IsUndefined());
5571cb0ef41Sopenharmony_ci  FixedArray::cast(*this).set(kFirstIndex + index, undefined,
5581cb0ef41Sopenharmony_ci                              SKIP_WRITE_BARRIER);
5591cb0ef41Sopenharmony_ci}
5601cb0ef41Sopenharmony_ci
5611cb0ef41Sopenharmony_ciint ByteArray::Size() { return RoundUp(length() + kHeaderSize, kTaggedSize); }
5621cb0ef41Sopenharmony_ci
5631cb0ef41Sopenharmony_cibyte ByteArray::get(int index) const {
5641cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
5651cb0ef41Sopenharmony_ci  DCHECK_LT(index, length());
5661cb0ef41Sopenharmony_ci  return ReadField<byte>(kHeaderSize + index * kCharSize);
5671cb0ef41Sopenharmony_ci}
5681cb0ef41Sopenharmony_ci
5691cb0ef41Sopenharmony_civoid ByteArray::set(int index, byte value) {
5701cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
5711cb0ef41Sopenharmony_ci  DCHECK_LT(index, length());
5721cb0ef41Sopenharmony_ci  WriteField<byte>(kHeaderSize + index * kCharSize, value);
5731cb0ef41Sopenharmony_ci}
5741cb0ef41Sopenharmony_ci
5751cb0ef41Sopenharmony_civoid ByteArray::copy_in(int index, const byte* buffer, int slice_length) {
5761cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
5771cb0ef41Sopenharmony_ci  DCHECK_GE(slice_length, 0);
5781cb0ef41Sopenharmony_ci  DCHECK_LE(slice_length, kMaxInt - index);
5791cb0ef41Sopenharmony_ci  DCHECK_LE(index + slice_length, length());
5801cb0ef41Sopenharmony_ci  Address dst_addr = field_address(kHeaderSize + index * kCharSize);
5811cb0ef41Sopenharmony_ci  memcpy(reinterpret_cast<void*>(dst_addr), buffer, slice_length);
5821cb0ef41Sopenharmony_ci}
5831cb0ef41Sopenharmony_ci
5841cb0ef41Sopenharmony_civoid ByteArray::copy_out(int index, byte* buffer, int slice_length) {
5851cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
5861cb0ef41Sopenharmony_ci  DCHECK_GE(slice_length, 0);
5871cb0ef41Sopenharmony_ci  DCHECK_LE(slice_length, kMaxInt - index);
5881cb0ef41Sopenharmony_ci  DCHECK_LE(index + slice_length, length());
5891cb0ef41Sopenharmony_ci  Address src_addr = field_address(kHeaderSize + index * kCharSize);
5901cb0ef41Sopenharmony_ci  memcpy(buffer, reinterpret_cast<void*>(src_addr), slice_length);
5911cb0ef41Sopenharmony_ci}
5921cb0ef41Sopenharmony_ci
5931cb0ef41Sopenharmony_ciint ByteArray::get_int(int index) const {
5941cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
5951cb0ef41Sopenharmony_ci  DCHECK_LT(index, length() / kIntSize);
5961cb0ef41Sopenharmony_ci  return ReadField<int>(kHeaderSize + index * kIntSize);
5971cb0ef41Sopenharmony_ci}
5981cb0ef41Sopenharmony_ci
5991cb0ef41Sopenharmony_civoid ByteArray::set_int(int index, int value) {
6001cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
6011cb0ef41Sopenharmony_ci  DCHECK_LT(index, length() / kIntSize);
6021cb0ef41Sopenharmony_ci  WriteField<int>(kHeaderSize + index * kIntSize, value);
6031cb0ef41Sopenharmony_ci}
6041cb0ef41Sopenharmony_ci
6051cb0ef41Sopenharmony_ciuint32_t ByteArray::get_uint32(int index) const {
6061cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
6071cb0ef41Sopenharmony_ci  DCHECK_LT(index, length() / kUInt32Size);
6081cb0ef41Sopenharmony_ci  return ReadField<uint32_t>(kHeaderSize + index * kUInt32Size);
6091cb0ef41Sopenharmony_ci}
6101cb0ef41Sopenharmony_ci
6111cb0ef41Sopenharmony_civoid ByteArray::set_uint32(int index, uint32_t value) {
6121cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
6131cb0ef41Sopenharmony_ci  DCHECK_LT(index, length() / kUInt32Size);
6141cb0ef41Sopenharmony_ci  WriteField<uint32_t>(kHeaderSize + index * kUInt32Size, value);
6151cb0ef41Sopenharmony_ci}
6161cb0ef41Sopenharmony_ci
6171cb0ef41Sopenharmony_ciuint32_t ByteArray::get_uint32_relaxed(int index) const {
6181cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
6191cb0ef41Sopenharmony_ci  DCHECK_LT(index, length() / kUInt32Size);
6201cb0ef41Sopenharmony_ci  return RELAXED_READ_UINT32_FIELD(*this, kHeaderSize + index * kUInt32Size);
6211cb0ef41Sopenharmony_ci}
6221cb0ef41Sopenharmony_ci
6231cb0ef41Sopenharmony_civoid ByteArray::set_uint32_relaxed(int index, uint32_t value) {
6241cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
6251cb0ef41Sopenharmony_ci  DCHECK_LT(index, length() / kUInt32Size);
6261cb0ef41Sopenharmony_ci  RELAXED_WRITE_UINT32_FIELD(*this, kHeaderSize + index * kUInt32Size, value);
6271cb0ef41Sopenharmony_ci}
6281cb0ef41Sopenharmony_ci
6291cb0ef41Sopenharmony_ciuint16_t ByteArray::get_uint16(int index) const {
6301cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
6311cb0ef41Sopenharmony_ci  DCHECK_LT(index, length() / kUInt16Size);
6321cb0ef41Sopenharmony_ci  return ReadField<uint16_t>(kHeaderSize + index * kUInt16Size);
6331cb0ef41Sopenharmony_ci}
6341cb0ef41Sopenharmony_ci
6351cb0ef41Sopenharmony_civoid ByteArray::set_uint16(int index, uint16_t value) {
6361cb0ef41Sopenharmony_ci  DCHECK_GE(index, 0);
6371cb0ef41Sopenharmony_ci  DCHECK_LT(index, length() / kUInt16Size);
6381cb0ef41Sopenharmony_ci  WriteField<uint16_t>(kHeaderSize + index * kUInt16Size, value);
6391cb0ef41Sopenharmony_ci}
6401cb0ef41Sopenharmony_ci
6411cb0ef41Sopenharmony_civoid ByteArray::clear_padding() {
6421cb0ef41Sopenharmony_ci  int data_size = length() + kHeaderSize;
6431cb0ef41Sopenharmony_ci  memset(reinterpret_cast<void*>(address() + data_size), 0, Size() - data_size);
6441cb0ef41Sopenharmony_ci}
6451cb0ef41Sopenharmony_ci
6461cb0ef41Sopenharmony_ciByteArray ByteArray::FromDataStartAddress(Address address) {
6471cb0ef41Sopenharmony_ci  DCHECK_TAG_ALIGNED(address);
6481cb0ef41Sopenharmony_ci  return ByteArray::cast(Object(address - kHeaderSize + kHeapObjectTag));
6491cb0ef41Sopenharmony_ci}
6501cb0ef41Sopenharmony_ci
6511cb0ef41Sopenharmony_ciint ByteArray::DataSize() const { return RoundUp(length(), kTaggedSize); }
6521cb0ef41Sopenharmony_ci
6531cb0ef41Sopenharmony_ciint ByteArray::ByteArraySize() { return SizeFor(length()); }
6541cb0ef41Sopenharmony_ci
6551cb0ef41Sopenharmony_cibyte* ByteArray::GetDataStartAddress() {
6561cb0ef41Sopenharmony_ci  return reinterpret_cast<byte*>(address() + kHeaderSize);
6571cb0ef41Sopenharmony_ci}
6581cb0ef41Sopenharmony_ci
6591cb0ef41Sopenharmony_cibyte* ByteArray::GetDataEndAddress() {
6601cb0ef41Sopenharmony_ci  return GetDataStartAddress() + length();
6611cb0ef41Sopenharmony_ci}
6621cb0ef41Sopenharmony_ci
6631cb0ef41Sopenharmony_citemplate <class T>
6641cb0ef41Sopenharmony_ciPodArray<T>::PodArray(Address ptr) : ByteArray(ptr) {}
6651cb0ef41Sopenharmony_ci
6661cb0ef41Sopenharmony_citemplate <class T>
6671cb0ef41Sopenharmony_ciPodArray<T> PodArray<T>::cast(Object object) {
6681cb0ef41Sopenharmony_ci  return PodArray<T>(object.ptr());
6691cb0ef41Sopenharmony_ci}
6701cb0ef41Sopenharmony_ci
6711cb0ef41Sopenharmony_ci// static
6721cb0ef41Sopenharmony_citemplate <class T>
6731cb0ef41Sopenharmony_ciHandle<PodArray<T>> PodArray<T>::New(Isolate* isolate, int length,
6741cb0ef41Sopenharmony_ci                                     AllocationType allocation) {
6751cb0ef41Sopenharmony_ci  return Handle<PodArray<T>>::cast(
6761cb0ef41Sopenharmony_ci      isolate->factory()->NewByteArray(length * sizeof(T), allocation));
6771cb0ef41Sopenharmony_ci}
6781cb0ef41Sopenharmony_ci
6791cb0ef41Sopenharmony_citemplate <class T>
6801cb0ef41Sopenharmony_ciint PodArray<T>::length() const {
6811cb0ef41Sopenharmony_ci  return ByteArray::length() / sizeof(T);
6821cb0ef41Sopenharmony_ci}
6831cb0ef41Sopenharmony_ci
6841cb0ef41Sopenharmony_ciint TemplateList::length() const {
6851cb0ef41Sopenharmony_ci  return Smi::ToInt(FixedArray::cast(*this).get(kLengthIndex));
6861cb0ef41Sopenharmony_ci}
6871cb0ef41Sopenharmony_ci
6881cb0ef41Sopenharmony_ciObject TemplateList::get(int index) const {
6891cb0ef41Sopenharmony_ci  return FixedArray::cast(*this).get(kFirstElementIndex + index);
6901cb0ef41Sopenharmony_ci}
6911cb0ef41Sopenharmony_ci
6921cb0ef41Sopenharmony_ciObject TemplateList::get(PtrComprCageBase cage_base, int index) const {
6931cb0ef41Sopenharmony_ci  return FixedArray::cast(*this).get(cage_base, kFirstElementIndex + index);
6941cb0ef41Sopenharmony_ci}
6951cb0ef41Sopenharmony_ci
6961cb0ef41Sopenharmony_civoid TemplateList::set(int index, Object value) {
6971cb0ef41Sopenharmony_ci  FixedArray::cast(*this).set(kFirstElementIndex + index, value);
6981cb0ef41Sopenharmony_ci}
6991cb0ef41Sopenharmony_ci
7001cb0ef41Sopenharmony_ci}  // namespace internal
7011cb0ef41Sopenharmony_ci}  // namespace v8
7021cb0ef41Sopenharmony_ci
7031cb0ef41Sopenharmony_ci#include "src/base/platform/wrappers.h"
7041cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h"
7051cb0ef41Sopenharmony_ci
7061cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_FIXED_ARRAY_INL_H_
707