• 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_INCREMENTAL_MARKING_SCHEDULE_H_
6 #define V8_HEAP_CPPGC_INCREMENTAL_MARKING_SCHEDULE_H_
7 
8 #include <atomic>
9 
10 #include "src/base/platform/time.h"
11 
12 namespace cppgc {
13 namespace internal {
14 
15 class V8_EXPORT_PRIVATE IncrementalMarkingSchedule {
16  public:
17   // Estimated duration of GC cycle in milliseconds.
18   static const double kEstimatedMarkingTimeMs;
19 
20   // Minimum number of bytes that should be marked during an incremental
21   // marking step.
22   static const size_t kMinimumMarkedBytesPerIncrementalStep;
23 
24   void NotifyIncrementalMarkingStart();
25 
26   void UpdateMutatorThreadMarkedBytes(size_t);
27   void AddConcurrentlyMarkedBytes(size_t);
28 
29   size_t GetOverallMarkedBytes() const;
30   size_t GetConcurrentlyMarkedBytes() const;
31 
32   size_t GetNextIncrementalStepDuration(size_t);
33 
SetElapsedTimeForTesting(double elapsed_time)34   void SetElapsedTimeForTesting(double elapsed_time) {
35     elapsed_time_for_testing_ = elapsed_time;
36   }
37 
38   bool ShouldFlushEphemeronPairs();
39 
40  private:
41   double GetElapsedTimeInMs(v8::base::TimeTicks);
42 
43   v8::base::TimeTicks incremental_marking_start_time_;
44 
45   size_t mutator_thread_marked_bytes_ = 0;
46   std::atomic_size_t concurrently_marked_bytes_{0};
47 
48   // Using -1 as sentinel to denote
49   static constexpr double kNoSetElapsedTimeForTesting = -1;
50   double elapsed_time_for_testing_ = kNoSetElapsedTimeForTesting;
51 
52   static constexpr size_t kInvalidLastEstimatedLiveBytes = -1;
53   size_t last_estimated_live_bytes_ = kInvalidLastEstimatedLiveBytes;
54   double ephemeron_pairs_flushing_ratio_target = 0.25;
55   static constexpr double kEphemeronPairsFlushingRatioIncrements = 0.25;
56 };
57 
58 }  // namespace internal
59 }  // namespace cppgc
60 
61 #endif  // V8_HEAP_CPPGC_INCREMENTAL_MARKING_SCHEDULE_H_
62