• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_HEAP_CPPGC_MARKING_VISITOR_H_
6 #define V8_HEAP_CPPGC_MARKING_VISITOR_H_
7 
8 #include "include/cppgc/trace-trait.h"
9 #include "src/base/macros.h"
10 #include "src/heap/base/stack.h"
11 #include "src/heap/cppgc/visitor.h"
12 
13 namespace cppgc {
14 namespace internal {
15 
16 class HeapBase;
17 class HeapObjectHeader;
18 class Marker;
19 class BasicMarkingState;
20 class MutatorMarkingState;
21 class ConcurrentMarkingState;
22 
23 class V8_EXPORT_PRIVATE MarkingVisitorBase : public VisitorBase {
24  public:
25   MarkingVisitorBase(HeapBase&, BasicMarkingState&);
26   ~MarkingVisitorBase() override = default;
27 
28  protected:
29   void Visit(const void*, TraceDescriptor) final;
30   void VisitWeak(const void*, TraceDescriptor, WeakCallback, const void*) final;
31   void VisitEphemeron(const void*, const void*, TraceDescriptor) final;
32   void VisitWeakContainer(const void* self, TraceDescriptor strong_desc,
33                           TraceDescriptor weak_desc, WeakCallback callback,
34                           const void* data) final;
35   void RegisterWeakCallback(WeakCallback, const void*) final;
36   void HandleMovableReference(const void**) final;
37 
38   BasicMarkingState& marking_state_;
39 };
40 
41 class V8_EXPORT_PRIVATE MutatorMarkingVisitor : public MarkingVisitorBase {
42  public:
43   MutatorMarkingVisitor(HeapBase&, MutatorMarkingState&);
44   ~MutatorMarkingVisitor() override = default;
45 
46  protected:
47   void VisitRoot(const void*, TraceDescriptor, const SourceLocation&) final;
48   void VisitWeakRoot(const void*, TraceDescriptor, WeakCallback, const void*,
49                      const SourceLocation&) final;
50 };
51 
52 class V8_EXPORT_PRIVATE ConcurrentMarkingVisitor final
53     : public MarkingVisitorBase {
54  public:
55   ConcurrentMarkingVisitor(HeapBase&, ConcurrentMarkingState&);
56   ~ConcurrentMarkingVisitor() override = default;
57 
58  protected:
VisitRoot(const void *,TraceDescriptor,const SourceLocation &)59   void VisitRoot(const void*, TraceDescriptor, const SourceLocation&) final {
60     UNREACHABLE();
61   }
VisitWeakRoot(const void *,TraceDescriptor,WeakCallback,const void *,const SourceLocation &)62   void VisitWeakRoot(const void*, TraceDescriptor, WeakCallback, const void*,
63                      const SourceLocation&) final {
64     UNREACHABLE();
65   }
66 
67   bool DeferTraceToMutatorThreadIfConcurrent(const void*, TraceCallback,
68                                              size_t) final;
69 };
70 
71 class ConservativeMarkingVisitor : public ConservativeTracingVisitor,
72                                    public heap::base::StackVisitor {
73  public:
74   ConservativeMarkingVisitor(HeapBase&, MutatorMarkingState&, cppgc::Visitor&);
75   ~ConservativeMarkingVisitor() override = default;
76 
77  private:
78   void VisitFullyConstructedConservatively(HeapObjectHeader&) final;
79   void VisitInConstructionConservatively(HeapObjectHeader&,
80                                          TraceConservativelyCallback) final;
81   void VisitPointer(const void*) final;
82 
83   MutatorMarkingState& marking_state_;
84 };
85 
86 }  // namespace internal
87 }  // namespace cppgc
88 
89 #endif  // V8_HEAP_CPPGC_MARKING_VISITOR_H_
90