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

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

Issue 2396043002: [wasm] Remove three fields from wasm object (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | no next file » | 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/base/atomic-utils.h" 7 #include "src/base/atomic-utils.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 9
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 // Internal constants for the layout of the module object. 51 // Internal constants for the layout of the module object.
52 enum WasmInstanceObjectFields { 52 enum WasmInstanceObjectFields {
53 kWasmCompiledModule = 0, 53 kWasmCompiledModule = 0,
54 kWasmModuleFunctionTable, 54 kWasmModuleFunctionTable,
55 kWasmModuleCodeTable, 55 kWasmModuleCodeTable,
56 kWasmMemArrayBuffer, 56 kWasmMemArrayBuffer,
57 kWasmGlobalsArrayBuffer, 57 kWasmGlobalsArrayBuffer,
58 // TODO(clemensh): Remove function name array, extract names from module 58 // TODO(clemensh): Remove function name array, extract names from module
59 // bytes. 59 // bytes.
60 kWasmFunctionNamesArray,
61 kWasmModuleBytesString,
62 kWasmDebugInfo, 60 kWasmDebugInfo,
63 kWasmNumImportedFunctions,
64 kWasmModuleInternalFieldCount 61 kWasmModuleInternalFieldCount
65 }; 62 };
66 63
67 enum WasmImportData { 64 enum WasmImportData {
68 kModuleName, // String 65 kModuleName, // String
69 kFunctionName, // maybe String 66 kFunctionName, // maybe String
70 kOutputCount, // Smi. an uint32_t 67 kOutputCount, // Smi. an uint32_t
71 kSignature, // ByteArray. A copy of the data in FunctionSig 68 kSignature, // ByteArray. A copy of the data in FunctionSig
72 kWasmImportDataSize // Sentinel value. 69 kWasmImportDataSize // Sentinel value.
73 }; 70 };
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 FixedArray* deopt_data = code->deoptimization_data(); 979 FixedArray* deopt_data = code->deoptimization_data();
983 DCHECK_NOT_NULL(deopt_data); 980 DCHECK_NOT_NULL(deopt_data);
984 DCHECK(deopt_data->length() == 2); 981 DCHECK(deopt_data->length() == 2);
985 Object* weak_link = deopt_data->get(0); 982 Object* weak_link = deopt_data->get(0);
986 if (!weak_link->IsWeakCell()) return nullptr; 983 if (!weak_link->IsWeakCell()) return nullptr;
987 WeakCell* cell = WeakCell::cast(weak_link); 984 WeakCell* cell = WeakCell::cast(weak_link);
988 return cell->value(); 985 return cell->value();
989 } 986 }
990 987
991 uint32_t GetNumImportedFunctions(Handle<JSObject> wasm_object) { 988 uint32_t GetNumImportedFunctions(Handle<JSObject> wasm_object) {
992 return static_cast<uint32_t>( 989 DCHECK(IsWasmObject(*wasm_object));
993 Smi::cast(wasm_object->GetInternalField(kWasmNumImportedFunctions)) 990 WasmCompiledModule* compiled_module = WasmCompiledModule::cast(
994 ->value()); 991 wasm_object->GetInternalField(kWasmCompiledModule));
992 return static_cast<uint32_t>(compiled_module->ptr_to_import_data()->length());
titzer 2016/10/06 15:55:09 That won't work in my latest patch; the number of
Clemens Hammacher 2016/10/06 18:46:50 Fixed as discussed.
995 } 993 }
996 994
997 WasmModule::WasmModule(byte* module_start) 995 WasmModule::WasmModule(byte* module_start)
998 : module_start(module_start), 996 : module_start(module_start),
999 module_end(nullptr), 997 module_end(nullptr),
1000 min_mem_pages(0), 998 min_mem_pages(0),
1001 max_mem_pages(0), 999 max_mem_pages(0),
1002 mem_export(false), 1000 mem_export(false),
1003 start_function_index(-1), 1001 start_function_index(-1),
1004 origin(kWasmOrigin), 1002 origin(kWasmOrigin),
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 for (int index = 0; index < num_imported_functions; index++) { 1335 for (int index = 0; index < num_imported_functions; index++) {
1338 Handle<Code> import_wrapper = 1336 Handle<Code> import_wrapper =
1339 CompileImportWrapper(isolate, ffi, index, import_data, thrower); 1337 CompileImportWrapper(isolate, ffi, index, import_data, thrower);
1340 if (thrower->error()) return nothing; 1338 if (thrower->error()) return nothing;
1341 code_table->set(index, *import_wrapper); 1339 code_table->set(index, *import_wrapper);
1342 RecordStats(isolate, *import_wrapper); 1340 RecordStats(isolate, *import_wrapper);
1343 } 1341 }
1344 } 1342 }
1345 1343
1346 //-------------------------------------------------------------------------- 1344 //--------------------------------------------------------------------------
1347 // Set up the debug support for the new instance.
1348 //--------------------------------------------------------------------------
1349 // TODO(clemensh): avoid referencing this stuff from the instance, use it off
1350 // the compiled module instead. See the following 3 assignments:
1351 if (compiled_module->has_module_bytes()) {
1352 instance->SetInternalField(kWasmModuleBytesString,
1353 compiled_module->ptr_to_module_bytes());
1354 }
1355
1356 if (compiled_module->has_function_names()) {
1357 instance->SetInternalField(kWasmFunctionNamesArray,
1358 compiled_module->ptr_to_function_names());
1359 }
1360
1361 {
1362 Handle<Object> handle = factory->NewNumber(num_imported_functions);
1363 instance->SetInternalField(kWasmNumImportedFunctions, *handle);
1364 }
1365
1366 //--------------------------------------------------------------------------
1367 // Set up the runtime support for the new instance. 1345 // Set up the runtime support for the new instance.
1368 //-------------------------------------------------------------------------- 1346 //--------------------------------------------------------------------------
1369 Handle<WeakCell> weak_link = isolate->factory()->NewWeakCell(instance); 1347 Handle<WeakCell> weak_link = isolate->factory()->NewWeakCell(instance);
1370 1348
1371 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs; 1349 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs;
1372 i < code_table->length(); ++i) { 1350 i < code_table->length(); ++i) {
1373 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i); 1351 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i);
1374 if (code->kind() == Code::WASM_FUNCTION) { 1352 if (code->kind() == Code::WASM_FUNCTION) {
1375 Handle<FixedArray> deopt_data = 1353 Handle<FixedArray> deopt_data =
1376 isolate->factory()->NewFixedArray(2, TENURED); 1354 isolate->factory()->NewFixedArray(2, TENURED);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 current = 1592 current =
1615 WasmCompiledModule::cast(current->ptr_to_weak_next_instance()->value()); 1593 WasmCompiledModule::cast(current->ptr_to_weak_next_instance()->value());
1616 } 1594 }
1617 PrintF("\n"); 1595 PrintF("\n");
1618 #endif 1596 #endif
1619 } 1597 }
1620 1598
1621 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, 1599 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm,
1622 uint32_t func_index) { 1600 uint32_t func_index) {
1623 if (!wasm->IsUndefined(isolate)) { 1601 if (!wasm->IsUndefined(isolate)) {
1602 DCHECK(IsWasmObject(*wasm));
1603 WasmCompiledModule* compiled_module = WasmCompiledModule::cast(
1604 Handle<JSObject>::cast(wasm)->GetInternalField(kWasmCompiledModule));
1624 Handle<ByteArray> func_names_arr_obj( 1605 Handle<ByteArray> func_names_arr_obj(
1625 ByteArray::cast(Handle<JSObject>::cast(wasm)->GetInternalField( 1606 compiled_module->ptr_to_function_names(), isolate);
Mircea Trofin 2016/10/06 15:43:21 wouldn't compiled_module->function_names() give yo
Clemens Hammacher 2016/10/06 18:46:50 Good catch, fixed.
1626 kWasmFunctionNamesArray)),
1627 isolate);
1628 // TODO(clemens): Extract this from the module bytes; skip whole function 1607 // TODO(clemens): Extract this from the module bytes; skip whole function
1629 // name table. 1608 // name table.
1630 Handle<Object> name; 1609 Handle<Object> name;
1631 if (GetWasmFunctionNameFromTable(func_names_arr_obj, func_index) 1610 if (GetWasmFunctionNameFromTable(func_names_arr_obj, func_index)
1632 .ToHandle(&name)) { 1611 .ToHandle(&name)) {
1633 return name; 1612 return name;
1634 } 1613 }
1635 } 1614 }
1636 return isolate->factory()->null_value(); 1615 return isolate->factory()->null_value();
1637 } 1616 }
(...skipping 13 matching lines...) Expand all
1651 1630
1652 JSObject* obj = JSObject::cast(object); 1631 JSObject* obj = JSObject::cast(object);
1653 Isolate* isolate = obj->GetIsolate(); 1632 Isolate* isolate = obj->GetIsolate();
1654 if (obj->GetInternalFieldCount() != kWasmModuleInternalFieldCount) { 1633 if (obj->GetInternalFieldCount() != kWasmModuleInternalFieldCount) {
1655 return false; 1634 return false;
1656 } 1635 }
1657 1636
1658 Object* mem = obj->GetInternalField(kWasmMemArrayBuffer); 1637 Object* mem = obj->GetInternalField(kWasmMemArrayBuffer);
1659 if (!obj->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() || 1638 if (!obj->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() ||
1660 !(mem->IsUndefined(isolate) || mem->IsJSArrayBuffer()) || 1639 !(mem->IsUndefined(isolate) || mem->IsJSArrayBuffer()) ||
1661 !obj->GetInternalField(kWasmFunctionNamesArray)->IsByteArray() ||
1662 !WasmCompiledModule::IsWasmCompiledModule( 1640 !WasmCompiledModule::IsWasmCompiledModule(
1663 obj->GetInternalField(kWasmCompiledModule))) { 1641 obj->GetInternalField(kWasmCompiledModule))) {
1664 return false; 1642 return false;
1665 } 1643 }
1666 1644
1667 // All checks passed. 1645 // All checks passed.
1668 return true; 1646 return true;
1669 } 1647 }
1670 1648
1671 SeqOneByteString* GetWasmBytes(JSObject* wasm) { 1649 SeqOneByteString* GetWasmBytes(JSObject* wasm) {
titzer 2016/10/06 15:55:09 Please return a handle instead of a raw pointer he
Clemens Hammacher 2016/10/06 18:46:50 Done.
1672 return SeqOneByteString::cast(wasm->GetInternalField(kWasmModuleBytesString)); 1650 DCHECK(IsWasmObject(wasm));
1651 WasmCompiledModule* compiled_module =
1652 WasmCompiledModule::cast(wasm->GetInternalField(kWasmCompiledModule));
1653 return compiled_module->ptr_to_module_bytes();
1673 } 1654 }
1674 1655
1675 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm) { 1656 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm) {
1676 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo), 1657 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo),
1677 wasm->GetIsolate()); 1658 wasm->GetIsolate());
1678 if (!info->IsUndefined(wasm->GetIsolate())) 1659 if (!info->IsUndefined(wasm->GetIsolate()))
1679 return Handle<WasmDebugInfo>::cast(info); 1660 return Handle<WasmDebugInfo>::cast(info);
1680 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm); 1661 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm);
1681 wasm->SetInternalField(kWasmDebugInfo, *new_info); 1662 wasm->SetInternalField(kWasmDebugInfo, *new_info);
1682 return new_info; 1663 return new_info;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 uint32_t max_size = table->length() / 2; 1723 uint32_t max_size = table->length() / 2;
1743 for (uint32_t i = max_size; i < max_size + table_size; ++i) { 1724 for (uint32_t i = max_size; i < max_size + table_size; ++i) {
1744 int index = Smi::cast(table->get(static_cast<int>(i)))->value(); 1725 int index = Smi::cast(table->get(static_cast<int>(i)))->value();
1745 DCHECK_GE(index, 0); 1726 DCHECK_GE(index, 0);
1746 DCHECK_LT(static_cast<size_t>(index), code_table->size()); 1727 DCHECK_LT(static_cast<size_t>(index), code_table->size());
1747 table->set(static_cast<int>(i), *(*code_table)[index]); 1728 table->set(static_cast<int>(i), *(*code_table)[index]);
1748 } 1729 }
1749 } 1730 }
1750 1731
1751 int GetNumberOfFunctions(JSObject* wasm) { 1732 int GetNumberOfFunctions(JSObject* wasm) {
1752 Object* func_names_obj = wasm->GetInternalField(kWasmFunctionNamesArray); 1733 DCHECK(IsWasmObject(wasm));
1734 WasmCompiledModule* compiled_module =
1735 WasmCompiledModule::cast(wasm->GetInternalField(kWasmCompiledModule));
1736 ByteArray* func_names_arr = compiled_module->ptr_to_function_names();
1753 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. 1737 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor.
1754 return ByteArray::cast(func_names_obj)->get_int(0); 1738 return func_names_arr->get_int(0);
1755 } 1739 }
1756 1740
1757 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, 1741 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate,
1758 Handle<FixedArray> compiled_module, 1742 Handle<FixedArray> compiled_module,
1759 ModuleOrigin origin) { 1743 ModuleOrigin origin) {
1760 Handle<JSObject> module_obj; 1744 Handle<JSObject> module_obj;
1761 if (origin == ModuleOrigin::kWasmOrigin) { 1745 if (origin == ModuleOrigin::kWasmOrigin) {
1762 Handle<JSFunction> module_cons( 1746 Handle<JSFunction> module_cons(
1763 isolate->native_context()->wasm_module_constructor()); 1747 isolate->native_context()->wasm_module_constructor());
1764 module_obj = isolate->factory()->NewJSObject(module_cons); 1748 module_obj = isolate->factory()->NewJSObject(module_cons);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 WasmCompiledModule* compiled_module = 1919 WasmCompiledModule* compiled_module =
1936 WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule)); 1920 WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule));
1937 CHECK(compiled_module->has_weak_module_object()); 1921 CHECK(compiled_module->has_weak_module_object());
1938 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); 1922 CHECK(compiled_module->ptr_to_weak_module_object()->cleared());
1939 } 1923 }
1940 1924
1941 } // namespace testing 1925 } // namespace testing
1942 } // namespace wasm 1926 } // namespace wasm
1943 } // namespace internal 1927 } // namespace internal
1944 } // namespace v8 1928 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698