Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/compiler-dispatcher/compiler-dispatcher.cc

Issue 2686673002: [Compiler] Avoid blocking on inner function parallel compilation. (Closed)
Patch Set: Fix outer_scope_info handling Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler-dispatcher/compiler-dispatcher.h" 5 #include "src/compiler-dispatcher/compiler-dispatcher.h"
6 6
7 #include "include/v8-platform.h" 7 #include "include/v8-platform.h"
8 #include "include/v8.h" 8 #include "include/v8.h"
9 #include "src/base/platform/time.h" 9 #include "src/base/platform/time.h"
10 #include "src/cancelable-task.h" 10 #include "src/cancelable-task.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 PrintF("\n"); 286 PrintF("\n");
287 } 287 }
288 JobMap::const_iterator job = GetJobFor(function); 288 JobMap::const_iterator job = GetJobFor(function);
289 DoNextStepOnMainThread(isolate_, job->second.get(), 289 DoNextStepOnMainThread(isolate_, job->second.get(),
290 ExceptionHandling::kSwallow); 290 ExceptionHandling::kSwallow);
291 ConsiderJobForBackgroundProcessing(job->second.get()); 291 ConsiderJobForBackgroundProcessing(job->second.get());
292 return true; 292 return true;
293 } 293 }
294 294
295 bool CompilerDispatcher::Enqueue( 295 bool CompilerDispatcher::Enqueue(
296 Handle<SharedFunctionInfo> function, FunctionLiteral* literal, 296 Handle<Script> script, Handle<SharedFunctionInfo> function,
297 std::shared_ptr<Zone> parse_zone, 297 FunctionLiteral* literal, std::shared_ptr<Zone> parse_zone,
298 std::shared_ptr<DeferredHandles> parse_handles, 298 std::shared_ptr<DeferredHandles> parse_handles,
299 std::shared_ptr<DeferredHandles> compile_handles) { 299 std::shared_ptr<DeferredHandles> compile_handles) {
300 if (!CanEnqueue(function)) return false; 300 if (!CanEnqueue(function)) return false;
301 if (IsEnqueued(function)) return true; 301 if (IsEnqueued(function)) return true;
302 302
303 if (trace_compiler_dispatcher_) { 303 if (trace_compiler_dispatcher_) {
304 PrintF("CompilerDispatcher: enqueuing "); 304 PrintF("CompilerDispatcher: enqueuing ");
305 function->ShortPrint(); 305 function->ShortPrint();
306 PrintF(" for compile\n"); 306 PrintF(" for compile\n");
307 } 307 }
308 308
309 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 309 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
310 isolate_, tracer_.get(), function, literal, parse_zone, parse_handles, 310 isolate_, tracer_.get(), script, function, literal, parse_zone,
311 compile_handles, max_stack_size_)); 311 parse_handles, compile_handles, max_stack_size_));
312 std::pair<int, int> key(Script::cast(function->script())->id(), 312 std::pair<int, int> key(Script::cast(function->script())->id(),
313 function->function_literal_id()); 313 function->function_literal_id());
314 jobs_.insert(std::make_pair(key, std::move(job))); 314 jobs_.insert(std::make_pair(key, std::move(job)));
315 ScheduleIdleTaskIfNeeded(); 315 ScheduleIdleTaskIfNeeded();
316 return true; 316 return true;
317 } 317 }
318 318
319 bool CompilerDispatcher::EnqueueAndStep( 319 bool CompilerDispatcher::EnqueueAndStep(
320 Handle<SharedFunctionInfo> function, FunctionLiteral* literal, 320 Handle<Script> script, Handle<SharedFunctionInfo> function,
321 std::shared_ptr<Zone> parse_zone, 321 FunctionLiteral* literal, std::shared_ptr<Zone> parse_zone,
322 std::shared_ptr<DeferredHandles> parse_handles, 322 std::shared_ptr<DeferredHandles> parse_handles,
323 std::shared_ptr<DeferredHandles> compile_handles) { 323 std::shared_ptr<DeferredHandles> compile_handles) {
324 if (!Enqueue(function, literal, parse_zone, parse_handles, compile_handles)) { 324 if (!Enqueue(script, function, literal, parse_zone, parse_handles,
325 compile_handles)) {
325 return false; 326 return false;
326 } 327 }
327 328
328 if (trace_compiler_dispatcher_) { 329 if (trace_compiler_dispatcher_) {
329 PrintF("CompilerDispatcher: stepping "); 330 PrintF("CompilerDispatcher: stepping ");
330 function->ShortPrint(); 331 function->ShortPrint();
331 PrintF("\n"); 332 PrintF("\n");
332 } 333 }
333 JobMap::const_iterator job = GetJobFor(function); 334 JobMap::const_iterator job = GetJobFor(function);
334 DoNextStepOnMainThread(isolate_, job->second.get(), 335 DoNextStepOnMainThread(isolate_, job->second.get(),
335 ExceptionHandling::kSwallow); 336 ExceptionHandling::kSwallow);
336 ConsiderJobForBackgroundProcessing(job->second.get()); 337 ConsiderJobForBackgroundProcessing(job->second.get());
337 return true; 338 return true;
338 } 339 }
339 340
340 bool CompilerDispatcher::IsEnabled() const { return FLAG_compiler_dispatcher; } 341 bool CompilerDispatcher::IsEnabled() const { return FLAG_compiler_dispatcher; }
341 342
342 bool CompilerDispatcher::IsEnqueued(Handle<SharedFunctionInfo> function) const { 343 bool CompilerDispatcher::IsEnqueued(Handle<SharedFunctionInfo> function) const {
343 return GetJobFor(function) != jobs_.end(); 344 return GetJobFor(function) != jobs_.end();
344 } 345 }
345 346
346 void CompilerDispatcher::WaitForJobIfRunningOnBackground( 347 void CompilerDispatcher::WaitForJobIfRunningOnBackground(
347 CompilerDispatcherJob* job) { 348 CompilerDispatcherJob* job) {
349 RuntimeCallTimerScope runtimeTimer(
350 isolate_, &RuntimeCallStats::CompileWaitForDispatcher);
351
348 base::LockGuard<base::Mutex> lock(&mutex_); 352 base::LockGuard<base::Mutex> lock(&mutex_);
349 if (running_background_jobs_.find(job) == running_background_jobs_.end()) { 353 if (running_background_jobs_.find(job) == running_background_jobs_.end()) {
350 pending_background_jobs_.erase(job); 354 pending_background_jobs_.erase(job);
351 return; 355 return;
352 } 356 }
353 DCHECK_NULL(main_thread_blocking_on_job_); 357 DCHECK_NULL(main_thread_blocking_on_job_);
354 main_thread_blocking_on_job_ = job; 358 main_thread_blocking_on_job_ = job;
355 while (main_thread_blocking_on_job_ != nullptr) { 359 while (main_thread_blocking_on_job_ != nullptr) {
356 main_thread_blocking_signal_.Wait(&mutex_); 360 main_thread_blocking_signal_.Wait(&mutex_);
357 } 361 }
358 DCHECK(pending_background_jobs_.find(job) == pending_background_jobs_.end()); 362 DCHECK(pending_background_jobs_.find(job) == pending_background_jobs_.end());
359 DCHECK(running_background_jobs_.find(job) == running_background_jobs_.end()); 363 DCHECK(running_background_jobs_.find(job) == running_background_jobs_.end());
360 } 364 }
361 365
362 bool CompilerDispatcher::FinishNow(CompilerDispatcherJob* job) {
363 WaitForJobIfRunningOnBackground(job);
364 while (!IsFinished(job)) {
365 DoNextStepOnMainThread(isolate_, job, ExceptionHandling::kThrow);
366 }
367 bool result = job->status() != CompileJobStatus::kFailed;
368 job->ResetOnMainThread();
369 return result;
370 }
371
372 bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) { 366 bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) {
373 JobMap::const_iterator job = GetJobFor(function); 367 JobMap::const_iterator job = GetJobFor(function);
374 CHECK(job != jobs_.end()); 368 CHECK(job != jobs_.end());
375 369
376 if (trace_compiler_dispatcher_) { 370 if (trace_compiler_dispatcher_) {
377 PrintF("CompilerDispatcher: finishing "); 371 PrintF("CompilerDispatcher: finishing ");
378 function->ShortPrint(); 372 function->ShortPrint();
379 PrintF(" now\n"); 373 PrintF(" now\n");
380 } 374 }
381 375
382 bool result = FinishNow(job->second.get()); 376 WaitForJobIfRunningOnBackground(job->second.get());
377 while (!IsFinished(job->second.get())) {
378 DoNextStepOnMainThread(isolate_, job->second.get(),
379 ExceptionHandling::kThrow);
380 }
381 bool result = job->second->status() != CompileJobStatus::kFailed;
383 382
384 if (trace_compiler_dispatcher_) { 383 if (trace_compiler_dispatcher_) {
385 PrintF("CompilerDispatcher: finished working on "); 384 PrintF("CompilerDispatcher: finished working on ");
386 function->ShortPrint(); 385 function->ShortPrint();
387 PrintF(": %s\n", result ? "success" : "failure"); 386 PrintF(": %s\n", result ? "success" : "failure");
388 tracer_->DumpStatistics(); 387 tracer_->DumpStatistics();
389 } 388 }
390 389
390 job->second->ResetOnMainThread();
391 jobs_.erase(job); 391 jobs_.erase(job);
392 if (jobs_.empty()) { 392 if (jobs_.empty()) {
393 base::LockGuard<base::Mutex> lock(&mutex_); 393 base::LockGuard<base::Mutex> lock(&mutex_);
394 abort_ = false; 394 abort_ = false;
395 } 395 }
396 return result; 396 return result;
397 } 397 }
398 398
399 bool CompilerDispatcher::FinishAllNow() {
400 if (trace_compiler_dispatcher_) {
401 PrintF("CompilerDispatcher: finishing all jobs now\n");
402 }
403
404 bool result = true;
405 for (auto& it : jobs_) {
406 result &= FinishNow(it.second.get());
407 }
408
409 if (trace_compiler_dispatcher_) {
410 PrintF("CompilerDispatcher: finished all jobs\n");
411 }
412
413 jobs_.clear();
414 {
415 base::LockGuard<base::Mutex> lock(&mutex_);
416 DCHECK(pending_background_jobs_.empty());
417 DCHECK(running_background_jobs_.empty());
418 abort_ = false;
419 }
420 return result;
421 }
422
423 void CompilerDispatcher::AbortAll(BlockingBehavior blocking) { 399 void CompilerDispatcher::AbortAll(BlockingBehavior blocking) {
424 bool background_tasks_running = 400 bool background_tasks_running =
425 task_manager_->TryAbortAll() == CancelableTaskManager::kTaskRunning; 401 task_manager_->TryAbortAll() == CancelableTaskManager::kTaskRunning;
426 if (!background_tasks_running || blocking == BlockingBehavior::kBlock) { 402 if (!background_tasks_running || blocking == BlockingBehavior::kBlock) {
427 for (auto& it : jobs_) { 403 for (auto& it : jobs_) {
428 WaitForJobIfRunningOnBackground(it.second.get()); 404 WaitForJobIfRunningOnBackground(it.second.get());
429 if (trace_compiler_dispatcher_) { 405 if (trace_compiler_dispatcher_) {
430 PrintF("CompilerDispatcher: aborted "); 406 PrintF("CompilerDispatcher: aborted ");
431 it.second->ShortPrint(); 407 it.second->ShortPrint();
432 PrintF("\n"); 408 PrintF("\n");
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 lock.reset(); 683 lock.reset();
708 DoNextStepOnMainThread(isolate_, job->second.get(), 684 DoNextStepOnMainThread(isolate_, job->second.get(),
709 ExceptionHandling::kSwallow); 685 ExceptionHandling::kSwallow);
710 } 686 }
711 } 687 }
712 if (jobs_.size() > too_long_jobs) ScheduleIdleTaskIfNeeded(); 688 if (jobs_.size() > too_long_jobs) ScheduleIdleTaskIfNeeded();
713 } 689 }
714 690
715 } // namespace internal 691 } // namespace internal
716 } // namespace v8 692 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher.h ('k') | src/compiler-dispatcher/compiler-dispatcher-job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698