[cleanup] Use the new TaskRunner API in the compiler dispatcher

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=leszeks@chromium.org

Bug: v8:8238
Change-Id: I6a1e55fe431225ffe4c77cd3387f3b060eb43edf
Reviewed-on: https://chromium-review.googlesource.com/c/1256866
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56375}
This commit is contained in:
Andreas Haas 2018-10-04 11:32:15 +02:00 committed by Commit Bot
parent b048c16b4f
commit 7149b87590
2 changed files with 10 additions and 13 deletions

View File

@ -49,6 +49,8 @@ CompilerDispatcher::CompilerDispatcher(Isolate* isolate, Platform* platform,
isolate->counters()->worker_thread_runtime_call_stats()), isolate->counters()->worker_thread_runtime_call_stats()),
background_compile_timer_( background_compile_timer_(
isolate->counters()->compile_function_on_background()), isolate->counters()->compile_function_on_background()),
taskrunner_(platform->GetForegroundTaskRunner(
reinterpret_cast<v8::Isolate*>(isolate))),
platform_(platform), platform_(platform),
max_stack_size_(max_stack_size), max_stack_size_(max_stack_size),
trace_compiler_dispatcher_(FLAG_trace_compiler_dispatcher), trace_compiler_dispatcher_(FLAG_trace_compiler_dispatcher),
@ -299,11 +301,9 @@ void CompilerDispatcher::MemoryPressureNotification(
abort_ = true; abort_ = true;
pending_background_jobs_.clear(); pending_background_jobs_.clear();
} }
auto abort_task = MakeCancelableLambdaTask(task_manager_.get(), [this] { taskrunner_->PostTask(MakeCancelableLambdaTask(task_manager_.get(), [this] {
AbortAll(BlockingBehavior::kDontBlock); AbortAll(BlockingBehavior::kDontBlock);
}); }));
platform_->CallOnForegroundThread(reinterpret_cast<v8::Isolate*>(isolate_),
abort_task.release());
} }
} }
@ -318,17 +318,15 @@ CompilerDispatcher::JobMap::const_iterator CompilerDispatcher::GetJobFor(
} }
void CompilerDispatcher::ScheduleIdleTaskFromAnyThread() { void CompilerDispatcher::ScheduleIdleTaskFromAnyThread() {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_); if (!taskrunner_->IdleTasksEnabled()) return;
if (!platform_->IdleTasksEnabled(v8_isolate)) return;
{ {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
if (idle_task_scheduled_ || abort_) return; if (idle_task_scheduled_ || abort_) return;
idle_task_scheduled_ = true; idle_task_scheduled_ = true;
} }
auto idle_task = MakeCancelableIdleLambdaTask( taskrunner_->PostIdleTask(MakeCancelableIdleLambdaTask(
task_manager_.get(), task_manager_.get(),
[this](double deadline_in_seconds) { DoIdleWork(deadline_in_seconds); }); [this](double deadline_in_seconds) { DoIdleWork(deadline_in_seconds); }));
platform_->CallIdleOnForegroundThread(v8_isolate, idle_task.release());
} }
void CompilerDispatcher::ScheduleIdleTaskIfNeeded() { void CompilerDispatcher::ScheduleIdleTaskIfNeeded() {
@ -337,10 +335,8 @@ void CompilerDispatcher::ScheduleIdleTaskIfNeeded() {
} }
void CompilerDispatcher::ScheduleAbortTask() { void CompilerDispatcher::ScheduleAbortTask() {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_); taskrunner_->PostTask(MakeCancelableLambdaTask(
auto abort_task = MakeCancelableLambdaTask(task_manager_.get(), task_manager_.get(), [this] { AbortInactiveJobs(); }));
[this] { AbortInactiveJobs(); });
platform_->CallOnForegroundThread(v8_isolate, abort_task.release());
} }
void CompilerDispatcher::ConsiderJobForBackgroundProcessing( void CompilerDispatcher::ConsiderJobForBackgroundProcessing(

View File

@ -155,6 +155,7 @@ class V8_EXPORT_PRIVATE CompilerDispatcher {
AccountingAllocator* allocator_; AccountingAllocator* allocator_;
WorkerThreadRuntimeCallStats* worker_thread_runtime_call_stats_; WorkerThreadRuntimeCallStats* worker_thread_runtime_call_stats_;
TimedHistogram* background_compile_timer_; TimedHistogram* background_compile_timer_;
std::shared_ptr<v8::TaskRunner> taskrunner_;
Platform* platform_; Platform* platform_;
size_t max_stack_size_; size_t max_stack_size_;