• 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_JS_UNIFIED_HEAP_MARKING_VISITOR_H_
6 #define V8_HEAP_CPPGC_JS_UNIFIED_HEAP_MARKING_VISITOR_H_
7 
8 #include "include/cppgc/trace-trait.h"
9 #include "include/v8-cppgc.h"
10 #include "src/base/macros.h"
11 #include "src/heap/cppgc-js/unified-heap-marking-state.h"
12 #include "src/heap/cppgc/marking-visitor.h"
13 
14 namespace cppgc {
15 
16 class SourceLocation;
17 
18 namespace internal {
19 class ConcurrentMarkingState;
20 class MarkingStateBase;
21 class MutatorMarkingState;
22 }  // namespace internal
23 }  // namespace cppgc
24 
25 namespace v8 {
26 namespace internal {
27 
28 using cppgc::SourceLocation;
29 using cppgc::TraceDescriptor;
30 using cppgc::WeakCallback;
31 using cppgc::internal::ConcurrentMarkingState;
32 using cppgc::internal::HeapBase;
33 using cppgc::internal::MarkingStateBase;
34 using cppgc::internal::MutatorMarkingState;
35 
36 class V8_EXPORT_PRIVATE UnifiedHeapMarkingVisitorBase : public JSVisitor {
37  public:
38   UnifiedHeapMarkingVisitorBase(HeapBase&, MarkingStateBase&,
39                                 UnifiedHeapMarkingState&);
40   ~UnifiedHeapMarkingVisitorBase() override = default;
41 
42  protected:
43   // C++ handling.
44   void Visit(const void*, TraceDescriptor) final;
45   void VisitWeak(const void*, TraceDescriptor, WeakCallback, const void*) final;
46   void VisitEphemeron(const void*, TraceDescriptor) final;
47   void VisitWeakContainer(const void* self, TraceDescriptor strong_desc,
48                           TraceDescriptor weak_desc, WeakCallback callback,
49                           const void* data) final;
50   void RegisterWeakCallback(WeakCallback, const void*) final;
51   void HandleMovableReference(const void**) final;
52 
53   // JS handling.
54   void Visit(const TracedReferenceBase& ref) final;
55 
56   MarkingStateBase& marking_state_;
57   UnifiedHeapMarkingState& unified_heap_marking_state_;
58 };
59 
60 class V8_EXPORT_PRIVATE MutatorUnifiedHeapMarkingVisitor final
61     : public UnifiedHeapMarkingVisitorBase {
62  public:
63   MutatorUnifiedHeapMarkingVisitor(HeapBase&, MutatorMarkingState&,
64                                    UnifiedHeapMarkingState&);
65   ~MutatorUnifiedHeapMarkingVisitor() override = default;
66 
67  protected:
68   void VisitRoot(const void*, TraceDescriptor, const SourceLocation&) final;
69   void VisitWeakRoot(const void*, TraceDescriptor, WeakCallback, const void*,
70                      const SourceLocation&) final;
71 };
72 
73 class V8_EXPORT_PRIVATE ConcurrentUnifiedHeapMarkingVisitor final
74     : public UnifiedHeapMarkingVisitorBase {
75  public:
76   ConcurrentUnifiedHeapMarkingVisitor(HeapBase&, ConcurrentMarkingState&,
77                                       UnifiedHeapMarkingState&);
78   ~ConcurrentUnifiedHeapMarkingVisitor() override = default;
79 
80  protected:
VisitRoot(const void *,TraceDescriptor,const SourceLocation &)81   void VisitRoot(const void*, TraceDescriptor, const SourceLocation&) final {
82     UNREACHABLE();
83   }
VisitWeakRoot(const void *,TraceDescriptor,WeakCallback,const void *,const SourceLocation &)84   void VisitWeakRoot(const void*, TraceDescriptor, WeakCallback, const void*,
85                      const SourceLocation&) final {
86     UNREACHABLE();
87   }
88 
89   bool DeferTraceToMutatorThreadIfConcurrent(const void*, cppgc::TraceCallback,
90                                              size_t) final;
91 };
92 
93 }  // namespace internal
94 }  // namespace v8
95 
96 #endif  // V8_HEAP_CPPGC_JS_UNIFIED_HEAP_MARKING_VISITOR_H_
97