heap.h 1.73 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_CPPGC_HEAP_H_
#define V8_HEAP_CPPGC_HEAP_H_

#include "include/cppgc/heap.h"
9
#include "include/cppgc/liveness-broker.h"
10
#include "include/cppgc/macros.h"
11 12
#include "src/heap/cppgc/garbage-collector.h"
#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 17 18

namespace cppgc {
namespace internal {

19 20
class V8_EXPORT_PRIVATE Heap final : public HeapBase,
                                     public cppgc::Heap,
21
                                     public GarbageCollector {
22 23
 public:
  static Heap* From(cppgc::Heap* heap) { return static_cast<Heap*>(heap); }
24 25 26
  static const Heap* From(const cppgc::Heap* heap) {
    return static_cast<const Heap*>(heap);
  }
27

28 29
  Heap(std::shared_ptr<cppgc::Platform> platform,
       cppgc::Heap::HeapOptions options);
30
  ~Heap() final;
31

32 33 34
  HeapBase& AsBase() { return *this; }
  const HeapBase& AsBase() const { return *this; }

35
  void CollectGarbage(Config) final;
36
  void StartIncrementalGarbageCollection(Config) final;
37
  void FinalizeIncrementalGarbageCollectionIfRunning(Config);
38

39
  size_t epoch() const final { return epoch_; }
40

41
 private:
42 43 44 45 46 47 48 49 50
  void StartGarbageCollection(Config);
  void FinalizeGarbageCollection(Config::StackState);

  void FinalizeIncrementalGarbageCollectionIfNeeded(
      Config::StackState stack_state) final {
    FinalizeGarbageCollection(stack_state);
  }

  Config config_;
51 52
  GCInvoker gc_invoker_;
  HeapGrowing growing_;
53

54
  bool gc_in_progress_ = false;
55
  size_t epoch_ = 0;
56 57 58 59 60 61
};

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_HEAP_H_