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

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2080223006: [wasm] Move the semaphore for parallel compilation to the wasm module. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Adjusted a comment. Created 4 years, 6 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
« no previous file with comments | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 WasmModule::WasmModule() 341 WasmModule::WasmModule()
342 : module_start(nullptr), 342 : module_start(nullptr),
343 module_end(nullptr), 343 module_end(nullptr),
344 min_mem_pages(0), 344 min_mem_pages(0),
345 max_mem_pages(0), 345 max_mem_pages(0),
346 mem_export(false), 346 mem_export(false),
347 mem_external(false), 347 mem_external(false),
348 start_function_index(-1), 348 start_function_index(-1),
349 origin(kWasmOrigin), 349 origin(kWasmOrigin),
350 globals_size(0), 350 globals_size(0),
351 indirect_table_size(0) {} 351 indirect_table_size(0),
352 pending_tasks(new base::Semaphore(0)) {}
352 353
353 static MaybeHandle<JSFunction> ReportFFIError(ErrorThrower& thrower, 354 static MaybeHandle<JSFunction> ReportFFIError(ErrorThrower& thrower,
354 const char* error, uint32_t index, 355 const char* error, uint32_t index,
355 wasm::WasmName module_name, 356 wasm::WasmName module_name,
356 wasm::WasmName function_name) { 357 wasm::WasmName function_name) {
357 if (!function_name.is_empty()) { 358 if (!function_name.is_empty()) {
358 thrower.Error("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", 359 thrower.Error("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s",
359 index, module_name.length(), module_name.start(), 360 index, module_name.length(), module_name.start(),
360 function_name.length(), function_name.start(), error); 361 function_name.length(), function_name.start(), error);
361 } else { 362 } else {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 // Turn on the {CanonicalHandleScope} so that the background threads can 608 // Turn on the {CanonicalHandleScope} so that the background threads can
608 // use the node cache. 609 // use the node cache.
609 CanonicalHandleScope canonical(isolate); 610 CanonicalHandleScope canonical(isolate);
610 611
611 // 1) The main thread allocates a compilation unit for each wasm function 612 // 1) The main thread allocates a compilation unit for each wasm function
612 // and stores them in the vector {compilation_units}. 613 // and stores them in the vector {compilation_units}.
613 InitializeParallelCompilation(isolate, module->functions, compilation_units, 614 InitializeParallelCompilation(isolate, module->functions, compilation_units,
614 *module_env, *thrower); 615 *module_env, *thrower);
615 616
616 // Objects for the synchronization with the background threads. 617 // Objects for the synchronization with the background threads.
617 base::SmartPointer<base::Semaphore> pending_tasks(new base::Semaphore(0));
618 base::Mutex result_mutex; 618 base::Mutex result_mutex;
619 base::AtomicNumber<size_t> next_unit( 619 base::AtomicNumber<size_t> next_unit(
620 static_cast<size_t>(FLAG_skip_compiling_wasm_funcs)); 620 static_cast<size_t>(FLAG_skip_compiling_wasm_funcs));
621 621
622 // 2) The main thread spawns {WasmCompilationTask} instances which run on 622 // 2) The main thread spawns {WasmCompilationTask} instances which run on
623 // the background threads. 623 // the background threads.
624 base::SmartArrayPointer<uint32_t> task_ids( 624 base::SmartArrayPointer<uint32_t> task_ids(StartCompilationTasks(
625 StartCompilationTasks(isolate, compilation_units, executed_units, 625 isolate, compilation_units, executed_units, module->pending_tasks.get(),
626 pending_tasks.get(), result_mutex, next_unit)); 626 result_mutex, next_unit));
627 627
628 // 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
629 // 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
630 // unit. After finishing the execution of the parallel phase, the 630 // unit. After finishing the execution of the parallel phase, the
631 // result is enqueued in {executed_units}. 631 // result is enqueued in {executed_units}.
632 while (FetchAndExecuteCompilationUnit(isolate, &compilation_units, 632 while (FetchAndExecuteCompilationUnit(isolate, &compilation_units,
633 &executed_units, &result_mutex, 633 &executed_units, &result_mutex,
634 &next_unit)) { 634 &next_unit)) {
635 // 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
636 // dequeues it and finishes the compilation unit. Compilation units 636 // dequeues it and finishes the compilation unit. Compilation units
637 // are finished concurrently to the background threads to save 637 // are finished concurrently to the background threads to save
638 // memory. 638 // memory.
639 FinishCompilationUnits(executed_units, functions, result_mutex); 639 FinishCompilationUnits(executed_units, functions, result_mutex);
640 } 640 }
641 // 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
642 // main thread waits for all {WasmCompilationTask} instances to finish. 642 // main thread waits for all {WasmCompilationTask} instances to finish.
643 WaitForCompilationTasks(isolate, task_ids.get(), pending_tasks.get()); 643 WaitForCompilationTasks(isolate, task_ids.get(), module->pending_tasks.get());
644 // Finish the compilation of the remaining compilation units. 644 // Finish the compilation of the remaining compilation units.
645 FinishCompilationUnits(executed_units, functions, result_mutex); 645 FinishCompilationUnits(executed_units, functions, result_mutex);
646 } 646 }
647 647
648 void CompileSequentially(Isolate* isolate, const WasmModule* module, 648 void CompileSequentially(Isolate* isolate, const WasmModule* module,
649 std::vector<Handle<Code>>& functions, 649 std::vector<Handle<Code>>& functions,
650 ErrorThrower* thrower, ModuleEnv* module_env) { 650 ErrorThrower* thrower, ModuleEnv* module_env) {
651 DCHECK(!thrower->error()); 651 DCHECK(!thrower->error());
652 652
653 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
1122 Object* info = wasm->GetInternalField(kWasmDebugInfo); 1122 Object* info = wasm->GetInternalField(kWasmDebugInfo);
1123 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); 1123 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info);
1124 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm)); 1124 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm));
1125 wasm->SetInternalField(kWasmDebugInfo, *new_info); 1125 wasm->SetInternalField(kWasmDebugInfo, *new_info);
1126 return *new_info; 1126 return *new_info;
1127 } 1127 }
1128 1128
1129 } // namespace wasm 1129 } // namespace wasm
1130 } // namespace internal 1130 } // namespace internal
1131 } // namespace v8 1131 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698