• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 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_INCREMENTAL_MARKING_JOB_H_
6 #define V8_HEAP_INCREMENTAL_MARKING_JOB_H_
7 
8 #include "src/tasks/cancelable-task.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 class Heap;
14 class Isolate;
15 
16 // The incremental marking job uses platform tasks to perform incremental
17 // marking steps. The job posts a foreground task that makes a small (~1ms)
18 // step and posts another task until the marking is completed.
19 class IncrementalMarkingJob final {
20  public:
21   enum class TaskType { kNormal, kDelayed };
22 
23   IncrementalMarkingJob() V8_NOEXCEPT = default;
24 
25   void Start(Heap* heap);
26 
27   void ScheduleTask(Heap* heap, TaskType task_type = TaskType::kNormal);
28 
29   double CurrentTimeToTask(Heap* heap) const;
30 
31  private:
32   class Task;
33   static constexpr double kDelayInSeconds = 10.0 / 1000.0;
34 
IsTaskPending(TaskType task_type)35   bool IsTaskPending(TaskType task_type) const {
36     return task_type == TaskType::kNormal ? normal_task_pending_
37                                           : delayed_task_pending_;
38   }
39 
SetTaskPending(TaskType task_type,bool value)40   void SetTaskPending(TaskType task_type, bool value) {
41     if (task_type == TaskType::kNormal) {
42       normal_task_pending_ = value;
43     } else {
44       delayed_task_pending_ = value;
45     }
46   }
47 
48   base::Mutex mutex_;
49   double scheduled_time_ = 0.0;
50   bool normal_task_pending_ = false;
51   bool delayed_task_pending_ = false;
52 };
53 }  // namespace internal
54 }  // namespace v8
55 
56 #endif  // V8_HEAP_INCREMENTAL_MARKING_JOB_H_
57