[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: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51645}
This commit is contained in:
Gabriel Charette 2018-03-01 09:45:52 +01:00 committed by Commit Bot
parent 1516520832
commit 86b4b5345a
17 changed files with 49 additions and 48 deletions

View File

@ -290,7 +290,7 @@ class Platform {
* 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.
* Note that a value of 0 won't prohibit V8 from posting tasks using
* |CallOnBackgroundThread|.
* |CallOnWorkerThread|.
*/
virtual size_t NumberOfAvailableBackgroundThreads() { return 0; }
@ -324,7 +324,27 @@ class Platform {
* thread the task will be run on.
*/
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

View File

@ -526,9 +526,8 @@ void CompilerDispatcher::ScheduleMoreBackgroundTasksIfNeeded() {
}
++num_background_tasks_;
}
platform_->CallOnBackgroundThread(
new BackgroundTask(isolate_, task_manager_.get(), this),
v8::Platform::kShortRunningTask);
platform_->CallOnWorkerThread(
new BackgroundTask(isolate_, task_manager_.get(), this));
}
void CompilerDispatcher::DoBackgroundWork() {

View File

@ -224,15 +224,15 @@ void OptimizingCompileDispatcher::QueueForOptimization(CompilationJob* job) {
if (FLAG_block_concurrent_recompilation) {
blocked_jobs_++;
} else {
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new CompileTask(isolate_, this), v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(
new CompileTask(isolate_, this));
}
}
void OptimizingCompileDispatcher::Unblock() {
while (blocked_jobs_ > 0) {
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new CompileTask(isolate_, this), v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(
new CompileTask(isolate_, this));
blocked_jobs_--;
}
}

View File

@ -204,8 +204,7 @@ class PredictablePlatform : public Platform {
return platform_->GetForegroundTaskRunner(isolate);
}
void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override {
void CallOnWorkerThread(Task* task) override {
// It's not defined when background tasks are being executed, so we can just
// execute them right away.
task->Run();

View File

@ -49,8 +49,7 @@ void ArrayBufferCollector::FreeAllocationsOnBackgroundThread() {
heap_->account_external_memory_concurrently_freed();
if (heap_->use_tasks() && FLAG_concurrent_array_buffer_freeing) {
FreeingTask* task = new FreeingTask(heap_);
V8::GetCurrentPlatform()->CallOnBackgroundThread(
task, v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(task);
} else {
// Fallback for when concurrency is disabled/restricted.
FreeAllocations();

View File

@ -523,8 +523,7 @@ void ConcurrentMarking::ScheduleTasks() {
++pending_task_count_;
Task* task = new Task(heap_->isolate(), this, &task_state_[i], i);
cancelable_id_[i] = task->id();
V8::GetCurrentPlatform()->CallOnBackgroundThread(
task, v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(task);
}
}
DCHECK_EQ(task_count_, pending_task_count_);

View File

@ -105,8 +105,7 @@ void ItemParallelJob::Run(std::shared_ptr<Counters> async_counters) {
: base::Optional<AsyncTimedHistogram>());
task_ids[i] = task->id();
if (i > 0) {
V8::GetCurrentPlatform()->CallOnBackgroundThread(
task, v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(task);
} else {
main_task = task;
}

View File

@ -359,8 +359,7 @@ void MemoryAllocator::Unmapper::FreeQueuedChunks() {
DCHECK_GE(active_unmapping_tasks_.Value(), 0);
active_unmapping_tasks_.Increment(1);
task_ids_[pending_unmapping_tasks_++] = task->id();
V8::GetCurrentPlatform()->CallOnBackgroundThread(
task, v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(task);
} else {
PerformFreeMemoryOnQueuedChunks<FreeMode::kUncommitPooled>();
}

View File

@ -95,8 +95,7 @@ void StoreBuffer::FlipStoreBuffers() {
if (!task_running_ && FLAG_concurrent_store_buffer) {
task_running_ = true;
Task* task = new Task(heap_->isolate(), this);
V8::GetCurrentPlatform()->CallOnBackgroundThread(
task, v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(task);
}
}

View File

@ -157,8 +157,7 @@ void Sweeper::StartSweeperTasks() {
&num_sweeping_tasks_, space);
DCHECK_LT(num_tasks_, kMaxSweeperTasks);
task_ids_[num_tasks_++] = task->id();
V8::GetCurrentPlatform()->CallOnBackgroundThread(
task, v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(task);
});
ScheduleIncrementalSweepingTask();
}
@ -554,8 +553,7 @@ void Sweeper::StartIterabilityTasks() {
&iterability_task_semaphore_);
iterability_task_id_ = task->id();
iterability_task_started_ = true;
V8::GetCurrentPlatform()->CallOnBackgroundThread(
task, v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(task);
}
}

View File

@ -202,8 +202,7 @@ std::shared_ptr<TaskRunner> DefaultPlatform::GetBackgroundTaskRunner(
return background_task_runner_;
}
void DefaultPlatform::CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) {
void DefaultPlatform::CallOnWorkerThread(Task* task) {
GetBackgroundTaskRunner(nullptr)->PostTask(std::unique_ptr<Task>(task));
}

View File

@ -60,8 +60,7 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
v8::Isolate* isolate) override;
std::shared_ptr<TaskRunner> GetBackgroundTaskRunner(
v8::Isolate* isolate) override;
void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override;
void CallOnWorkerThread(Task* task) override;
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override;
void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
double delay_in_seconds) override;

View File

@ -683,9 +683,8 @@ class TestPlatform : public v8::Platform {
return old_platform_->GetBackgroundTaskRunner(isolate);
}
void CallOnBackgroundThread(v8::Task* task,
ExpectedRuntime expected_runtime) override {
old_platform_->CallOnBackgroundThread(task, expected_runtime);
void CallOnWorkerThread(v8::Task* task) override {
old_platform_->CallOnWorkerThread(task);
}
void CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) override {

View File

@ -44,8 +44,7 @@ class MockPlatform final : public TestPlatform {
task_runner_->PostTask(std::unique_ptr<Task>(task));
}
void CallOnBackgroundThread(v8::Task* task,
ExpectedRuntime expected_runtime) override {
void CallOnWorkerThread(v8::Task* task) override {
task_runner_->PostTask(std::unique_ptr<Task>(task));
}

View File

@ -60,9 +60,8 @@ TEST_F(IsolateTest, MemoryPressureNotificationBackground) {
base::Semaphore semaphore(0);
internal::V8::GetCurrentPlatform()->CallOnBackgroundThread(
new MemoryPressureTask(isolate(), &semaphore),
v8::Platform::kShortRunningTask);
internal::V8::GetCurrentPlatform()->CallOnWorkerThread(
new MemoryPressureTask(isolate(), &semaphore));
semaphore.Wait();

View File

@ -111,8 +111,7 @@ class MockPlatform : public v8::Platform {
return std::make_shared<MockTaskRunner>(this, is_foreground_task_runner);
}
void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override {
void CallOnWorkerThread(Task* task) override {
base::LockGuard<base::Mutex> lock(&mutex_);
background_tasks_.push_back(task);
}
@ -183,8 +182,7 @@ class MockPlatform : public v8::Platform {
base::LockGuard<base::Mutex> lock(&mutex_);
tasks.swap(background_tasks_);
}
platform->CallOnBackgroundThread(new TaskWrapper(this, tasks, true),
kShortRunningTask);
platform->CallOnWorkerThread(new TaskWrapper(this, tasks, true));
sem_.Wait();
}
@ -194,8 +192,7 @@ class MockPlatform : public v8::Platform {
base::LockGuard<base::Mutex> lock(&mutex_);
tasks.swap(background_tasks_);
}
platform->CallOnBackgroundThread(new TaskWrapper(this, tasks, false),
kShortRunningTask);
platform->CallOnWorkerThread(new TaskWrapper(this, tasks, false));
}
void RunForegroundTasks() {
@ -868,9 +865,8 @@ TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
ASSERT_TRUE(dispatcher.Enqueue(shared));
base::Semaphore sem(0);
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new PressureNotificationTask(i_isolate(), &dispatcher, &sem),
v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(
new PressureNotificationTask(i_isolate(), &dispatcher, &sem));
sem.Wait();

View File

@ -228,8 +228,7 @@ TEST_F(UnoptimizedCompileJobTest, CompileOnBackgroundThread) {
base::Semaphore semaphore(0);
CompileTask* background_task = new CompileTask(job.get(), &semaphore);
ASSERT_JOB_STATUS(CompilerDispatcherJob::Status::kPrepared, job);
V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task,
Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnWorkerThread(background_task);
semaphore.Wait();
job->FinalizeOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());