Line data Source code
1 : // Copyright 2017 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_VISITORS_H_
6 : #define V8_VISITORS_H_
7 :
8 : #include "src/globals.h"
9 : #include "src/objects/code.h"
10 : #include "src/objects/foreign.h"
11 : #include "src/objects/slots.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 : class CodeDataContainer;
17 : class MaybeObject;
18 : class Object;
19 :
20 : #define ROOT_ID_LIST(V) \
21 : V(kStringTable, "(Internalized strings)") \
22 : V(kExternalStringsTable, "(External strings)") \
23 : V(kReadOnlyRootList, "(Read-only roots)") \
24 : V(kStrongRootList, "(Strong roots)") \
25 : V(kSmiRootList, "(Smi roots)") \
26 : V(kBootstrapper, "(Bootstrapper)") \
27 : V(kTop, "(Isolate)") \
28 : V(kRelocatable, "(Relocatable)") \
29 : V(kDebug, "(Debugger)") \
30 : V(kCompilationCache, "(Compilation cache)") \
31 : V(kHandleScope, "(Handle scope)") \
32 : V(kDispatchTable, "(Dispatch table)") \
33 : V(kBuiltins, "(Builtins)") \
34 : V(kGlobalHandles, "(Global handles)") \
35 : V(kEternalHandles, "(Eternal handles)") \
36 : V(kThreadManager, "(Thread manager)") \
37 : V(kStrongRoots, "(Strong roots)") \
38 : V(kExtensions, "(Extensions)") \
39 : V(kCodeFlusher, "(Code flusher)") \
40 : V(kPartialSnapshotCache, "(Partial snapshot cache)") \
41 : V(kReadOnlyObjectCache, "(Read-only object cache)") \
42 : V(kWeakCollections, "(Weak collections)") \
43 : V(kWrapperTracing, "(Wrapper tracing)") \
44 : V(kUnknown, "(Unknown)")
45 :
46 : class VisitorSynchronization : public AllStatic {
47 : public:
48 : #define DECLARE_ENUM(enum_item, ignore) enum_item,
49 : enum SyncTag { ROOT_ID_LIST(DECLARE_ENUM) kNumberOfSyncTags };
50 : #undef DECLARE_ENUM
51 : };
52 :
53 : enum class Root {
54 : #define DECLARE_ENUM(enum_item, ignore) enum_item,
55 : ROOT_ID_LIST(DECLARE_ENUM)
56 : #undef DECLARE_ENUM
57 : kNumberOfRoots
58 : };
59 :
60 : // Abstract base class for visiting, and optionally modifying, the
61 : // pointers contained in roots. Used in GC and serialization/deserialization.
62 939934 : class RootVisitor {
63 : public:
64 578637 : virtual ~RootVisitor() = default;
65 :
66 : // Visits a contiguous arrays of pointers in the half-open range
67 : // [start, end). Any or all of the values may be modified on return.
68 : virtual void VisitRootPointers(Root root, const char* description,
69 : FullObjectSlot start, FullObjectSlot end) = 0;
70 :
71 : // Handy shorthand for visiting a single pointer.
72 207233556 : virtual void VisitRootPointer(Root root, const char* description,
73 : FullObjectSlot p) {
74 414467112 : VisitRootPointers(root, description, p, p + 1);
75 207232326 : }
76 :
77 : // Intended for serialization/deserialization checking: insert, or
78 : // check for the presence of, a tag at this position in the stream.
79 : // Also used for marking up GC roots in heap snapshots.
80 : // TODO(ulan): Remove this.
81 3833342 : virtual void Synchronize(VisitorSynchronization::SyncTag tag) {}
82 :
83 : static const char* RootName(Root root);
84 : };
85 :
86 : class RelocIterator;
87 :
88 : // Abstract base class for visiting, and optionally modifying, the
89 : // pointers contained in Objects. Used in GC and serialization/deserialization.
90 195091431 : class ObjectVisitor {
91 : public:
92 64918688 : virtual ~ObjectVisitor() = default;
93 :
94 : // Visits a contiguous arrays of pointers in the half-open range
95 : // [start, end). Any or all of the values may be modified on return.
96 : virtual void VisitPointers(HeapObject host, ObjectSlot start,
97 : ObjectSlot end) = 0;
98 : virtual void VisitPointers(HeapObject host, MaybeObjectSlot start,
99 : MaybeObjectSlot end) = 0;
100 :
101 : // Custom weak pointers must be ignored by the GC but not other
102 : // visitors. They're used for e.g., lists that are recreated after GC. The
103 : // default implementation treats them as strong pointers. Visitors who want to
104 : // ignore them must override this function with empty.
105 4982773 : virtual void VisitCustomWeakPointers(HeapObject host, ObjectSlot start,
106 : ObjectSlot end) {
107 4982773 : VisitPointers(host, start, end);
108 4982731 : }
109 :
110 : // Handy shorthand for visiting a single pointer.
111 486219690 : virtual void VisitPointer(HeapObject host, ObjectSlot p) {
112 1032371081 : VisitPointers(host, p, p + 1);
113 482087008 : }
114 37439809 : virtual void VisitPointer(HeapObject host, MaybeObjectSlot p) {
115 74879618 : VisitPointers(host, p, p + 1);
116 37232283 : }
117 68764759 : virtual void VisitCustomWeakPointer(HeapObject host, ObjectSlot p) {
118 137529518 : VisitCustomWeakPointers(host, p, p + 1);
119 68856304 : }
120 :
121 : // To allow lazy clearing of inline caches the visitor has
122 : // a rich interface for iterating over Code objects ...
123 :
124 : // Visits a code target in the instruction stream.
125 : virtual void VisitCodeTarget(Code host, RelocInfo* rinfo) = 0;
126 :
127 : // Visit pointer embedded into a code object.
128 : virtual void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) = 0;
129 :
130 : // Visits a runtime entry in the instruction stream.
131 3159782 : virtual void VisitRuntimeEntry(Code host, RelocInfo* rinfo) {}
132 :
133 : // Visits an external reference embedded into a code object.
134 2503 : virtual void VisitExternalReference(Code host, RelocInfo* rinfo) {}
135 :
136 : // Visits an external reference.
137 3295257 : virtual void VisitExternalReference(Foreign host, Address* p) {}
138 :
139 : // Visits an (encoded) internal reference.
140 250 : virtual void VisitInternalReference(Code host, RelocInfo* rinfo) {}
141 :
142 : // Visits an off-heap target in the instruction stream.
143 126650858 : virtual void VisitOffHeapTarget(Code host, RelocInfo* rinfo) {}
144 :
145 : // Visits the relocation info using the given iterator.
146 : virtual void VisitRelocInfo(RelocIterator* it);
147 : };
148 :
149 : } // namespace internal
150 : } // namespace v8
151 :
152 : #endif // V8_VISITORS_H_
|