5 #ifndef V8_HEAP_OBJECTS_VISITING_INL_H_ 6 #define V8_HEAP_OBJECTS_VISITING_INL_H_ 8 #include "src/heap/objects-visiting.h" 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" 22 template <
typename ResultType,
typename ConcreteVisitor>
23 template <
typename T,
typename>
24 T* HeapVisitor<ResultType, ConcreteVisitor>::Cast(HeapObject*
object) {
25 return T::cast(
object);
28 template <
typename ResultType,
typename ConcreteVisitor>
29 template <
typename T,
typename>
30 T HeapVisitor<ResultType, ConcreteVisitor>::Cast(HeapObject*
object) {
31 return T::cast(
object);
34 template <
typename ResultType,
typename ConcreteVisitor>
35 ResultType HeapVisitor<ResultType, ConcreteVisitor>::Visit(HeapObject*
object) {
36 return Visit(object->map(), object);
39 template <
typename ResultType,
typename ConcreteVisitor>
40 ResultType HeapVisitor<ResultType, ConcreteVisitor>::Visit(Map map,
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)
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));
62 return visitor->VisitStruct(map,
object);
64 return visitor->VisitFreeSpace(map, FreeSpace::cast(
object));
66 return visitor->VisitWeakArray(map,
object);
67 case kVisitJSWeakCell:
68 return visitor->VisitJSWeakCell(map, JSWeakCell::cast(
object));
77 template <
typename ResultType,
typename ConcreteVisitor>
78 void HeapVisitor<ResultType, ConcreteVisitor>::VisitMapPointer(HeapObject* host,
80 static_cast<ConcreteVisitor*
>(
this)->VisitPointer(host, map);
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"); \ 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); \ 100 TYPED_VISITOR_ID_LIST(VISIT)
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);
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);
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);
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);
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);
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());
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);
175 template <
typename ConcreteVisitor>
176 int NewSpaceVisitor<ConcreteVisitor>::VisitJSApiObject(Map map,
178 ConcreteVisitor* visitor =
static_cast<ConcreteVisitor*
>(
this);
179 return visitor->VisitJSObject(map,
object);
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);
197 #endif // V8_HEAP_OBJECTS_VISITING_INL_H_