1 // Copyright 2018 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_PROPERTY_ARRAY_H_ 6 #define V8_OBJECTS_PROPERTY_ARRAY_H_ 7 8 #include "src/objects/heap-object.h" 9 #include "torque-generated/field-offsets.h" 10 11 // Has to be the last include (doesn't have include guards): 12 #include "src/objects/object-macros.h" 13 14 namespace v8 { 15 namespace internal { 16 17 class PropertyArray : public HeapObject { 18 public: 19 // [length]: length of the array. 20 inline int length() const; 21 22 // Get the length using acquire loads. 23 inline int synchronized_length() const; 24 25 // This is only used on a newly allocated PropertyArray which 26 // doesn't have an existing hash. 27 inline void initialize_length(int length); 28 29 inline void SetHash(int hash); 30 inline int Hash() const; 31 32 inline Object get(int index) const; 33 inline Object get(IsolateRoot isolate, int index) const; 34 35 inline void set(int index, Object value); 36 // Setter with explicit barrier mode. 37 inline void set(int index, Object value, WriteBarrierMode mode); 38 39 // Signature must be in sync with FixedArray::CopyElements(). 40 inline void CopyElements(Isolate* isolate, int dst_index, PropertyArray src, 41 int src_index, int len, WriteBarrierMode mode); 42 43 // Gives access to raw memory which stores the array's data. 44 inline ObjectSlot data_start(); 45 46 // Garbage collection support. SizeFor(int length)47 static constexpr int SizeFor(int length) { 48 return kHeaderSize + length * kTaggedSize; 49 } OffsetOfElementAt(int index)50 static constexpr int OffsetOfElementAt(int index) { return SizeFor(index); } 51 52 DECL_CAST(PropertyArray) 53 DECL_PRINTER(PropertyArray) 54 DECL_VERIFIER(PropertyArray) 55 56 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, 57 TORQUE_GENERATED_PROPERTY_ARRAY_FIELDS) 58 59 // Garbage collection support. 60 using BodyDescriptor = FlexibleBodyDescriptor<kHeaderSize>; 61 62 static const int kLengthFieldSize = 10; 63 using LengthField = base::BitField<int, 0, kLengthFieldSize>; 64 static const int kMaxLength = LengthField::kMax; 65 using HashField = base::BitField<int, kLengthFieldSize, 66 kSmiValueSize - kLengthFieldSize - 1>; 67 68 static const int kNoHashSentinel = 0; 69 70 private: 71 DECL_INT_ACCESSORS(length_and_hash) 72 73 DECL_SYNCHRONIZED_INT_ACCESSORS(length_and_hash) 74 75 OBJECT_CONSTRUCTORS(PropertyArray, HeapObject); 76 }; 77 78 } // namespace internal 79 } // namespace v8 80 81 #include "src/objects/object-macros-undef.h" 82 83 #endif // V8_OBJECTS_PROPERTY_ARRAY_H_ 84