V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
objects-body-descriptors.h
1 // Copyright 2015 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_BODY_DESCRIPTORS_H_
6 #define V8_OBJECTS_BODY_DESCRIPTORS_H_
7 
8 #include "src/objects.h"
9 #include "src/objects/map.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 // This is the base class for object's body descriptors.
15 //
16 // Each BodyDescriptor subclass must provide the following methods:
17 //
18 // 1) Returns true if the object contains a tagged value at given offset.
19 // It is used for invalid slots filtering. If the offset points outside
20 // of the object or to the map word, the result is UNDEFINED (!!!).
21 //
22 // static bool IsValidSlot(Map map, HeapObject* obj, int offset);
23 //
24 //
25 // 2) Iterate object's body using stateful object visitor.
26 //
27 // template <typename ObjectVisitor>
28 // static inline void IterateBody(Map map, HeapObject* obj, int object_size,
29 // ObjectVisitor* v);
31  public:
32  template <typename ObjectVisitor>
33  static inline void IteratePointers(HeapObject* obj, int start_offset,
34  int end_offset, ObjectVisitor* v);
35 
36  template <typename ObjectVisitor>
37  static inline void IteratePointer(HeapObject* obj, int offset,
38  ObjectVisitor* v);
39 
40  template <typename ObjectVisitor>
41  static inline void IterateCustomWeakPointers(HeapObject* obj,
42  int start_offset, int end_offset,
43  ObjectVisitor* v);
44 
45  template <typename ObjectVisitor>
46  static inline void IterateCustomWeakPointer(HeapObject* obj, int offset,
47  ObjectVisitor* v);
48 
49  template <typename ObjectVisitor>
50  static inline void IterateMaybeWeakPointers(HeapObject* obj, int start_offset,
51  int end_offset, ObjectVisitor* v);
52 
53  template <typename ObjectVisitor>
54  static inline void IterateMaybeWeakPointer(HeapObject* obj, int offset,
55  ObjectVisitor* v);
56 
57  protected:
58  // Returns true for all header and embedder fields.
59  static inline bool IsValidSlotImpl(Map map, HeapObject* obj, int offset);
60 
61  // Treats all header and embedder fields in the range as tagged.
62  template <typename ObjectVisitor>
63  static inline void IterateBodyImpl(Map map, HeapObject* obj, int start_offset,
64  int end_offset, ObjectVisitor* v);
65 };
66 
67 
68 // This class describes a body of an object of a fixed size
69 // in which all pointer fields are located in the [start_offset, end_offset)
70 // interval.
71 template <int start_offset, int end_offset, int size>
73  public:
74  static const int kStartOffset = start_offset;
75  static const int kEndOffset = end_offset;
76  static const int kSize = size;
77 
78  static bool IsValidSlot(Map map, HeapObject* obj, int offset) {
79  return offset >= kStartOffset && offset < kEndOffset;
80  }
81 
82  template <typename ObjectVisitor>
83  static inline void IterateBody(Map map, HeapObject* obj, ObjectVisitor* v) {
84  IteratePointers(obj, start_offset, end_offset, v);
85  }
86 
87  template <typename ObjectVisitor>
88  static inline void IterateBody(Map map, HeapObject* obj, int object_size,
89  ObjectVisitor* v) {
90  IterateBody(map, obj, v);
91  }
92 
93  static inline int SizeOf(Map map, HeapObject* object) { return kSize; }
94 };
95 
96 
97 // This class describes a body of an object of a variable size
98 // in which all pointer fields are located in the [start_offset, object_size)
99 // interval.
100 template <int start_offset>
102  public:
103  static const int kStartOffset = start_offset;
104 
105  static bool IsValidSlot(Map map, HeapObject* obj, int offset) {
106  return (offset >= kStartOffset);
107  }
108 
109  template <typename ObjectVisitor>
110  static inline void IterateBody(Map map, HeapObject* obj, int object_size,
111  ObjectVisitor* v) {
112  IteratePointers(obj, start_offset, object_size, v);
113  }
114 
115  static inline int SizeOf(Map map, HeapObject* object);
116 };
117 
118 
120 
121 template <int start_offset>
123  public:
124  static const int kStartOffset = start_offset;
125 
126  static bool IsValidSlot(Map map, HeapObject* obj, int offset) {
127  return (offset >= kStartOffset);
128  }
129 
130  template <typename ObjectVisitor>
131  static inline void IterateBody(Map map, HeapObject* obj, int object_size,
132  ObjectVisitor* v) {
133  IterateMaybeWeakPointers(obj, start_offset, object_size, v);
134  }
135 
136  static inline int SizeOf(Map map, HeapObject* object);
137 };
138 
139 // This class describes a body of an object which has a parent class that also
140 // has a body descriptor. This represents a union of the parent's body
141 // descriptor, and a new descriptor for the child -- so, both parent and child's
142 // slots are iterated. The parent must be fixed size, and its slots be disjoint
143 // with the child's.
144 template <class ParentBodyDescriptor, class ChildBodyDescriptor>
146  public:
147  // The parent must end be before the child's start offset, to make sure that
148  // their slots are disjoint.
149  STATIC_ASSERT(ParentBodyDescriptor::kSize <=
150  ChildBodyDescriptor::kStartOffset);
151 
152  static bool IsValidSlot(Map map, HeapObject* obj, int offset) {
153  return ParentBodyDescriptor::IsValidSlot(map, obj, offset) ||
154  ChildBodyDescriptor::IsValidSlot(map, obj, offset);
155  }
156 
157  template <typename ObjectVisitor>
158  static inline void IterateBody(Map map, HeapObject* obj, ObjectVisitor* v) {
159  ParentBodyDescriptor::IterateBody(map, obj, v);
160  ChildBodyDescriptor::IterateBody(map, obj, v);
161  }
162 
163  template <typename ObjectVisitor>
164  static inline void IterateBody(Map map, HeapObject* obj, int object_size,
165  ObjectVisitor* v) {
166  ParentBodyDescriptor::IterateBody(map, obj, object_size, v);
167  ChildBodyDescriptor::IterateBody(map, obj, object_size, v);
168  }
169 
170  static inline int SizeOf(Map map, HeapObject* object) {
171  // The child should know its full size.
172  return ChildBodyDescriptor::SizeOf(map, object);
173  }
174 };
175 
176 } // namespace internal
177 } // namespace v8
178 
179 #endif // V8_OBJECTS_BODY_DESCRIPTORS_H_
Definition: libplatform.h:13