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

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

Issue 2625093004: [wasm] Instantiate the interpreter on demand (Closed)
Patch Set: Remove partilly dead variable 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
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 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 deopt_data->set(0, *weak_link); 1344 deopt_data->set(0, *weak_link);
1345 deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); 1345 deopt_data->set(1, Smi::FromInt(static_cast<int>(i)));
1346 deopt_data->set_length(2); 1346 deopt_data->set_length(2);
1347 code->set_deoptimization_data(*deopt_data); 1347 code->set_deoptimization_data(*deopt_data);
1348 } 1348 }
1349 } 1349 }
1350 1350
1351 //-------------------------------------------------------------------------- 1351 //--------------------------------------------------------------------------
1352 // Set up the exports object for the new instance. 1352 // Set up the exports object for the new instance.
1353 //-------------------------------------------------------------------------- 1353 //--------------------------------------------------------------------------
1354 ProcessExports(code_table, instance); 1354 ProcessExports(code_table, instance, compiled_module_);
1355 1355
1356 //-------------------------------------------------------------------------- 1356 //--------------------------------------------------------------------------
1357 // Add instance to Memory object 1357 // Add instance to Memory object
1358 //-------------------------------------------------------------------------- 1358 //--------------------------------------------------------------------------
1359 DCHECK(wasm::IsWasmInstance(*instance)); 1359 DCHECK(wasm::IsWasmInstance(*instance));
1360 if (instance->has_memory_object()) { 1360 if (instance->has_memory_object()) {
1361 instance->memory_object()->AddInstance(isolate_, instance); 1361 instance->memory_object()->AddInstance(isolate_, instance);
1362 } 1362 }
1363 1363
1364 //-------------------------------------------------------------------------- 1364 //--------------------------------------------------------------------------
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 const bool enable_guard_regions = EnableGuardRegions(); 1808 const bool enable_guard_regions = EnableGuardRegions();
1809 Handle<JSArrayBuffer> mem_buffer = NewArrayBuffer( 1809 Handle<JSArrayBuffer> mem_buffer = NewArrayBuffer(
1810 isolate_, min_mem_pages * WasmModule::kPageSize, enable_guard_regions); 1810 isolate_, min_mem_pages * WasmModule::kPageSize, enable_guard_regions);
1811 1811
1812 if (mem_buffer.is_null()) { 1812 if (mem_buffer.is_null()) {
1813 thrower_->RangeError("Out of memory: wasm memory"); 1813 thrower_->RangeError("Out of memory: wasm memory");
1814 } 1814 }
1815 return mem_buffer; 1815 return mem_buffer;
1816 } 1816 }
1817 1817
1818 bool NeedsWrappers() {
1819 if (module_->num_exported_functions > 0) return true;
1820 for (auto table_instance : table_instances_) {
1821 if (!table_instance.js_wrappers.is_null()) return true;
1822 }
1823 for (auto table : module_->function_tables) {
1824 if (table.exported) return true;
1825 }
1826 return false;
1827 }
1828
1818 // Process the exports, creating wrappers for functions, tables, memories, 1829 // Process the exports, creating wrappers for functions, tables, memories,
1819 // and globals. 1830 // and globals.
1820 void ProcessExports(Handle<FixedArray> code_table, 1831 void ProcessExports(Handle<FixedArray> code_table,
1821 Handle<WasmInstanceObject> instance) { 1832 Handle<WasmInstanceObject> instance,
1822 bool needs_wrappers = module_->num_exported_functions > 0; 1833 Handle<WasmCompiledModule> compiled_module) {
1823 for (auto table_instance : table_instances_) { 1834 if (NeedsWrappers()) {
1824 if (!table_instance.js_wrappers.is_null()) {
1825 needs_wrappers = true;
1826 break;
1827 }
1828 }
1829 for (auto table : module_->function_tables) {
1830 if (table.exported) {
1831 needs_wrappers = true;
1832 break;
1833 }
1834 }
1835 if (needs_wrappers) {
1836 // Fill the table to cache the exported JSFunction wrappers. 1835 // Fill the table to cache the exported JSFunction wrappers.
1837 js_wrappers_.insert(js_wrappers_.begin(), module_->functions.size(), 1836 js_wrappers_.insert(js_wrappers_.begin(), module_->functions.size(),
1838 Handle<JSFunction>::null()); 1837 Handle<JSFunction>::null());
1839 } 1838 }
1840 1839
1841 Handle<JSObject> exports_object = instance; 1840 Handle<JSObject> exports_object = instance;
1842 if (module_->origin == kWasmOrigin) { 1841 if (module_->origin == kWasmOrigin) {
1843 // Create the "exports" object. 1842 // Create the "exports" object.
1844 Handle<JSFunction> object_function = Handle<JSFunction>( 1843 Handle<JSFunction> object_function = Handle<JSFunction>(
1845 isolate_->native_context()->object_function(), isolate_); 1844 isolate_->native_context()->object_function(), isolate_);
1846 exports_object = 1845 exports_object =
1847 isolate_->factory()->NewJSObject(object_function, TENURED); 1846 isolate_->factory()->NewJSObject(object_function, TENURED);
1848 Handle<String> exports_name = 1847 Handle<String> exports_name =
1849 isolate_->factory()->InternalizeUtf8String("exports"); 1848 isolate_->factory()->InternalizeUtf8String("exports");
1850 JSObject::AddProperty(instance, exports_name, exports_object, NONE); 1849 JSObject::AddProperty(instance, exports_name, exports_object, NONE);
1851 } 1850 }
1852 1851
1853 PropertyDescriptor desc; 1852 PropertyDescriptor desc;
1854 desc.set_writable(false); 1853 desc.set_writable(false);
1855 1854
1856 // Count up export indexes. 1855 // Count up export indexes.
1857 int export_index = 0; 1856 int export_index = 0;
1858 for (auto exp : module_->export_table) { 1857 for (auto exp : module_->export_table) {
1859 if (exp.kind == kExternalFunction) { 1858 if (exp.kind == kExternalFunction) {
1860 ++export_index; 1859 ++export_index;
1861 } 1860 }
1862 } 1861 }
1862
1863 // Store weak references to all exported functions.
1864 Handle<FixedArray> weak_exported_functions;
1865 if (compiled_module->has_weak_exported_functions()) {
1866 weak_exported_functions = compiled_module->weak_exported_functions();
1867 } else {
1868 weak_exported_functions =
1869 isolate_->factory()->NewFixedArray(export_index);
1870 compiled_module->set_weak_exported_functions(weak_exported_functions);
1871 }
1872 DCHECK_EQ(export_index, weak_exported_functions->length());
1873
1863 // Process each export in the export table (go in reverse so asm.js 1874 // Process each export in the export table (go in reverse so asm.js
1864 // can skip duplicates). 1875 // can skip duplicates).
1865 for (auto exp : base::Reversed(module_->export_table)) { 1876 for (auto exp : base::Reversed(module_->export_table)) {
1866 Handle<String> name = 1877 Handle<String> name =
1867 WasmCompiledModule::ExtractUtf8StringFromModuleBytes( 1878 WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
1868 isolate_, compiled_module_, exp.name_offset, exp.name_length) 1879 isolate_, compiled_module_, exp.name_offset, exp.name_length)
1869 .ToHandleChecked(); 1880 .ToHandleChecked();
1870 switch (exp.kind) { 1881 switch (exp.kind) {
1871 case kExternalFunction: { 1882 case kExternalFunction: {
1872 // Wrap and export the code as a JSFunction. 1883 // Wrap and export the code as a JSFunction.
(...skipping 12 matching lines...) Expand all
1885 isolate_, compiled_module_, function.name_offset, 1896 isolate_, compiled_module_, function.name_offset,
1886 function.name_length) 1897 function.name_length)
1887 .ToHandleChecked(); 1898 .ToHandleChecked();
1888 } 1899 }
1889 js_function = WasmExportedFunction::New( 1900 js_function = WasmExportedFunction::New(
1890 isolate_, instance, func_name, function.func_index, 1901 isolate_, instance, func_name, function.func_index,
1891 static_cast<int>(function.sig->parameter_count()), export_code); 1902 static_cast<int>(function.sig->parameter_count()), export_code);
1892 js_wrappers_[exp.index] = js_function; 1903 js_wrappers_[exp.index] = js_function;
1893 } 1904 }
1894 desc.set_value(js_function); 1905 desc.set_value(js_function);
1906 Handle<WeakCell> weak_export =
1907 isolate_->factory()->NewWeakCell(js_function);
1908 DCHECK_GT(weak_exported_functions->length(), export_index);
1909 weak_exported_functions->set(export_index, *weak_export);
1895 break; 1910 break;
1896 } 1911 }
1897 case kExternalTable: { 1912 case kExternalTable: {
1898 // Export a table as a WebAssembly.Table object. 1913 // Export a table as a WebAssembly.Table object.
1899 TableInstance& table_instance = table_instances_[exp.index]; 1914 TableInstance& table_instance = table_instances_[exp.index];
1900 WasmIndirectFunctionTable& table = 1915 WasmIndirectFunctionTable& table =
1901 module_->function_tables[exp.index]; 1916 module_->function_tables[exp.index];
1902 if (table_instance.table_object.is_null()) { 1917 if (table_instance.table_object.is_null()) {
1903 uint32_t maximum = 1918 uint32_t maximum =
1904 table.has_max ? table.max_size : kV8MaxWasmTableSize; 1919 table.has_max ? table.max_size : kV8MaxWasmTableSize;
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 2536
2522 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), 2537 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(),
2523 NONE); 2538 NONE);
2524 JSObject::AddProperty(entry, kind_string, export_kind, NONE); 2539 JSObject::AddProperty(entry, kind_string, export_kind, NONE);
2525 2540
2526 storage->set(index, *entry); 2541 storage->set(index, *entry);
2527 } 2542 }
2528 2543
2529 return array_object; 2544 return array_object;
2530 } 2545 }
OLDNEW
« src/wasm/wasm-debug.cc ('K') | « src/wasm/wasm-debug.cc ('k') | src/wasm/wasm-objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698