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( ...@@ -855,10 +855,10 @@ int GlobalHandles::DispatchPendingPhantomCallbacks(
GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags); GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
} else if (!second_pass_callbacks_task_posted_) { } else if (!second_pass_callbacks_task_posted_) {
second_pass_callbacks_task_posted_ = true; second_pass_callbacks_task_posted_ = true;
auto task = MakeCancelableLambdaTask( auto taskrunner = V8::GetCurrentPlatform()->GetForegroundTaskRunner(
isolate(), [this] { InvokeSecondPassPhantomCallbacksFromTask(); }); reinterpret_cast<v8::Isolate*>(isolate()));
V8::GetCurrentPlatform()->CallOnForegroundThread( taskrunner->PostTask(MakeCancelableLambdaTask(
reinterpret_cast<v8::Isolate*>(isolate()), task.release()); isolate(), [this] { InvokeSecondPassPhantomCallbacksFromTask(); }));
} }
} }
return freed_nodes; return freed_nodes;
......
...@@ -3243,9 +3243,10 @@ void Heap::MemoryPressureNotification(MemoryPressureLevel level, ...@@ -3243,9 +3243,10 @@ void Heap::MemoryPressureNotification(MemoryPressureLevel level,
} else { } else {
ExecutionAccess access(isolate()); ExecutionAccess access(isolate());
isolate()->stack_guard()->RequestGC(); isolate()->stack_guard()->RequestGC();
V8::GetCurrentPlatform()->CallOnForegroundThread( auto taskrunner = V8::GetCurrentPlatform()->GetForegroundTaskRunner(
reinterpret_cast<v8::Isolate*>(isolate()), reinterpret_cast<v8::Isolate*>(isolate()));
new MemoryPressureInterruptTask(this)); taskrunner->PostTask(
base::make_unique<MemoryPressureInterruptTask>(this));
} }
} }
} }
......
...@@ -24,8 +24,9 @@ void IncrementalMarkingJob::ScheduleTask(Heap* heap) { ...@@ -24,8 +24,9 @@ void IncrementalMarkingJob::ScheduleTask(Heap* heap) {
if (!task_pending_ && !heap->IsTearingDown()) { if (!task_pending_ && !heap->IsTearingDown()) {
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap->isolate()); v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap->isolate());
task_pending_ = true; task_pending_ = true;
auto task = new Task(heap->isolate(), this); auto taskrunner =
V8::GetCurrentPlatform()->CallOnForegroundThread(isolate, task); V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate);
taskrunner->PostTask(base::make_unique<Task>(heap->isolate(), this));
} }
} }
......
...@@ -447,10 +447,11 @@ int Sweeper::ParallelSweepPage(Page* page, AllocationSpace identity) { ...@@ -447,10 +447,11 @@ int Sweeper::ParallelSweepPage(Page* page, AllocationSpace identity) {
void Sweeper::ScheduleIncrementalSweepingTask() { void Sweeper::ScheduleIncrementalSweepingTask() {
if (!incremental_sweeper_pending_) { if (!incremental_sweeper_pending_) {
incremental_sweeper_pending_ = true; incremental_sweeper_pending_ = true;
IncrementalSweeperTask* task =
new IncrementalSweeperTask(heap_->isolate(), this);
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap_->isolate()); 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 { ...@@ -33,12 +33,13 @@ namespace heap {
class MockPlatform : public TestPlatform { class MockPlatform : public TestPlatform {
public: 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. // Now that it's completely constructed, make this the current platform.
i::V8::SetPlatformForTesting(this); i::V8::SetPlatformForTesting(this);
} }
~MockPlatform() override { ~MockPlatform() override {
delete task_;
i::V8::SetPlatformForTesting(old_platform_); i::V8::SetPlatformForTesting(old_platform_);
for (auto& task : worker_tasks_) { for (auto& task : worker_tasks_) {
old_platform_->CallOnWorkerThread(std::move(task)); old_platform_->CallOnWorkerThread(std::move(task));
...@@ -46,8 +47,9 @@ class MockPlatform : public TestPlatform { ...@@ -46,8 +47,9 @@ class MockPlatform : public TestPlatform {
worker_tasks_.clear(); worker_tasks_.clear();
} }
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override { std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
task_ = task; v8::Isolate* isolate) override {
return taskrunner_;
} }
void CallOnWorkerThread(std::unique_ptr<Task> task) override { void CallOnWorkerThread(std::unique_ptr<Task> task) override {
...@@ -56,17 +58,40 @@ class MockPlatform : public TestPlatform { ...@@ -56,17 +58,40 @@ class MockPlatform : public TestPlatform {
bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; } bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
bool PendingTask() { return task_ != nullptr; } bool PendingTask() { return taskrunner_->PendingTask(); }
void PerformTask() { void PerformTask() { taskrunner_->PerformTask(); }
Task* task = task_;
task_ = nullptr;
task->Run();
delete task;
}
private: 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_; std::vector<std::unique_ptr<Task>> worker_tasks_;
v8::Platform* old_platform_; 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