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_GC_INVOKER_H_
6 #define V8_HEAP_CPPGC_GC_INVOKER_H_
7 
8 #include "include/cppgc/common.h"
9 #include "include/cppgc/heap.h"
10 #include "src/base/macros.h"
11 #include "src/heap/cppgc/garbage-collector.h"
12 
13 namespace cppgc {
14 
15 class Platform;
16 
17 namespace internal {
18 
19 // GC invoker that dispatches GC depending on StackSupport and StackState:
20 // 1. If StackState specifies no stack scan needed the GC is invoked
21 //    synchronously.
22 // 2. If StackState specifies conservative GC and StackSupport prohibits stack
23 //    scanning: Delay GC until it can be invoked without accessing the stack.
24 //    To do so, a precise GC without stack scan is scheduled using the platform
25 //    if non-nestable tasks are supported, and otherwise no operation is carried
26 //    out. This means that the heuristics allows to arbitrary go over the limit
27 //    in case non-nestable tasks are not supported and only conservative GCs are
28 //    requested.
29 class V8_EXPORT_PRIVATE GCInvoker final : public GarbageCollector {
30  public:
31   GCInvoker(GarbageCollector*, cppgc::Platform*, cppgc::Heap::StackSupport);
32   ~GCInvoker();
33 
34   GCInvoker(const GCInvoker&) = delete;
35   GCInvoker& operator=(const GCInvoker&) = delete;
36 
37   void CollectGarbage(GarbageCollector::Config) final;
38   void StartIncrementalGarbageCollection(GarbageCollector::Config) final;
39   size_t epoch() const final;
40   const EmbedderStackState* override_stack_state() const final;
41 
42  private:
43   class GCInvokerImpl;
44   std::unique_ptr<GCInvokerImpl> impl_;
45 };
46 
47 }  // namespace internal
48 }  // namespace cppgc
49 
50 #endif  // V8_HEAP_CPPGC_GC_INVOKER_H_
51