• 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_; }
40 
41   void DisableHeapGrowingForTesting();
42 
43  private:
44   void StartGarbageCollection(Config);
45   void FinalizeGarbageCollection(Config::StackState);
46 
FinalizeIncrementalGarbageCollectionIfNeeded(Config::StackState stack_state)47   void FinalizeIncrementalGarbageCollectionIfNeeded(
48       Config::StackState stack_state) final {
49     FinalizeGarbageCollection(stack_state);
50   }
51 
52   Config config_;
53   GCInvoker gc_invoker_;
54   HeapGrowing growing_;
55 
56   bool gc_in_progress_ = false;
57   size_t epoch_ = 0;
58 };
59 
60 }  // namespace internal
61 }  // namespace cppgc
62 
63 #endif  // V8_HEAP_CPPGC_HEAP_H_
64