Chromium Code Reviews| 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 HistogramTimerScope wasm_instantiate_module_time_scope( | 1156 // Record build time into correct bucket, then build instance. |
| 1157 isolate_->counters()->wasm_instantiate_module_time()); | 1157 if (module_->origin == ModuleOrigin::kWasmOrigin) { |
| 1158 HistogramTimerScope wasm_instantiate_module_time_scope( | |
| 1159 isolate_->counters()->wasm_instantiate_wasm_module_time()); | |
| 1160 return BuildInstance(); | |
| 1161 } else { | |
| 1162 HistogramTimerScope wasm_instantiate_module_time_scope( | |
| 1163 isolate_->counters()->wasm_instantiate_asm_module_time()); | |
| 1164 return BuildInstance(); | |
| 1165 } | |
|
bbudge
2017/03/23 22:04:58
Why not return BuildInstance() here? Or why not ju
bbudge
2017/03/23 22:14:48
I didn't see the scope objects before. You could c
Karl
2017/03/24 16:49:19
I factored out the rest of the code, as you note,
| |
| 1166 } | |
| 1167 | |
| 1168 private: | |
| 1169 // Represents the initialized state of a table. | |
| 1170 struct TableInstance { | |
| 1171 Handle<WasmTableObject> table_object; // WebAssembly.Table instance | |
| 1172 Handle<FixedArray> js_wrappers; // JSFunctions exported | |
| 1173 Handle<FixedArray> function_table; // internal code array | |
| 1174 Handle<FixedArray> signature_table; // internal sig array | |
| 1175 }; | |
| 1176 | |
| 1177 Isolate* isolate_; | |
| 1178 WasmModule* const module_; | |
| 1179 ErrorThrower* thrower_; | |
| 1180 Handle<WasmModuleObject> module_object_; | |
| 1181 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle | |
| 1182 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle | |
| 1183 Handle<JSArrayBuffer> globals_; | |
| 1184 Handle<WasmCompiledModule> compiled_module_; | |
| 1185 std::vector<TableInstance> table_instances_; | |
| 1186 std::vector<Handle<JSFunction>> js_wrappers_; | |
| 1187 JSToWasmWrapperCache js_to_wasm_cache_; | |
| 1188 | |
| 1189 // Helper routines to print out errors with imports. | |
| 1190 void ReportLinkError(const char* error, uint32_t index, | |
| 1191 Handle<String> module_name, Handle<String> import_name) { | |
| 1192 thrower_->LinkError( | |
| 1193 "Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", index, | |
| 1194 module_name->length(), module_name->ToCString().get(), | |
| 1195 import_name->length(), import_name->ToCString().get(), error); | |
| 1196 } | |
| 1197 | |
| 1198 MaybeHandle<Object> ReportLinkError(const char* error, uint32_t index, | |
| 1199 Handle<String> module_name) { | |
| 1200 thrower_->LinkError("Import #%d module=\"%.*s\" error: %s", index, | |
| 1201 module_name->length(), module_name->ToCString().get(), | |
| 1202 error); | |
| 1203 return MaybeHandle<Object>(); | |
| 1204 } | |
| 1205 | |
| 1206 // Build an instance, in all its glory. | |
| 1207 MaybeHandle<WasmInstanceObject> BuildInstance() { | |
| 1158 Factory* factory = isolate_->factory(); | 1208 Factory* factory = isolate_->factory(); |
| 1159 | 1209 |
| 1160 //-------------------------------------------------------------------------- | 1210 //-------------------------------------------------------------------------- |
| 1161 // Reuse the compiled module (if no owner), otherwise clone. | 1211 // Reuse the compiled module (if no owner), otherwise clone. |
| 1162 //-------------------------------------------------------------------------- | 1212 //-------------------------------------------------------------------------- |
| 1163 Handle<FixedArray> code_table; | 1213 Handle<FixedArray> code_table; |
| 1164 Handle<FixedArray> old_code_table; | 1214 Handle<FixedArray> old_code_table; |
| 1165 MaybeHandle<WasmInstanceObject> owner; | 1215 MaybeHandle<WasmInstanceObject> owner; |
| 1166 | 1216 |
| 1167 TRACE("Starting new module instantiation\n"); | 1217 TRACE("Starting new module instantiation\n"); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1517 return {}; | 1567 return {}; |
| 1518 } | 1568 } |
| 1519 } | 1569 } |
| 1520 | 1570 |
| 1521 DCHECK(!isolate_->has_pending_exception()); | 1571 DCHECK(!isolate_->has_pending_exception()); |
| 1522 TRACE("Finishing instance %d\n", compiled_module_->instance_id()); | 1572 TRACE("Finishing instance %d\n", compiled_module_->instance_id()); |
| 1523 TRACE_CHAIN(module_object_->compiled_module()); | 1573 TRACE_CHAIN(module_object_->compiled_module()); |
| 1524 return instance; | 1574 return instance; |
| 1525 } | 1575 } |
| 1526 | 1576 |
| 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. | 1577 // Look up an import value in the {ffi_} object. |
| 1566 MaybeHandle<Object> LookupImport(uint32_t index, Handle<String> module_name, | 1578 MaybeHandle<Object> LookupImport(uint32_t index, Handle<String> module_name, |
| 1567 Handle<String> import_name) { | 1579 Handle<String> import_name) { |
| 1568 // We pre-validated in the js-api layer that the ffi object is present, and | 1580 // We pre-validated in the js-api layer that the ffi object is present, and |
| 1569 // a JSObject, if the module has imports. | 1581 // a JSObject, if the module has imports. |
| 1570 DCHECK(!ffi_.is_null()); | 1582 DCHECK(!ffi_.is_null()); |
| 1571 | 1583 |
| 1572 // Look up the module first. | 1584 // Look up the module first. |
| 1573 MaybeHandle<Object> result = | 1585 MaybeHandle<Object> result = |
| 1574 Object::GetPropertyOrElement(ffi_, module_name); | 1586 Object::GetPropertyOrElement(ffi_, module_name); |
| (...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3202 callee_compiled->instruction_start()); | 3214 callee_compiled->instruction_start()); |
| 3203 } | 3215 } |
| 3204 DCHECK_EQ(non_compiled_functions.size(), idx); | 3216 DCHECK_EQ(non_compiled_functions.size(), idx); |
| 3205 } | 3217 } |
| 3206 | 3218 |
| 3207 Code* ret = | 3219 Code* ret = |
| 3208 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); | 3220 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); |
| 3209 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); | 3221 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); |
| 3210 return handle(ret, isolate); | 3222 return handle(ret, isolate); |
| 3211 } | 3223 } |
| OLD | NEW |