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

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

Issue 2121593002: [wasm] Compile and Instantiation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: module_sym Created 4 years, 5 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') | test/mjsunit/wasm/instantiate-module-basic.js » ('j') | 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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 Handle<JSArrayBuffer> memory = Handle<JSArrayBuffer>( 1006 Handle<JSArrayBuffer> memory = Handle<JSArrayBuffer>(
1007 JSArrayBuffer::cast(instance->GetInternalField(kWasmMemArrayBuffer))); 1007 JSArrayBuffer::cast(instance->GetInternalField(kWasmMemArrayBuffer)));
1008 JSObject::AddProperty(exports_object, name, memory, READ_ONLY); 1008 JSObject::AddProperty(exports_object, name, memory, READ_ONLY);
1009 } 1009 }
1010 } 1010 }
1011 return true; 1011 return true;
1012 } 1012 }
1013 1013
1014 } // namespace 1014 } // namespace
1015 1015
1016 MaybeHandle<FixedArray> WasmModule::CompileFunctions(Isolate* isolate) const { 1016 MaybeHandle<FixedArray> WasmModule::CompileFunctions(
1017 Isolate* isolate, ErrorThrower* thrower) const {
1017 Factory* factory = isolate->factory(); 1018 Factory* factory = isolate->factory();
1018 ErrorThrower thrower(isolate, "WasmModule::CompileFunctions()");
1019 1019
1020 MaybeHandle<FixedArray> nothing; 1020 MaybeHandle<FixedArray> nothing;
1021 1021
1022 WasmModuleInstance temp_instance_for_compilation(this); 1022 WasmModuleInstance temp_instance_for_compilation(this);
1023 temp_instance_for_compilation.context = isolate->native_context(); 1023 temp_instance_for_compilation.context = isolate->native_context();
1024 temp_instance_for_compilation.mem_size = GetMinModuleMemSize(this); 1024 temp_instance_for_compilation.mem_size = GetMinModuleMemSize(this);
1025 temp_instance_for_compilation.mem_start = nullptr; 1025 temp_instance_for_compilation.mem_start = nullptr;
1026 temp_instance_for_compilation.globals_start = nullptr; 1026 temp_instance_for_compilation.globals_start = nullptr;
1027 1027
1028 MaybeHandle<FixedArray> indirect_table = BuildFunctionTable(isolate, this); 1028 MaybeHandle<FixedArray> indirect_table = BuildFunctionTable(isolate, this);
(...skipping 16 matching lines...) Expand all
1045 1045
1046 temp_instance_for_compilation.import_code.resize(import_table.size()); 1046 temp_instance_for_compilation.import_code.resize(import_table.size());
1047 for (uint32_t i = 0; i < import_table.size(); ++i) { 1047 for (uint32_t i = 0; i < import_table.size(); ++i) {
1048 temp_instance_for_compilation.import_code[i] = 1048 temp_instance_for_compilation.import_code[i] =
1049 CreatePlaceholder(factory, i, Code::WASM_TO_JS_FUNCTION); 1049 CreatePlaceholder(factory, i, Code::WASM_TO_JS_FUNCTION);
1050 } 1050 }
1051 isolate->counters()->wasm_functions_per_module()->AddSample( 1051 isolate->counters()->wasm_functions_per_module()->AddSample(
1052 static_cast<int>(functions.size())); 1052 static_cast<int>(functions.size()));
1053 if (FLAG_wasm_num_compilation_tasks != 0) { 1053 if (FLAG_wasm_num_compilation_tasks != 0) {
1054 CompileInParallel(isolate, this, 1054 CompileInParallel(isolate, this,
1055 temp_instance_for_compilation.function_code, &thrower, 1055 temp_instance_for_compilation.function_code, thrower,
1056 &module_env); 1056 &module_env);
1057 } else { 1057 } else {
1058 CompileSequentially(isolate, this, 1058 CompileSequentially(isolate, this,
1059 temp_instance_for_compilation.function_code, &thrower, 1059 temp_instance_for_compilation.function_code, thrower,
1060 &module_env); 1060 &module_env);
1061 } 1061 }
1062 if (thrower.error()) return nothing; 1062 if (thrower->error()) return nothing;
1063 1063
1064 // At this point, compilation has completed. Update the code table. 1064 // At this point, compilation has completed. Update the code table.
1065 for (size_t i = FLAG_skip_compiling_wasm_funcs; 1065 for (size_t i = FLAG_skip_compiling_wasm_funcs;
1066 i < temp_instance_for_compilation.function_code.size(); ++i) { 1066 i < temp_instance_for_compilation.function_code.size(); ++i) {
1067 Code* code = *temp_instance_for_compilation.function_code[i]; 1067 Code* code = *temp_instance_for_compilation.function_code[i];
1068 compiled_functions->set(static_cast<int>(i), code); 1068 compiled_functions->set(static_cast<int>(i), code);
1069 } 1069 }
1070 1070
1071 // Create the compiled module object, and populate with compiled functions 1071 // Create the compiled module object, and populate with compiled functions
1072 // and information needed at instantiation time. This object needs to be 1072 // and information needed at instantiation time. This object needs to be
(...skipping 19 matching lines...) Expand all
1092 for (int i = 0; i < export_size; ++i) { 1092 for (int i = 0; i < export_size; ++i) {
1093 Handle<FixedArray> export_metadata = 1093 Handle<FixedArray> export_metadata =
1094 factory->NewFixedArray(kWasmExportMetadataTableSize, TENURED); 1094 factory->NewFixedArray(kWasmExportMetadataTableSize, TENURED);
1095 const WasmExport& exp = export_table[i]; 1095 const WasmExport& exp = export_table[i];
1096 WasmName str = GetName(exp.name_offset, exp.name_length); 1096 WasmName str = GetName(exp.name_offset, exp.name_length);
1097 Handle<String> name = factory->InternalizeUtf8String(str); 1097 Handle<String> name = factory->InternalizeUtf8String(str);
1098 Handle<Code> code = 1098 Handle<Code> code =
1099 temp_instance_for_compilation.function_code[exp.func_index]; 1099 temp_instance_for_compilation.function_code[exp.func_index];
1100 Handle<Code> export_code = compiler::CompileJSToWasmWrapper( 1100 Handle<Code> export_code = compiler::CompileJSToWasmWrapper(
1101 isolate, &module_env, code, exp.func_index); 1101 isolate, &module_env, code, exp.func_index);
1102 if (thrower.error()) return nothing; 1102 if (thrower->error()) return nothing;
1103 export_metadata->set(kExportCode, *export_code); 1103 export_metadata->set(kExportCode, *export_code);
1104 export_metadata->set(kExportName, *name); 1104 export_metadata->set(kExportName, *name);
1105 export_metadata->set( 1105 export_metadata->set(
1106 kExportArity, Smi::FromInt(static_cast<int>( 1106 kExportArity, Smi::FromInt(static_cast<int>(
1107 functions[exp.func_index].sig->parameter_count()))); 1107 functions[exp.func_index].sig->parameter_count())));
1108 export_metadata->set(kExportedFunctionIndex, 1108 export_metadata->set(kExportedFunctionIndex,
1109 Smi::FromInt(static_cast<int>(exp.func_index))); 1109 Smi::FromInt(static_cast<int>(exp.func_index)));
1110 exports->set(i, *export_metadata); 1110 exports->set(i, *export_metadata);
1111 if (exp.func_index == start_function_index) { 1111 if (exp.func_index == start_function_index) {
1112 startup_fct = export_code; 1112 startup_fct = export_code;
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 } 1502 }
1503 1503
1504 if (module->import_table.size() > 0) { 1504 if (module->import_table.size() > 0) {
1505 thrower.Error("Not supported: module has imports."); 1505 thrower.Error("Not supported: module has imports.");
1506 } 1506 }
1507 if (module->export_table.size() == 0) { 1507 if (module->export_table.size() == 0) {
1508 thrower.Error("Not supported: module has no exports."); 1508 thrower.Error("Not supported: module has no exports.");
1509 } 1509 }
1510 1510
1511 if (thrower.error()) return -1; 1511 if (thrower.error()) return -1;
1512 MaybeHandle<FixedArray> compiled_module = module->CompileFunctions(isolate); 1512 MaybeHandle<FixedArray> compiled_module =
1513 module->CompileFunctions(isolate, &thrower);
1513 1514
1514 if (compiled_module.is_null()) return -1; 1515 if (compiled_module.is_null()) return -1;
1515 Handle<JSObject> instance = 1516 Handle<JSObject> instance =
1516 WasmModule::Instantiate(isolate, compiled_module.ToHandleChecked(), 1517 WasmModule::Instantiate(isolate, compiled_module.ToHandleChecked(),
1517 Handle<JSReceiver>::null(), 1518 Handle<JSReceiver>::null(),
1518 Handle<JSArrayBuffer>::null()) 1519 Handle<JSArrayBuffer>::null())
1519 .ToHandleChecked(); 1520 .ToHandleChecked();
1520 1521
1521 Handle<Name> exports = isolate->factory()->InternalizeUtf8String("exports"); 1522 Handle<Name> exports = isolate->factory()->InternalizeUtf8String("exports");
1522 Handle<JSObject> exports_object = Handle<JSObject>::cast( 1523 Handle<JSObject> exports_object = Handle<JSObject>::cast(
(...skipping 24 matching lines...) Expand all
1547 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); 1548 return static_cast<int32_t>(HeapNumber::cast(*result)->value());
1548 } 1549 }
1549 thrower.Error("WASM.compileRun() failed: Return value should be number"); 1550 thrower.Error("WASM.compileRun() failed: Return value should be number");
1550 return -1; 1551 return -1;
1551 } 1552 }
1552 1553
1553 } // namespace testing 1554 } // namespace testing
1554 } // namespace wasm 1555 } // namespace wasm
1555 } // namespace internal 1556 } // namespace internal
1556 } // namespace v8 1557 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/instantiate-module-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698