2015-09-08 15:54:24 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2015-09-08 15:54:24 +00:00
|
|
|
|
2019-05-22 12:44:24 +00:00
|
|
|
#include "src/handles/global-handles.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/heap/incremental-marking.h"
|
|
|
|
#include "src/heap/spaces.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2015-09-08 15:54:24 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2016-05-20 13:30:22 +00:00
|
|
|
#include "test/cctest/heap/heap-utils.h"
|
2015-09-08 15:54:24 +00:00
|
|
|
|
|
|
|
using v8::IdleTask;
|
|
|
|
using v8::Task;
|
|
|
|
using v8::Isolate;
|
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-08-11 10:04:47 +00:00
|
|
|
namespace heap {
|
2015-09-08 15:54:24 +00:00
|
|
|
|
2017-08-01 14:16:30 +00:00
|
|
|
class MockPlatform : public TestPlatform {
|
2015-09-08 15:54:24 +00:00
|
|
|
public:
|
2018-10-04 09:56:52 +00:00
|
|
|
MockPlatform()
|
|
|
|
: taskrunner_(new MockTaskRunner()),
|
|
|
|
old_platform_(i::V8::GetCurrentPlatform()) {
|
2017-08-01 14:16:30 +00:00
|
|
|
// Now that it's completely constructed, make this the current platform.
|
|
|
|
i::V8::SetPlatformForTesting(this);
|
2015-09-08 15:54:24 +00:00
|
|
|
}
|
2018-09-14 14:02:15 +00:00
|
|
|
~MockPlatform() override {
|
2017-12-07 17:19:13 +00:00
|
|
|
i::V8::SetPlatformForTesting(old_platform_);
|
2018-03-26 16:44:23 +00:00
|
|
|
for (auto& task : worker_tasks_) {
|
|
|
|
old_platform_->CallOnWorkerThread(std::move(task));
|
2018-03-05 16:51:21 +00:00
|
|
|
}
|
|
|
|
worker_tasks_.clear();
|
2017-12-07 17:19:13 +00:00
|
|
|
}
|
2015-09-08 15:54:24 +00:00
|
|
|
|
2018-10-04 09:56:52 +00:00
|
|
|
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
|
|
|
|
v8::Isolate* isolate) override {
|
|
|
|
return taskrunner_;
|
2015-09-08 15:54:24 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 16:44:23 +00:00
|
|
|
void CallOnWorkerThread(std::unique_ptr<Task> task) override {
|
|
|
|
worker_tasks_.push_back(std::move(task));
|
2018-03-05 16:51:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 10:06:42 +00:00
|
|
|
bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
|
2015-09-08 15:54:24 +00:00
|
|
|
|
2018-10-04 09:56:52 +00:00
|
|
|
bool PendingTask() { return taskrunner_->PendingTask(); }
|
2015-09-08 15:54:24 +00:00
|
|
|
|
2018-10-04 09:56:52 +00:00
|
|
|
void PerformTask() { taskrunner_->PerformTask(); }
|
2015-09-08 15:54:24 +00:00
|
|
|
|
|
|
|
private:
|
2018-10-04 09:56:52 +00:00
|
|
|
class MockTaskRunner : public v8::TaskRunner {
|
|
|
|
public:
|
|
|
|
void PostTask(std::unique_ptr<v8::Task> task) override {
|
|
|
|
task_ = std::move(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostDelayedTask(std::unique_ptr<Task> task,
|
|
|
|
double delay_in_seconds) override {
|
2019-02-07 10:58:09 +00:00
|
|
|
task_ = std::move(task);
|
2019-02-13 00:33:17 +00:00
|
|
|
}
|
2018-10-04 09:56:52 +00:00
|
|
|
|
|
|
|
void PostIdleTask(std::unique_ptr<IdleTask> task) override {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2019-02-13 00:33:17 +00:00
|
|
|
bool IdleTasksEnabled() override { return false; }
|
2018-10-04 09:56:52 +00:00
|
|
|
|
|
|
|
bool PendingTask() { return task_ != nullptr; }
|
|
|
|
|
|
|
|
void PerformTask() {
|
|
|
|
std::unique_ptr<Task> task = std::move(task_);
|
|
|
|
task->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<Task> task_;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::shared_ptr<MockTaskRunner> taskrunner_;
|
2018-03-26 16:44:23 +00:00
|
|
|
std::vector<std::unique_ptr<Task>> worker_tasks_;
|
2017-12-07 17:19:13 +00:00
|
|
|
v8::Platform* old_platform_;
|
2015-09-08 15:54:24 +00:00
|
|
|
};
|
|
|
|
|
2016-09-12 11:46:14 +00:00
|
|
|
TEST(IncrementalMarkingUsingTasks) {
|
2015-09-08 15:54:24 +00:00
|
|
|
if (!i::FLAG_incremental_marking) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_incremental_marking = false;
|
2015-09-08 15:54:24 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2016-05-20 13:30:22 +00:00
|
|
|
i::heap::SimulateFullSpace(CcTest::heap()->old_space());
|
2015-09-08 15:54:24 +00:00
|
|
|
i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
|
|
|
marking->Stop();
|
2016-09-07 10:02:58 +00:00
|
|
|
marking->Start(i::GarbageCollectionReason::kTesting);
|
2016-09-12 11:46:14 +00:00
|
|
|
CHECK(platform.PendingTask());
|
|
|
|
while (platform.PendingTask()) {
|
|
|
|
platform.PerformTask();
|
2015-09-08 15:54:24 +00:00
|
|
|
}
|
|
|
|
CHECK(marking->IsStopped());
|
|
|
|
}
|
|
|
|
|
2017-08-11 10:04:47 +00:00
|
|
|
} // namespace heap
|
2015-11-09 19:48:08 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|