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

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

Issue 2627543003: [wasm] Prerequisites for WebAssembly Table.Grow (Closed)
Patch Set: Rename update function Created 3 years, 11 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') | src/wasm/wasm-objects.h » ('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 <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 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 WasmInstance temp_instance(this); 842 WasmInstance temp_instance(this);
843 temp_instance.context = isolate->native_context(); 843 temp_instance.context = isolate->native_context();
844 temp_instance.mem_size = WasmModule::kPageSize * min_mem_pages; 844 temp_instance.mem_size = WasmModule::kPageSize * min_mem_pages;
845 temp_instance.mem_start = nullptr; 845 temp_instance.mem_start = nullptr;
846 temp_instance.globals_start = nullptr; 846 temp_instance.globals_start = nullptr;
847 847
848 // Initialize the indirect tables with placeholders. 848 // Initialize the indirect tables with placeholders.
849 int function_table_count = static_cast<int>(function_tables.size()); 849 int function_table_count = static_cast<int>(function_tables.size());
850 Handle<FixedArray> function_tables = 850 Handle<FixedArray> function_tables =
851 factory->NewFixedArray(function_table_count, TENURED); 851 factory->NewFixedArray(function_table_count, TENURED);
852 Handle<FixedArray> signature_tables =
853 factory->NewFixedArray(function_table_count, TENURED);
852 for (int i = 0; i < function_table_count; ++i) { 854 for (int i = 0; i < function_table_count; ++i) {
853 temp_instance.function_tables[i] = factory->NewFixedArray(0, TENURED); 855 temp_instance.function_tables[i] = factory->NewFixedArray(1, TENURED);
856 temp_instance.signature_tables[i] = factory->NewFixedArray(1, TENURED);
854 function_tables->set(i, *temp_instance.function_tables[i]); 857 function_tables->set(i, *temp_instance.function_tables[i]);
858 signature_tables->set(i, *temp_instance.signature_tables[i]);
855 } 859 }
856 860
857 HistogramTimerScope wasm_compile_module_time_scope( 861 HistogramTimerScope wasm_compile_module_time_scope(
858 isolate->counters()->wasm_compile_module_time()); 862 isolate->counters()->wasm_compile_module_time());
859 863
860 ModuleBytesEnv module_env(this, &temp_instance, wire_bytes); 864 ModuleBytesEnv module_env(this, &temp_instance, wire_bytes);
861 865
862 // The {code_table} array contains import wrappers and functions (which 866 // The {code_table} array contains import wrappers and functions (which
863 // are both included in {functions.size()}, and export wrappers. 867 // are both included in {functions.size()}, and export wrappers.
864 int code_table_size = 868 int code_table_size =
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 // Create the compiled module object, and populate with compiled functions 951 // Create the compiled module object, and populate with compiled functions
948 // and information needed at instantiation time. This object needs to be 952 // and information needed at instantiation time. This object needs to be
949 // serializable. Instantiation may occur off a deserialized version of this 953 // serializable. Instantiation may occur off a deserialized version of this
950 // object. 954 // object.
951 Handle<WasmCompiledModule> ret = WasmCompiledModule::New(isolate, shared); 955 Handle<WasmCompiledModule> ret = WasmCompiledModule::New(isolate, shared);
952 ret->set_code_table(code_table); 956 ret->set_code_table(code_table);
953 ret->set_min_mem_pages(min_mem_pages); 957 ret->set_min_mem_pages(min_mem_pages);
954 ret->set_max_mem_pages(max_mem_pages); 958 ret->set_max_mem_pages(max_mem_pages);
955 if (function_table_count > 0) { 959 if (function_table_count > 0) {
956 ret->set_function_tables(function_tables); 960 ret->set_function_tables(function_tables);
961 ret->set_signature_tables(signature_tables);
957 ret->set_empty_function_tables(function_tables); 962 ret->set_empty_function_tables(function_tables);
958 } 963 }
959 964
960 // If we created a wasm script, finish it now and make it public to the 965 // If we created a wasm script, finish it now and make it public to the
961 // debugger. 966 // debugger.
962 if (asm_js_script.is_null()) { 967 if (asm_js_script.is_null()) {
963 script->set_wasm_compiled_module(*ret); 968 script->set_wasm_compiled_module(*ret);
964 isolate->debug()->OnAfterCompile(script); 969 isolate->debug()->OnAfterCompile(script);
965 } 970 }
966 971
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 // Signature mismatch. Compile a new wrapper for the new signature. 1040 // Signature mismatch. Compile a new wrapper for the new signature.
1036 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, 1041 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index,
1037 module_name, import_name, origin); 1042 module_name, import_name, origin);
1038 } 1043 }
1039 } 1044 }
1040 1045
1041 static void UpdateDispatchTablesInternal(Isolate* isolate, 1046 static void UpdateDispatchTablesInternal(Isolate* isolate,
1042 Handle<FixedArray> dispatch_tables, 1047 Handle<FixedArray> dispatch_tables,
1043 int index, WasmFunction* function, 1048 int index, WasmFunction* function,
1044 Handle<Code> code) { 1049 Handle<Code> code) {
1045 DCHECK_EQ(0, dispatch_tables->length() % 3); 1050 DCHECK_EQ(0, dispatch_tables->length() % 4);
1046 for (int i = 0; i < dispatch_tables->length(); i += 3) { 1051 for (int i = 0; i < dispatch_tables->length(); i += 4) {
1047 int table_index = Smi::cast(dispatch_tables->get(i + 1))->value(); 1052 int table_index = Smi::cast(dispatch_tables->get(i + 1))->value();
1048 Handle<FixedArray> dispatch_table( 1053 Handle<FixedArray> function_table(
1049 FixedArray::cast(dispatch_tables->get(i + 2)), isolate); 1054 FixedArray::cast(dispatch_tables->get(i + 2)), isolate);
1055 Handle<FixedArray> signature_table(
1056 FixedArray::cast(dispatch_tables->get(i + 3)), isolate);
1050 if (function) { 1057 if (function) {
1051 // TODO(titzer): the signature might need to be copied to avoid 1058 // TODO(titzer): the signature might need to be copied to avoid
1052 // a dangling pointer in the signature map. 1059 // a dangling pointer in the signature map.
1053 Handle<WasmInstanceObject> instance( 1060 Handle<WasmInstanceObject> instance(
1054 WasmInstanceObject::cast(dispatch_tables->get(i)), isolate); 1061 WasmInstanceObject::cast(dispatch_tables->get(i)), isolate);
1055 int sig_index = static_cast<int>( 1062 int sig_index = static_cast<int>(
1056 instance->module()->function_tables[table_index].map.FindOrInsert( 1063 instance->module()->function_tables[table_index].map.FindOrInsert(
1057 function->sig)); 1064 function->sig));
1058 dispatch_table->set(index, Smi::FromInt(sig_index)); 1065 signature_table->set(index, Smi::FromInt(sig_index));
1059 dispatch_table->set(index + (dispatch_table->length() / 2), *code); 1066 function_table->set(index, *code);
1060 } else { 1067 } else {
1061 Code* code = nullptr; 1068 Code* code = nullptr;
1062 dispatch_table->set(index, Smi::FromInt(-1)); 1069 signature_table->set(index, Smi::FromInt(-1));
1063 dispatch_table->set(index + (dispatch_table->length() / 2), code); 1070 function_table->set(index, code);
1064 } 1071 }
1065 } 1072 }
1066 } 1073 }
1067 1074
1068 void wasm::UpdateDispatchTables(Isolate* isolate, 1075 void wasm::UpdateDispatchTables(Isolate* isolate,
1069 Handle<FixedArray> dispatch_tables, int index, 1076 Handle<FixedArray> dispatch_tables, int index,
1070 Handle<JSFunction> function) { 1077 Handle<JSFunction> function) {
1071 if (function.is_null()) { 1078 if (function.is_null()) {
1072 UpdateDispatchTablesInternal(isolate, dispatch_tables, index, nullptr, 1079 UpdateDispatchTablesInternal(isolate, dispatch_tables, index, nullptr,
1073 Handle<Code>::null()); 1080 Handle<Code>::null());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 instance->set_globals_buffer(*global_buffer); 1207 instance->set_globals_buffer(*global_buffer);
1201 } 1208 }
1202 1209
1203 //-------------------------------------------------------------------------- 1210 //--------------------------------------------------------------------------
1204 // Prepare for initialization of function tables. 1211 // Prepare for initialization of function tables.
1205 //-------------------------------------------------------------------------- 1212 //--------------------------------------------------------------------------
1206 int function_table_count = 1213 int function_table_count =
1207 static_cast<int>(module_->function_tables.size()); 1214 static_cast<int>(module_->function_tables.size());
1208 table_instances_.reserve(module_->function_tables.size()); 1215 table_instances_.reserve(module_->function_tables.size());
1209 for (int index = 0; index < function_table_count; ++index) { 1216 for (int index = 0; index < function_table_count; ++index) {
1210 table_instances_.push_back({Handle<WasmTableObject>::null(), 1217 table_instances_.push_back(
1211 Handle<FixedArray>::null(), 1218 {Handle<WasmTableObject>::null(), Handle<FixedArray>::null(),
1212 Handle<FixedArray>::null()}); 1219 Handle<FixedArray>::null(), Handle<FixedArray>::null()});
1213 } 1220 }
1214 1221
1215 //-------------------------------------------------------------------------- 1222 //--------------------------------------------------------------------------
1216 // Process the imports for the module. 1223 // Process the imports for the module.
1217 //-------------------------------------------------------------------------- 1224 //--------------------------------------------------------------------------
1218 int num_imported_functions = ProcessImports(code_table, instance); 1225 int num_imported_functions = ProcessImports(code_table, instance);
1219 if (num_imported_functions < 0) return nothing; 1226 if (num_imported_functions < 0) return nothing;
1220 1227
1221 //-------------------------------------------------------------------------- 1228 //--------------------------------------------------------------------------
1222 // Process the initialization for the module's globals. 1229 // Process the initialization for the module's globals.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 TRACE("Finishing instance %d\n", compiled_module_->instance_id()); 1415 TRACE("Finishing instance %d\n", compiled_module_->instance_id());
1409 TRACE_CHAIN(WasmCompiledModule::cast(module_object_->GetInternalField(0))); 1416 TRACE_CHAIN(WasmCompiledModule::cast(module_object_->GetInternalField(0)));
1410 return instance; 1417 return instance;
1411 } 1418 }
1412 1419
1413 private: 1420 private:
1414 // Represents the initialized state of a table. 1421 // Represents the initialized state of a table.
1415 struct TableInstance { 1422 struct TableInstance {
1416 Handle<WasmTableObject> table_object; // WebAssembly.Table instance 1423 Handle<WasmTableObject> table_object; // WebAssembly.Table instance
1417 Handle<FixedArray> js_wrappers; // JSFunctions exported 1424 Handle<FixedArray> js_wrappers; // JSFunctions exported
1418 Handle<FixedArray> dispatch_table; // internal (code, sig) pairs 1425 Handle<FixedArray> function_table; // internal code array
1426 Handle<FixedArray> signature_table; // internal sig array
1419 }; 1427 };
1420 1428
1421 Isolate* isolate_; 1429 Isolate* isolate_;
1422 WasmModule* module_; 1430 WasmModule* module_;
1423 ErrorThrower* thrower_; 1431 ErrorThrower* thrower_;
1424 Handle<JSObject> module_object_; 1432 Handle<JSObject> module_object_;
1425 Handle<JSReceiver> ffi_; 1433 Handle<JSReceiver> ffi_;
1426 Handle<JSArrayBuffer> memory_; 1434 Handle<JSArrayBuffer> memory_;
1427 Handle<JSArrayBuffer> globals_; 1435 Handle<JSArrayBuffer> globals_;
1428 Handle<WasmCompiledModule> compiled_module_; 1436 Handle<WasmCompiledModule> compiled_module_;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 1621
1614 // TODO(titzer): import table size must match exactly for now. 1622 // TODO(titzer): import table size must match exactly for now.
1615 int table_size = table_instance.js_wrappers->length(); 1623 int table_size = table_instance.js_wrappers->length();
1616 if (table_size != static_cast<int>(table.min_size)) { 1624 if (table_size != static_cast<int>(table.min_size)) {
1617 thrower_->LinkError( 1625 thrower_->LinkError(
1618 "table import %d is wrong size (%d), expected %u", index, 1626 "table import %d is wrong size (%d), expected %u", index,
1619 table_size, table.min_size); 1627 table_size, table.min_size);
1620 return -1; 1628 return -1;
1621 } 1629 }
1622 1630
1623 // Allocate a new dispatch table. 1631 // Allocate a new dispatch table and signature table.
1624 table_instance.dispatch_table = 1632 table_instance.function_table =
1625 isolate_->factory()->NewFixedArray(table_size * 2); 1633 isolate_->factory()->NewFixedArray(table_size);
1626 for (int i = 0; i < table_size * 2; ++i) { 1634 table_instance.signature_table =
1627 table_instance.dispatch_table->set(i, 1635 isolate_->factory()->NewFixedArray(table_size);
1628 Smi::FromInt(kInvalidSigIndex)); 1636 for (int i = 0; i < table_size; ++i) {
1637 table_instance.signature_table->set(i,
1638 Smi::FromInt(kInvalidSigIndex));
1629 } 1639 }
1630 // Initialize the dispatch table with the (foreign) JS functions 1640 // Initialize the dispatch table with the (foreign) JS functions
1631 // that are already in the table. 1641 // that are already in the table.
1632 for (int i = 0; i < table_size; ++i) { 1642 for (int i = 0; i < table_size; ++i) {
1633 Handle<Object> val(table_instance.js_wrappers->get(i), isolate_); 1643 Handle<Object> val(table_instance.js_wrappers->get(i), isolate_);
1634 if (!val->IsJSFunction()) continue; 1644 if (!val->IsJSFunction()) continue;
1635 WasmFunction* function = 1645 WasmFunction* function =
1636 GetWasmFunctionForImportWrapper(isolate_, val); 1646 GetWasmFunctionForImportWrapper(isolate_, val);
1637 if (function == nullptr) { 1647 if (function == nullptr) {
1638 thrower_->LinkError("table import %d[%d] is not a WASM function", 1648 thrower_->LinkError("table import %d[%d] is not a WASM function",
1639 index, i); 1649 index, i);
1640 return -1; 1650 return -1;
1641 } 1651 }
1642 int sig_index = table.map.FindOrInsert(function->sig); 1652 int sig_index = table.map.FindOrInsert(function->sig);
1643 table_instance.dispatch_table->set(i, Smi::FromInt(sig_index)); 1653 table_instance.signature_table->set(i, Smi::FromInt(sig_index));
1644 table_instance.dispatch_table->set(i + table_size, 1654 table_instance.function_table->set(i, *UnwrapImportWrapper(val));
1645 *UnwrapImportWrapper(val));
1646 } 1655 }
1647 1656
1648 num_imported_tables++; 1657 num_imported_tables++;
1649 break; 1658 break;
1650 } 1659 }
1651 case kExternalMemory: { 1660 case kExternalMemory: {
1652 if (!WasmJs::IsWasmMemoryObject(isolate_, value)) { 1661 if (!WasmJs::IsWasmMemoryObject(isolate_, value)) {
1653 ReportLinkError("memory import must be a WebAssembly.Memory object", 1662 ReportLinkError("memory import must be a WebAssembly.Memory object",
1654 index, module_name, import_name); 1663 index, module_name, import_name);
1655 return -1; 1664 return -1;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 exports_object, FROZEN, Object::DONT_THROW); 1909 exports_object, FROZEN, Object::DONT_THROW);
1901 DCHECK(success.FromMaybe(false)); 1910 DCHECK(success.FromMaybe(false));
1902 USE(success); 1911 USE(success);
1903 } 1912 }
1904 } 1913 }
1905 1914
1906 void InitializeTables(Handle<FixedArray> code_table, 1915 void InitializeTables(Handle<FixedArray> code_table,
1907 Handle<WasmInstanceObject> instance) { 1916 Handle<WasmInstanceObject> instance) {
1908 Handle<FixedArray> old_function_tables = 1917 Handle<FixedArray> old_function_tables =
1909 compiled_module_->function_tables(); 1918 compiled_module_->function_tables();
1919 Handle<FixedArray> old_signature_tables =
1920 compiled_module_->signature_tables();
1910 int function_table_count = 1921 int function_table_count =
1911 static_cast<int>(module_->function_tables.size()); 1922 static_cast<int>(module_->function_tables.size());
1912 Handle<FixedArray> new_function_tables = 1923 Handle<FixedArray> new_function_tables =
1913 isolate_->factory()->NewFixedArray(function_table_count); 1924 isolate_->factory()->NewFixedArray(function_table_count);
1925 Handle<FixedArray> new_signature_tables =
1926 isolate_->factory()->NewFixedArray(function_table_count);
1914 for (int index = 0; index < function_table_count; ++index) { 1927 for (int index = 0; index < function_table_count; ++index) {
1915 WasmIndirectFunctionTable& table = module_->function_tables[index]; 1928 WasmIndirectFunctionTable& table = module_->function_tables[index];
1916 TableInstance& table_instance = table_instances_[index]; 1929 TableInstance& table_instance = table_instances_[index];
1917 int table_size = static_cast<int>(table.min_size); 1930 int table_size = static_cast<int>(table.min_size);
1918 1931
1919 if (table_instance.dispatch_table.is_null()) { 1932 if (table_instance.function_table.is_null()) {
1920 // Create a new dispatch table if necessary. 1933 // Create a new dispatch table if necessary.
1921 table_instance.dispatch_table = 1934 table_instance.function_table =
1922 isolate_->factory()->NewFixedArray(table_size * 2); 1935 isolate_->factory()->NewFixedArray(table_size);
1936 table_instance.signature_table =
1937 isolate_->factory()->NewFixedArray(table_size);
1923 for (int i = 0; i < table_size; ++i) { 1938 for (int i = 0; i < table_size; ++i) {
1924 // Fill the table with invalid signature indexes so that 1939 // Fill the table with invalid signature indexes so that
1925 // uninitialized entries will always fail the signature check. 1940 // uninitialized entries will always fail the signature check.
1926 table_instance.dispatch_table->set(i, Smi::FromInt(kInvalidSigIndex)); 1941 table_instance.signature_table->set(i,
1942 Smi::FromInt(kInvalidSigIndex));
1927 } 1943 }
1928 } 1944 }
1929 1945
1930 new_function_tables->set(static_cast<int>(index), 1946 new_function_tables->set(static_cast<int>(index),
1931 *table_instance.dispatch_table); 1947 *table_instance.function_table);
1948 new_signature_tables->set(static_cast<int>(index),
1949 *table_instance.signature_table);
1932 1950
1933 Handle<FixedArray> all_dispatch_tables; 1951 Handle<FixedArray> all_dispatch_tables;
1934 if (!table_instance.table_object.is_null()) { 1952 if (!table_instance.table_object.is_null()) {
1935 // Get the existing dispatch table(s) with the WebAssembly.Table object. 1953 // Get the existing dispatch table(s) with the WebAssembly.Table object.
1936 all_dispatch_tables = WasmTableObject::AddDispatchTable( 1954 all_dispatch_tables = WasmTableObject::AddDispatchTable(
1937 isolate_, table_instance.table_object, 1955 isolate_, table_instance.table_object,
1938 Handle<WasmInstanceObject>::null(), index, 1956 Handle<WasmInstanceObject>::null(), index,
1939 Handle<FixedArray>::null()); 1957 Handle<FixedArray>::null(), Handle<FixedArray>::null());
1940 } 1958 }
1941 1959
1942 // TODO(titzer): this does redundant work if there are multiple tables, 1960 // TODO(titzer): this does redundant work if there are multiple tables,
1943 // since initializations are not sorted by table index. 1961 // since initializations are not sorted by table index.
1944 for (auto table_init : module_->table_inits) { 1962 for (auto table_init : module_->table_inits) {
1945 uint32_t base = EvalUint32InitExpr(table_init.offset); 1963 uint32_t base = EvalUint32InitExpr(table_init.offset);
1946 if (base > static_cast<uint32_t>(table_size) || 1964 if (base > static_cast<uint32_t>(table_size) ||
1947 (base + table_init.entries.size() > 1965 (base + table_init.entries.size() >
1948 static_cast<uint32_t>(table_size))) { 1966 static_cast<uint32_t>(table_size))) {
1949 thrower_->LinkError("table initializer is out of bounds"); 1967 thrower_->LinkError("table initializer is out of bounds");
1950 continue; 1968 continue;
1951 } 1969 }
1952 for (int i = 0; i < static_cast<int>(table_init.entries.size()); ++i) { 1970 for (int i = 0; i < static_cast<int>(table_init.entries.size()); ++i) {
1953 uint32_t func_index = table_init.entries[i]; 1971 uint32_t func_index = table_init.entries[i];
1954 WasmFunction* function = &module_->functions[func_index]; 1972 WasmFunction* function = &module_->functions[func_index];
1955 int table_index = static_cast<int>(i + base); 1973 int table_index = static_cast<int>(i + base);
1956 int32_t sig_index = table.map.Find(function->sig); 1974 int32_t sig_index = table.map.Find(function->sig);
1957 DCHECK_GE(sig_index, 0); 1975 DCHECK_GE(sig_index, 0);
1958 table_instance.dispatch_table->set(table_index, 1976 table_instance.signature_table->set(table_index,
1959 Smi::FromInt(sig_index)); 1977 Smi::FromInt(sig_index));
1960 table_instance.dispatch_table->set(table_index + table_size, 1978 table_instance.function_table->set(table_index,
1961 code_table->get(func_index)); 1979 code_table->get(func_index));
1962 1980
1963 if (!all_dispatch_tables.is_null()) { 1981 if (!all_dispatch_tables.is_null()) {
1964 Handle<Code> wasm_code(Code::cast(code_table->get(func_index)), 1982 Handle<Code> wasm_code(Code::cast(code_table->get(func_index)),
1965 isolate_); 1983 isolate_);
1966 if (js_wrappers_[func_index].is_null()) { 1984 if (js_wrappers_[func_index].is_null()) {
1967 // No JSFunction entry yet exists for this function. Create one. 1985 // No JSFunction entry yet exists for this function. Create one.
1968 // TODO(titzer): We compile JS->WASM wrappers for functions are 1986 // TODO(titzer): We compile JS->WASM wrappers for functions are
1969 // not exported but are in an exported table. This should be done 1987 // not exported but are in an exported table. This should be done
1970 // at module compile time and cached instead. 1988 // at module compile time and cached instead.
(...skipping 30 matching lines...) Expand all
2001 } 2019 }
2002 } 2020 }
2003 2021
2004 // TODO(titzer): we add the new dispatch table at the end to avoid 2022 // TODO(titzer): we add the new dispatch table at the end to avoid
2005 // redundant work and also because the new instance is not yet fully 2023 // redundant work and also because the new instance is not yet fully
2006 // initialized. 2024 // initialized.
2007 if (!table_instance.table_object.is_null()) { 2025 if (!table_instance.table_object.is_null()) {
2008 // Add the new dispatch table to the WebAssembly.Table object. 2026 // Add the new dispatch table to the WebAssembly.Table object.
2009 all_dispatch_tables = WasmTableObject::AddDispatchTable( 2027 all_dispatch_tables = WasmTableObject::AddDispatchTable(
2010 isolate_, table_instance.table_object, instance, index, 2028 isolate_, table_instance.table_object, instance, index,
2011 table_instance.dispatch_table); 2029 table_instance.function_table, table_instance.signature_table);
2012 } 2030 }
2013 } 2031 }
2014 // Patch all code that has references to the old indirect tables. 2032 // Patch all code that has references to the old indirect tables.
2015 for (int i = 0; i < code_table->length(); ++i) { 2033 for (int i = 0; i < code_table->length(); ++i) {
2016 if (!code_table->get(i)->IsCode()) continue; 2034 if (!code_table->get(i)->IsCode()) continue;
2017 Handle<Code> code(Code::cast(code_table->get(i)), isolate_); 2035 Handle<Code> code(Code::cast(code_table->get(i)), isolate_);
2018 for (int j = 0; j < function_table_count; ++j) { 2036 for (int j = 0; j < function_table_count; ++j) {
2019 ReplaceReferenceInCode( 2037 ReplaceReferenceInCode(
2020 code, Handle<Object>(old_function_tables->get(j), isolate_), 2038 code, Handle<Object>(old_function_tables->get(j), isolate_),
2021 Handle<Object>(new_function_tables->get(j), isolate_)); 2039 Handle<Object>(new_function_tables->get(j), isolate_));
2040 ReplaceReferenceInCode(
2041 code, Handle<Object>(old_signature_tables->get(j), isolate_),
2042 Handle<Object>(new_signature_tables->get(j), isolate_));
2022 } 2043 }
2023 } 2044 }
2024 compiled_module_->set_function_tables(new_function_tables); 2045 compiled_module_->set_function_tables(new_function_tables);
2046 compiled_module_->set_signature_tables(new_signature_tables);
2025 } 2047 }
2026 }; 2048 };
2027 2049
2028 // Instantiates a WASM module, creating a WebAssembly.Instance from a 2050 // Instantiates a WASM module, creating a WebAssembly.Instance from a
2029 // WebAssembly.Module. 2051 // WebAssembly.Module.
2030 MaybeHandle<WasmInstanceObject> WasmModule::Instantiate( 2052 MaybeHandle<WasmInstanceObject> WasmModule::Instantiate(
2031 Isolate* isolate, ErrorThrower* thrower, Handle<JSObject> wasm_module, 2053 Isolate* isolate, ErrorThrower* thrower, Handle<JSObject> wasm_module,
2032 Handle<JSReceiver> ffi, Handle<JSArrayBuffer> memory) { 2054 Handle<JSReceiver> ffi, Handle<JSArrayBuffer> memory) {
2033 WasmInstanceBuilder builder(isolate, thrower, wasm_module, ffi, memory); 2055 WasmInstanceBuilder builder(isolate, thrower, wasm_module, ffi, memory);
2034 return builder.Build(); 2056 return builder.Build();
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 CHECK(!compiled_module->has_weak_owning_instance()); 2320 CHECK(!compiled_module->has_weak_owning_instance());
2299 } 2321 }
2300 2322
2301 void testing::ValidateOrphanedInstance(Isolate* isolate, 2323 void testing::ValidateOrphanedInstance(Isolate* isolate,
2302 Handle<WasmInstanceObject> instance) { 2324 Handle<WasmInstanceObject> instance) {
2303 DisallowHeapAllocation no_gc; 2325 DisallowHeapAllocation no_gc;
2304 WasmCompiledModule* compiled_module = instance->compiled_module(); 2326 WasmCompiledModule* compiled_module = instance->compiled_module();
2305 CHECK(compiled_module->has_weak_wasm_module()); 2327 CHECK(compiled_module->has_weak_wasm_module());
2306 CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared()); 2328 CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared());
2307 } 2329 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | src/wasm/wasm-objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698