Commit c862d2c2 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[cleanup] Use the new taskrunner API in the gc

We want to replace all uses of CallOnForegroundThread eventually by the
new TaskRunner API so that we can eventually deprecate the old API and
remove it.

R=ulan@chromium.org

Bug: v8:8238
Change-Id: I7e451eddf05f1f7f273c5cfd57d82737380f3f02
Reviewed-on: https://chromium-review.googlesource.com/c/1261145Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56378}
parent 06e73f0b
......@@ -855,10 +855,10 @@ int GlobalHandles::DispatchPendingPhantomCallbacks(
GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
} else if (!second_pass_callbacks_task_posted_) {
second_pass_callbacks_task_posted_ = true;
auto task = MakeCancelableLambdaTask(
isolate(), [this] { InvokeSecondPassPhantomCallbacksFromTask(); });
V8::GetCurrentPlatform()->CallOnForegroundThread(
reinterpret_cast<v8::Isolate*>(isolate()), task.release());
auto taskrunner = V8::GetCurrentPlatform()->GetForegroundTaskRunner(
reinterpret_cast<v8::Isolate*>(isolate()));
taskrunner->PostTask(MakeCancelableLambdaTask(
isolate(), [this] { InvokeSecondPassPhantomCallbacksFromTask(); }));
}
}
return freed_nodes;
......
......@@ -3243,9 +3243,10 @@ void Heap::MemoryPressureNotification(MemoryPressureLevel level,
} else {
ExecutionAccess access(isolate());
isolate()->stack_guard()->RequestGC();
V8::GetCurrentPlatform()->CallOnForegroundThread(
reinterpret_cast<v8::Isolate*>(isolate()),
new MemoryPressureInterruptTask(this));
auto taskrunner = V8::GetCurrentPlatform()->GetForegroundTaskRunner(
reinterpret_cast<v8::Isolate*>(isolate()));
taskrunner->PostTask(
base::make_unique<MemoryPressureInterruptTask>(this));
}
}
}
......
......@@ -24,8 +24,9 @@ void IncrementalMarkingJob::ScheduleTask(Heap* heap) {
if (!task_pending_ && !heap->IsTearingDown()) {
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap->isolate());
task_pending_ = true;
auto task = new Task(heap->isolate(), this);
V8::GetCurrentPlatform()->CallOnForegroundThread(isolate, task);
auto taskrunner =
V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate);
taskrunner->PostTask(base::make_unique<Task>(heap->isolate(), this));
}
}
......
......@@ -447,10 +447,11 @@ int Sweeper::ParallelSweepPage(Page* page, AllocationSpace identity) {
void Sweeper::ScheduleIncrementalSweepingTask() {
if (!incremental_sweeper_pending_) {
incremental_sweeper_pending_ = true;
IncrementalSweeperTask* task =
new IncrementalSweeperTask(heap_->isolate(), this);
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap_->isolate());
V8::GetCurrentPlatform()->CallOnForegroundThread(isolate, task);
auto taskrunner =
V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate);
taskrunner->PostTask(
base::make_unique<IncrementalSweeperTask>(heap_->isolate(), this));
}
}
......
......@@ -33,12 +33,13 @@ namespace heap {
class MockPlatform : public TestPlatform {
public:
MockPlatform() : task_(nullptr), old_platform_(i::V8::GetCurrentPlatform()) {
MockPlatform()
: taskrunner_(new MockTaskRunner()),
old_platform_(i::V8::GetCurrentPlatform()) {
// Now that it's completely constructed, make this the current platform.
i::V8::SetPlatformForTesting(this);
}
~MockPlatform() override {
delete task_;
i::V8::SetPlatformForTesting(old_platform_);
for (auto& task : worker_tasks_) {
old_platform_->CallOnWorkerThread(std::move(task));
......@@ -46,8 +47,9 @@ class MockPlatform : public TestPlatform {
worker_tasks_.clear();
}
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
task_ = task;
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override {
return taskrunner_;
}
void CallOnWorkerThread(std::unique_ptr<Task> task) override {
......@@ -56,17 +58,40 @@ class MockPlatform : public TestPlatform {
bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
bool PendingTask() { return task_ != nullptr; }
bool PendingTask() { return taskrunner_->PendingTask(); }
void PerformTask() {
Task* task = task_;
task_ = nullptr;
task->Run();
delete task;
}
void PerformTask() { taskrunner_->PerformTask(); }
private:
Task* task_;
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 {
UNREACHABLE();
};
void PostIdleTask(std::unique_ptr<IdleTask> task) override {
UNREACHABLE();
}
bool IdleTasksEnabled() override { return false; };
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_;
std::vector<std::unique_ptr<Task>> worker_tasks_;
v8::Platform* old_platform_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment