Commit 86b4b534 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[v8 platform] Get rid of unused ExpectedRuntime parameter.

With a temporary intermediate step to allow adapting embedders before
getting rid of the ExpectedRuntime method altogether.

The method is being renamed to CallOnWorkerThread() as an effort to
go away from "background" nomenclature for worker threads ("background"
usually refers to a priority but worker threads are commonly used for
high priority tasks in v8).
Other CLs will follow to rename other "background" APIs.

Bug: v8:7310
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I2fd4eac7458708d4eacb0f4871c982a567a3865e
Reviewed-on: https://chromium-review.googlesource.com/941442
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51645}
parent 15165208
...@@ -290,7 +290,7 @@ class Platform { ...@@ -290,7 +290,7 @@ class Platform {
* used to estimate the number of tasks a work package should be split into. * used to estimate the number of tasks a work package should be split into.
* A return value of 0 means that there are no background threads available. * A return value of 0 means that there are no background threads available.
* Note that a value of 0 won't prohibit V8 from posting tasks using * Note that a value of 0 won't prohibit V8 from posting tasks using
* |CallOnBackgroundThread|. * |CallOnWorkerThread|.
*/ */
virtual size_t NumberOfAvailableBackgroundThreads() { return 0; } virtual size_t NumberOfAvailableBackgroundThreads() { return 0; }
...@@ -324,7 +324,27 @@ class Platform { ...@@ -324,7 +324,27 @@ class Platform {
* thread the task will be run on. * thread the task will be run on.
*/ */
virtual void CallOnBackgroundThread(Task* task, virtual void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) = 0; ExpectedRuntime expected_runtime) {
// TODO(gab): Remove this when embedders override CallOnWorkerThread()
// instead.
// An implementation needs to be provided here because this is called by the
// default implementation below. In practice however, all code either:
// - Overrides the new method (thus not making this call) -- i.e. all v8
// code.
// - Overrides this method (thus not making this call) -- i.e. all
// unadapted embedders.
abort();
}
/**
* Schedules a task to be invoked on a worker thread.
* TODO(gab): Make pure virtual when all embedders override this instead of
* CallOnBackgroundThread().
*/
virtual void CallOnWorkerThread(Task* task) {
CallOnBackgroundThread(task, kShortRunningTask);
}
/** /**
* Schedules a task to be invoked on a foreground thread wrt a specific * Schedules a task to be invoked on a foreground thread wrt a specific
......
...@@ -526,9 +526,8 @@ void CompilerDispatcher::ScheduleMoreBackgroundTasksIfNeeded() { ...@@ -526,9 +526,8 @@ void CompilerDispatcher::ScheduleMoreBackgroundTasksIfNeeded() {
} }
++num_background_tasks_; ++num_background_tasks_;
} }
platform_->CallOnBackgroundThread( platform_->CallOnWorkerThread(
new BackgroundTask(isolate_, task_manager_.get(), this), new BackgroundTask(isolate_, task_manager_.get(), this));
v8::Platform::kShortRunningTask);
} }
void CompilerDispatcher::DoBackgroundWork() { void CompilerDispatcher::DoBackgroundWork() {
......
...@@ -224,15 +224,15 @@ void OptimizingCompileDispatcher::QueueForOptimization(CompilationJob* job) { ...@@ -224,15 +224,15 @@ void OptimizingCompileDispatcher::QueueForOptimization(CompilationJob* job) {
if (FLAG_block_concurrent_recompilation) { if (FLAG_block_concurrent_recompilation) {
blocked_jobs_++; blocked_jobs_++;
} else { } else {
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(
new CompileTask(isolate_, this), v8::Platform::kShortRunningTask); new CompileTask(isolate_, this));
} }
} }
void OptimizingCompileDispatcher::Unblock() { void OptimizingCompileDispatcher::Unblock() {
while (blocked_jobs_ > 0) { while (blocked_jobs_ > 0) {
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(
new CompileTask(isolate_, this), v8::Platform::kShortRunningTask); new CompileTask(isolate_, this));
blocked_jobs_--; blocked_jobs_--;
} }
} }
......
...@@ -204,8 +204,7 @@ class PredictablePlatform : public Platform { ...@@ -204,8 +204,7 @@ class PredictablePlatform : public Platform {
return platform_->GetForegroundTaskRunner(isolate); return platform_->GetForegroundTaskRunner(isolate);
} }
void CallOnBackgroundThread(Task* task, void CallOnWorkerThread(Task* task) override {
ExpectedRuntime expected_runtime) override {
// It's not defined when background tasks are being executed, so we can just // It's not defined when background tasks are being executed, so we can just
// execute them right away. // execute them right away.
task->Run(); task->Run();
......
...@@ -49,8 +49,7 @@ void ArrayBufferCollector::FreeAllocationsOnBackgroundThread() { ...@@ -49,8 +49,7 @@ void ArrayBufferCollector::FreeAllocationsOnBackgroundThread() {
heap_->account_external_memory_concurrently_freed(); heap_->account_external_memory_concurrently_freed();
if (heap_->use_tasks() && FLAG_concurrent_array_buffer_freeing) { if (heap_->use_tasks() && FLAG_concurrent_array_buffer_freeing) {
FreeingTask* task = new FreeingTask(heap_); FreeingTask* task = new FreeingTask(heap_);
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(task);
task, v8::Platform::kShortRunningTask);
} else { } else {
// Fallback for when concurrency is disabled/restricted. // Fallback for when concurrency is disabled/restricted.
FreeAllocations(); FreeAllocations();
......
...@@ -523,8 +523,7 @@ void ConcurrentMarking::ScheduleTasks() { ...@@ -523,8 +523,7 @@ void ConcurrentMarking::ScheduleTasks() {
++pending_task_count_; ++pending_task_count_;
Task* task = new Task(heap_->isolate(), this, &task_state_[i], i); Task* task = new Task(heap_->isolate(), this, &task_state_[i], i);
cancelable_id_[i] = task->id(); cancelable_id_[i] = task->id();
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(task);
task, v8::Platform::kShortRunningTask);
} }
} }
DCHECK_EQ(task_count_, pending_task_count_); DCHECK_EQ(task_count_, pending_task_count_);
......
...@@ -105,8 +105,7 @@ void ItemParallelJob::Run(std::shared_ptr<Counters> async_counters) { ...@@ -105,8 +105,7 @@ void ItemParallelJob::Run(std::shared_ptr<Counters> async_counters) {
: base::Optional<AsyncTimedHistogram>()); : base::Optional<AsyncTimedHistogram>());
task_ids[i] = task->id(); task_ids[i] = task->id();
if (i > 0) { if (i > 0) {
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(task);
task, v8::Platform::kShortRunningTask);
} else { } else {
main_task = task; main_task = task;
} }
......
...@@ -359,8 +359,7 @@ void MemoryAllocator::Unmapper::FreeQueuedChunks() { ...@@ -359,8 +359,7 @@ void MemoryAllocator::Unmapper::FreeQueuedChunks() {
DCHECK_GE(active_unmapping_tasks_.Value(), 0); DCHECK_GE(active_unmapping_tasks_.Value(), 0);
active_unmapping_tasks_.Increment(1); active_unmapping_tasks_.Increment(1);
task_ids_[pending_unmapping_tasks_++] = task->id(); task_ids_[pending_unmapping_tasks_++] = task->id();
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(task);
task, v8::Platform::kShortRunningTask);
} else { } else {
PerformFreeMemoryOnQueuedChunks<FreeMode::kUncommitPooled>(); PerformFreeMemoryOnQueuedChunks<FreeMode::kUncommitPooled>();
} }
......
...@@ -95,8 +95,7 @@ void StoreBuffer::FlipStoreBuffers() { ...@@ -95,8 +95,7 @@ void StoreBuffer::FlipStoreBuffers() {
if (!task_running_ && FLAG_concurrent_store_buffer) { if (!task_running_ && FLAG_concurrent_store_buffer) {
task_running_ = true; task_running_ = true;
Task* task = new Task(heap_->isolate(), this); Task* task = new Task(heap_->isolate(), this);
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(task);
task, v8::Platform::kShortRunningTask);
} }
} }
......
...@@ -157,8 +157,7 @@ void Sweeper::StartSweeperTasks() { ...@@ -157,8 +157,7 @@ void Sweeper::StartSweeperTasks() {
&num_sweeping_tasks_, space); &num_sweeping_tasks_, space);
DCHECK_LT(num_tasks_, kMaxSweeperTasks); DCHECK_LT(num_tasks_, kMaxSweeperTasks);
task_ids_[num_tasks_++] = task->id(); task_ids_[num_tasks_++] = task->id();
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(task);
task, v8::Platform::kShortRunningTask);
}); });
ScheduleIncrementalSweepingTask(); ScheduleIncrementalSweepingTask();
} }
...@@ -554,8 +553,7 @@ void Sweeper::StartIterabilityTasks() { ...@@ -554,8 +553,7 @@ void Sweeper::StartIterabilityTasks() {
&iterability_task_semaphore_); &iterability_task_semaphore_);
iterability_task_id_ = task->id(); iterability_task_id_ = task->id();
iterability_task_started_ = true; iterability_task_started_ = true;
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(task);
task, v8::Platform::kShortRunningTask);
} }
} }
......
...@@ -202,8 +202,7 @@ std::shared_ptr<TaskRunner> DefaultPlatform::GetBackgroundTaskRunner( ...@@ -202,8 +202,7 @@ std::shared_ptr<TaskRunner> DefaultPlatform::GetBackgroundTaskRunner(
return background_task_runner_; return background_task_runner_;
} }
void DefaultPlatform::CallOnBackgroundThread(Task* task, void DefaultPlatform::CallOnWorkerThread(Task* task) {
ExpectedRuntime expected_runtime) {
GetBackgroundTaskRunner(nullptr)->PostTask(std::unique_ptr<Task>(task)); GetBackgroundTaskRunner(nullptr)->PostTask(std::unique_ptr<Task>(task));
} }
......
...@@ -60,8 +60,7 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) { ...@@ -60,8 +60,7 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
v8::Isolate* isolate) override; v8::Isolate* isolate) override;
std::shared_ptr<TaskRunner> GetBackgroundTaskRunner( std::shared_ptr<TaskRunner> GetBackgroundTaskRunner(
v8::Isolate* isolate) override; v8::Isolate* isolate) override;
void CallOnBackgroundThread(Task* task, void CallOnWorkerThread(Task* task) override;
ExpectedRuntime expected_runtime) override;
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override; void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override;
void CallDelayedOnForegroundThread(Isolate* isolate, Task* task, void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
double delay_in_seconds) override; double delay_in_seconds) override;
......
...@@ -683,9 +683,8 @@ class TestPlatform : public v8::Platform { ...@@ -683,9 +683,8 @@ class TestPlatform : public v8::Platform {
return old_platform_->GetBackgroundTaskRunner(isolate); return old_platform_->GetBackgroundTaskRunner(isolate);
} }
void CallOnBackgroundThread(v8::Task* task, void CallOnWorkerThread(v8::Task* task) override {
ExpectedRuntime expected_runtime) override { old_platform_->CallOnWorkerThread(task);
old_platform_->CallOnBackgroundThread(task, expected_runtime);
} }
void CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) override { void CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) override {
......
...@@ -44,8 +44,7 @@ class MockPlatform final : public TestPlatform { ...@@ -44,8 +44,7 @@ class MockPlatform final : public TestPlatform {
task_runner_->PostTask(std::unique_ptr<Task>(task)); task_runner_->PostTask(std::unique_ptr<Task>(task));
} }
void CallOnBackgroundThread(v8::Task* task, void CallOnWorkerThread(v8::Task* task) override {
ExpectedRuntime expected_runtime) override {
task_runner_->PostTask(std::unique_ptr<Task>(task)); task_runner_->PostTask(std::unique_ptr<Task>(task));
} }
......
...@@ -60,9 +60,8 @@ TEST_F(IsolateTest, MemoryPressureNotificationBackground) { ...@@ -60,9 +60,8 @@ TEST_F(IsolateTest, MemoryPressureNotificationBackground) {
base::Semaphore semaphore(0); base::Semaphore semaphore(0);
internal::V8::GetCurrentPlatform()->CallOnBackgroundThread( internal::V8::GetCurrentPlatform()->CallOnWorkerThread(
new MemoryPressureTask(isolate(), &semaphore), new MemoryPressureTask(isolate(), &semaphore));
v8::Platform::kShortRunningTask);
semaphore.Wait(); semaphore.Wait();
......
...@@ -111,8 +111,7 @@ class MockPlatform : public v8::Platform { ...@@ -111,8 +111,7 @@ class MockPlatform : public v8::Platform {
return std::make_shared<MockTaskRunner>(this, is_foreground_task_runner); return std::make_shared<MockTaskRunner>(this, is_foreground_task_runner);
} }
void CallOnBackgroundThread(Task* task, void CallOnWorkerThread(Task* task) override {
ExpectedRuntime expected_runtime) override {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
background_tasks_.push_back(task); background_tasks_.push_back(task);
} }
...@@ -183,8 +182,7 @@ class MockPlatform : public v8::Platform { ...@@ -183,8 +182,7 @@ class MockPlatform : public v8::Platform {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
tasks.swap(background_tasks_); tasks.swap(background_tasks_);
} }
platform->CallOnBackgroundThread(new TaskWrapper(this, tasks, true), platform->CallOnWorkerThread(new TaskWrapper(this, tasks, true));
kShortRunningTask);
sem_.Wait(); sem_.Wait();
} }
...@@ -194,8 +192,7 @@ class MockPlatform : public v8::Platform { ...@@ -194,8 +192,7 @@ class MockPlatform : public v8::Platform {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
tasks.swap(background_tasks_); tasks.swap(background_tasks_);
} }
platform->CallOnBackgroundThread(new TaskWrapper(this, tasks, false), platform->CallOnWorkerThread(new TaskWrapper(this, tasks, false));
kShortRunningTask);
} }
void RunForegroundTasks() { void RunForegroundTasks() {
...@@ -868,9 +865,8 @@ TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) { ...@@ -868,9 +865,8 @@ TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
ASSERT_TRUE(dispatcher.Enqueue(shared)); ASSERT_TRUE(dispatcher.Enqueue(shared));
base::Semaphore sem(0); base::Semaphore sem(0);
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnWorkerThread(
new PressureNotificationTask(i_isolate(), &dispatcher, &sem), new PressureNotificationTask(i_isolate(), &dispatcher, &sem));
v8::Platform::kShortRunningTask);
sem.Wait(); sem.Wait();
......
...@@ -228,8 +228,7 @@ TEST_F(UnoptimizedCompileJobTest, CompileOnBackgroundThread) { ...@@ -228,8 +228,7 @@ TEST_F(UnoptimizedCompileJobTest, CompileOnBackgroundThread) {
base::Semaphore semaphore(0); base::Semaphore semaphore(0);
CompileTask* background_task = new CompileTask(job.get(), &semaphore); CompileTask* background_task = new CompileTask(job.get(), &semaphore);
ASSERT_JOB_STATUS(CompilerDispatcherJob::Status::kPrepared, job); ASSERT_JOB_STATUS(CompilerDispatcherJob::Status::kPrepared, job);
V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task, V8::GetCurrentPlatform()->CallOnWorkerThread(background_task);
Platform::kShortRunningTask);
semaphore.Wait(); semaphore.Wait();
job->FinalizeOnMainThread(isolate()); job->FinalizeOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed()); ASSERT_FALSE(job->IsFailed());
......
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