OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/base/atomic-utils.h" | 5 #include "src/base/atomic-utils.h" |
6 #include "src/macro-assembler.h" | 6 #include "src/macro-assembler.h" |
7 #include "src/objects.h" | 7 #include "src/objects.h" |
8 #include "src/property-descriptor.h" | 8 #include "src/property-descriptor.h" |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); i++) { | 523 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); i++) { |
524 compilation_units[i] = new compiler::WasmCompilationUnit( | 524 compilation_units[i] = new compiler::WasmCompilationUnit( |
525 &thrower, isolate, &module_env, &functions[i], i); | 525 &thrower, isolate, &module_env, &functions[i], i); |
526 } | 526 } |
527 } | 527 } |
528 | 528 |
529 uint32_t* StartCompilationTasks( | 529 uint32_t* StartCompilationTasks( |
530 Isolate* isolate, | 530 Isolate* isolate, |
531 std::vector<compiler::WasmCompilationUnit*>& compilation_units, | 531 std::vector<compiler::WasmCompilationUnit*>& compilation_units, |
532 std::queue<compiler::WasmCompilationUnit*>& executed_units, | 532 std::queue<compiler::WasmCompilationUnit*>& executed_units, |
533 const base::SmartPointer<base::Semaphore>& pending_tasks, | 533 base::Semaphore* pending_tasks, base::Mutex& result_mutex, |
534 base::Mutex& result_mutex, base::AtomicNumber<size_t>& next_unit) { | 534 base::AtomicNumber<size_t>& next_unit) { |
535 const size_t num_tasks = | 535 const size_t num_tasks = |
536 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), | 536 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), |
537 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); | 537 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); |
538 uint32_t* task_ids = new uint32_t[num_tasks]; | 538 uint32_t* task_ids = new uint32_t[num_tasks]; |
539 for (size_t i = 0; i < num_tasks; i++) { | 539 for (size_t i = 0; i < num_tasks; i++) { |
540 WasmCompilationTask* task = | 540 WasmCompilationTask* task = |
541 new WasmCompilationTask(isolate, &compilation_units, &executed_units, | 541 new WasmCompilationTask(isolate, &compilation_units, &executed_units, |
542 pending_tasks.get(), &result_mutex, &next_unit); | 542 pending_tasks, &result_mutex, &next_unit); |
543 task_ids[i] = task->id(); | 543 task_ids[i] = task->id(); |
544 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 544 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
545 task, v8::Platform::kShortRunningTask); | 545 task, v8::Platform::kShortRunningTask); |
546 } | 546 } |
547 return task_ids; | 547 return task_ids; |
548 } | 548 } |
549 | 549 |
550 void WaitForCompilationTasks( | 550 void WaitForCompilationTasks(Isolate* isolate, uint32_t* task_ids, |
551 Isolate* isolate, uint32_t* task_ids, | 551 base::Semaphore* pending_tasks) { |
552 const base::SmartPointer<base::Semaphore>& pending_tasks) { | |
553 const size_t num_tasks = | 552 const size_t num_tasks = |
554 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), | 553 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), |
555 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); | 554 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); |
556 for (size_t i = 0; i < num_tasks; i++) { | 555 for (size_t i = 0; i < num_tasks; i++) { |
557 // If the task has not started yet, then we abort it. Otherwise we wait for | 556 // If the task has not started yet, then we abort it. Otherwise we wait for |
558 // it to finish. | 557 // it to finish. |
559 if (!isolate->cancelable_task_manager()->TryAbort(task_ids[i])) { | 558 if (!isolate->cancelable_task_manager()->TryAbort(task_ids[i])) { |
560 pending_tasks->Wait(); | 559 pending_tasks->Wait(); |
561 } | 560 } |
562 } | 561 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 // Objects for the synchronization with the background threads. | 616 // Objects for the synchronization with the background threads. |
618 base::SmartPointer<base::Semaphore> pending_tasks(new base::Semaphore(0)); | 617 base::SmartPointer<base::Semaphore> pending_tasks(new base::Semaphore(0)); |
619 base::Mutex result_mutex; | 618 base::Mutex result_mutex; |
620 base::AtomicNumber<size_t> next_unit( | 619 base::AtomicNumber<size_t> next_unit( |
621 static_cast<size_t>(FLAG_skip_compiling_wasm_funcs)); | 620 static_cast<size_t>(FLAG_skip_compiling_wasm_funcs)); |
622 | 621 |
623 // 2) The main thread spawns {WasmCompilationTask} instances which run on | 622 // 2) The main thread spawns {WasmCompilationTask} instances which run on |
624 // the background threads. | 623 // the background threads. |
625 base::SmartArrayPointer<uint32_t> task_ids( | 624 base::SmartArrayPointer<uint32_t> task_ids( |
626 StartCompilationTasks(isolate, compilation_units, executed_units, | 625 StartCompilationTasks(isolate, compilation_units, executed_units, |
627 pending_tasks, result_mutex, next_unit)); | 626 pending_tasks.get(), result_mutex, next_unit)); |
628 | 627 |
629 // 3.a) The background threads and the main thread pick one compilation | 628 // 3.a) The background threads and the main thread pick one compilation |
630 // unit at a time and execute the parallel phase of the compilation | 629 // unit at a time and execute the parallel phase of the compilation |
631 // unit. After finishing the execution of the parallel phase, the | 630 // unit. After finishing the execution of the parallel phase, the |
632 // result is enqueued in {executed_units}. | 631 // result is enqueued in {executed_units}. |
633 while (FetchAndExecuteCompilationUnit(isolate, &compilation_units, | 632 while (FetchAndExecuteCompilationUnit(isolate, &compilation_units, |
634 &executed_units, &result_mutex, | 633 &executed_units, &result_mutex, |
635 &next_unit)) { | 634 &next_unit)) { |
636 // 3.b) If {executed_units} contains a compilation unit, the main thread | 635 // 3.b) If {executed_units} contains a compilation unit, the main thread |
637 // dequeues it and finishes the compilation unit. Compilation units | 636 // dequeues it and finishes the compilation unit. Compilation units |
638 // are finished concurrently to the background threads to save | 637 // are finished concurrently to the background threads to save |
639 // memory. | 638 // memory. |
640 FinishCompilationUnits(executed_units, functions, result_mutex); | 639 FinishCompilationUnits(executed_units, functions, result_mutex); |
641 } | 640 } |
642 // 4) After the parallel phase of all compilation units has started, the | 641 // 4) After the parallel phase of all compilation units has started, the |
643 // main thread waits for all {WasmCompilationTask} instances to finish. | 642 // main thread waits for all {WasmCompilationTask} instances to finish. |
644 WaitForCompilationTasks(isolate, task_ids.get(), pending_tasks); | 643 WaitForCompilationTasks(isolate, task_ids.get(), pending_tasks.get()); |
645 // Finish the compilation of the remaining compilation units. | 644 // Finish the compilation of the remaining compilation units. |
646 FinishCompilationUnits(executed_units, functions, result_mutex); | 645 FinishCompilationUnits(executed_units, functions, result_mutex); |
647 } | 646 } |
648 | 647 |
649 void CompileSequentially(Isolate* isolate, const WasmModule* module, | 648 void CompileSequentially(Isolate* isolate, const WasmModule* module, |
650 std::vector<Handle<Code>>& functions, | 649 std::vector<Handle<Code>>& functions, |
651 ErrorThrower* thrower, ModuleEnv* module_env) { | 650 ErrorThrower* thrower, ModuleEnv* module_env) { |
652 DCHECK(!thrower->error()); | 651 DCHECK(!thrower->error()); |
653 | 652 |
654 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; | 653 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 Object* info = wasm->GetInternalField(kWasmDebugInfo); | 1122 Object* info = wasm->GetInternalField(kWasmDebugInfo); |
1124 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); | 1123 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); |
1125 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm)); | 1124 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm)); |
1126 wasm->SetInternalField(kWasmDebugInfo, *new_info); | 1125 wasm->SetInternalField(kWasmDebugInfo, *new_info); |
1127 return *new_info; | 1126 return *new_info; |
1128 } | 1127 } |
1129 | 1128 |
1130 } // namespace wasm | 1129 } // namespace wasm |
1131 } // namespace internal | 1130 } // namespace internal |
1132 } // namespace v8 | 1131 } // namespace v8 |
OLD | NEW |