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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 } | 483 } |
484 | 484 |
485 inline void Report() { | 485 inline void Report() { |
486 if (FLAG_print_wasm_code_size) { | 486 if (FLAG_print_wasm_code_size) { |
487 PrintF("Total generated wasm code: %zu bytes\n", code_size); | 487 PrintF("Total generated wasm code: %zu bytes\n", code_size); |
488 PrintF("Total generated wasm reloc: %zu bytes\n", reloc_size); | 488 PrintF("Total generated wasm reloc: %zu bytes\n", reloc_size); |
489 } | 489 } |
490 } | 490 } |
491 }; | 491 }; |
492 | 492 |
493 bool CompileWrappersToImportedFunctions( | 493 bool CompileWrappersToImportedFunctions(Isolate* isolate, |
494 Isolate* isolate, const WasmModule* module, const Handle<JSReceiver> ffi, | 494 const WasmModule* module, |
495 WasmModuleInstance* instance, ErrorThrower* thrower, Factory* factory, | 495 const Handle<JSReceiver> ffi, |
496 ModuleEnv* module_env, CodeStats& code_stats) { | 496 WasmModuleInstance* instance, |
497 ErrorThrower* thrower, Factory* factory, | |
498 ModuleEnv* module_env) { | |
497 if (module->import_table.size() > 0) { | 499 if (module->import_table.size() > 0) { |
498 instance->import_code.reserve(module->import_table.size()); | 500 instance->import_code.reserve(module->import_table.size()); |
499 for (uint32_t index = 0; index < module->import_table.size(); ++index) { | 501 for (uint32_t index = 0; index < module->import_table.size(); ++index) { |
500 const WasmImport& import = module->import_table[index]; | 502 const WasmImport& import = module->import_table[index]; |
501 WasmName module_name = module->GetNameOrNull(import.module_name_offset, | 503 WasmName module_name = module->GetNameOrNull(import.module_name_offset, |
502 import.module_name_length); | 504 import.module_name_length); |
503 WasmName function_name = module->GetNameOrNull( | 505 WasmName function_name = module->GetNameOrNull( |
504 import.function_name_offset, import.function_name_length); | 506 import.function_name_offset, import.function_name_length); |
505 MaybeHandle<JSFunction> function = LookupFunction( | 507 MaybeHandle<JSFunction> function = LookupFunction( |
506 *thrower, factory, ffi, index, module_name, function_name); | 508 *thrower, factory, ffi, index, module_name, function_name); |
507 if (function.is_null()) return false; | 509 if (function.is_null()) return false; |
508 | 510 |
509 Handle<Code> code = compiler::CompileWasmToJSWrapper( | 511 Handle<Code> code = compiler::CompileWasmToJSWrapper( |
510 isolate, module_env, function.ToHandleChecked(), import.sig, | 512 isolate, module_env, function.ToHandleChecked(), import.sig, |
511 module_name, function_name); | 513 module_name, function_name); |
512 instance->import_code[index] = code; | 514 instance->import_code[index] = code; |
513 code_stats.Record(*code); | |
514 } | 515 } |
515 } | 516 } |
516 return true; | 517 return true; |
517 } | 518 } |
518 | 519 |
519 void InitializeParallelCompilation( | 520 void InitializeParallelCompilation( |
520 Isolate* isolate, const std::vector<WasmFunction>& functions, | 521 Isolate* isolate, const std::vector<WasmFunction>& functions, |
521 std::vector<compiler::WasmCompilationUnit*>& compilation_units, | 522 std::vector<compiler::WasmCompilationUnit*>& compilation_units, |
522 ModuleEnv& module_env, ErrorThrower& thrower) { | 523 ModuleEnv& module_env, ErrorThrower& thrower) { |
523 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); i++) { | 524 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); i++) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 } | 697 } |
697 deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); | 698 deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); |
698 deopt_data->set_length(2); | 699 deopt_data->set_length(2); |
699 code->set_deoptimization_data(*deopt_data); | 700 code->set_deoptimization_data(*deopt_data); |
700 } | 701 } |
701 } | 702 } |
702 | 703 |
703 Handle<FixedArray> WasmModule::CompileFunctions(Isolate* isolate) const { | 704 Handle<FixedArray> WasmModule::CompileFunctions(Isolate* isolate) const { |
704 Factory* factory = isolate->factory(); | 705 Factory* factory = isolate->factory(); |
705 ErrorThrower thrower(isolate, "WasmModule::CompileFunctions()"); | 706 ErrorThrower thrower(isolate, "WasmModule::CompileFunctions()"); |
706 CodeStats code_stats; | |
707 | 707 |
708 WasmModuleInstance temp_instance_for_compilation(this); | 708 WasmModuleInstance temp_instance_for_compilation(this); |
709 temp_instance_for_compilation.function_table = | 709 temp_instance_for_compilation.function_table = |
710 BuildFunctionTable(isolate, this); | 710 BuildFunctionTable(isolate, this); |
711 temp_instance_for_compilation.context = isolate->native_context(); | 711 temp_instance_for_compilation.context = isolate->native_context(); |
712 temp_instance_for_compilation.mem_size = GetMinModuleMemSize(this); | 712 temp_instance_for_compilation.mem_size = GetMinModuleMemSize(this); |
713 temp_instance_for_compilation.mem_start = nullptr; | 713 temp_instance_for_compilation.mem_start = nullptr; |
714 temp_instance_for_compilation.globals_start = nullptr; | 714 temp_instance_for_compilation.globals_start = nullptr; |
715 | 715 |
716 ModuleEnv module_env; | 716 ModuleEnv module_env; |
(...skipping 26 matching lines...) Expand all Loading... | |
743 } | 743 } |
744 | 744 |
745 LinkModuleFunctions(isolate, temp_instance_for_compilation.function_code); | 745 LinkModuleFunctions(isolate, temp_instance_for_compilation.function_code); |
746 | 746 |
747 // At this point, compilation has completed. Update the code table | 747 // At this point, compilation has completed. Update the code table |
748 // and record sizes. | 748 // and record sizes. |
749 for (size_t i = FLAG_skip_compiling_wasm_funcs; | 749 for (size_t i = FLAG_skip_compiling_wasm_funcs; |
750 i < temp_instance_for_compilation.function_code.size(); ++i) { | 750 i < temp_instance_for_compilation.function_code.size(); ++i) { |
751 Code* code = *temp_instance_for_compilation.function_code[i]; | 751 Code* code = *temp_instance_for_compilation.function_code[i]; |
752 ret->set(static_cast<int>(i), code); | 752 ret->set(static_cast<int>(i), code); |
753 code_stats.Record(code); | |
754 } | 753 } |
755 | 754 |
756 PopulateFunctionTable(&temp_instance_for_compilation); | 755 PopulateFunctionTable(&temp_instance_for_compilation); |
757 | 756 |
758 return ret; | 757 return ret; |
759 } | 758 } |
760 | 759 |
761 // Instantiates a wasm module as a JSObject. | 760 // Instantiates a wasm module as a JSObject. |
762 // * allocates a backing store of {mem_size} bytes. | 761 // * allocates a backing store of {mem_size} bytes. |
763 // * installs a named property "memory" for that buffer if exported | 762 // * installs a named property "memory" for that buffer if exported |
764 // * installs named properties on the object for exported functions | 763 // * installs named properties on the object for exported functions |
765 // * compiles wasm code to machine code | 764 // * compiles wasm code to machine code |
766 MaybeHandle<JSObject> WasmModule::Instantiate( | 765 MaybeHandle<JSObject> WasmModule::Instantiate( |
767 Isolate* isolate, Handle<JSReceiver> ffi, | 766 Isolate* isolate, Handle<JSReceiver> ffi, |
768 Handle<JSArrayBuffer> memory) const { | 767 Handle<JSArrayBuffer> memory) const { |
769 HistogramTimerScope wasm_instantiate_module_time_scope( | 768 HistogramTimerScope wasm_instantiate_module_time_scope( |
770 isolate->counters()->wasm_instantiate_module_time()); | 769 isolate->counters()->wasm_instantiate_module_time()); |
771 ErrorThrower thrower(isolate, "WasmModule::Instantiate()"); | 770 ErrorThrower thrower(isolate, "WasmModule::Instantiate()"); |
772 Factory* factory = isolate->factory(); | 771 Factory* factory = isolate->factory(); |
773 | 772 |
774 // If FLAG_print_wasm_code_size is set, this aggregates the sum of all code | |
775 // objects created for this module. | |
776 // TODO(titzer): switch this to TRACE_EVENT | |
777 CodeStats code_stats; | |
778 | |
779 //------------------------------------------------------------------------- | 773 //------------------------------------------------------------------------- |
780 // Allocate the instance and its JS counterpart. | 774 // Allocate the instance and its JS counterpart. |
781 //------------------------------------------------------------------------- | 775 //------------------------------------------------------------------------- |
782 Handle<Map> map = factory->NewMap( | 776 Handle<Map> map = factory->NewMap( |
783 JS_OBJECT_TYPE, | 777 JS_OBJECT_TYPE, |
784 JSObject::kHeaderSize + kWasmModuleInternalFieldCount * kPointerSize); | 778 JSObject::kHeaderSize + kWasmModuleInternalFieldCount * kPointerSize); |
785 WasmModuleInstance instance(this); | 779 WasmModuleInstance instance(this); |
786 instance.context = isolate->native_context(); | 780 instance.context = isolate->native_context(); |
787 instance.js_object = factory->NewJSObjectFromMap(map, TENURED); | 781 instance.js_object = factory->NewJSObjectFromMap(map, TENURED); |
788 | 782 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 | 834 |
841 ModuleEnv module_env; | 835 ModuleEnv module_env; |
842 module_env.module = this; | 836 module_env.module = this; |
843 module_env.instance = &instance; | 837 module_env.instance = &instance; |
844 module_env.origin = origin; | 838 module_env.origin = origin; |
845 | 839 |
846 //------------------------------------------------------------------------- | 840 //------------------------------------------------------------------------- |
847 // Compile wrappers to imported functions. | 841 // Compile wrappers to imported functions. |
848 //------------------------------------------------------------------------- | 842 //------------------------------------------------------------------------- |
849 if (!CompileWrappersToImportedFunctions(isolate, this, ffi, &instance, | 843 if (!CompileWrappersToImportedFunctions(isolate, this, ffi, &instance, |
850 &thrower, factory, &module_env, | 844 &thrower, factory, &module_env)) { |
851 code_stats)) { | |
852 return MaybeHandle<JSObject>(); | 845 return MaybeHandle<JSObject>(); |
853 } | 846 } |
847 | |
848 // If FLAG_print_wasm_code_size is set, this aggregates the sum of all code | |
849 // objects created for this module. | |
850 // TODO(titzer): switch this to TRACE_EVENT | |
851 CodeStats code_stats; | |
Clemens Hammacher
2016/06/20 16:13:04
Now in this design it would make sense to pull the
Mircea Trofin
2016/06/20 22:47:03
Makes sense - done.
| |
852 for (Handle<Code> c : instance.function_code) code_stats.Record(*c); | |
853 for (Handle<Code> c : instance.import_code) code_stats.Record(*c); | |
854 | |
854 { | 855 { |
855 instance.js_object->SetInternalField(kWasmModuleFunctionTable, | 856 instance.js_object->SetInternalField(kWasmModuleFunctionTable, |
856 Smi::FromInt(0)); | 857 Smi::FromInt(0)); |
857 LinkImports(isolate, instance.function_code, instance.import_code); | 858 LinkImports(isolate, instance.function_code, instance.import_code); |
858 | 859 |
859 SetDeoptimizationData(factory, instance.js_object, instance.function_code); | 860 SetDeoptimizationData(factory, instance.js_object, instance.function_code); |
860 | 861 |
861 //------------------------------------------------------------------------- | 862 //------------------------------------------------------------------------- |
862 // Create and populate the exports object. | 863 // Create and populate the exports object. |
863 //------------------------------------------------------------------------- | 864 //------------------------------------------------------------------------- |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1116 Object* info = wasm->GetInternalField(kWasmDebugInfo); | 1117 Object* info = wasm->GetInternalField(kWasmDebugInfo); |
1117 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); | 1118 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); |
1118 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm)); | 1119 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm)); |
1119 wasm->SetInternalField(kWasmDebugInfo, *new_info); | 1120 wasm->SetInternalField(kWasmDebugInfo, *new_info); |
1120 return *new_info; | 1121 return *new_info; |
1121 } | 1122 } |
1122 | 1123 |
1123 } // namespace wasm | 1124 } // namespace wasm |
1124 } // namespace internal | 1125 } // namespace internal |
1125 } // namespace v8 | 1126 } // namespace v8 |
OLD | NEW |