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/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 | 9 |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 min_mem_pages(0), | 477 min_mem_pages(0), |
478 max_mem_pages(0), | 478 max_mem_pages(0), |
479 mem_export(false), | 479 mem_export(false), |
480 mem_external(false), | 480 mem_external(false), |
481 start_function_index(-1), | 481 start_function_index(-1), |
482 origin(kWasmOrigin), | 482 origin(kWasmOrigin), |
483 globals_size(0), | 483 globals_size(0), |
484 pending_tasks(new base::Semaphore(0)) {} | 484 pending_tasks(new base::Semaphore(0)) {} |
485 | 485 |
486 static MaybeHandle<JSFunction> ReportFFIError( | 486 static MaybeHandle<JSFunction> ReportFFIError( |
487 ErrorThrower& thrower, const char* error, uint32_t index, | 487 ErrorThrower* thrower, const char* error, uint32_t index, |
488 Handle<String> module_name, MaybeHandle<String> function_name) { | 488 Handle<String> module_name, MaybeHandle<String> function_name) { |
489 Handle<String> function_name_handle; | 489 Handle<String> function_name_handle; |
490 if (function_name.ToHandle(&function_name_handle)) { | 490 if (function_name.ToHandle(&function_name_handle)) { |
491 thrower.Error("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", | 491 thrower->Error("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", |
492 index, module_name->length(), module_name->ToCString().get(), | 492 index, module_name->length(), module_name->ToCString().get(), |
493 function_name_handle->length(), | 493 function_name_handle->length(), |
494 function_name_handle->ToCString().get(), error); | 494 function_name_handle->ToCString().get(), error); |
495 } else { | 495 } else { |
496 thrower.Error("Import #%d module=\"%.*s\" error: %s", index, | 496 thrower->Error("Import #%d module=\"%.*s\" error: %s", index, |
497 module_name->length(), module_name->ToCString().get(), error); | 497 module_name->length(), module_name->ToCString().get(), |
| 498 error); |
498 } | 499 } |
499 thrower.Error("Import "); | 500 thrower->Error("Import "); |
500 return MaybeHandle<JSFunction>(); | 501 return MaybeHandle<JSFunction>(); |
501 } | 502 } |
502 | 503 |
503 static MaybeHandle<JSReceiver> LookupFunction( | 504 static MaybeHandle<JSReceiver> LookupFunction( |
504 ErrorThrower& thrower, Factory* factory, Handle<JSReceiver> ffi, | 505 ErrorThrower* thrower, Factory* factory, Handle<JSReceiver> ffi, |
505 uint32_t index, Handle<String> module_name, | 506 uint32_t index, Handle<String> module_name, |
506 MaybeHandle<String> function_name) { | 507 MaybeHandle<String> function_name) { |
507 if (ffi.is_null()) { | 508 if (ffi.is_null()) { |
508 return ReportFFIError(thrower, "FFI is not an object", index, module_name, | 509 return ReportFFIError(thrower, "FFI is not an object", index, module_name, |
509 function_name); | 510 function_name); |
510 } | 511 } |
511 | 512 |
512 // Look up the module first. | 513 // Look up the module first. |
513 MaybeHandle<Object> result = Object::GetProperty(ffi, module_name); | 514 MaybeHandle<Object> result = Object::GetProperty(ffi, module_name); |
514 if (result.is_null()) { | 515 if (result.is_null()) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 // it when we rationalize signed/unsigned stuff. | 696 // it when we rationalize signed/unsigned stuff. |
696 int ret_count = Smi::cast(data->get(kOutputCount))->value(); | 697 int ret_count = Smi::cast(data->get(kOutputCount))->value(); |
697 CHECK(ret_count >= 0); | 698 CHECK(ret_count >= 0); |
698 Handle<ByteArray> sig_data = | 699 Handle<ByteArray> sig_data = |
699 data->GetValueChecked<ByteArray>(isolate, kSignature); | 700 data->GetValueChecked<ByteArray>(isolate, kSignature); |
700 int sig_data_size = sig_data->length(); | 701 int sig_data_size = sig_data->length(); |
701 int param_count = sig_data_size - ret_count; | 702 int param_count = sig_data_size - ret_count; |
702 CHECK(param_count >= 0); | 703 CHECK(param_count >= 0); |
703 | 704 |
704 MaybeHandle<JSReceiver> function = LookupFunction( | 705 MaybeHandle<JSReceiver> function = LookupFunction( |
705 *thrower, isolate->factory(), ffi, index, module_name, function_name); | 706 thrower, isolate->factory(), ffi, index, module_name, function_name); |
706 if (function.is_null()) return false; | 707 if (function.is_null()) return false; |
707 Handle<Code> code; | 708 Handle<Code> code; |
708 Handle<JSReceiver> target = function.ToHandleChecked(); | 709 Handle<JSReceiver> target = function.ToHandleChecked(); |
709 bool isMatch = false; | 710 bool isMatch = false; |
710 Handle<Code> export_wrapper_code; | 711 Handle<Code> export_wrapper_code; |
711 if (target->IsJSFunction()) { | 712 if (target->IsJSFunction()) { |
712 Handle<JSFunction> func = Handle<JSFunction>::cast(target); | 713 Handle<JSFunction> func = Handle<JSFunction>::cast(target); |
713 export_wrapper_code = handle(func->code()); | 714 export_wrapper_code = handle(func->code()); |
714 if (export_wrapper_code->kind() == Code::JS_TO_WASM_FUNCTION) { | 715 if (export_wrapper_code->kind() == Code::JS_TO_WASM_FUNCTION) { |
715 int exported_param_count = | 716 int exported_param_count = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 } | 754 } |
754 imports.push_back(code); | 755 imports.push_back(code); |
755 } | 756 } |
756 } | 757 } |
757 return true; | 758 return true; |
758 } | 759 } |
759 | 760 |
760 void InitializeParallelCompilation( | 761 void InitializeParallelCompilation( |
761 Isolate* isolate, const std::vector<WasmFunction>& functions, | 762 Isolate* isolate, const std::vector<WasmFunction>& functions, |
762 std::vector<compiler::WasmCompilationUnit*>& compilation_units, | 763 std::vector<compiler::WasmCompilationUnit*>& compilation_units, |
763 ModuleEnv& module_env, ErrorThrower& thrower) { | 764 ModuleEnv& module_env, ErrorThrower* thrower) { |
764 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); ++i) { | 765 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); ++i) { |
765 compilation_units[i] = new compiler::WasmCompilationUnit( | 766 compilation_units[i] = new compiler::WasmCompilationUnit( |
766 &thrower, isolate, &module_env, &functions[i], i); | 767 thrower, isolate, &module_env, &functions[i], i); |
767 } | 768 } |
768 } | 769 } |
769 | 770 |
770 uint32_t* StartCompilationTasks( | 771 uint32_t* StartCompilationTasks( |
771 Isolate* isolate, | 772 Isolate* isolate, |
772 std::vector<compiler::WasmCompilationUnit*>& compilation_units, | 773 std::vector<compiler::WasmCompilationUnit*>& compilation_units, |
773 std::queue<compiler::WasmCompilationUnit*>& executed_units, | 774 std::queue<compiler::WasmCompilationUnit*>& executed_units, |
774 base::Semaphore* pending_tasks, base::Mutex& result_mutex, | 775 base::Semaphore* pending_tasks, base::Mutex& result_mutex, |
775 base::AtomicNumber<size_t>& next_unit) { | 776 base::AtomicNumber<size_t>& next_unit) { |
776 const size_t num_tasks = | 777 const size_t num_tasks = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 // main thread waits for all {WasmCompilationTask} instances to finish. | 846 // main thread waits for all {WasmCompilationTask} instances to finish. |
846 // 5) The main thread finishes the compilation. | 847 // 5) The main thread finishes the compilation. |
847 | 848 |
848 // Turn on the {CanonicalHandleScope} so that the background threads can | 849 // Turn on the {CanonicalHandleScope} so that the background threads can |
849 // use the node cache. | 850 // use the node cache. |
850 CanonicalHandleScope canonical(isolate); | 851 CanonicalHandleScope canonical(isolate); |
851 | 852 |
852 // 1) The main thread allocates a compilation unit for each wasm function | 853 // 1) The main thread allocates a compilation unit for each wasm function |
853 // and stores them in the vector {compilation_units}. | 854 // and stores them in the vector {compilation_units}. |
854 InitializeParallelCompilation(isolate, module->functions, compilation_units, | 855 InitializeParallelCompilation(isolate, module->functions, compilation_units, |
855 *module_env, *thrower); | 856 *module_env, thrower); |
856 | 857 |
857 // Objects for the synchronization with the background threads. | 858 // Objects for the synchronization with the background threads. |
858 base::Mutex result_mutex; | 859 base::Mutex result_mutex; |
859 base::AtomicNumber<size_t> next_unit( | 860 base::AtomicNumber<size_t> next_unit( |
860 static_cast<size_t>(FLAG_skip_compiling_wasm_funcs)); | 861 static_cast<size_t>(FLAG_skip_compiling_wasm_funcs)); |
861 | 862 |
862 // 2) The main thread spawns {WasmCompilationTask} instances which run on | 863 // 2) The main thread spawns {WasmCompilationTask} instances which run on |
863 // the background threads. | 864 // the background threads. |
864 std::unique_ptr<uint32_t[]> task_ids(StartCompilationTasks( | 865 std::unique_ptr<uint32_t[]> task_ids(StartCompilationTasks( |
865 isolate, compilation_units, executed_units, module->pending_tasks.get(), | 866 isolate, compilation_units, executed_units, module->pending_tasks.get(), |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 FixedArray* compiled_module = | 1987 FixedArray* compiled_module = |
1987 FixedArray::cast(instance->GetInternalField(kWasmCompiledModule)); | 1988 FixedArray::cast(instance->GetInternalField(kWasmCompiledModule)); |
1988 CHECK_NOT_NULL(GetModuleObject(compiled_module)); | 1989 CHECK_NOT_NULL(GetModuleObject(compiled_module)); |
1989 CHECK(GetModuleObject(compiled_module)->cleared()); | 1990 CHECK(GetModuleObject(compiled_module)->cleared()); |
1990 } | 1991 } |
1991 | 1992 |
1992 } // namespace testing | 1993 } // namespace testing |
1993 } // namespace wasm | 1994 } // namespace wasm |
1994 } // namespace internal | 1995 } // namespace internal |
1995 } // namespace v8 | 1996 } // namespace v8 |
OLD | NEW |