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