summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/cppgc/garbage-collector.h
blob: 6c906fd501af99e57843afc9b9bbdb0306a5ccd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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_GARBAGE_COLLECTOR_H_
#define V8_HEAP_CPPGC_GARBAGE_COLLECTOR_H_

#include "src/heap/cppgc/marker.h"
#include "src/heap/cppgc/sweeper.h"

namespace cppgc {
namespace internal {

// GC interface that allows abstraction over the actual GC invocation. This is
// needed to mock/fake GC for testing.
class GarbageCollector {
 public:
  struct Config {
    using CollectionType = Marker::MarkingConfig::CollectionType;
    using StackState = cppgc::Heap::StackState;
    using MarkingType = Marker::MarkingConfig::MarkingType;
    using SweepingType = Sweeper::Config;

    static constexpr Config ConservativeAtomicConfig() {
      return {CollectionType::kMajor, StackState::kMayContainHeapPointers,
              MarkingType::kAtomic, SweepingType::kAtomic};
    }

    static constexpr Config PreciseAtomicConfig() {
      return {CollectionType::kMajor, StackState::kNoHeapPointers,
              MarkingType::kAtomic, SweepingType::kAtomic};
    }

    static constexpr Config MinorPreciseAtomicConfig() {
      return {CollectionType::kMinor, StackState::kNoHeapPointers,
              MarkingType::kAtomic, SweepingType::kAtomic};
    }

    CollectionType collection_type = CollectionType::kMajor;
    StackState stack_state = StackState::kMayContainHeapPointers;
    MarkingType marking_type = MarkingType::kAtomic;
    SweepingType sweeping_type = SweepingType::kAtomic;
  };

  // Executes a garbage collection specified in config.
  virtual void CollectGarbage(Config config) = 0;

  // The current epoch that the GC maintains. The epoch is increased on every
  // GC invocation.
  virtual size_t epoch() const = 0;
};

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_GARBAGE_COLLECTOR_H_