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.
5 #ifndef V8_HEAP_INCREMENTAL_MARKING_JOB_H_
6 #define V8_HEAP_INCREMENTAL_MARKING_JOB_H_
8 #include "src/cancelable-task.h"
16 // The incremental marking job uses platform tasks to perform incremental
17 // marking steps. The job posts an idle and a delayed task with a large delay.
18 // The delayed task performs steps only if the idle task is not making progress.
19 // We expect this to be a rare event since incremental marking should finish
20 // quickly with the help of the mutator and the idle task.
21 // The delayed task guarantees that we eventually finish incremental marking
22 // even if the mutator becomes idle and the platform stops running idle tasks,
23 // which can happen for background tabs in Chrome.
24 class IncrementalMarkingJob {
26 class IdleTask : public CancelableIdleTask {
28 explicit IdleTask(Isolate* isolate, IncrementalMarkingJob* job)
29 : CancelableIdleTask(isolate), job_(job) {}
30 enum Progress { kDone, kMoreWork };
31 static Progress Step(Heap* heap, double deadline_in_ms);
32 // CancelableIdleTask overrides.
33 void RunInternal(double deadline_in_seconds) override;
36 IncrementalMarkingJob* job_;
39 class DelayedTask : public CancelableTask {
41 explicit DelayedTask(Isolate* isolate, IncrementalMarkingJob* job)
42 : CancelableTask(isolate), job_(job) {}
43 static void Step(Heap* heap);
44 // CancelableTask overrides.
45 void RunInternal() override;
48 IncrementalMarkingJob* job_;
51 // Delay of the delayed task.
52 static const int kDelayInSeconds = 5;
54 IncrementalMarkingJob()
55 : idle_task_pending_(false),
56 delayed_task_pending_(false),
57 made_progress_since_last_delayed_task_(false) {}
59 bool ShouldForceMarkingStep() {
60 return !made_progress_since_last_delayed_task_;
63 bool IdleTaskPending() { return idle_task_pending_; }
65 void Start(Heap* heap);
67 void NotifyIdleTask();
68 void NotifyDelayedTask();
69 void NotifyIdleTaskProgress();
70 void ScheduleIdleTask(Heap* heap);
71 void ScheduleDelayedTask(Heap* heap);
74 bool idle_task_pending_;
75 bool delayed_task_pending_;
76 bool made_progress_since_last_delayed_task_;
79 } // namespace v8::internal
81 #endif // V8_HEAP_INCREMENTAL_MARKING_JOB_H_