5 #ifndef V8_OBJECTS_FIXED_ARRAY_H_ 6 #define V8_OBJECTS_FIXED_ARRAY_H_ 8 #include "src/maybe-handles.h" 9 #include "src/objects/instance-type.h" 10 #include "src/objects/slots.h" 11 #include "src/objects/smi.h" 14 #include "src/objects/object-macros.h" 18 typedef FlexibleWeakBodyDescriptor<HeapObject::kHeaderSize>
19 WeakArrayBodyDescriptor;
21 #define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \ 22 V(BYTECODE_ARRAY_CONSTANT_POOL_SUB_TYPE) \ 23 V(BYTECODE_ARRAY_HANDLER_TABLE_SUB_TYPE) \ 24 V(CODE_STUBS_TABLE_SUB_TYPE) \ 25 V(COMPILATION_CACHE_TABLE_SUB_TYPE) \ 27 V(COPY_ON_WRITE_SUB_TYPE) \ 28 V(DEOPTIMIZATION_DATA_SUB_TYPE) \ 29 V(DESCRIPTOR_ARRAY_SUB_TYPE) \ 30 V(EMBEDDED_OBJECT_SUB_TYPE) \ 31 V(ENUM_CACHE_SUB_TYPE) \ 32 V(ENUM_INDICES_CACHE_SUB_TYPE) \ 33 V(DEPENDENT_CODE_SUB_TYPE) \ 34 V(DICTIONARY_ELEMENTS_SUB_TYPE) \ 35 V(DICTIONARY_PROPERTIES_SUB_TYPE) \ 36 V(EMPTY_PROPERTIES_DICTIONARY_SUB_TYPE) \ 37 V(PACKED_ELEMENTS_SUB_TYPE) \ 38 V(FAST_PROPERTIES_SUB_TYPE) \ 39 V(FAST_TEMPLATE_INSTANTIATIONS_CACHE_SUB_TYPE) \ 40 V(HANDLER_TABLE_SUB_TYPE) \ 41 V(JS_COLLECTION_SUB_TYPE) \ 42 V(JS_WEAK_COLLECTION_SUB_TYPE) \ 43 V(NOSCRIPT_SHARED_FUNCTION_INFOS_SUB_TYPE) \ 44 V(NUMBER_STRING_CACHE_SUB_TYPE) \ 45 V(OBJECT_TO_CODE_SUB_TYPE) \ 46 V(OPTIMIZED_CODE_LITERALS_SUB_TYPE) \ 47 V(OPTIMIZED_CODE_MAP_SUB_TYPE) \ 48 V(PROTOTYPE_USERS_SUB_TYPE) \ 49 V(REGEXP_MULTIPLE_CACHE_SUB_TYPE) \ 50 V(RETAINED_MAPS_SUB_TYPE) \ 51 V(SCOPE_INFO_SUB_TYPE) \ 52 V(SCRIPT_LIST_SUB_TYPE) \ 53 V(SERIALIZED_OBJECTS_SUB_TYPE) \ 54 V(SHARED_FUNCTION_INFOS_SUB_TYPE) \ 55 V(SINGLE_CHARACTER_STRING_CACHE_SUB_TYPE) \ 56 V(SLOW_TEMPLATE_INSTANTIATIONS_CACHE_SUB_TYPE) \ 57 V(STRING_SPLIT_CACHE_SUB_TYPE) \ 58 V(STRING_TABLE_SUB_TYPE) \ 59 V(TEMPLATE_INFO_SUB_TYPE) \ 60 V(FEEDBACK_METADATA_SUB_TYPE) \ 61 V(WEAK_NEW_SPACE_OBJECT_TO_CODE_SUB_TYPE) 63 enum FixedArraySubInstanceType {
64 #define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name, 65 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE)
66 #undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE 67 LAST_FIXED_ARRAY_SUB_TYPE = WEAK_NEW_SPACE_OBJECT_TO_CODE_SUB_TYPE
75 inline int length()
const;
76 inline void set_length(
int value);
79 inline int synchronized_length()
const;
80 inline void synchronized_set_length(
int value);
82 inline Object* unchecked_synchronized_length()
const;
86 static int GetMaxLengthForNewSpaceAllocation(ElementsKind kind);
88 bool IsCowArray()
const;
93 #ifdef V8_HOST_ARCH_32_BIT 94 static const int kMaxSize = 512 * MB;
96 static const int kMaxSize = 1024 * MB;
97 #endif // V8_HOST_ARCH_32_BIT 100 #define FIXED_ARRAY_BASE_FIELDS(V) \ 101 V(kLengthOffset, kTaggedSize) \ 105 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
106 FIXED_ARRAY_BASE_FIELDS)
107 #undef FIXED_ARRAY_BASE_FIELDS 121 inline Object*
get(
int index)
const;
134 PretenureFlag pretenure = NOT_TENURED);
137 inline void set(
int index,
Object* value);
138 inline bool is_the_hole(
Isolate* isolate,
int index);
141 inline void set(
int index,
Smi value);
143 inline void set(
int index,
Object* value, WriteBarrierMode mode);
146 inline void set_undefined(
int index);
147 inline void set_undefined(
Isolate* isolate,
int index);
148 inline void set_null(
int index);
149 inline void set_null(
Isolate* isolate,
int index);
150 inline void set_the_hole(
int index);
151 inline void set_the_hole(
Isolate* isolate,
int index);
154 inline bool ContainsOnlySmisOrHoles();
156 bool ContainsSortedNumbers();
161 inline void MoveElements(
Heap* heap,
int dst_index,
int src_index,
int len,
162 WriteBarrierMode mode);
164 inline void FillWithHoles(
int from,
int to);
167 void Shrink(
Isolate* isolate,
int new_length);
175 void CopyTo(
int pos,
FixedArray dest,
int dest_pos,
int len)
const;
178 static constexpr
int SizeFor(
int length) {
179 return kHeaderSize + length * kTaggedSize;
183 static constexpr
int OffsetOfElementAt(
int index) {
return SizeFor(index); }
186 inline ObjectSlot RawFieldOfElementAt(
int index);
190 static const int kMaxLength = (kMaxSize - kHeaderSize) / kTaggedSize;
191 static_assert(Internals::IsValidSmi(kMaxLength),
192 "FixedArray maxLength not a Smi");
195 STATIC_ASSERT(kMaxRegularHeapObjectSize < kMaxSize);
196 static const int kMaxRegularLength =
197 (kMaxRegularHeapObjectSize - kHeaderSize) / kTaggedSize;
208 static inline void NoWriteBarrierSet(
FixedArray array,
int index,
212 STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize);
214 inline void set_undefined(
ReadOnlyRoots ro_roots,
int index);
230 inline double get_scalar(
int index);
231 inline uint64_t get_representation(
int index);
234 inline void set(
int index,
double value);
235 inline void set_the_hole(
Isolate* isolate,
int index);
236 inline void set_the_hole(
int index);
239 inline bool is_the_hole(
Isolate* isolate,
int index);
240 inline bool is_the_hole(
int index);
243 inline static int SizeFor(
int length) {
244 return kHeaderSize + length * kDoubleSize;
247 inline void MoveElements(
Heap* heap,
int dst_index,
int src_index,
int len,
248 WriteBarrierMode mode);
250 inline void FillWithHoles(
int from,
int to);
253 static int OffsetOfElementAt(
int index) {
return SizeFor(index); }
258 static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
259 static_assert(Internals::IsValidSmi(kMaxLength),
260 "FixedDoubleArray maxLength not a Smi");
283 inline void Set(
int index,
MaybeObject value, WriteBarrierMode mode);
285 static constexpr
int SizeFor(
int length) {
286 return kHeaderSize + length * kTaggedSize;
289 DECL_INT_ACCESSORS(length)
292 inline int synchronized_length()
const;
293 inline void synchronized_set_length(
int value);
306 #define WEAK_FIXED_ARRAY_FIELDS(V) \ 307 V(kLengthOffset, kTaggedSize) \ 311 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
312 WEAK_FIXED_ARRAY_FIELDS)
313 #undef WEAK_FIXED_ARRAY_FIELDS 315 static const int kMaxLength =
316 (FixedArray::kMaxSize - kHeaderSize) / kTaggedSize;
317 static_assert(Internals::IsValidSmi(kMaxLength),
318 "WeakFixedArray maxLength not a Smi");
321 static int OffsetOfElementAt(
int index) {
322 return kHeaderSize + index * kTaggedSize;
328 static const int kFirstIndex = 1;
354 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
356 static constexpr
int SizeForCapacity(
int capacity) {
357 return kHeaderSize + capacity * kTaggedSize;
365 DECL_INT_ACCESSORS(capacity)
366 DECL_INT_ACCESSORS(length)
369 inline int synchronized_capacity()
const;
370 inline void synchronized_set_capacity(
int value);
374 #define WEAK_ARRAY_LIST_FIELDS(V) \ 375 V(kCapacityOffset, kTaggedSize) \ 376 V(kLengthOffset, kTaggedSize) \ 380 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, WEAK_ARRAY_LIST_FIELDS)
381 #undef WEAK_ARRAY_LIST_FIELDS 385 static const int kMaxCapacity =
386 (FixedArray::kMaxSize - kHeaderSize) / kTaggedSize;
390 PretenureFlag pretenure = NOT_TENURED);
393 int CountLiveWeakReferences()
const;
417 static int OffsetOfElementAt(
int index) {
418 return kHeaderSize + index * kTaggedSize;
441 inline int Length()
const;
445 inline void SetLength(
int length);
446 inline Object* Get(
int index)
const;
452 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
455 inline void Clear(
int index,
Object* undefined);
465 static const int kLengthIndex = 0;
466 static const int kFirstIndex = 1;
470 enum SearchMode { ALL_ENTRIES, VALID_ENTRIES };
472 template <SearchMode search_mode,
typename T>
473 inline int Search(
T* array,
Name name,
int valid_entries = 0,
474 int* out_insertion_index =
nullptr);
483 inline byte
get(
int index)
const;
484 inline void set(
int index, byte value);
487 inline void copy_out(
int index, byte* buffer,
int length);
488 inline void copy_in(
int index,
const byte* buffer,
int length);
491 inline int get_int(
int index)
const;
492 inline void set_int(
int index,
int value);
494 inline uint32_t get_uint32(
int index)
const;
495 inline void set_uint32(
int index,
uint32_t value);
499 inline void clear_padding();
501 static int SizeFor(
int length) {
502 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
508 static int LengthFor(
int size_in_bytes) {
509 DCHECK(IsAligned(size_in_bytes, kTaggedSize));
510 DCHECK_GE(size_in_bytes, kHeaderSize);
511 return size_in_bytes - kHeaderSize;
515 inline byte* GetDataStartAddress();
517 inline byte* GetDataEndAddress();
519 inline int DataSize()
const;
527 inline int ByteArraySize();
532 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
535 static const int kMaxLength = kMaxSize - kHeaderSize;
536 static_assert(Internals::IsValidSmi(kMaxLength),
537 "ByteArray maxLength not a Smi");
555 PretenureFlag pretenure = NOT_TENURED);
556 void copy_out(
int index,
T* result) {
557 ByteArray::copy_out(index *
sizeof(
T), reinterpret_cast<byte*>(result),
562 copy_out(index, &result);
565 void set(
int index,
const T& value) {
566 copy_in(index *
sizeof(
T), reinterpret_cast<const byte*>(&value),
569 inline int length()
const;
578 DECL_ACCESSORS(base_pointer,
Object);
583 DECL_ACCESSORS(external_pointer,
void)
588 #define FIXED_TYPED_ARRAY_BASE_FIELDS(V) \ 589 V(kBasePointerOffset, kTaggedSize) \ 590 V(kExternalPointerOffset, kSystemPointerSize) \ 594 DEFINE_FIELD_OFFSET_CONSTANTS(FixedArrayBase::kHeaderSize,
595 FIXED_TYPED_ARRAY_BASE_FIELDS)
596 #undef FIXED_TYPED_ARRAY_BASE_FIELDS 598 STATIC_ASSERT(IsAligned(kHeaderSize, kDoubleAlignment));
600 static const int kDataOffset = kHeaderSize;
602 static const int kMaxElementSize = 8;
604 #ifdef V8_HOST_ARCH_32_BIT 605 static const size_t kMaxByteLength = std::numeric_limits<size_t>::max();
607 static const size_t kMaxByteLength =
608 static_cast<size_t>(Smi::kMaxValue) * kMaxElementSize;
609 #endif // V8_HOST_ARCH_32_BIT 611 static const size_t kMaxLength = Smi::kMaxValue;
615 inline int size()
const;
617 static inline int TypedArraySize(InstanceType
type,
int length);
618 inline int TypedArraySize(InstanceType
type)
const;
621 inline void* DataPtr();
623 inline int DataSize()
const;
625 inline size_t ByteLength()
const;
628 static inline int ElementSize(InstanceType
type);
630 inline int DataSize(InstanceType
type)
const;
635 template <
class Traits>
638 typedef typename Traits::ElementType ElementType;
639 static const InstanceType kInstanceType = Traits::kInstanceType;
643 static inline ElementType get_scalar_from_data_ptr(
void* data_ptr,
int index);
644 inline ElementType get_scalar(
int index);
647 inline void set(
int index, ElementType value);
649 static inline ElementType from(
int value);
650 static inline ElementType from(
uint32_t value);
651 static inline ElementType from(
double value);
652 static inline ElementType from(
int64_t value);
653 static inline ElementType from(uint64_t value);
656 bool* lossless =
nullptr);
669 #define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType) \ 670 STATIC_ASSERT(sizeof(elementType) <= FixedTypedArrayBase::kMaxElementSize); \ 671 class Type##ArrayTraits { \ 673 typedef elementType ElementType; \ 674 static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \ 675 static const char* Designator() { return #type " array"; } \ 676 static inline Handle<Object> ToHandle(Isolate* isolate, \ 677 elementType scalar); \ 678 static inline elementType defaultValue(); \ 681 typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array; 683 TYPED_ARRAYS(FIXED_TYPED_ARRAY_TRAITS)
685 #undef FIXED_TYPED_ARRAY_TRAITS 690 inline int length()
const;
691 inline Object*
get(
int index)
const;
692 inline void set(
int index,
Object* value);
697 static const int kLengthIndex = 0;
698 static const int kFirstElementIndex = kLengthIndex + 1;
706 #include "src/objects/object-macros-undef.h" 708 #endif // V8_OBJECTS_FIXED_ARRAY_H_