summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/cppgc/incremental-marking-schedule.h
blob: 3c8a9e1a01f238fab387bdf39f3fa7b5949dd64b (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
// 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_INCREMENTAL_MARKING_SCHEDULE_H_
#define V8_HEAP_CPPGC_INCREMENTAL_MARKING_SCHEDULE_H_

#include <atomic>

#include "src/base/platform/time.h"

namespace cppgc {
namespace internal {

class V8_EXPORT_PRIVATE IncrementalMarkingSchedule {
 public:
  // Estimated duration of GC cycle in milliseconds.
  static const double kEstimatedMarkingTimeMs;

  // Minimum number of bytes that should be marked during an incremental
  // marking step.
  static const size_t kMinimumMarkedBytesPerIncrementalStep;

  void NotifyIncrementalMarkingStart();

  void UpdateIncrementalMarkedBytes(size_t);
  void AddConcurrentlyMarkedBytes(size_t);

  size_t GetOverallMarkedBytes();

  size_t GetNextIncrementalStepDuration(size_t);

  void SetElapsedTimeForTesting(double elapsed_time) {
    elapsed_time_for_testing_ = elapsed_time;
  }

 private:
  double GetElapsedTimeInMs(v8::base::TimeTicks);

  v8::base::TimeTicks incremental_marking_start_time_;

  size_t incrementally_marked_bytes_ = 0;
  std::atomic_size_t concurrently_marked_bytes_{0};

  // Using -1 as sentinel to denote
  static constexpr double kNoSetElapsedTimeForTesting = -1;
  double elapsed_time_for_testing_ = kNoSetElapsedTimeForTesting;
};

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_INCREMENTAL_MARKING_SCHEDULE_H_