Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: test/cctest/test-incremental-marking.cc

Issue 1265423002: Use idle task to perform incremental marking steps. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: More test fixes Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/unittests/heap/gc-idle-time-handler-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 #include <stdlib.h>
6
7 #ifdef __linux__
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <unistd.h>
13 #endif
14
15 #include <utility>
16
17 #include "src/v8.h"
18
19 #include "src/full-codegen/full-codegen.h"
20 #include "src/global-handles.h"
21 #include "test/cctest/cctest.h"
22
23 using v8::IdleTask;
24 using v8::Task;
25 using v8::Isolate;
26
27
28 class MockPlatform : public v8::Platform {
29 public:
30 explicit MockPlatform(v8::Platform* platform)
31 : platform_(platform), idle_task_(nullptr), delayed_task_(nullptr) {}
32 virtual ~MockPlatform() {
33 delete idle_task_;
34 delete delayed_task_;
35 }
36
37 void CallOnBackgroundThread(Task* task,
38 ExpectedRuntime expected_runtime) override {
39 platform_->CallOnBackgroundThread(task, expected_runtime);
40 }
41
42 void CallOnForegroundThread(Isolate* isolate, Task* task) override {
43 platform_->CallOnForegroundThread(isolate, task);
44 }
45
46 void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
47 double delay_in_seconds) override {
48 if (delayed_task_ != nullptr) {
49 delete delayed_task_;
50 }
51 delayed_task_ = task;
52 }
53
54 double MonotonicallyIncreasingTime() override {
55 return platform_->MonotonicallyIncreasingTime();
56 }
57
58 void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override {
59 CHECK(nullptr == idle_task_);
60 idle_task_ = task;
61 }
62
63 bool IdleTasksEnabled(Isolate* isolate) override { return true; }
64
65 bool PendingIdleTask() { return idle_task_ != nullptr; }
66
67 void PerformIdleTask(double idle_time_in_seconds) {
68 IdleTask* task = idle_task_;
69 idle_task_ = nullptr;
70 task->Run(MonotonicallyIncreasingTime() + idle_time_in_seconds);
71 delete task;
72 }
73
74 bool PendingDelayedTask() { return delayed_task_ != nullptr; }
75
76 void PerformDelayedTask() {
77 Task* task = delayed_task_;
78 delayed_task_ = nullptr;
79 task->Run();
80 delete task;
81 }
82
83 private:
84 v8::Platform* platform_;
85 IdleTask* idle_task_;
86 Task* delayed_task_;
87 };
88
89
90 TEST(IncrementalMarkingUsingIdleTasks) {
91 if (!i::FLAG_incremental_marking) return;
92 CcTest::InitializeVM();
93 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
94 MockPlatform platform(old_platform);
95 i::V8::SetPlatformForTesting(&platform);
96 SimulateFullSpace(CcTest::heap()->old_space());
97 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
98 marking->Stop();
99 marking->Start();
100 CHECK(platform.PendingIdleTask());
101 const double kLongIdleTimeInSeconds = 1;
102 const double kShortIdleTimeInSeconds = 0.010;
103 const int kShortStepCount = 10;
104 for (int i = 0; i < kShortStepCount && platform.PendingIdleTask(); i++) {
105 platform.PerformIdleTask(kShortIdleTimeInSeconds);
106 }
107 while (platform.PendingIdleTask()) {
108 platform.PerformIdleTask(kLongIdleTimeInSeconds);
109 }
110 CHECK(marking->IsStopped());
111 i::V8::SetPlatformForTesting(old_platform);
112 }
113
114
115 TEST(IncrementalMarkingUsingIdleTasksAfterGC) {
116 if (!i::FLAG_incremental_marking) return;
117 CcTest::InitializeVM();
118 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
119 MockPlatform platform(old_platform);
120 i::V8::SetPlatformForTesting(&platform);
121 SimulateFullSpace(CcTest::heap()->old_space());
122 CcTest::heap()->CollectAllGarbage();
123 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
124 marking->Stop();
125 marking->Start();
126 CHECK(platform.PendingIdleTask());
127 const double kLongIdleTimeInSeconds = 1;
128 const double kShortIdleTimeInSeconds = 0.010;
129 const int kShortStepCount = 10;
130 for (int i = 0; i < kShortStepCount && platform.PendingIdleTask(); i++) {
131 platform.PerformIdleTask(kShortIdleTimeInSeconds);
132 }
133 while (platform.PendingIdleTask()) {
134 platform.PerformIdleTask(kLongIdleTimeInSeconds);
135 }
136 CHECK(marking->IsStopped());
137 i::V8::SetPlatformForTesting(old_platform);
138 }
139
140
141 TEST(IncrementalMarkingUsingDelayedTasks) {
142 if (!i::FLAG_incremental_marking) return;
143 CcTest::InitializeVM();
144 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
145 MockPlatform platform(old_platform);
146 i::V8::SetPlatformForTesting(&platform);
147 SimulateFullSpace(CcTest::heap()->old_space());
148 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
149 marking->Stop();
150 marking->Start();
151 CHECK(platform.PendingIdleTask());
152 // The delayed task should be a no-op if the idle task makes progress.
153 const int kIgnoredDelayedTaskStepCount = 1000;
154 for (int i = 0; i < kIgnoredDelayedTaskStepCount; i++) {
155 // Dummy idle task progress.
156 marking->incremental_marking_job()->NotifyIdleTaskProgress();
157 CHECK(platform.PendingDelayedTask());
158 platform.PerformDelayedTask();
159 }
160 // Once we stop notifying idle task progress, the delayed tasks
161 // should finish marking.
162 while (!marking->IsStopped() && platform.PendingDelayedTask()) {
163 platform.PerformDelayedTask();
164 }
165 // There could be pending delayed task from memory reducer after GC finishes.
166 CHECK(marking->IsStopped());
167 i::V8::SetPlatformForTesting(old_platform);
168 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/unittests/heap/gc-idle-time-handler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698