V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
objects-visiting-inl.h
1 // Copyright 2012 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_HEAP_OBJECTS_VISITING_INL_H_
6 #define V8_HEAP_OBJECTS_VISITING_INL_H_
7 
8 #include "src/heap/objects-visiting.h"
9 
10 #include "src/heap/array-buffer-tracker.h"
11 #include "src/heap/embedder-tracing.h"
12 #include "src/heap/mark-compact.h"
13 #include "src/macro-assembler.h"
14 #include "src/objects-body-descriptors-inl.h"
15 #include "src/objects-inl.h"
16 #include "src/objects/js-weak-refs-inl.h"
17 #include "src/wasm/wasm-objects.h"
18 
19 namespace v8 {
20 namespace internal {
21 
22 template <typename ResultType, typename ConcreteVisitor>
23 template <typename T, typename>
24 T* HeapVisitor<ResultType, ConcreteVisitor>::Cast(HeapObject* object) {
25  return T::cast(object);
26 }
27 
28 template <typename ResultType, typename ConcreteVisitor>
29 template <typename T, typename>
30 T HeapVisitor<ResultType, ConcreteVisitor>::Cast(HeapObject* object) {
31  return T::cast(object);
32 }
33 
34 template <typename ResultType, typename ConcreteVisitor>
35 ResultType HeapVisitor<ResultType, ConcreteVisitor>::Visit(HeapObject* object) {
36  return Visit(object->map(), object);
37 }
38 
39 template <typename ResultType, typename ConcreteVisitor>
40 ResultType HeapVisitor<ResultType, ConcreteVisitor>::Visit(Map map,
41  HeapObject* object) {
42  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
43  switch (map->visitor_id()) {
44 #define CASE(TypeName, Type) \
45  case kVisit##TypeName: \
46  return visitor->Visit##TypeName( \
47  map, ConcreteVisitor::template Cast<TypeName>(object));
48  TYPED_VISITOR_ID_LIST(CASE)
49 #undef CASE
50  case kVisitShortcutCandidate:
51  return visitor->VisitShortcutCandidate(
52  map, ConcreteVisitor::template Cast<ConsString>(object));
53  case kVisitDataObject:
54  return visitor->VisitDataObject(map, object);
55  case kVisitJSObjectFast:
56  return visitor->VisitJSObjectFast(
57  map, ConcreteVisitor::template Cast<JSObject>(object));
58  case kVisitJSApiObject:
59  return visitor->VisitJSApiObject(
60  map, ConcreteVisitor::template Cast<JSObject>(object));
61  case kVisitStruct:
62  return visitor->VisitStruct(map, object);
63  case kVisitFreeSpace:
64  return visitor->VisitFreeSpace(map, FreeSpace::cast(object));
65  case kVisitWeakArray:
66  return visitor->VisitWeakArray(map, object);
67  case kVisitJSWeakCell:
68  return visitor->VisitJSWeakCell(map, JSWeakCell::cast(object));
69  case kVisitorIdCount:
70  UNREACHABLE();
71  }
72  UNREACHABLE();
73  // Make the compiler happy.
74  return ResultType();
75 }
76 
77 template <typename ResultType, typename ConcreteVisitor>
78 void HeapVisitor<ResultType, ConcreteVisitor>::VisitMapPointer(HeapObject* host,
79  ObjectSlot map) {
80  static_cast<ConcreteVisitor*>(this)->VisitPointer(host, map);
81 }
82 
83 #define VISIT(TypeName, Type) \
84  template <typename ResultType, typename ConcreteVisitor> \
85  ResultType HeapVisitor<ResultType, ConcreteVisitor>::Visit##TypeName( \
86  Map map, Type object) { \
87  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this); \
88  if (!visitor->ShouldVisit(object)) return ResultType(); \
89  if (!visitor->AllowDefaultJSObjectVisit()) { \
90  DCHECK_WITH_MSG(!map->IsJSObjectMap(), \
91  "Implement custom visitor for new JSObject subclass in " \
92  "concurrent marker"); \
93  } \
94  int size = TypeName::BodyDescriptor::SizeOf(map, object); \
95  if (visitor->ShouldVisitMapPointer()) \
96  visitor->VisitMapPointer(object, object->map_slot()); \
97  TypeName::BodyDescriptor::IterateBody(map, object, size, visitor); \
98  return static_cast<ResultType>(size); \
99  }
100 TYPED_VISITOR_ID_LIST(VISIT)
101 #undef VISIT
102 
103 template <typename ResultType, typename ConcreteVisitor>
104 ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitShortcutCandidate(
105  Map map, ConsString object) {
106  return static_cast<ConcreteVisitor*>(this)->VisitConsString(map, object);
107 }
108 
109 template <typename ResultType, typename ConcreteVisitor>
110 ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitDataObject(
111  Map map, HeapObject* object) {
112  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
113  if (!visitor->ShouldVisit(object)) return ResultType();
114  int size = map->instance_size();
115  if (visitor->ShouldVisitMapPointer())
116  visitor->VisitMapPointer(object, object->map_slot());
117  return static_cast<ResultType>(size);
118 }
119 
120 template <typename ResultType, typename ConcreteVisitor>
121 ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitJSObjectFast(
122  Map map, JSObject* object) {
123  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
124  if (!visitor->ShouldVisit(object)) return ResultType();
125  int size = JSObject::FastBodyDescriptor::SizeOf(map, object);
126  if (visitor->ShouldVisitMapPointer())
127  visitor->VisitMapPointer(object, object->map_slot());
128  JSObject::FastBodyDescriptor::IterateBody(map, object, size, visitor);
129  return static_cast<ResultType>(size);
130 }
131 
132 template <typename ResultType, typename ConcreteVisitor>
133 ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitJSApiObject(
134  Map map, JSObject* object) {
135  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
136  if (!visitor->ShouldVisit(object)) return ResultType();
137  int size = JSObject::BodyDescriptor::SizeOf(map, object);
138  if (visitor->ShouldVisitMapPointer())
139  visitor->VisitMapPointer(object, object->map_slot());
140  JSObject::BodyDescriptor::IterateBody(map, object, size, visitor);
141  return static_cast<ResultType>(size);
142 }
143 
144 template <typename ResultType, typename ConcreteVisitor>
145 ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitStruct(
146  Map map, HeapObject* object) {
147  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
148  if (!visitor->ShouldVisit(object)) return ResultType();
149  int size = map->instance_size();
150  if (visitor->ShouldVisitMapPointer())
151  visitor->VisitMapPointer(object, object->map_slot());
152  StructBodyDescriptor::IterateBody(map, object, size, visitor);
153  return static_cast<ResultType>(size);
154 }
155 
156 template <typename ResultType, typename ConcreteVisitor>
157 ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitFreeSpace(
158  Map map, FreeSpace* object) {
159  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
160  if (!visitor->ShouldVisit(object)) return ResultType();
161  if (visitor->ShouldVisitMapPointer())
162  visitor->VisitMapPointer(object, object->map_slot());
163  return static_cast<ResultType>(FreeSpace::cast(object)->size());
164 }
165 
166 template <typename ConcreteVisitor>
167 int NewSpaceVisitor<ConcreteVisitor>::VisitNativeContext(Map map,
168  NativeContext object) {
169  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
170  int size = NativeContext::BodyDescriptor::SizeOf(map, object);
171  NativeContext::BodyDescriptor::IterateBody(map, object, size, visitor);
172  return size;
173 }
174 
175 template <typename ConcreteVisitor>
176 int NewSpaceVisitor<ConcreteVisitor>::VisitJSApiObject(Map map,
177  JSObject* object) {
178  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
179  return visitor->VisitJSObject(map, object);
180 }
181 
182 template <typename ResultType, typename ConcreteVisitor>
183 ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitWeakArray(
184  Map map, HeapObject* object) {
185  ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
186  if (!visitor->ShouldVisit(object)) return ResultType();
187  int size = WeakArrayBodyDescriptor::SizeOf(map, object);
188  if (visitor->ShouldVisitMapPointer())
189  visitor->VisitMapPointer(object, object->map_slot());
190  WeakArrayBodyDescriptor::IterateBody(map, object, size, visitor);
191  return size;
192 }
193 
194 } // namespace internal
195 } // namespace v8
196 
197 #endif // V8_HEAP_OBJECTS_VISITING_INL_H_
Definition: libplatform.h:13