1 // Copyright 2017 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_OBJECTS_FIXED_ARRAY_H_ 6 #define V8_OBJECTS_FIXED_ARRAY_H_ 7 8 #include "src/handles/maybe-handles.h" 9 #include "src/objects/instance-type.h" 10 #include "src/objects/objects.h" 11 #include "src/objects/smi.h" 12 13 // Has to be the last include (doesn't have include guards): 14 #include "src/objects/object-macros.h" 15 16 namespace v8 { 17 namespace internal { 18 19 #define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \ 20 V(BYTECODE_ARRAY_CONSTANT_POOL_SUB_TYPE) \ 21 V(BYTECODE_ARRAY_HANDLER_TABLE_SUB_TYPE) \ 22 V(CODE_STUBS_TABLE_SUB_TYPE) \ 23 V(COMPILATION_CACHE_TABLE_SUB_TYPE) \ 24 V(CONTEXT_SUB_TYPE) \ 25 V(COPY_ON_WRITE_SUB_TYPE) \ 26 V(DEOPTIMIZATION_DATA_SUB_TYPE) \ 27 V(DESCRIPTOR_ARRAY_SUB_TYPE) \ 28 V(EMBEDDED_OBJECT_SUB_TYPE) \ 29 V(ENUM_CACHE_SUB_TYPE) \ 30 V(ENUM_INDICES_CACHE_SUB_TYPE) \ 31 V(DEPENDENT_CODE_SUB_TYPE) \ 32 V(DICTIONARY_ELEMENTS_SUB_TYPE) \ 33 V(DICTIONARY_PROPERTIES_SUB_TYPE) \ 34 V(EMPTY_PROPERTIES_DICTIONARY_SUB_TYPE) \ 35 V(PACKED_ELEMENTS_SUB_TYPE) \ 36 V(FAST_PROPERTIES_SUB_TYPE) \ 37 V(FAST_TEMPLATE_INSTANTIATIONS_CACHE_SUB_TYPE) \ 38 V(HANDLER_TABLE_SUB_TYPE) \ 39 V(JS_COLLECTION_SUB_TYPE) \ 40 V(JS_WEAK_COLLECTION_SUB_TYPE) \ 41 V(NOSCRIPT_SHARED_FUNCTION_INFOS_SUB_TYPE) \ 42 V(NUMBER_STRING_CACHE_SUB_TYPE) \ 43 V(OBJECT_TO_CODE_SUB_TYPE) \ 44 V(OPTIMIZED_CODE_LITERALS_SUB_TYPE) \ 45 V(OPTIMIZED_CODE_MAP_SUB_TYPE) \ 46 V(PROTOTYPE_USERS_SUB_TYPE) \ 47 V(REGEXP_MULTIPLE_CACHE_SUB_TYPE) \ 48 V(RETAINED_MAPS_SUB_TYPE) \ 49 V(SCOPE_INFO_SUB_TYPE) \ 50 V(SCRIPT_LIST_SUB_TYPE) \ 51 V(SERIALIZED_OBJECTS_SUB_TYPE) \ 52 V(SHARED_FUNCTION_INFOS_SUB_TYPE) \ 53 V(SINGLE_CHARACTER_STRING_CACHE_SUB_TYPE) \ 54 V(SLOW_TEMPLATE_INSTANTIATIONS_CACHE_SUB_TYPE) \ 55 V(STRING_SPLIT_CACHE_SUB_TYPE) \ 56 V(TEMPLATE_INFO_SUB_TYPE) \ 57 V(FEEDBACK_METADATA_SUB_TYPE) \ 58 V(WEAK_NEW_SPACE_OBJECT_TO_CODE_SUB_TYPE) 59 60 enum FixedArraySubInstanceType { 61 #define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name, 62 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE) 63 #undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE 64 LAST_FIXED_ARRAY_SUB_TYPE = WEAK_NEW_SPACE_OBJECT_TO_CODE_SUB_TYPE 65 }; 66 67 #include "torque-generated/src/objects/fixed-array-tq.inc" 68 69 // Common superclass for FixedArrays that allow implementations to share 70 // common accessors and some code paths. 71 class FixedArrayBase 72 : public TorqueGeneratedFixedArrayBase<FixedArrayBase, HeapObject> { 73 public: 74 // Get and set the length using acquire loads and release stores. 75 DECL_SYNCHRONIZED_INT_ACCESSORS(length) 76 77 inline Object unchecked_synchronized_length() const; 78 79 static int GetMaxLengthForNewSpaceAllocation(ElementsKind kind); 80 81 V8_EXPORT_PRIVATE bool IsCowArray() const; 82 83 // Maximal allowed size, in bytes, of a single FixedArrayBase. 84 // Prevents overflowing size computations, as well as extreme memory 85 // consumption. It's either (512Mb - kTaggedSize) or (1024Mb - kTaggedSize). 86 // -kTaggedSize is here to ensure that this max size always fits into Smi 87 // which is necessary for being able to create a free space filler for the 88 // whole array of kMaxSize. 89 static const int kMaxSize = 128 * kTaggedSize * MB - kTaggedSize; 90 STATIC_ASSERT(Smi::IsValid(kMaxSize)); 91 92 protected: 93 TQ_OBJECT_CONSTRUCTORS(FixedArrayBase) 94 inline FixedArrayBase(Address ptr, 95 HeapObject::AllowInlineSmiStorage allow_smi); 96 }; 97 98 // FixedArray describes fixed-sized arrays with element type Object. 99 class FixedArray 100 : public TorqueGeneratedFixedArray<FixedArray, FixedArrayBase> { 101 public: 102 // Setter and getter for elements. 103 inline Object get(int index) const; 104 inline Object get(IsolateRoot isolate, int index) const; 105 106 static inline Handle<Object> get(FixedArray array, int index, 107 Isolate* isolate); 108 109 // Return a grown copy if the index is bigger than the array's length. 110 V8_EXPORT_PRIVATE static Handle<FixedArray> SetAndGrow( 111 Isolate* isolate, Handle<FixedArray> array, int index, 112 Handle<Object> value); 113 114 // Synchronized setters and getters. 115 inline Object synchronized_get(int index) const; 116 inline Object synchronized_get(IsolateRoot isolate, int index) const; 117 // Currently only Smis are written with release semantics, hence we can avoid 118 // a write barrier. 119 inline void synchronized_set(int index, Smi value); 120 121 // Setter that uses write barrier. 122 inline void set(int index, Object value); 123 inline bool is_the_hole(Isolate* isolate, int index); 124 125 // Setter that doesn't need write barrier. 126 inline void set(int index, Smi value); 127 // Setter with explicit barrier mode. 128 inline void set(int index, Object value, WriteBarrierMode mode); 129 130 // Setters for frequently used oddballs located in old space. 131 inline void set_undefined(int index); 132 inline void set_undefined(Isolate* isolate, int index); 133 inline void set_null(int index); 134 inline void set_null(Isolate* isolate, int index); 135 inline void set_the_hole(int index); 136 inline void set_the_hole(Isolate* isolate, int index); 137 138 inline ObjectSlot GetFirstElementAddress(); 139 inline bool ContainsOnlySmisOrHoles(); 140 141 // Gives access to raw memory which stores the array's data. 142 inline ObjectSlot data_start(); 143 144 inline void MoveElements(Isolate* isolate, int dst_index, int src_index, 145 int len, WriteBarrierMode mode); 146 147 inline void CopyElements(Isolate* isolate, int dst_index, FixedArray src, 148 int src_index, int len, WriteBarrierMode mode); 149 150 inline void FillWithHoles(int from, int to); 151 152 // Shrink the array and insert filler objects. {new_length} must be > 0. 153 V8_EXPORT_PRIVATE void Shrink(Isolate* isolate, int new_length); 154 // If {new_length} is 0, return the canonical empty FixedArray. Otherwise 155 // like above. 156 static Handle<FixedArray> ShrinkOrEmpty(Isolate* isolate, 157 Handle<FixedArray> array, 158 int new_length); 159 160 // Copy a sub array from the receiver to dest. 161 V8_EXPORT_PRIVATE void CopyTo(int pos, FixedArray dest, int dest_pos, 162 int len) const; 163 164 // Garbage collection support. SizeFor(int length)165 static constexpr int SizeFor(int length) { 166 return kHeaderSize + length * kTaggedSize; 167 } 168 169 // Code Generation support. OffsetOfElementAt(int index)170 static constexpr int OffsetOfElementAt(int index) { 171 STATIC_ASSERT(kObjectsOffset == SizeFor(0)); 172 return SizeFor(index); 173 } 174 175 // Garbage collection support. 176 inline ObjectSlot RawFieldOfElementAt(int index); 177 178 // Maximally allowed length of a FixedArray. 179 static const int kMaxLength = (kMaxSize - kHeaderSize) / kTaggedSize; 180 static_assert(Internals::IsValidSmi(kMaxLength), 181 "FixedArray maxLength not a Smi"); 182 183 // Maximally allowed length for regular (non large object space) object. 184 STATIC_ASSERT(kMaxRegularHeapObjectSize < kMaxSize); 185 static const int kMaxRegularLength = 186 (kMaxRegularHeapObjectSize - kHeaderSize) / kTaggedSize; 187 188 // Dispatched behavior. 189 DECL_PRINTER(FixedArray) 190 191 int AllocatedSize(); 192 193 class BodyDescriptor; 194 195 static constexpr int kObjectsOffset = kHeaderSize; 196 197 protected: 198 // Set operation on FixedArray without using write barriers. Can 199 // only be used for storing old space objects or smis. 200 static inline void NoWriteBarrierSet(FixedArray array, int index, 201 Object value); 202 203 private: 204 STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize); 205 206 inline void set_undefined(ReadOnlyRoots ro_roots, int index); 207 inline void set_null(ReadOnlyRoots ro_roots, int index); 208 inline void set_the_hole(ReadOnlyRoots ro_roots, int index); 209 210 TQ_OBJECT_CONSTRUCTORS(FixedArray) 211 }; 212 213 // FixedArray alias added only because of IsFixedArrayExact() predicate, which 214 // checks for the exact instance type FIXED_ARRAY_TYPE instead of a range 215 // check: [FIRST_FIXED_ARRAY_TYPE, LAST_FIXED_ARRAY_TYPE]. 216 class FixedArrayExact final : public FixedArray {}; 217 218 // FixedDoubleArray describes fixed-sized arrays with element type double. 219 class FixedDoubleArray 220 : public TorqueGeneratedFixedDoubleArray<FixedDoubleArray, FixedArrayBase> { 221 public: 222 // Setter and getter for elements. 223 inline double get_scalar(int index); 224 inline uint64_t get_representation(int index); 225 static inline Handle<Object> get(FixedDoubleArray array, int index, 226 Isolate* isolate); 227 inline void set(int index, double value); 228 inline void set_the_hole(Isolate* isolate, int index); 229 inline void set_the_hole(int index); 230 231 // Checking for the hole. 232 inline bool is_the_hole(Isolate* isolate, int index); 233 inline bool is_the_hole(int index); 234 235 // Garbage collection support. SizeFor(int length)236 inline static int SizeFor(int length) { 237 return kHeaderSize + length * kDoubleSize; 238 } 239 240 inline void MoveElements(Isolate* isolate, int dst_index, int src_index, 241 int len, WriteBarrierMode mode); 242 243 inline void FillWithHoles(int from, int to); 244 245 // Code Generation support. OffsetOfElementAt(int index)246 static int OffsetOfElementAt(int index) { return SizeFor(index); } 247 248 // Start offset of elements. 249 static constexpr int kFloatsOffset = kHeaderSize; 250 251 // Maximally allowed length of a FixedDoubleArray. 252 static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; 253 static_assert(Internals::IsValidSmi(kMaxLength), 254 "FixedDoubleArray maxLength not a Smi"); 255 256 // Dispatched behavior. 257 DECL_PRINTER(FixedDoubleArray) 258 DECL_VERIFIER(FixedDoubleArray) 259 260 class BodyDescriptor; 261 262 TQ_OBJECT_CONSTRUCTORS(FixedDoubleArray) 263 }; 264 265 // WeakFixedArray describes fixed-sized arrays with element type 266 // MaybeObject. 267 class WeakFixedArray 268 : public TorqueGeneratedWeakFixedArray<WeakFixedArray, HeapObject> { 269 public: 270 inline MaybeObject Get(int index) const; 271 inline MaybeObject Get(IsolateRoot isolate, int index) const; 272 273 inline void Set( 274 int index, MaybeObject value, 275 WriteBarrierMode mode = WriteBarrierMode::UPDATE_WRITE_BARRIER); 276 277 // Get and set the length using acquire loads and release stores. 278 DECL_SYNCHRONIZED_INT_ACCESSORS(length) 279 280 // Gives access to raw memory which stores the array's data. 281 inline MaybeObjectSlot data_start(); 282 283 inline MaybeObjectSlot RawFieldOfElementAt(int index); 284 285 inline void CopyElements(Isolate* isolate, int dst_index, WeakFixedArray src, 286 int src_index, int len, WriteBarrierMode mode); 287 288 DECL_PRINTER(WeakFixedArray) 289 DECL_VERIFIER(WeakFixedArray) 290 291 class BodyDescriptor; 292 293 static const int kMaxLength = 294 (FixedArray::kMaxSize - kHeaderSize) / kTaggedSize; 295 static_assert(Internals::IsValidSmi(kMaxLength), 296 "WeakFixedArray maxLength not a Smi"); 297 298 int AllocatedSize(); 299 OffsetOfElementAt(int index)300 static int OffsetOfElementAt(int index) { 301 STATIC_ASSERT(kObjectsOffset == SizeFor(0)); 302 return SizeFor(index); 303 } 304 305 private: 306 friend class Heap; 307 308 static const int kFirstIndex = 1; 309 310 TQ_OBJECT_CONSTRUCTORS(WeakFixedArray) 311 }; 312 313 // WeakArrayList is like a WeakFixedArray with static convenience methods for 314 // adding more elements. length() returns the number of elements in the list and 315 // capacity() returns the allocated size. The number of elements is stored at 316 // kLengthOffset and is updated with every insertion. The array grows 317 // dynamically with O(1) amortized insertion. 318 class WeakArrayList 319 : public TorqueGeneratedWeakArrayList<WeakArrayList, HeapObject> { 320 public: 321 NEVER_READ_ONLY_SPACE 322 DECL_PRINTER(WeakArrayList) 323 324 V8_EXPORT_PRIVATE static Handle<WeakArrayList> AddToEnd( 325 Isolate* isolate, Handle<WeakArrayList> array, 326 const MaybeObjectHandle& value); 327 328 // A version that adds to elements. This ensures that the elements are 329 // inserted atomically w.r.t GC. 330 V8_EXPORT_PRIVATE static Handle<WeakArrayList> AddToEnd( 331 Isolate* isolate, Handle<WeakArrayList> array, 332 const MaybeObjectHandle& value1, const MaybeObjectHandle& value2); 333 334 // Appends an element to the array and possibly compacts and shrinks live weak 335 // references to the start of the collection. Only use this method when 336 // indices to elements can change. 337 static Handle<WeakArrayList> Append( 338 Isolate* isolate, Handle<WeakArrayList> array, 339 const MaybeObjectHandle& value, 340 AllocationType allocation = AllocationType::kYoung); 341 342 // Compact weak references to the beginning of the array. 343 V8_EXPORT_PRIVATE void Compact(Isolate* isolate); 344 345 inline MaybeObject Get(int index) const; 346 inline MaybeObject Get(IsolateRoot isolate, int index) const; 347 348 // Set the element at index to obj. The underlying array must be large enough. 349 // If you need to grow the WeakArrayList, use the static AddToEnd() method 350 // instead. 351 inline void Set(int index, MaybeObject value, 352 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 353 SizeForCapacity(int capacity)354 static constexpr int SizeForCapacity(int capacity) { 355 return SizeFor(capacity); 356 } 357 CapacityForLength(int length)358 static constexpr int CapacityForLength(int length) { 359 return length + std::max(length / 2, 2); 360 } 361 362 // Gives access to raw memory which stores the array's data. 363 inline MaybeObjectSlot data_start(); 364 365 inline void CopyElements(Isolate* isolate, int dst_index, WeakArrayList src, 366 int src_index, int len, WriteBarrierMode mode); 367 368 V8_EXPORT_PRIVATE bool IsFull(); 369 370 // Get and set the capacity using acquire loads and release stores. 371 DECL_SYNCHRONIZED_INT_ACCESSORS(capacity) 372 373 int AllocatedSize(); 374 375 class BodyDescriptor; 376 377 static const int kMaxCapacity = 378 (FixedArray::kMaxSize - kHeaderSize) / kTaggedSize; 379 380 static Handle<WeakArrayList> EnsureSpace( 381 Isolate* isolate, Handle<WeakArrayList> array, int length, 382 AllocationType allocation = AllocationType::kYoung); 383 384 // Returns the number of non-cleaned weak references in the array. 385 int CountLiveWeakReferences() const; 386 387 // Returns the number of non-cleaned elements in the array. 388 int CountLiveElements() const; 389 390 // Returns whether an entry was found and removed. Will move the elements 391 // around in the array - this method can only be used in cases where the user 392 // doesn't care about the indices! Users should make sure there are no 393 // duplicates. 394 V8_EXPORT_PRIVATE bool RemoveOne(const MaybeObjectHandle& value); 395 396 class Iterator; 397 398 private: OffsetOfElementAt(int index)399 static int OffsetOfElementAt(int index) { 400 return kHeaderSize + index * kTaggedSize; 401 } 402 403 TQ_OBJECT_CONSTRUCTORS(WeakArrayList) 404 }; 405 406 class WeakArrayList::Iterator { 407 public: Iterator(WeakArrayList array)408 explicit Iterator(WeakArrayList array) : index_(0), array_(array) {} 409 Iterator(const Iterator&) = delete; 410 Iterator& operator=(const Iterator&) = delete; 411 412 inline HeapObject Next(); 413 414 private: 415 int index_; 416 WeakArrayList array_; 417 #ifdef DEBUG 418 DisallowHeapAllocation no_gc_; 419 #endif // DEBUG 420 }; 421 422 // Generic array grows dynamically with O(1) amortized insertion. 423 // 424 // ArrayList is a FixedArray with static convenience methods for adding more 425 // elements. The Length() method returns the number of elements in the list, not 426 // the allocated size. The number of elements is stored at kLengthIndex and is 427 // updated with every insertion. The elements of the ArrayList are stored in the 428 // underlying FixedArray starting at kFirstIndex. 429 class ArrayList : public TorqueGeneratedArrayList<ArrayList, FixedArray> { 430 public: 431 V8_EXPORT_PRIVATE static Handle<ArrayList> Add(Isolate* isolate, 432 Handle<ArrayList> array, 433 Handle<Object> obj); 434 V8_EXPORT_PRIVATE static Handle<ArrayList> Add(Isolate* isolate, 435 Handle<ArrayList> array, 436 Handle<Object> obj1, 437 Handle<Object> obj2); 438 static Handle<ArrayList> New(Isolate* isolate, int size); 439 440 // Returns the number of elements in the list, not the allocated size, which 441 // is length(). Lower and upper case length() return different results! 442 inline int Length() const; 443 444 // Sets the Length() as used by Elements(). Does not change the underlying 445 // storage capacity, i.e., length(). 446 inline void SetLength(int length); 447 inline Object Get(int index) const; 448 inline Object Get(IsolateRoot isolate, int index) const; 449 inline ObjectSlot Slot(int index); 450 451 // Set the element at index to obj. The underlying array must be large enough. 452 // If you need to grow the ArrayList, use the static Add() methods instead. 453 inline void Set(int index, Object obj, 454 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 455 456 // Set the element at index to undefined. This does not change the Length(). 457 inline void Clear(int index, Object undefined); 458 459 // Return a copy of the list of size Length() without the first entry. The 460 // number returned by Length() is stored in the first entry. 461 static Handle<FixedArray> Elements(Isolate* isolate, Handle<ArrayList> array); 462 463 static const int kHeaderFields = 1; 464 465 private: 466 static Handle<ArrayList> EnsureSpace(Isolate* isolate, 467 Handle<ArrayList> array, int length); 468 static const int kLengthIndex = 0; 469 static const int kFirstIndex = 1; 470 STATIC_ASSERT(kHeaderFields == kFirstIndex); 471 TQ_OBJECT_CONSTRUCTORS(ArrayList) 472 }; 473 474 enum SearchMode { ALL_ENTRIES, VALID_ENTRIES }; 475 476 template <SearchMode search_mode, typename T> 477 inline int Search(T* array, Name name, int valid_entries = 0, 478 int* out_insertion_index = nullptr, 479 bool concurrent_search = false); 480 481 // ByteArray represents fixed sized byte arrays. Used for the relocation info 482 // that is attached to code objects. 483 class ByteArray : public TorqueGeneratedByteArray<ByteArray, FixedArrayBase> { 484 public: 485 inline int Size(); 486 487 // Setter and getter. 488 inline byte get(int index) const; 489 inline void set(int index, byte value); 490 491 // Copy in / copy out whole byte slices. 492 inline void copy_out(int index, byte* buffer, int length); 493 inline void copy_in(int index, const byte* buffer, int length); 494 495 // Treat contents as an int array. 496 inline int get_int(int index) const; 497 inline void set_int(int index, int value); 498 499 inline uint32_t get_uint32(int index) const; 500 inline void set_uint32(int index, uint32_t value); 501 502 inline uint32_t get_uint32_relaxed(int index) const; 503 inline void set_uint32_relaxed(int index, uint32_t value); 504 505 // Clear uninitialized padding space. This ensures that the snapshot content 506 // is deterministic. 507 inline void clear_padding(); 508 SizeFor(int length)509 static int SizeFor(int length) { 510 return OBJECT_POINTER_ALIGN(kHeaderSize + length); 511 } 512 // We use byte arrays for free blocks in the heap. Given a desired size in 513 // bytes that is a multiple of the word size and big enough to hold a byte 514 // array, this function returns the number of elements a byte array should 515 // have. LengthFor(int size_in_bytes)516 static int LengthFor(int size_in_bytes) { 517 DCHECK(IsAligned(size_in_bytes, kTaggedSize)); 518 DCHECK_GE(size_in_bytes, kHeaderSize); 519 return size_in_bytes - kHeaderSize; 520 } 521 522 // Returns data start address. 523 inline byte* GetDataStartAddress(); 524 // Returns address of the past-the-end element. 525 inline byte* GetDataEndAddress(); 526 527 inline int DataSize() const; 528 529 // Returns a pointer to the ByteArray object for a given data start address. 530 static inline ByteArray FromDataStartAddress(Address address); 531 532 // Dispatched behavior. 533 inline int ByteArraySize(); 534 DECL_PRINTER(ByteArray) 535 536 // Layout description. 537 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); 538 539 // Maximal length of a single ByteArray. 540 static const int kMaxLength = kMaxSize - kHeaderSize; 541 static_assert(Internals::IsValidSmi(kMaxLength), 542 "ByteArray maxLength not a Smi"); 543 544 class BodyDescriptor; 545 546 protected: 547 TQ_OBJECT_CONSTRUCTORS(ByteArray) 548 inline ByteArray(Address ptr, HeapObject::AllowInlineSmiStorage allow_smi); 549 }; 550 551 // Wrapper class for ByteArray which can store arbitrary C++ classes, as long 552 // as they can be copied with memcpy. 553 template <class T> 554 class PodArray : public ByteArray { 555 public: 556 static Handle<PodArray<T>> New( 557 Isolate* isolate, int length, 558 AllocationType allocation = AllocationType::kYoung); copy_out(int index,T * result,int length)559 void copy_out(int index, T* result, int length) { 560 ByteArray::copy_out(index * sizeof(T), reinterpret_cast<byte*>(result), 561 length * sizeof(T)); 562 } 563 copy_in(int index,const T * buffer,int length)564 void copy_in(int index, const T* buffer, int length) { 565 ByteArray::copy_in(index * sizeof(T), reinterpret_cast<const byte*>(buffer), 566 length * sizeof(T)); 567 } 568 matches(const T * buffer,int length)569 bool matches(const T* buffer, int length) { 570 DCHECK_LE(length, this->length()); 571 return memcmp(GetDataStartAddress(), buffer, length * sizeof(T)) == 0; 572 } 573 get(int index)574 T get(int index) { 575 T result; 576 copy_out(index, &result, 1); 577 return result; 578 } 579 set(int index,const T & value)580 void set(int index, const T& value) { copy_in(index, &value, 1); } 581 582 inline int length() const; 583 DECL_CAST(PodArray<T>) 584 585 OBJECT_CONSTRUCTORS(PodArray<T>, ByteArray); 586 }; 587 588 class TemplateList 589 : public TorqueGeneratedTemplateList<TemplateList, FixedArray> { 590 public: 591 static Handle<TemplateList> New(Isolate* isolate, int size); 592 inline int length() const; 593 inline Object get(int index) const; 594 inline Object get(IsolateRoot isolate, int index) const; 595 inline void set(int index, Object value); 596 static Handle<TemplateList> Add(Isolate* isolate, Handle<TemplateList> list, 597 Handle<Object> value); 598 private: 599 static const int kLengthIndex = 0; 600 static const int kFirstElementIndex = kLengthIndex + 1; 601 602 TQ_OBJECT_CONSTRUCTORS(TemplateList) 603 }; 604 605 } // namespace internal 606 } // namespace v8 607 608 #include "src/objects/object-macros-undef.h" 609 610 #endif // V8_OBJECTS_FIXED_ARRAY_H_ 611