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 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 // Build an instance, in all of its glory. | 1146 // Build an instance, in all of its glory. |
1147 MaybeHandle<WasmInstanceObject> Build() { | 1147 MaybeHandle<WasmInstanceObject> Build() { |
1148 // Check that an imports argument was provided, if the module requires it. | 1148 // Check that an imports argument was provided, if the module requires it. |
1149 // No point in continuing otherwise. | 1149 // No point in continuing otherwise. |
1150 if (!module_->import_table.empty() && ffi_.is_null()) { | 1150 if (!module_->import_table.empty() && ffi_.is_null()) { |
1151 thrower_->TypeError( | 1151 thrower_->TypeError( |
1152 "Imports argument must be present and must be an object"); | 1152 "Imports argument must be present and must be an object"); |
1153 return {}; | 1153 return {}; |
1154 } | 1154 } |
1155 | 1155 |
1156 // Record build time into correct bucket, then build instance. | |
1156 HistogramTimerScope wasm_instantiate_module_time_scope( | 1157 HistogramTimerScope wasm_instantiate_module_time_scope( |
1157 isolate_->counters()->wasm_instantiate_module_time()); | 1158 module_->origin == ModuleOrigin::kWasmOrigin |
1159 ? isolate_->counters()->wasm_instantiate_wasm_module_time() | |
1160 : isolate_->counters()->wasm_instantiate_asm_module_time()); | |
1161 return BuildInstance(); | |
bbudge
2017/03/23 22:43:58
Now that there's only a single call, if you move t
Karl
2017/03/24 16:49:19
Done.
| |
1162 } | |
1163 | |
1164 private: | |
1165 // Represents the initialized state of a table. | |
1166 struct TableInstance { | |
1167 Handle<WasmTableObject> table_object; // WebAssembly.Table instance | |
1168 Handle<FixedArray> js_wrappers; // JSFunctions exported | |
1169 Handle<FixedArray> function_table; // internal code array | |
1170 Handle<FixedArray> signature_table; // internal sig array | |
1171 }; | |
1172 | |
1173 Isolate* isolate_; | |
1174 WasmModule* const module_; | |
1175 ErrorThrower* thrower_; | |
1176 Handle<WasmModuleObject> module_object_; | |
1177 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle | |
1178 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle | |
1179 Handle<JSArrayBuffer> globals_; | |
1180 Handle<WasmCompiledModule> compiled_module_; | |
1181 std::vector<TableInstance> table_instances_; | |
1182 std::vector<Handle<JSFunction>> js_wrappers_; | |
1183 JSToWasmWrapperCache js_to_wasm_cache_; | |
1184 | |
1185 // Helper routines to print out errors with imports. | |
1186 void ReportLinkError(const char* error, uint32_t index, | |
1187 Handle<String> module_name, Handle<String> import_name) { | |
1188 thrower_->LinkError( | |
1189 "Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", index, | |
1190 module_name->length(), module_name->ToCString().get(), | |
1191 import_name->length(), import_name->ToCString().get(), error); | |
1192 } | |
1193 | |
1194 MaybeHandle<Object> ReportLinkError(const char* error, uint32_t index, | |
1195 Handle<String> module_name) { | |
1196 thrower_->LinkError("Import #%d module=\"%.*s\" error: %s", index, | |
1197 module_name->length(), module_name->ToCString().get(), | |
1198 error); | |
1199 return MaybeHandle<Object>(); | |
1200 } | |
1201 | |
1202 // Build an instance, in all its glory. | |
1203 MaybeHandle<WasmInstanceObject> BuildInstance() { | |
1158 Factory* factory = isolate_->factory(); | 1204 Factory* factory = isolate_->factory(); |
1159 | 1205 |
1160 //-------------------------------------------------------------------------- | 1206 //-------------------------------------------------------------------------- |
1161 // Reuse the compiled module (if no owner), otherwise clone. | 1207 // Reuse the compiled module (if no owner), otherwise clone. |
1162 //-------------------------------------------------------------------------- | 1208 //-------------------------------------------------------------------------- |
1163 Handle<FixedArray> code_table; | 1209 Handle<FixedArray> code_table; |
1164 Handle<FixedArray> old_code_table; | 1210 Handle<FixedArray> old_code_table; |
1165 MaybeHandle<WasmInstanceObject> owner; | 1211 MaybeHandle<WasmInstanceObject> owner; |
1166 | 1212 |
1167 TRACE("Starting new module instantiation\n"); | 1213 TRACE("Starting new module instantiation\n"); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 return {}; | 1563 return {}; |
1518 } | 1564 } |
1519 } | 1565 } |
1520 | 1566 |
1521 DCHECK(!isolate_->has_pending_exception()); | 1567 DCHECK(!isolate_->has_pending_exception()); |
1522 TRACE("Finishing instance %d\n", compiled_module_->instance_id()); | 1568 TRACE("Finishing instance %d\n", compiled_module_->instance_id()); |
1523 TRACE_CHAIN(module_object_->compiled_module()); | 1569 TRACE_CHAIN(module_object_->compiled_module()); |
1524 return instance; | 1570 return instance; |
1525 } | 1571 } |
1526 | 1572 |
1527 private: | |
1528 // Represents the initialized state of a table. | |
1529 struct TableInstance { | |
1530 Handle<WasmTableObject> table_object; // WebAssembly.Table instance | |
1531 Handle<FixedArray> js_wrappers; // JSFunctions exported | |
1532 Handle<FixedArray> function_table; // internal code array | |
1533 Handle<FixedArray> signature_table; // internal sig array | |
1534 }; | |
1535 | |
1536 Isolate* isolate_; | |
1537 WasmModule* const module_; | |
1538 ErrorThrower* thrower_; | |
1539 Handle<WasmModuleObject> module_object_; | |
1540 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle | |
1541 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle | |
1542 Handle<JSArrayBuffer> globals_; | |
1543 Handle<WasmCompiledModule> compiled_module_; | |
1544 std::vector<TableInstance> table_instances_; | |
1545 std::vector<Handle<JSFunction>> js_wrappers_; | |
1546 JSToWasmWrapperCache js_to_wasm_cache_; | |
1547 | |
1548 // Helper routines to print out errors with imports. | |
1549 void ReportLinkError(const char* error, uint32_t index, | |
1550 Handle<String> module_name, Handle<String> import_name) { | |
1551 thrower_->LinkError( | |
1552 "Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", index, | |
1553 module_name->length(), module_name->ToCString().get(), | |
1554 import_name->length(), import_name->ToCString().get(), error); | |
1555 } | |
1556 | |
1557 MaybeHandle<Object> ReportLinkError(const char* error, uint32_t index, | |
1558 Handle<String> module_name) { | |
1559 thrower_->LinkError("Import #%d module=\"%.*s\" error: %s", index, | |
1560 module_name->length(), module_name->ToCString().get(), | |
1561 error); | |
1562 return MaybeHandle<Object>(); | |
1563 } | |
1564 | |
1565 // Look up an import value in the {ffi_} object. | 1573 // Look up an import value in the {ffi_} object. |
1566 MaybeHandle<Object> LookupImport(uint32_t index, Handle<String> module_name, | 1574 MaybeHandle<Object> LookupImport(uint32_t index, Handle<String> module_name, |
1567 Handle<String> import_name) { | 1575 Handle<String> import_name) { |
1568 // We pre-validated in the js-api layer that the ffi object is present, and | 1576 // We pre-validated in the js-api layer that the ffi object is present, and |
1569 // a JSObject, if the module has imports. | 1577 // a JSObject, if the module has imports. |
1570 DCHECK(!ffi_.is_null()); | 1578 DCHECK(!ffi_.is_null()); |
1571 | 1579 |
1572 // Look up the module first. | 1580 // Look up the module first. |
1573 MaybeHandle<Object> result = | 1581 MaybeHandle<Object> result = |
1574 Object::GetPropertyOrElement(ffi_, module_name); | 1582 Object::GetPropertyOrElement(ffi_, module_name); |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3202 callee_compiled->instruction_start()); | 3210 callee_compiled->instruction_start()); |
3203 } | 3211 } |
3204 DCHECK_EQ(non_compiled_functions.size(), idx); | 3212 DCHECK_EQ(non_compiled_functions.size(), idx); |
3205 } | 3213 } |
3206 | 3214 |
3207 Code* ret = | 3215 Code* ret = |
3208 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); | 3216 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); |
3209 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); | 3217 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); |
3210 return handle(ret, isolate); | 3218 return handle(ret, isolate); |
3211 } | 3219 } |
OLD | NEW |