| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #ifdef __linux__ | 7 #ifdef __linux__ |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 using v8::IdleTask; | 24 using v8::IdleTask; |
| 25 using v8::Task; | 25 using v8::Task; |
| 26 using v8::Isolate; | 26 using v8::Isolate; |
| 27 | 27 |
| 28 namespace v8 { | 28 namespace v8 { |
| 29 namespace internal { | 29 namespace internal { |
| 30 | 30 |
| 31 class MockPlatform : public v8::Platform { | 31 class MockPlatform : public v8::Platform { |
| 32 public: | 32 public: |
| 33 explicit MockPlatform(v8::Platform* platform) | 33 explicit MockPlatform(v8::Platform* platform) |
| 34 : platform_(platform), idle_task_(nullptr), delayed_task_(nullptr) {} | 34 : platform_(platform), task_(nullptr) {} |
| 35 virtual ~MockPlatform() { | 35 virtual ~MockPlatform() { delete task_; } |
| 36 delete idle_task_; | |
| 37 delete delayed_task_; | |
| 38 } | |
| 39 | 36 |
| 40 void CallOnBackgroundThread(Task* task, | 37 void CallOnBackgroundThread(Task* task, |
| 41 ExpectedRuntime expected_runtime) override { | 38 ExpectedRuntime expected_runtime) override { |
| 42 platform_->CallOnBackgroundThread(task, expected_runtime); | 39 platform_->CallOnBackgroundThread(task, expected_runtime); |
| 43 } | 40 } |
| 44 | 41 |
| 45 void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override { | 42 void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override { |
| 46 platform_->CallOnForegroundThread(isolate, task); | 43 task_ = task; |
| 47 } | 44 } |
| 48 | 45 |
| 49 void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task, | 46 void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task, |
| 50 double delay_in_seconds) override { | 47 double delay_in_seconds) override { |
| 51 if (delayed_task_ != nullptr) { | 48 platform_->CallDelayedOnForegroundThread(isolate, task, delay_in_seconds); |
| 52 delete delayed_task_; | |
| 53 } | |
| 54 delayed_task_ = task; | |
| 55 } | 49 } |
| 56 | 50 |
| 57 double MonotonicallyIncreasingTime() override { | 51 double MonotonicallyIncreasingTime() override { |
| 58 return platform_->MonotonicallyIncreasingTime(); | 52 return platform_->MonotonicallyIncreasingTime(); |
| 59 } | 53 } |
| 60 | 54 |
| 61 void CallIdleOnForegroundThread(v8::Isolate* isolate, | 55 void CallIdleOnForegroundThread(v8::Isolate* isolate, |
| 62 IdleTask* task) override { | 56 IdleTask* task) override { |
| 63 CHECK(nullptr == idle_task_); | 57 platform_->CallIdleOnForegroundThread(isolate, task); |
| 64 idle_task_ = task; | |
| 65 } | 58 } |
| 66 | 59 |
| 67 bool IdleTasksEnabled(v8::Isolate* isolate) override { return true; } | 60 bool IdleTasksEnabled(v8::Isolate* isolate) override { return true; } |
| 68 | 61 |
| 69 bool PendingIdleTask() { return idle_task_ != nullptr; } | 62 bool PendingTask() { return task_ != nullptr; } |
| 70 | 63 |
| 71 void PerformIdleTask(double idle_time_in_seconds) { | 64 void PerformTask() { |
| 72 IdleTask* task = idle_task_; | 65 Task* task = task_; |
| 73 idle_task_ = nullptr; | 66 task_ = nullptr; |
| 74 task->Run(MonotonicallyIncreasingTime() + idle_time_in_seconds); | |
| 75 delete task; | |
| 76 } | |
| 77 | |
| 78 bool PendingDelayedTask() { return delayed_task_ != nullptr; } | |
| 79 | |
| 80 void PerformDelayedTask() { | |
| 81 Task* task = delayed_task_; | |
| 82 delayed_task_ = nullptr; | |
| 83 task->Run(); | 67 task->Run(); |
| 84 delete task; | 68 delete task; |
| 85 } | 69 } |
| 86 | 70 |
| 87 uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag, | 71 uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag, |
| 88 const char* name, const char* scope, uint64_t id, | 72 const char* name, const char* scope, uint64_t id, |
| 89 uint64_t bind_id, int numArgs, const char** argNames, | 73 uint64_t bind_id, int numArgs, const char** argNames, |
| 90 const uint8_t* argTypes, const uint64_t* argValues, | 74 const uint8_t* argTypes, const uint64_t* argValues, |
| 91 unsigned int flags) override { | 75 unsigned int flags) override { |
| 92 return 0; | 76 return 0; |
| 93 } | 77 } |
| 94 | 78 |
| 95 void UpdateTraceEventDuration(const uint8_t* categoryEnabledFlag, | 79 void UpdateTraceEventDuration(const uint8_t* categoryEnabledFlag, |
| 96 const char* name, uint64_t handle) override {} | 80 const char* name, uint64_t handle) override {} |
| 97 | 81 |
| 98 const uint8_t* GetCategoryGroupEnabled(const char* name) override { | 82 const uint8_t* GetCategoryGroupEnabled(const char* name) override { |
| 99 static uint8_t no = 0; | 83 static uint8_t no = 0; |
| 100 return &no; | 84 return &no; |
| 101 } | 85 } |
| 102 | 86 |
| 103 const char* GetCategoryGroupName( | 87 const char* GetCategoryGroupName( |
| 104 const uint8_t* categoryEnabledFlag) override { | 88 const uint8_t* categoryEnabledFlag) override { |
| 105 static const char* dummy = "dummy"; | 89 static const char* dummy = "dummy"; |
| 106 return dummy; | 90 return dummy; |
| 107 } | 91 } |
| 108 | 92 |
| 109 private: | 93 private: |
| 110 v8::Platform* platform_; | 94 v8::Platform* platform_; |
| 111 IdleTask* idle_task_; | 95 Task* task_; |
| 112 Task* delayed_task_; | |
| 113 }; | 96 }; |
| 114 | 97 |
| 115 | 98 TEST(IncrementalMarkingUsingTasks) { |
| 116 TEST(IncrementalMarkingUsingIdleTasks) { | |
| 117 if (!i::FLAG_incremental_marking) return; | 99 if (!i::FLAG_incremental_marking) return; |
| 118 CcTest::InitializeVM(); | 100 CcTest::InitializeVM(); |
| 119 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | 101 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); |
| 120 MockPlatform platform(old_platform); | 102 MockPlatform platform(old_platform); |
| 121 i::V8::SetPlatformForTesting(&platform); | 103 i::V8::SetPlatformForTesting(&platform); |
| 122 i::heap::SimulateFullSpace(CcTest::heap()->old_space()); | 104 i::heap::SimulateFullSpace(CcTest::heap()->old_space()); |
| 123 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 105 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |
| 124 marking->Stop(); | 106 marking->Stop(); |
| 125 marking->Start(i::GarbageCollectionReason::kTesting); | 107 marking->Start(i::GarbageCollectionReason::kTesting); |
| 126 CHECK(platform.PendingIdleTask()); | 108 CHECK(platform.PendingTask()); |
| 127 const double kLongIdleTimeInSeconds = 1; | 109 while (platform.PendingTask()) { |
| 128 const double kShortIdleTimeInSeconds = 0.010; | 110 platform.PerformTask(); |
| 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 } | 111 } |
| 136 CHECK(marking->IsStopped()); | 112 CHECK(marking->IsStopped()); |
| 137 i::V8::SetPlatformForTesting(old_platform); | 113 i::V8::SetPlatformForTesting(old_platform); |
| 138 } | 114 } |
| 139 | 115 |
| 140 | 116 |
| 141 TEST(IncrementalMarkingUsingIdleTasksAfterGC) { | 117 TEST(IncrementalMarkingUsingIdleTasksAfterGC) { |
| 142 if (!i::FLAG_incremental_marking) return; | 118 if (!i::FLAG_incremental_marking) return; |
| 143 | 119 |
| 144 const double kLongIdleTimeInSeconds = 1; | |
| 145 const double kShortIdleTimeInSeconds = 0.010; | |
| 146 | |
| 147 CcTest::InitializeVM(); | 120 CcTest::InitializeVM(); |
| 148 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | 121 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); |
| 149 MockPlatform platform(old_platform); | 122 MockPlatform platform(old_platform); |
| 150 i::V8::SetPlatformForTesting(&platform); | 123 i::V8::SetPlatformForTesting(&platform); |
| 151 i::heap::SimulateFullSpace(CcTest::heap()->old_space()); | 124 i::heap::SimulateFullSpace(CcTest::heap()->old_space()); |
| 152 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); | 125 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); |
| 153 // Perform any pending idle tasks. | 126 // Perform any pending idle tasks. |
| 154 while (platform.PendingIdleTask()) { | 127 while (platform.PendingTask()) { |
| 155 platform.PerformIdleTask(kLongIdleTimeInSeconds); | 128 platform.PerformTask(); |
| 156 } | 129 } |
| 157 CHECK(!platform.PendingIdleTask()); | 130 CHECK(!platform.PendingTask()); |
| 158 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 131 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |
| 159 marking->Stop(); | 132 marking->Stop(); |
| 160 marking->Start(i::GarbageCollectionReason::kTesting); | 133 marking->Start(i::GarbageCollectionReason::kTesting); |
| 161 CHECK(platform.PendingIdleTask()); | 134 CHECK(platform.PendingTask()); |
| 162 const int kShortStepCount = 10; | 135 while (platform.PendingTask()) { |
| 163 for (int i = 0; i < kShortStepCount && platform.PendingIdleTask(); i++) { | 136 platform.PerformTask(); |
| 164 platform.PerformIdleTask(kShortIdleTimeInSeconds); | |
| 165 } | |
| 166 while (platform.PendingIdleTask()) { | |
| 167 platform.PerformIdleTask(kLongIdleTimeInSeconds); | |
| 168 } | 137 } |
| 169 CHECK(marking->IsStopped()); | 138 CHECK(marking->IsStopped()); |
| 170 i::V8::SetPlatformForTesting(old_platform); | 139 i::V8::SetPlatformForTesting(old_platform); |
| 171 } | 140 } |
| 172 | |
| 173 | |
| 174 TEST(IncrementalMarkingUsingDelayedTasks) { | |
| 175 if (!i::FLAG_incremental_marking) return; | |
| 176 CcTest::InitializeVM(); | |
| 177 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | |
| 178 MockPlatform platform(old_platform); | |
| 179 i::V8::SetPlatformForTesting(&platform); | |
| 180 i::heap::SimulateFullSpace(CcTest::heap()->old_space()); | |
| 181 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | |
| 182 marking->Stop(); | |
| 183 marking->Start(i::GarbageCollectionReason::kTesting); | |
| 184 CHECK(platform.PendingIdleTask()); | |
| 185 // The delayed task should be a no-op if the idle task makes progress. | |
| 186 const int kIgnoredDelayedTaskStepCount = 1000; | |
| 187 for (int i = 0; i < kIgnoredDelayedTaskStepCount; i++) { | |
| 188 // Dummy idle task progress. | |
| 189 marking->incremental_marking_job()->NotifyIdleTaskProgress(); | |
| 190 CHECK(platform.PendingDelayedTask()); | |
| 191 platform.PerformDelayedTask(); | |
| 192 } | |
| 193 // Once we stop notifying idle task progress, the delayed tasks | |
| 194 // should finish marking. | |
| 195 while (!marking->IsStopped() && platform.PendingDelayedTask()) { | |
| 196 platform.PerformDelayedTask(); | |
| 197 } | |
| 198 // There could be pending delayed task from memory reducer after GC finishes. | |
| 199 CHECK(marking->IsStopped()); | |
| 200 i::V8::SetPlatformForTesting(old_platform); | |
| 201 } | |
| 202 | 141 |
| 203 } // namespace internal | 142 } // namespace internal |
| 204 } // namespace v8 | 143 } // namespace v8 |
| OLD | NEW |