V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
objects-visiting.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_H_
6 #define V8_HEAP_OBJECTS_VISITING_H_
7 
8 #include "src/allocation.h"
9 #include "src/layout-descriptor.h"
10 #include "src/objects-body-descriptors.h"
11 #include "src/objects.h"
12 #include "src/objects/hash-table.h"
13 #include "src/objects/ordered-hash-table.h"
14 #include "src/objects/string.h"
15 #include "src/visitors.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 class BigInt;
21 class BytecodeArray;
22 class DataHandler;
23 class EmbedderDataArray;
24 class JSArrayBuffer;
25 class JSDataView;
26 class JSRegExp;
27 class JSTypedArray;
28 class JSWeakCell;
29 class JSWeakCollection;
30 class NativeContext;
31 class UncompiledDataWithoutPreParsedScope;
32 class UncompiledDataWithPreParsedScope;
33 class WasmInstanceObject;
34 
35 #define TYPED_VISITOR_ID_LIST(V) \
36  V(AllocationSite, AllocationSite*) \
37  V(BigInt, BigInt*) \
38  V(ByteArray, ByteArray) \
39  V(BytecodeArray, BytecodeArray) \
40  V(Cell, Cell*) \
41  V(Code, Code) \
42  V(CodeDataContainer, CodeDataContainer*) \
43  V(ConsString, ConsString) \
44  V(Context, Context) \
45  V(DataHandler, DataHandler*) \
46  V(DescriptorArray, DescriptorArray*) \
47  V(EmbedderDataArray, EmbedderDataArray) \
48  V(EphemeronHashTable, EphemeronHashTable) \
49  V(FeedbackCell, FeedbackCell*) \
50  V(FeedbackVector, FeedbackVector*) \
51  V(FixedArray, FixedArray) \
52  V(FixedDoubleArray, FixedDoubleArray) \
53  V(FixedFloat64Array, FixedFloat64Array) \
54  V(FixedTypedArrayBase, FixedTypedArrayBase) \
55  V(JSArrayBuffer, JSArrayBuffer*) \
56  V(JSDataView, JSDataView*) \
57  V(JSObject, JSObject*) \
58  V(JSTypedArray, JSTypedArray*) \
59  V(JSWeakCollection, JSWeakCollection*) \
60  V(Map, Map) \
61  V(NativeContext, NativeContext) \
62  V(Oddball, Oddball*) \
63  V(PreParsedScopeData, PreParsedScopeData*) \
64  V(PropertyArray, PropertyArray) \
65  V(PropertyCell, PropertyCell*) \
66  V(PrototypeInfo, PrototypeInfo*) \
67  V(SeqOneByteString, SeqOneByteString) \
68  V(SeqTwoByteString, SeqTwoByteString) \
69  V(SharedFunctionInfo, SharedFunctionInfo*) \
70  V(SlicedString, SlicedString) \
71  V(SmallOrderedHashMap, SmallOrderedHashMap) \
72  V(SmallOrderedHashSet, SmallOrderedHashSet) \
73  V(SmallOrderedNameDictionary, SmallOrderedNameDictionary) \
74  V(Symbol, Symbol) \
75  V(ThinString, ThinString) \
76  V(TransitionArray, TransitionArray*) \
77  V(UncompiledDataWithoutPreParsedScope, UncompiledDataWithoutPreParsedScope*) \
78  V(UncompiledDataWithPreParsedScope, UncompiledDataWithPreParsedScope*) \
79  V(WasmInstanceObject, WasmInstanceObject*)
80 
81 // The base class for visitors that need to dispatch on object type. The default
82 // behavior of all visit functions is to iterate body of the given object using
83 // the BodyDescriptor of the object.
84 //
85 // The visit functions return the size of the object cast to ResultType.
86 //
87 // This class is intended to be used in the following way:
88 //
89 // class SomeVisitor : public HeapVisitor<ResultType, SomeVisitor> {
90 // ...
91 // }
92 template <typename ResultType, typename ConcreteVisitor>
93 class HeapVisitor : public ObjectVisitor {
94  public:
95  V8_INLINE ResultType Visit(HeapObject* object);
96  V8_INLINE ResultType Visit(Map map, HeapObject* object);
97 
98  protected:
99  // A guard predicate for visiting the object.
100  // If it returns false then the default implementations of the Visit*
101  // functions bailout from iterating the object pointers.
102  V8_INLINE bool ShouldVisit(HeapObject* object) { return true; }
103  // Guard predicate for visiting the objects map pointer separately.
104  V8_INLINE bool ShouldVisitMapPointer() { return true; }
105  // A callback for visiting the map pointer in the object header.
106  V8_INLINE void VisitMapPointer(HeapObject* host, ObjectSlot map);
107  // If this predicate returns false, then the heap visitor will fail
108  // in default Visit implemention for subclasses of JSObject.
109  V8_INLINE bool AllowDefaultJSObjectVisit() { return true; }
110 
111 #define VISIT(TypeName, Type) \
112  V8_INLINE ResultType Visit##TypeName(Map map, Type object);
113  TYPED_VISITOR_ID_LIST(VISIT)
114 #undef VISIT
115  V8_INLINE ResultType VisitShortcutCandidate(Map map, ConsString object);
116  V8_INLINE ResultType VisitDataObject(Map map, HeapObject* object);
117  V8_INLINE ResultType VisitJSObjectFast(Map map, JSObject* object);
118  V8_INLINE ResultType VisitJSApiObject(Map map, JSObject* object);
119  V8_INLINE ResultType VisitStruct(Map map, HeapObject* object);
120  V8_INLINE ResultType VisitFreeSpace(Map map, FreeSpace* object);
121  V8_INLINE ResultType VisitWeakArray(Map map, HeapObject* object);
122 
123  template <typename T, typename = typename std::enable_if<
124  std::is_base_of<Object, T>::value>::type>
125  static V8_INLINE T* Cast(HeapObject* object);
126 
127  template <typename T, typename = typename std::enable_if<
128  std::is_base_of<ObjectPtr, T>::value>::type>
129  static V8_INLINE T Cast(HeapObject* object);
130 };
131 
132 template <typename ConcreteVisitor>
133 class NewSpaceVisitor : public HeapVisitor<int, ConcreteVisitor> {
134  public:
135  V8_INLINE bool ShouldVisitMapPointer() { return false; }
136 
137  // Special cases for young generation.
138 
139  V8_INLINE int VisitNativeContext(Map map, NativeContext object);
140  V8_INLINE int VisitJSApiObject(Map map, JSObject* object);
141 
142  int VisitBytecodeArray(Map map, BytecodeArray object) {
143  UNREACHABLE();
144  return 0;
145  }
146 
147  int VisitSharedFunctionInfo(Map map, SharedFunctionInfo* object) {
148  UNREACHABLE();
149  return 0;
150  }
151 
152  int VisitJSWeakCell(Map map, JSWeakCell* js_weak_cell) {
153  UNREACHABLE();
154  return 0;
155  }
156 };
157 
158 class WeakObjectRetainer;
159 
160 // A weak list is single linked list where each element has a weak pointer to
161 // the next element. Given the head of the list, this function removes dead
162 // elements from the list and if requested records slots for next-element
163 // pointers. The template parameter T is a WeakListVisitor that defines how to
164 // access the next-element pointers.
165 template <class T>
166 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer);
167 template <class T>
168 Object* VisitWeakList2(Heap* heap, Object* list, WeakObjectRetainer* retainer);
169 } // namespace internal
170 } // namespace v8
171 
172 #endif // V8_HEAP_OBJECTS_VISITING_H_
Definition: libplatform.h:13