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

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

Issue 1912103002: [wasm] Store function names in the wasm object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-offset-table-2
Patch Set: rebase Created 4 years, 7 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') | test/cctest/wasm/wasm-run-utils.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 "src/macro-assembler.h" 5 #include "src/macro-assembler.h"
6 #include "src/objects.h" 6 #include "src/objects.h"
7 #include "src/property-descriptor.h" 7 #include "src/property-descriptor.h"
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/simulator.h" 10 #include "src/simulator.h"
11 11
12 #include "src/wasm/ast-decoder.h" 12 #include "src/wasm/ast-decoder.h"
13 #include "src/wasm/module-decoder.h" 13 #include "src/wasm/module-decoder.h"
14 #include "src/wasm/wasm-function-name-table.h"
14 #include "src/wasm/wasm-module.h" 15 #include "src/wasm/wasm-module.h"
15 #include "src/wasm/wasm-result.h" 16 #include "src/wasm/wasm-result.h"
16 17
17 #include "src/compiler/wasm-compiler.h" 18 #include "src/compiler/wasm-compiler.h"
18 19
19 namespace v8 { 20 namespace v8 {
20 namespace internal { 21 namespace internal {
21 namespace wasm { 22 namespace wasm {
22 23
23 static const char* wasmSections[] = { 24 static const char* wasmSections[] = {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 195 }
195 if (modified) { 196 if (modified) {
196 Assembler::FlushICache(isolate_, code->instruction_start(), 197 Assembler::FlushICache(isolate_, code->instruction_start(),
197 code->instruction_size()); 198 code->instruction_size());
198 } 199 }
199 } 200 }
200 }; 201 };
201 202
202 namespace { 203 namespace {
203 // Internal constants for the layout of the module object. 204 // Internal constants for the layout of the module object.
204 const int kWasmModuleInternalFieldCount = 4; 205 const int kWasmModuleInternalFieldCount = 5;
205 const int kWasmModuleFunctionTable = 0; 206 const int kWasmModuleFunctionTable = 0;
206 const int kWasmModuleCodeTable = 1; 207 const int kWasmModuleCodeTable = 1;
207 const int kWasmMemArrayBuffer = 2; 208 const int kWasmMemArrayBuffer = 2;
208 const int kWasmGlobalsArrayBuffer = 3; 209 const int kWasmGlobalsArrayBuffer = 3;
210 const int kWasmFunctionNamesArray = 4;
209 211
210 size_t AllocateGlobalsOffsets(std::vector<WasmGlobal>& globals) { 212 size_t AllocateGlobalsOffsets(std::vector<WasmGlobal>& globals) {
211 uint32_t offset = 0; 213 uint32_t offset = 0;
212 if (globals.size() == 0) return 0; 214 if (globals.size() == 0) return 0;
213 for (WasmGlobal& global : globals) { 215 for (WasmGlobal& global : globals) {
214 byte size = WasmOpcodes::MemSize(global.type); 216 byte size = WasmOpcodes::MemSize(global.type);
215 offset = (offset + size - 1) & ~(size - 1); // align 217 offset = (offset + size - 1) & ~(size - 1); // align
216 global.offset = offset; 218 global.offset = offset;
217 offset += size; 219 offset += size;
218 } 220 }
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 625
624 if (mem_export) { 626 if (mem_export) {
625 // Export the memory as a named property. 627 // Export the memory as a named property.
626 Handle<String> name = factory->InternalizeUtf8String("memory"); 628 Handle<String> name = factory->InternalizeUtf8String("memory");
627 JSObject::AddProperty(exports_object, name, instance.mem_buffer, 629 JSObject::AddProperty(exports_object, name, instance.mem_buffer,
628 READ_ONLY); 630 READ_ONLY);
629 } 631 }
630 } 632 }
631 } 633 }
632 634
635 //-------------------------------------------------------------------------
636 // Attach an array with function names and an array with offsets into that
637 // first array.
638 //-------------------------------------------------------------------------
639 {
640 Handle<Object> arr = BuildFunctionNamesTable(isolate, module_env.module);
641 instance.js_object->SetInternalField(kWasmFunctionNamesArray, *arr);
642 }
643
633 if (FLAG_print_wasm_code_size) 644 if (FLAG_print_wasm_code_size)
634 printf("Total generated wasm code: %u bytes\n", total_code_size); 645 printf("Total generated wasm code: %u bytes\n", total_code_size);
635 646
636 // Run the start function if one was specified. 647 // Run the start function if one was specified.
637 if (this->start_function_index >= 0) { 648 if (this->start_function_index >= 0) {
638 HandleScope scope(isolate); 649 HandleScope scope(isolate);
639 uint32_t index = static_cast<uint32_t>(this->start_function_index); 650 uint32_t index = static_cast<uint32_t>(this->start_function_index);
640 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); 651 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start");
641 Handle<Code> code = linker.GetFunctionCode(index); 652 Handle<Code> code = linker.GetFunctionCode(index);
642 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( 653 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 Handle<Object> result = retval.ToHandleChecked(); 787 Handle<Object> result = retval.ToHandleChecked();
777 if (result->IsSmi()) { 788 if (result->IsSmi()) {
778 return Smi::cast(*result)->value(); 789 return Smi::cast(*result)->value();
779 } 790 }
780 if (result->IsHeapNumber()) { 791 if (result->IsHeapNumber()) {
781 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); 792 return static_cast<int32_t>(HeapNumber::cast(*result)->value());
782 } 793 }
783 thrower.Error("WASM.compileRun() failed: Return value should be number"); 794 thrower.Error("WASM.compileRun() failed: Return value should be number");
784 return -1; 795 return -1;
785 } 796 }
797
798 Handle<Object> GetWasmFunctionName(Handle<JSObject> wasm, uint32_t func_index) {
799 Handle<Object> func_names_arr_obj = handle(
800 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate());
801 if (func_names_arr_obj->IsUndefined())
802 return func_names_arr_obj; // Return undefined.
803 return GetWasmFunctionNameFromTable(
804 Handle<ByteArray>::cast(func_names_arr_obj), func_index);
805 }
806
786 } // namespace wasm 807 } // namespace wasm
787 } // namespace internal 808 } // namespace internal
788 } // namespace v8 809 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698