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

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

Issue 2726553003: [wasm] Prepare WasmCompilationUnit for lazy compilation (Closed)
Patch Set: Created 3 years, 9 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 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 <memory> 5 #include <memory>
6 6
7 #include "src/assembler-inl.h" 7 #include "src/assembler-inl.h"
8 #include "src/base/adapters.h" 8 #include "src/base/adapters.h"
9 #include "src/base/atomic-utils.h" 9 #include "src/base/atomic-utils.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 void InitializeParallelCompilation(const std::vector<WasmFunction>& functions, 255 void InitializeParallelCompilation(const std::vector<WasmFunction>& functions,
256 ModuleBytesEnv& module_env, 256 ModuleBytesEnv& module_env,
257 ErrorThrower* thrower) { 257 ErrorThrower* thrower) {
258 uint32_t start = module_env.module_env.module->num_imported_functions + 258 uint32_t start = module_env.module_env.module->num_imported_functions +
259 FLAG_skip_compiling_wasm_funcs; 259 FLAG_skip_compiling_wasm_funcs;
260 uint32_t num_funcs = static_cast<uint32_t>(functions.size()); 260 uint32_t num_funcs = static_cast<uint32_t>(functions.size());
261 uint32_t funcs_to_compile = start > num_funcs ? 0 : num_funcs - start; 261 uint32_t funcs_to_compile = start > num_funcs ? 0 : num_funcs - start;
262 compilation_units_.reserve(funcs_to_compile); 262 compilation_units_.reserve(funcs_to_compile);
263 for (uint32_t i = start; i < num_funcs; ++i) { 263 for (uint32_t i = start; i < num_funcs; ++i) {
264 const WasmFunction* func = &functions[i]; 264 const WasmFunction* func = &functions[i];
265 compilation_units_.push_back(new compiler::WasmCompilationUnit( 265 compilation_units_.push_back(
266 thrower, isolate_, &module_env, func, i)); 266 new compiler::WasmCompilationUnit(isolate_, &module_env, func));
267 } 267 }
268 } 268 }
269 269
270 uint32_t* StartCompilationTasks() { 270 uint32_t* StartCompilationTasks() {
271 const size_t num_tasks = 271 const size_t num_tasks =
272 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), 272 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks),
273 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); 273 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads());
274 uint32_t* task_ids = new uint32_t[num_tasks]; 274 uint32_t* task_ids = new uint32_t[num_tasks];
275 for (size_t i = 0; i < num_tasks; ++i) { 275 for (size_t i = 0; i < num_tasks; ++i) {
276 CompilationTask* task = new CompilationTask(this); 276 CompilationTask* task = new CompilationTask(this);
(...skipping 12 matching lines...) Expand all
289 // If the task has not started yet, then we abort it. Otherwise we wait 289 // If the task has not started yet, then we abort it. Otherwise we wait
290 // for 290 // for
291 // it to finish. 291 // it to finish.
292 if (isolate_->cancelable_task_manager()->TryAbort(task_ids[i]) != 292 if (isolate_->cancelable_task_manager()->TryAbort(task_ids[i]) !=
293 CancelableTaskManager::kTaskAborted) { 293 CancelableTaskManager::kTaskAborted) {
294 module_->pending_tasks.get()->Wait(); 294 module_->pending_tasks.get()->Wait();
295 } 295 }
296 } 296 }
297 } 297 }
298 298
299 void FinishCompilationUnits(std::vector<Handle<Code>>& results) { 299 void FinishCompilationUnits(std::vector<Handle<Code>>& results,
300 ErrorThrower* thrower) {
300 while (true) { 301 while (true) {
301 compiler::WasmCompilationUnit* unit = nullptr; 302 compiler::WasmCompilationUnit* unit = nullptr;
302 { 303 {
303 base::LockGuard<base::Mutex> guard(&result_mutex_); 304 base::LockGuard<base::Mutex> guard(&result_mutex_);
304 if (executed_units_.empty()) { 305 if (executed_units_.empty()) {
305 break; 306 break;
306 } 307 }
307 unit = executed_units_.front(); 308 unit = executed_units_.front();
308 executed_units_.pop(); 309 executed_units_.pop();
309 } 310 }
310 int j = unit->index(); 311 int j = unit->func_index();
311 results[j] = unit->FinishCompilation(); 312 results[j] = unit->FinishCompilation(thrower);
312 delete unit; 313 delete unit;
313 } 314 }
314 } 315 }
315 316
316 void CompileInParallel(ModuleBytesEnv* module_env, 317 void CompileInParallel(ModuleBytesEnv* module_env,
317 std::vector<Handle<Code>>& results, 318 std::vector<Handle<Code>>& results,
318 ErrorThrower* thrower) { 319 ErrorThrower* thrower) {
319 const WasmModule* module = module_env->module_env.module; 320 const WasmModule* module = module_env->module_env.module;
320 // Data structures for the parallel compilation. 321 // Data structures for the parallel compilation.
321 322
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 354
354 // 3.a) The background threads and the main thread pick one compilation 355 // 3.a) The background threads and the main thread pick one compilation
355 // unit at a time and execute the parallel phase of the compilation 356 // unit at a time and execute the parallel phase of the compilation
356 // unit. After finishing the execution of the parallel phase, the 357 // unit. After finishing the execution of the parallel phase, the
357 // result is enqueued in {executed_units}. 358 // result is enqueued in {executed_units}.
358 while (FetchAndExecuteCompilationUnit()) { 359 while (FetchAndExecuteCompilationUnit()) {
359 // 3.b) If {executed_units} contains a compilation unit, the main thread 360 // 3.b) If {executed_units} contains a compilation unit, the main thread
360 // dequeues it and finishes the compilation unit. Compilation units 361 // dequeues it and finishes the compilation unit. Compilation units
361 // are finished concurrently to the background threads to save 362 // are finished concurrently to the background threads to save
362 // memory. 363 // memory.
363 FinishCompilationUnits(results); 364 FinishCompilationUnits(results, thrower);
364 } 365 }
365 // 4) After the parallel phase of all compilation units has started, the 366 // 4) After the parallel phase of all compilation units has started, the
366 // main thread waits for all {CompilationTask} instances to finish. 367 // main thread waits for all {CompilationTask} instances to finish.
367 WaitForCompilationTasks(task_ids.get()); 368 WaitForCompilationTasks(task_ids.get());
368 // Finish the compilation of the remaining compilation units. 369 // Finish the compilation of the remaining compilation units.
369 FinishCompilationUnits(results); 370 FinishCompilationUnits(results, thrower);
370 } 371 }
371 372
372 void CompileSequentially(ModuleBytesEnv* module_env, 373 void CompileSequentially(ModuleBytesEnv* module_env,
373 std::vector<Handle<Code>>& results, 374 std::vector<Handle<Code>>& results,
374 ErrorThrower* thrower) { 375 ErrorThrower* thrower) {
375 DCHECK(!thrower->error()); 376 DCHECK(!thrower->error());
376 377
377 const WasmModule* module = module_env->module_env.module; 378 const WasmModule* module = module_env->module_env.module;
378 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; 379 for (uint32_t i = FLAG_skip_compiling_wasm_funcs;
379 i < module->functions.size(); ++i) { 380 i < module->functions.size(); ++i) {
(...skipping 2336 matching lines...) Expand 10 before | Expand all | Expand 10 after
2716 Handle<String> module_property_name = 2717 Handle<String> module_property_name =
2717 isolate->factory()->InternalizeUtf8String("module"); 2718 isolate->factory()->InternalizeUtf8String("module");
2718 Handle<String> instance_property_name = 2719 Handle<String> instance_property_name =
2719 isolate->factory()->InternalizeUtf8String("instance"); 2720 isolate->factory()->InternalizeUtf8String("instance");
2720 JSObject::AddProperty(ret, module_property_name, module, NONE); 2721 JSObject::AddProperty(ret, module_property_name, module, NONE);
2721 JSObject::AddProperty(ret, instance_property_name, 2722 JSObject::AddProperty(ret, instance_property_name,
2722 instance_object.ToHandleChecked(), NONE); 2723 instance_object.ToHandleChecked(), NONE);
2723 2724
2724 ResolvePromise(isolate, promise, ret); 2725 ResolvePromise(isolate, promise, ret);
2725 } 2726 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698