Line data Source code
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/globals.h"
9 : #include "src/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 : // This is a storage array for embedder data fields stored in native context.
19 : // It's basically an "array of EmbedderDataSlots".
20 : // Note, if the pointer compression is enabled the embedder data slot also
21 : // contains a raw data part in addition to tagged part.
22 : class EmbedderDataArray : public HeapObject {
23 : public:
24 : // [length]: length of the array in an embedder data slots.
25 : V8_INLINE int length() const;
26 : V8_INLINE void set_length(int value);
27 :
28 : DECL_CAST(EmbedderDataArray)
29 :
30 : // Layout description.
31 : #define EMBEDDER_DATA_ARRAY_FIELDS(V) \
32 : V(kLengthOffset, kTaggedSize) \
33 : V(kHeaderSize, 0)
34 :
35 : DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
36 : EMBEDDER_DATA_ARRAY_FIELDS)
37 : #undef EMBEDDER_DATA_ARRAY_FIELDS
38 :
39 : // Garbage collection support.
40 : static constexpr int SizeFor(int length) {
41 768992 : return kHeaderSize + length * kEmbedderDataSlotSize;
42 : }
43 :
44 : // Returns a grown copy if the index is bigger than the array's length.
45 : static Handle<EmbedderDataArray> EnsureCapacity(
46 : Isolate* isolate, Handle<EmbedderDataArray> array, int index);
47 :
48 : // Code Generation support.
49 583892 : static constexpr int OffsetOfElementAt(int index) { return SizeFor(index); }
50 :
51 : // Address of the first slot.
52 : V8_INLINE Address slots_start();
53 :
54 : // Address of the one past last slot.
55 : V8_INLINE Address slots_end();
56 :
57 : // Dispatched behavior.
58 : DECL_PRINTER(EmbedderDataArray)
59 : DECL_VERIFIER(EmbedderDataArray)
60 :
61 : class BodyDescriptor;
62 :
63 : static const int kMaxSize = kMaxRegularHeapObjectSize;
64 : static constexpr int kMaxLength =
65 : (kMaxSize - kHeaderSize) / kEmbedderDataSlotSize;
66 :
67 : private:
68 : STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize);
69 :
70 57576 : OBJECT_CONSTRUCTORS(EmbedderDataArray, HeapObject);
71 : };
72 :
73 : } // namespace internal
74 : } // namespace v8
75 :
76 : #include "src/objects/object-macros-undef.h"
77 :
78 : #endif // V8_OBJECTS_EMBEDDER_DATA_ARRAY_H_
|