• 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_HEAP_H_
6 #define V8_HEAP_CPPGC_HEAP_H_
7 
8 #include "include/cppgc/heap.h"
9 #include "include/cppgc/liveness-broker.h"
10 #include "include/cppgc/macros.h"
11 #include "src/heap/cppgc/garbage-collector.h"
12 #include "src/heap/cppgc/gc-invoker.h"
13 #include "src/heap/cppgc/heap-base.h"
14 #include "src/heap/cppgc/heap-growing.h"
15 
16 namespace cppgc {
17 namespace internal {
18 
19 class V8_EXPORT_PRIVATE Heap final : public HeapBase,
20                                      public cppgc::Heap,
21                                      public GarbageCollector {
22  public:
From(cppgc::Heap * heap)23   static Heap* From(cppgc::Heap* heap) { return static_cast<Heap*>(heap); }
From(const cppgc::Heap * heap)24   static const Heap* From(const cppgc::Heap* heap) {
25     return static_cast<const Heap*>(heap);
26   }
27 
28   Heap(std::shared_ptr<cppgc::Platform> platform,
29        cppgc::Heap::HeapOptions options);
30   ~Heap() final;
31 
AsBase()32   HeapBase& AsBase() { return *this; }
AsBase()33   const HeapBase& AsBase() const { return *this; }
34 
35   void CollectGarbage(Config) final;
36   void StartIncrementalGarbageCollection(Config) final;
37   void FinalizeIncrementalGarbageCollectionIfRunning(Config);
38 
epoch()39   size_t epoch() const final { return epoch_; }
override_stack_state()40   const EmbedderStackState* override_stack_state() const final {
41     return HeapBase::override_stack_state();
42   }
43 
44   void DisableHeapGrowingForTesting();
45 
46  private:
47   void StartGarbageCollection(Config);
48   void FinalizeGarbageCollection(Config::StackState);
49 
50   void FinalizeIncrementalGarbageCollectionIfNeeded(Config::StackState) final;
51 
52   void StartIncrementalGarbageCollectionForTesting() final;
53   void FinalizeIncrementalGarbageCollectionForTesting(EmbedderStackState) final;
54 
55   Config config_;
56   GCInvoker gc_invoker_;
57   HeapGrowing growing_;
58 
59   size_t epoch_ = 0;
60 };
61 
62 }  // namespace internal
63 }  // namespace cppgc
64 
65 #endif  // V8_HEAP_CPPGC_HEAP_H_
66