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>
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
|
|
|
|
#include "src/global-handles.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/heap/incremental-marking.h"
|
|
|
|
#include "src/heap/spaces.h"
|
|
|
|
#include "src/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:
|
2017-12-07 17:19:13 +00:00
|
|
|
MockPlatform() : task_(nullptr), 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
|
|
|
}
|
2017-12-07 17:19:13 +00:00
|
|
|
virtual ~MockPlatform() {
|
|
|
|
delete task_;
|
|
|
|
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
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
|
2016-09-12 11:46:14 +00:00
|
|
|
task_ = task;
|
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
|
|
|
|
2016-09-12 11:46:14 +00:00
|
|
|
bool PendingTask() { return task_ != nullptr; }
|
2015-09-08 15:54:24 +00:00
|
|
|
|
2016-09-12 11:46:14 +00:00
|
|
|
void PerformTask() {
|
|
|
|
Task* task = task_;
|
|
|
|
task_ = nullptr;
|
2015-09-08 15:54:24 +00:00
|
|
|
task->Run();
|
|
|
|
delete task;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-12 11:46:14 +00:00
|
|
|
Task* task_;
|
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
|