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 #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) {} |
| 32 virtual ~MockPlatform() {} |
| 33 |
| 34 void CallOnBackgroundThread(Task* task, |
| 35 ExpectedRuntime expected_runtime) override { |
| 36 platform_->CallOnBackgroundThread(task, expected_runtime); |
| 37 } |
| 38 |
| 39 void CallOnForegroundThread(Isolate* isolate, Task* task) override { |
| 40 platform_->CallOnForegroundThread(isolate, task); |
| 41 } |
| 42 |
| 43 void CallDelayedOnForegroundThread(Isolate* isolate, Task* task, |
| 44 double delay_in_seconds) override { |
| 45 platform_->CallDelayedOnForegroundThread(isolate, task, delay_in_seconds); |
| 46 } |
| 47 |
| 48 double MonotonicallyIncreasingTime() override { |
| 49 return platform_->MonotonicallyIncreasingTime(); |
| 50 } |
| 51 |
| 52 void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override { |
| 53 CHECK(nullptr == idle_task_); |
| 54 idle_task_ = task; |
| 55 } |
| 56 |
| 57 bool IdleTasksEnabled(Isolate* isolate) override { return true; } |
| 58 |
| 59 bool PendingIdleTask() { return idle_task_ != nullptr; } |
| 60 |
| 61 void PerformIdleTask(double idle_time_in_seconds) { |
| 62 IdleTask* task = idle_task_; |
| 63 idle_task_ = nullptr; |
| 64 task->Run(MonotonicallyIncreasingTime() + idle_time_in_seconds); |
| 65 delete task; |
| 66 } |
| 67 |
| 68 private: |
| 69 v8::Platform* platform_; |
| 70 IdleTask* idle_task_; |
| 71 }; |
| 72 |
| 73 |
| 74 TEST(IncrementalMarkingUsingIdleTasks) { |
| 75 if (!i::FLAG_incremental_marking) return; |
| 76 CcTest::InitializeVM(); |
| 77 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); |
| 78 MockPlatform platform(old_platform); |
| 79 i::V8::SetPlatformForTesting(&platform); |
| 80 SimulateFullSpace(CcTest::heap()->old_space()); |
| 81 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |
| 82 marking->Stop(); |
| 83 marking->Start(); |
| 84 CHECK(platform.PendingIdleTask()); |
| 85 const double kLongIdleTimeInSeconds = 1; |
| 86 const double kShortIdleTimeInSeconds = 0.010; |
| 87 const int kShortStepCount = 10; |
| 88 for (int i = 0; i < kShortStepCount && platform.PendingIdleTask(); i++) { |
| 89 platform.PerformIdleTask(kShortIdleTimeInSeconds); |
| 90 } |
| 91 while (platform.PendingIdleTask()) { |
| 92 platform.PerformIdleTask(kLongIdleTimeInSeconds); |
| 93 } |
| 94 CHECK(marking->IsStopped()); |
| 95 i::V8::SetPlatformForTesting(old_platform); |
| 96 } |
| 97 |
| 98 |
| 99 TEST(IncrementalMarkingUsingIdleTasksAfterGC) { |
| 100 if (!i::FLAG_incremental_marking) return; |
| 101 CcTest::InitializeVM(); |
| 102 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); |
| 103 MockPlatform platform(old_platform); |
| 104 i::V8::SetPlatformForTesting(&platform); |
| 105 SimulateFullSpace(CcTest::heap()->old_space()); |
| 106 CcTest::heap()->CollectAllGarbage(); |
| 107 i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |
| 108 marking->Stop(); |
| 109 marking->Start(); |
| 110 CHECK(platform.PendingIdleTask()); |
| 111 const double kLongIdleTimeInSeconds = 1; |
| 112 const double kShortIdleTimeInSeconds = 0.010; |
| 113 const int kShortStepCount = 10; |
| 114 for (int i = 0; i < kShortStepCount && platform.PendingIdleTask(); i++) { |
| 115 platform.PerformIdleTask(kShortIdleTimeInSeconds); |
| 116 } |
| 117 while (platform.PendingIdleTask()) { |
| 118 platform.PerformIdleTask(kLongIdleTimeInSeconds); |
| 119 } |
| 120 CHECK(marking->IsStopped()); |
| 121 i::V8::SetPlatformForTesting(old_platform); |
| 122 } |
OLD | NEW |