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 <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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 DisallowHandleDereference no_deref; | 239 DisallowHandleDereference no_deref; |
240 DisallowCodeDependencyChange no_dependency_change; | 240 DisallowCodeDependencyChange no_dependency_change; |
241 | 241 |
242 // - 1 because AtomicIncrement returns the value after the atomic increment. | 242 // - 1 because AtomicIncrement returns the value after the atomic increment. |
243 size_t index = next_unit_.Increment(1) - 1; | 243 size_t index = next_unit_.Increment(1) - 1; |
244 if (index >= compilation_units_.size()) { | 244 if (index >= compilation_units_.size()) { |
245 return false; | 245 return false; |
246 } | 246 } |
247 | 247 |
248 compiler::WasmCompilationUnit* unit = compilation_units_.at(index); | 248 compiler::WasmCompilationUnit* unit = compilation_units_.at(index); |
249 if (unit != nullptr) { | 249 unit->ExecuteCompilation(); |
250 unit->ExecuteCompilation(); | 250 base::LockGuard<base::Mutex> guard(&result_mutex_); |
251 base::LockGuard<base::Mutex> guard(&result_mutex_); | 251 executed_units_.push(unit); |
252 executed_units_.push(unit); | |
253 } | |
254 return true; | 252 return true; |
255 } | 253 } |
256 | 254 |
257 void InitializeParallelCompilation(const std::vector<WasmFunction>& functions, | 255 void InitializeParallelCompilation(const std::vector<WasmFunction>& functions, |
258 ModuleBytesEnv& module_env, | 256 ModuleBytesEnv& module_env, |
259 ErrorThrower* thrower) { | 257 ErrorThrower* thrower) { |
260 compilation_units_.reserve(functions.size()); | 258 uint32_t start = module_env.module_env.module->num_imported_functions + |
261 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); | 259 FLAG_skip_compiling_wasm_funcs; |
262 ++i) { | 260 uint32_t num_funcs = static_cast<uint32_t>(functions.size()); |
| 261 uint32_t funcs_to_compile = start > num_funcs ? 0 : num_funcs - start; |
| 262 compilation_units_.reserve(funcs_to_compile); |
| 263 for (uint32_t i = start; i < num_funcs; ++i) { |
263 const WasmFunction* func = &functions[i]; | 264 const WasmFunction* func = &functions[i]; |
264 compilation_units_.push_back( | 265 compilation_units_.push_back(new compiler::WasmCompilationUnit( |
265 func->imported ? nullptr | 266 thrower, isolate_, &module_env, func, i)); |
266 : new compiler::WasmCompilationUnit( | |
267 thrower, isolate_, &module_env, func, i)); | |
268 } | 267 } |
269 } | 268 } |
270 | 269 |
271 uint32_t* StartCompilationTasks() { | 270 uint32_t* StartCompilationTasks() { |
272 const size_t num_tasks = | 271 const size_t num_tasks = |
273 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), | 272 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), |
274 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); | 273 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); |
275 uint32_t* task_ids = new uint32_t[num_tasks]; | 274 uint32_t* task_ids = new uint32_t[num_tasks]; |
276 for (size_t i = 0; i < num_tasks; ++i) { | 275 for (size_t i = 0; i < num_tasks; ++i) { |
277 CompilationTask* task = new CompilationTask(this); | 276 CompilationTask* task = new CompilationTask(this); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // patched at instantiation. | 441 // patched at instantiation. |
443 Handle<Code> illegal_builtin = isolate_->builtins()->Illegal(); | 442 Handle<Code> illegal_builtin = isolate_->builtins()->Illegal(); |
444 for (uint32_t i = 0; i < module_->functions.size(); ++i) { | 443 for (uint32_t i = 0; i < module_->functions.size(); ++i) { |
445 code_table->set(static_cast<int>(i), *illegal_builtin); | 444 code_table->set(static_cast<int>(i), *illegal_builtin); |
446 temp_instance.function_code[i] = illegal_builtin; | 445 temp_instance.function_code[i] = illegal_builtin; |
447 } | 446 } |
448 | 447 |
449 isolate_->counters()->wasm_functions_per_module()->AddSample( | 448 isolate_->counters()->wasm_functions_per_module()->AddSample( |
450 static_cast<int>(module_->functions.size())); | 449 static_cast<int>(module_->functions.size())); |
451 CompilationHelper helper(isolate_, module_); | 450 CompilationHelper helper(isolate_, module_); |
452 if (!FLAG_trace_wasm_decoder && FLAG_wasm_num_compilation_tasks != 0) { | 451 size_t funcs_to_compile = |
| 452 module_->functions.size() - module_->num_imported_functions; |
| 453 if (!FLAG_trace_wasm_decoder && FLAG_wasm_num_compilation_tasks != 0 && |
| 454 funcs_to_compile > 1) { |
453 // Avoid a race condition by collecting results into a second vector. | 455 // Avoid a race condition by collecting results into a second vector. |
454 std::vector<Handle<Code>> results(temp_instance.function_code); | 456 std::vector<Handle<Code>> results(temp_instance.function_code); |
455 helper.CompileInParallel(&module_env, results, thrower); | 457 helper.CompileInParallel(&module_env, results, thrower); |
456 temp_instance.function_code.swap(results); | 458 temp_instance.function_code.swap(results); |
457 } else { | 459 } else { |
458 helper.CompileSequentially(&module_env, temp_instance.function_code, | 460 helper.CompileSequentially(&module_env, temp_instance.function_code, |
459 thrower); | 461 thrower); |
460 } | 462 } |
461 if (thrower->error()) return {}; | 463 if (thrower->error()) return {}; |
462 | 464 |
(...skipping 2245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 Handle<String> module_property_name = | 2710 Handle<String> module_property_name = |
2709 isolate->factory()->InternalizeUtf8String("module"); | 2711 isolate->factory()->InternalizeUtf8String("module"); |
2710 Handle<String> instance_property_name = | 2712 Handle<String> instance_property_name = |
2711 isolate->factory()->InternalizeUtf8String("instance"); | 2713 isolate->factory()->InternalizeUtf8String("instance"); |
2712 JSObject::AddProperty(ret, module_property_name, module, NONE); | 2714 JSObject::AddProperty(ret, module_property_name, module, NONE); |
2713 JSObject::AddProperty(ret, instance_property_name, | 2715 JSObject::AddProperty(ret, instance_property_name, |
2714 instance_object.ToHandleChecked(), NONE); | 2716 instance_object.ToHandleChecked(), NONE); |
2715 | 2717 |
2716 ResolvePromise(isolate, promise, ret); | 2718 ResolvePromise(isolate, promise, ret); |
2717 } | 2719 } |
OLD | NEW |