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