LCOV - code coverage report
Current view: top level - src - visitors.h (source / functions) Hit Total Coverage
Test: app.info Lines: 29 29 100.0 %
Date: 2019-04-17 Functions: 12 12 100.0 %

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

Generated by: LCOV version 1.10