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

Unified Diff: src/wasm/wasm-module.h

Issue 2174123002: [wasm] Add support for multiple indirect function tables (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix loop bug, cleanups, style Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: src/wasm/wasm-module.h
diff --git a/src/wasm/wasm-module.h b/src/wasm/wasm-module.h
index 6bab4e6e725d6a05f2927a3f98a07921894480ea..2fa8a856714024df5b788dad7643a17ec09c7200 100644
--- a/src/wasm/wasm-module.h
+++ b/src/wasm/wasm-module.h
@@ -41,7 +41,6 @@ const uint8_t kWasmFunctionTypeForm = 0x40;
F(FunctionBodies, 8, "code") \
F(DataSegments, 9, "data") \
F(Names, 10, "name") \
- F(FunctionTablePad, 11, "table_pad") \
F(Globals, 0, "global") \
F(End, 0, "end")
@@ -59,8 +58,6 @@ const uint8_t kWasmFunctionTypeForm = 0x40;
8, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n'
#define WASM_SECTION_FUNCTION_BODIES 4, 'c', 'o', 'd', 'e'
#define WASM_SECTION_NAMES 4, 'n', 'a', 'm', 'e'
-#define WASM_SECTION_FUNCTION_TABLE_PAD \
- 9, 't', 'a', 'b', 'l', 'e', '_', 'p', 'a', 'd'
// Constants for the above section headers' size (LEB128 + characters).
#define WASM_SECTION_MEMORY_SIZE ((size_t)7)
@@ -75,7 +72,6 @@ const uint8_t kWasmFunctionTypeForm = 0x40;
#define WASM_SECTION_FUNCTION_SIGNATURES_SIZE ((size_t)9)
#define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)5)
#define WASM_SECTION_NAMES_SIZE ((size_t)5)
-#define WASM_SECTION_FUNCTION_TABLE_PAD_SIZE ((size_t)10)
class WasmDebugInfo;
@@ -151,6 +147,13 @@ struct WasmDataSegment {
bool init; // true if loaded upon instantiation.
};
+// Static representation of a wasm indirect call table.
+struct WasmTable {
Mircea Trofin 2016/07/26 03:37:27 WasmIndirectFunctionTable. WasmTable is very ambi
ddchen 2016/07/26 05:44:44 Done.
+ uint32_t size; // initial table size.
+ uint32_t max_size; // maximum table size.
+ std::vector<uint16_t> values; // function table.
+};
+
enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin };
// Static representation of a module.
@@ -173,12 +176,10 @@ struct WasmModule {
std::vector<WasmGlobal> globals; // globals in this module.
uint32_t globals_size; // size of globals table.
- uint32_t indirect_table_size; // size of indirect function
- // table (includes padding).
std::vector<FunctionSig*> signatures; // signatures in this module.
std::vector<WasmFunction> functions; // functions in this module.
std::vector<WasmDataSegment> data_segments; // data segments in this module.
- std::vector<uint16_t> function_table; // function table.
+ std::vector<WasmTable> function_tables; // function tables.
std::vector<WasmImport> import_table; // import table.
std::vector<WasmExport> export_table; // export table.
// We store the semaphore here to extend its lifetime. In <libc-2.21, which we
@@ -235,14 +236,6 @@ struct WasmModule {
MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate,
ErrorThrower* thrower) const;
-
- uint32_t FunctionTableSize() const {
- if (indirect_table_size > 0) {
- return indirect_table_size;
- }
- DCHECK_LE(function_table.size(), UINT32_MAX);
- return static_cast<uint32_t>(function_table.size());
- }
};
// An instantiated WASM module, including memory, function table, etc.
@@ -253,7 +246,7 @@ struct WasmModuleInstance {
Handle<Context> context; // JavaScript native context.
Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory.
Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals.
- Handle<FixedArray> function_table; // indirect function table.
+ std::vector<Handle<FixedArray>> function_tables; // indirect function tables.
std::vector<Handle<Code>> function_code; // code objects for each function.
std::vector<Handle<Code>> import_code; // code objects for each import.
// -- raw memory ------------------------------------------------------------
@@ -264,6 +257,7 @@ struct WasmModuleInstance {
explicit WasmModuleInstance(const WasmModule* m)
: module(m),
+ function_tables(m->function_tables.size()),
function_code(m->functions.size()),
import_code(m->import_table.size()),
mem_start(nullptr),
@@ -293,6 +287,9 @@ struct ModuleEnv {
bool IsValidImport(uint32_t index) {
return module && index < module->import_table.size();
}
+ bool IsValidTable(uint32_t index) {
Mircea Trofin 2016/07/26 03:37:27 const if you didn't mind, while at it, could you
ddchen 2016/07/26 05:44:44 Done.
+ return module && index < module->function_tables.size();
+ }
LocalType GetGlobalType(uint32_t index) {
DCHECK(IsValidGlobal(index));
return module->globals[index].type;
@@ -309,8 +306,9 @@ struct ModuleEnv {
DCHECK(IsValidSignature(index));
return module->signatures[index];
}
- uint32_t FunctionTableSize() const {
- return module->FunctionTableSize();
+ const WasmTable* GetTable(uint32_t index) {
Mircea Trofin 2016/07/26 03:37:27 this one's const, too
ddchen 2016/07/26 05:44:44 Done.
+ DCHECK(IsValidTable(index));
+ return &module->function_tables[index];
}
bool asm_js() { return origin == kAsmJsOrigin; }
@@ -382,6 +380,12 @@ bool UpdateWasmModuleMemory(Handle<JSObject> object, Address old_start,
Address new_start, uint32_t old_size,
uint32_t new_size);
+Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index,
+ const WasmModule* module);
+
+void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size,
+ const std::vector<Handle<Code>>* code_table);
+
namespace testing {
// Decode, verify, and run the function labeled "main" in the

Powered by Google App Engine
This is Rietveld 408576698