| OLD | NEW |
| (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 // TODO(jochen): Remove this after the setting is turned on globally. | |
| 6 #define V8_IMMINENT_DEPRECATION_WARNINGS | |
| 7 | |
| 8 #include <stdlib.h> | |
| 9 | |
| 10 #ifdef __linux__ | |
| 11 #include <errno.h> | |
| 12 #include <fcntl.h> | |
| 13 #include <sys/stat.h> | |
| 14 #include <sys/types.h> | |
| 15 #include <unistd.h> | |
| 16 #endif | |
| 17 | |
| 18 #include <utility> | |
| 19 | |
| 20 #include "src/v8.h" | |
| 21 | |
| 22 #include "src/full-codegen/full-codegen.h" | |
| 23 #include "src/global-handles.h" | |
| 24 #include "test/cctest/cctest.h" | |
| 25 | |
| 26 using v8::IdleTask; | |
| 27 using v8::Task; | |
| 28 using v8::Isolate; | |
| 29 | |
| 30 namespace v8 { | |
| 31 namespace internal { | |
| 32 | |
| 33 class MockPlatform : public v8::Platform { | |
| 34 public: | |
| 35 explicit MockPlatform(v8::Platform* platform) | |
| 36 : platform_(platform), idle_task_(nullptr), delayed_task_(nullptr) {} | |
| 37 virtual ~MockPlatform() { | |
| 38 delete idle_task_; | |
| 39 delete delayed_task_; | |
| 40 } | |
| 41 | |
| 42 void CallOnBackgroundThread(Task* task, | |
| 43 ExpectedRuntime expected_runtime) override { | |
| 44 platform_->CallOnBackgroundThread(task, expected_runtime); | |
| 45 } | |
| 46 | |
| 47 void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override { | |
| 48 platform_->CallOnForegroundThread(isolate, task); | |
| 49 } | |
| 50 | |
| 51 void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task, | |
| 52 double delay_in_seconds) override { | |
| 53 if (delayed_task_ != nullptr) { | |
| 54 delete delayed_task_; | |
| 55 } | |
| 56 delayed_task_ = task; | |
| 57 } | |
| 58 | |
| 59 double MonotonicallyIncreasingTime() override { | |
| 60 return platform_->MonotonicallyIncreasingTime(); | |
| 61 } | |
| 62 | |
| 63 void CallIdleOnForegroundThread(v8::Isolate* isolate, | |
| 64 IdleTask* task) override { | |
| 65 CHECK(nullptr == idle_task_); | |
| 66 idle_task_ = task; | |
| 67 } | |
| 68 | |
| 69 bool IdleTasksEnabled(v8::Isolate* isolate) override { return true; } | |
| 70 | |
| 71 bool PendingIdleTask() { return idle_task_ != nullptr; } | |
| 72 | |
| 73 void PerformIdleTask(double idle_time_in_seconds) { | |
| 74 IdleTask* task = idle_task_; | |
| 75 idle_task_ = nullptr; | |
| 76 task->Run(MonotonicallyIncreasingTime() + idle_time_in_seconds); | |
| 77 delete task; | |
| 78 } | |
| 79 | |
| 80 bool PendingDelayedTask() { return delayed_task_ != nullptr; } | |
| 81 | |
| 82 void PerformDelayedTask() { | |
| 83 Task* task = delayed_task_; | |
| 84 delayed_task_ = nullptr; | |
| 85 task->Run(); | |
| 86 delete task; | |
| 87 } | |
| 88 | |
| 89 private: | |
| 90 v8::Platform* platform_; | |
| 91 IdleTask* idle_task_; | |
| 92 Task* delayed_task_; | |
| 93 }; | |
| 94 | |
| 95 | |
| 96 TEST(IncrementalMarkingUsingIdleTasks) { | |
| 97 if (!i::FLAG_incremental_marking) return; | |
| 98 CcTest::InitializeVM(); | |
| 99 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | |
| 100 MockPlatform platform(old_platform); | |
| 101 i::V8::SetPlatformForTesting(&platform); | |
| 102 SimulateFullSpace(CcTest::heap()->old_space()); | |
| 103 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | |
| 104 marking->Stop(); | |
| 105 marking->Start(); | |
| 106 CHECK(platform.PendingIdleTask()); | |
| 107 const double kLongIdleTimeInSeconds = 1; | |
| 108 const double kShortIdleTimeInSeconds = 0.010; | |
| 109 const int kShortStepCount = 10; | |
| 110 for (int i = 0; i < kShortStepCount && platform.PendingIdleTask(); i++) { | |
| 111 platform.PerformIdleTask(kShortIdleTimeInSeconds); | |
| 112 } | |
| 113 while (platform.PendingIdleTask()) { | |
| 114 platform.PerformIdleTask(kLongIdleTimeInSeconds); | |
| 115 } | |
| 116 CHECK(marking->IsStopped()); | |
| 117 i::V8::SetPlatformForTesting(old_platform); | |
| 118 } | |
| 119 | |
| 120 | |
| 121 TEST(IncrementalMarkingUsingIdleTasksAfterGC) { | |
| 122 if (!i::FLAG_incremental_marking) return; | |
| 123 CcTest::InitializeVM(); | |
| 124 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | |
| 125 MockPlatform platform(old_platform); | |
| 126 i::V8::SetPlatformForTesting(&platform); | |
| 127 SimulateFullSpace(CcTest::heap()->old_space()); | |
| 128 CcTest::heap()->CollectAllGarbage(); | |
| 129 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | |
| 130 marking->Stop(); | |
| 131 marking->Start(); | |
| 132 CHECK(platform.PendingIdleTask()); | |
| 133 const double kLongIdleTimeInSeconds = 1; | |
| 134 const double kShortIdleTimeInSeconds = 0.010; | |
| 135 const int kShortStepCount = 10; | |
| 136 for (int i = 0; i < kShortStepCount && platform.PendingIdleTask(); i++) { | |
| 137 platform.PerformIdleTask(kShortIdleTimeInSeconds); | |
| 138 } | |
| 139 while (platform.PendingIdleTask()) { | |
| 140 platform.PerformIdleTask(kLongIdleTimeInSeconds); | |
| 141 } | |
| 142 CHECK(marking->IsStopped()); | |
| 143 i::V8::SetPlatformForTesting(old_platform); | |
| 144 } | |
| 145 | |
| 146 | |
| 147 TEST(IncrementalMarkingUsingDelayedTasks) { | |
| 148 if (!i::FLAG_incremental_marking) return; | |
| 149 CcTest::InitializeVM(); | |
| 150 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | |
| 151 MockPlatform platform(old_platform); | |
| 152 i::V8::SetPlatformForTesting(&platform); | |
| 153 SimulateFullSpace(CcTest::heap()->old_space()); | |
| 154 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | |
| 155 marking->Stop(); | |
| 156 marking->Start(); | |
| 157 CHECK(platform.PendingIdleTask()); | |
| 158 // The delayed task should be a no-op if the idle task makes progress. | |
| 159 const int kIgnoredDelayedTaskStepCount = 1000; | |
| 160 for (int i = 0; i < kIgnoredDelayedTaskStepCount; i++) { | |
| 161 // Dummy idle task progress. | |
| 162 marking->incremental_marking_job()->NotifyIdleTaskProgress(); | |
| 163 CHECK(platform.PendingDelayedTask()); | |
| 164 platform.PerformDelayedTask(); | |
| 165 } | |
| 166 // Once we stop notifying idle task progress, the delayed tasks | |
| 167 // should finish marking. | |
| 168 while (!marking->IsStopped() && platform.PendingDelayedTask()) { | |
| 169 platform.PerformDelayedTask(); | |
| 170 } | |
| 171 // There could be pending delayed task from memory reducer after GC finishes. | |
| 172 CHECK(marking->IsStopped()); | |
| 173 i::V8::SetPlatformForTesting(old_platform); | |
| 174 } | |
| 175 | |
| 176 } // namespace internal | |
| 177 } // namespace v8 | |
| OLD | NEW |