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 :
10 : namespace v8 {
11 : namespace internal {
12 :
13 : class Object;
14 :
15 : #define ROOT_ID_LIST(V) \
16 : V(kStringTable, "string_table", "(Internalized strings)") \
17 : V(kExternalStringsTable, "external_strings_table", "(External strings)") \
18 : V(kStrongRootList, "strong_root_list", "(Strong roots)") \
19 : V(kSmiRootList, "smi_root_list", "(Smi roots)") \
20 : V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \
21 : V(kTop, "top", "(Isolate)") \
22 : V(kRelocatable, "relocatable", "(Relocatable)") \
23 : V(kDebug, "debug", "(Debugger)") \
24 : V(kCompilationCache, "compilationcache", "(Compilation cache)") \
25 : V(kHandleScope, "handlescope", "(Handle scope)") \
26 : V(kDispatchTable, "dispatchtable", "(Dispatch table)") \
27 : V(kBuiltins, "builtins", "(Builtins)") \
28 : V(kGlobalHandles, "globalhandles", "(Global handles)") \
29 : V(kEternalHandles, "eternalhandles", "(Eternal handles)") \
30 : V(kThreadManager, "threadmanager", "(Thread manager)") \
31 : V(kStrongRoots, "strong roots", "(Strong roots)") \
32 : V(kExtensions, "Extensions", "(Extensions)")
33 :
34 : class VisitorSynchronization : public AllStatic {
35 : public:
36 : #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
37 : enum SyncTag { ROOT_ID_LIST(DECLARE_ENUM) kNumberOfSyncTags };
38 : #undef DECLARE_ENUM
39 :
40 : static const char* const kTags[kNumberOfSyncTags];
41 : static const char* const kTagNames[kNumberOfSyncTags];
42 : };
43 :
44 : enum class Root {
45 : #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
46 : ROOT_ID_LIST(DECLARE_ENUM)
47 : #undef DECLARE_ENUM
48 : // TODO(ulan): Merge with the ROOT_ID_LIST.
49 : kCodeFlusher,
50 : kPartialSnapshotCache,
51 : kWeakCollections,
52 : kWrapperTracing,
53 : kUnknown
54 : };
55 :
56 : // Abstract base class for visiting, and optionally modifying, the
57 : // pointers contained in roots. Used in GC and serialization/deserialization.
58 705162 : class RootVisitor BASE_EMBEDDED {
59 : public:
60 496135 : virtual ~RootVisitor() {}
61 :
62 : // Visits a contiguous arrays of pointers in the half-open range
63 : // [start, end). Any or all of the values may be modified on return.
64 : virtual void VisitRootPointers(Root root, Object** start, Object** end) = 0;
65 :
66 : // Handy shorthand for visiting a single pointer.
67 168492643 : virtual void VisitRootPointer(Root root, Object** p) {
68 168492643 : VisitRootPointers(root, p, p + 1);
69 168491948 : }
70 :
71 : // Intended for serialization/deserialization checking: insert, or
72 : // check for the presence of, a tag at this position in the stream.
73 : // Also used for marking up GC roots in heap snapshots.
74 : // TODO(ulan): Remove this.
75 2589478 : virtual void Synchronize(VisitorSynchronization::SyncTag tag) {}
76 : };
77 :
78 : // Abstract base class for visiting, and optionally modifying, the
79 : // pointers contained in Objects. Used in GC and serialization/deserialization.
80 141502323 : class ObjectVisitor BASE_EMBEDDED {
81 : public:
82 57898057 : virtual ~ObjectVisitor() {}
83 :
84 : // Visits a contiguous arrays of pointers in the half-open range
85 : // [start, end). Any or all of the values may be modified on return.
86 : virtual void VisitPointers(HeapObject* host, Object** start,
87 : Object** end) = 0;
88 :
89 : // Handy shorthand for visiting a single pointer.
90 530376266 : virtual void VisitPointer(HeapObject* host, Object** p) {
91 554631942 : VisitPointers(host, p, p + 1);
92 530802847 : }
93 :
94 : // Visit weak next_code_link in Code object.
95 : virtual void VisitNextCodeLink(Code* host, Object** p);
96 :
97 : // To allow lazy clearing of inline caches the visitor has
98 : // a rich interface for iterating over Code objects..
99 :
100 : // Visits a code target in the instruction stream.
101 : virtual void VisitCodeTarget(Code* host, RelocInfo* rinfo);
102 :
103 : // Visits a runtime entry in the instruction stream.
104 2683815 : virtual void VisitRuntimeEntry(Code* host, RelocInfo* rinfo) {}
105 :
106 : // Visit pointer embedded into a code object.
107 : virtual void VisitEmbeddedPointer(Code* host, RelocInfo* rinfo);
108 :
109 : // Visits an external reference embedded into a code object.
110 186885865 : virtual void VisitExternalReference(Code* host, RelocInfo* rinfo) {}
111 :
112 : // Visits an external reference.
113 1242997 : virtual void VisitExternalReference(Foreign* host, Address* p) {}
114 :
115 : // Visits an (encoded) internal reference.
116 38849519 : virtual void VisitInternalReference(Code* host, RelocInfo* rinfo) {}
117 : };
118 :
119 : } // namespace internal
120 : } // namespace v8
121 :
122 : #endif // V8_VISITORS_H_
|