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