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_EMBEDDER_DATA_ARRAY_H_ 6 #define V8_OBJECTS_EMBEDDER_DATA_ARRAY_H_ 7 8 #include "src/common/globals.h" 9 #include "src/handles/maybe-handles.h" 10 #include "src/objects/heap-object.h" 11 12 // Has to be the last include (doesn't have include guards): 13 #include "src/objects/object-macros.h" 14 15 namespace v8 { 16 namespace internal { 17 18 #include "torque-generated/src/objects/embedder-data-array-tq.inc" 19 20 // This is a storage array for embedder data fields stored in native context. 21 // It's basically an "array of EmbedderDataSlots". 22 // Note, if the pointer compression is enabled the embedder data slot also 23 // contains a raw data part in addition to tagged part. 24 class EmbedderDataArray 25 : public TorqueGeneratedEmbedderDataArray<EmbedderDataArray, HeapObject> { 26 public: 27 // TODO(v8:8989): [torque] Support marker constants. 28 static const int kHeaderSize = kSize; 29 30 // Garbage collection support. SizeFor(int length)31 static constexpr int SizeFor(int length) { 32 return kHeaderSize + length * kEmbedderDataSlotSize; 33 } 34 35 // Returns a grown copy if the index is bigger than the array's length. 36 static Handle<EmbedderDataArray> EnsureCapacity( 37 Isolate* isolate, Handle<EmbedderDataArray> array, int index); 38 39 // Code Generation support. OffsetOfElementAt(int index)40 static constexpr int OffsetOfElementAt(int index) { return SizeFor(index); } 41 42 // Address of the first slot. 43 V8_INLINE Address slots_start(); 44 45 // Address of the one past last slot. 46 V8_INLINE Address slots_end(); 47 48 // Dispatched behavior. 49 DECL_PRINTER(EmbedderDataArray) 50 DECL_VERIFIER(EmbedderDataArray) 51 52 class BodyDescriptor; 53 54 static const int kMaxSize = kMaxRegularHeapObjectSize; 55 static constexpr int kMaxLength = 56 (kMaxSize - kHeaderSize) / kEmbedderDataSlotSize; 57 58 private: 59 STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize); 60 61 TQ_OBJECT_CONSTRUCTORS(EmbedderDataArray) 62 }; 63 64 } // namespace internal 65 } // namespace v8 66 67 #include "src/objects/object-macros-undef.h" 68 69 #endif // V8_OBJECTS_EMBEDDER_DATA_ARRAY_H_ 70