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