Chromium Code Reviews| Index: src/wasm/wasm-module.h |
| diff --git a/src/wasm/wasm-module.h b/src/wasm/wasm-module.h |
| index 25a50ed68ee5471f5ac0f77e4633402cf653baa3..3811901125e3e1b3b45be8dbb009a3f74e89ab02 100644 |
| --- a/src/wasm/wasm-module.h |
| +++ b/src/wasm/wasm-module.h |
| @@ -11,6 +11,7 @@ |
| #include "src/handles.h" |
| #include "src/parsing/preparse-data.h" |
| +#include "src/wasm/managed.h" |
| #include "src/wasm/signature-map.h" |
| #include "src/wasm/wasm-opcodes.h" |
| @@ -175,22 +176,23 @@ struct WasmModule { |
| static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb |
| static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb |
| - const byte* module_start; // starting address for the module bytes. |
| - const byte* module_end; // end address for the module bytes. |
| - uint32_t min_mem_pages; // minimum size of the memory in 64k pages. |
| - uint32_t max_mem_pages; // maximum size of the memory in 64k pages. |
| - bool mem_export; // true if the memory is exported. |
| + Zone* owned_zone; |
| + const byte* module_start = nullptr; // starting address for the module bytes |
| + const byte* module_end = nullptr; // end address for the module bytes |
| + uint32_t min_mem_pages = 0; // minimum size of the memory in 64k pages |
| + uint32_t max_mem_pages = 0; // maximum size of the memory in 64k pages |
| + bool mem_export = false; // true if the memory is exported |
| // TODO(wasm): reconcile start function index being an int with |
| // the fact that we index on uint32_t, so we may technically not be |
| // able to represent some start_function_index -es. |
| - int start_function_index; // start function, if any. |
| - ModuleOrigin origin; // origin of the module |
| + int start_function_index = -1; // start function, if any |
| + ModuleOrigin origin = kWasmOrigin; // origin of the module |
| std::vector<WasmGlobal> globals; // globals in this module. |
| - uint32_t globals_size; // size of globals table. |
| - uint32_t num_imported_functions; // number of imported functions. |
| - uint32_t num_declared_functions; // number of declared functions. |
| - uint32_t num_exported_functions; // number of exported functions. |
| + uint32_t globals_size = 0; // size of globals table. |
| + uint32_t num_imported_functions = 0; // number of imported functions. |
| + uint32_t num_declared_functions = 0; // number of declared functions. |
| + uint32_t num_exported_functions = 0; // number of exported functions. |
| 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. |
| @@ -207,8 +209,11 @@ struct WasmModule { |
| // switch to libc-2.21 or higher. |
| std::unique_ptr<base::Semaphore> pending_tasks; |
| - WasmModule() : WasmModule(nullptr) {} |
| - explicit WasmModule(byte* module_start); |
| + WasmModule() : WasmModule(nullptr, nullptr) {} |
| + WasmModule(Zone* owned_zone, const byte* module_start); |
| + ~WasmModule() { |
| + if (owned_zone) delete owned_zone; |
| + } |
| // Get a string stored in the module bytes representing a name. |
| WasmName GetName(uint32_t offset, uint32_t length) const { |
| @@ -246,16 +251,16 @@ struct WasmModule { |
| // Creates a new instantiation of the module in the given isolate. |
| V8_EXPORT_PRIVATE static MaybeHandle<JSObject> Instantiate( |
| - Isolate* isolate, ErrorThrower* thrower, Handle<JSObject> module_object, |
| + Isolate* isolate, ErrorThrower* thrower, Handle<JSObject> wasm_module, |
| Handle<JSReceiver> ffi, Handle<JSArrayBuffer> memory); |
| - MaybeHandle<WasmCompiledModule> CompileFunctions(Isolate* isolate, |
| - ErrorThrower* thrower) const; |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(WasmModule); |
| + MaybeHandle<WasmCompiledModule> CompileFunctions( |
| + Isolate* isolate, Handle<Managed<WasmModule>> module_wrapper, |
| + ErrorThrower* thrower) const; |
| }; |
| +typedef Managed<WasmModule> WasmModuleWrapper; |
| + |
| // An instantiated WASM module, including memory, function table, etc. |
| struct WasmInstance { |
| const WasmModule* module; // static representation of the module. |
| @@ -267,18 +272,15 @@ struct WasmInstance { |
| std::vector<Handle<FixedArray>> function_tables; // indirect function tables. |
| std::vector<Handle<Code>> function_code; // code objects for each function. |
| // -- raw memory ------------------------------------------------------------ |
| - byte* mem_start; // start of linear memory. |
| - uint32_t mem_size; // size of the linear memory. |
| + byte* mem_start = nullptr; // start of linear memory. |
| + uint32_t mem_size = 0; // size of the linear memory. |
| // -- raw globals ----------------------------------------------------------- |
| - byte* globals_start; // start of the globals area. |
| + byte* globals_start = nullptr; // start of the globals area. |
| explicit WasmInstance(const WasmModule* m) |
| : module(m), |
| function_tables(m->function_tables.size()), |
| - function_code(m->functions.size()), |
| - mem_start(nullptr), |
| - mem_size(0), |
| - globals_start(nullptr) {} |
| + function_code(m->functions.size()) {} |
| }; |
| // Interface provided to the decoder/graph builder which contains only |
| @@ -387,25 +389,16 @@ class WasmCompiledModule : public FixedArray { |
| #define CORE_WCM_PROPERTY_TABLE(MACRO) \ |
| MACRO(OBJECT, FixedArray, code_table) \ |
| - MACRO(OBJECT, FixedArray, imports) \ |
| - MACRO(OBJECT, FixedArray, exports) \ |
| - MACRO(OBJECT, FixedArray, inits) \ |
| - MACRO(OBJECT, FixedArray, startup_function) \ |
| - MACRO(OBJECT, FixedArray, indirect_function_tables) \ |
| + MACRO(OBJECT, Foreign, module_wrapper) \ |
|
Mircea Trofin
2016/10/15 17:38:41
I assume the pointer held by the Foreign is delete
|
| MACRO(OBJECT, SeqOneByteString, module_bytes) \ |
| - MACRO(OBJECT, ByteArray, function_names) \ |
| MACRO(OBJECT, Script, asm_js_script) \ |
| + MACRO(OBJECT, FixedArray, function_tables) \ |
|
Mircea Trofin
2016/10/15 17:38:41
Why drop the "indirect" prefix?
|
| MACRO(OBJECT, ByteArray, asm_js_offset_tables) \ |
| - MACRO(SMALL_NUMBER, uint32_t, min_memory_pages) \ |
| - MACRO(OBJECT, FixedArray, data_segments_info) \ |
| - MACRO(OBJECT, ByteArray, data_segments) \ |
| - MACRO(SMALL_NUMBER, uint32_t, globals_size) \ |
| - MACRO(OBJECT, JSArrayBuffer, heap) \ |
| - MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ |
| + MACRO(OBJECT, JSArrayBuffer, memory) \ |
| MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ |
| MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ |
| MACRO(WEAK_LINK, JSObject, owning_instance) \ |
| - MACRO(WEAK_LINK, JSObject, module_object) |
| + MACRO(WEAK_LINK, JSObject, wasm_module) |
| #if DEBUG |
| #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id) |
| @@ -426,25 +419,29 @@ class WasmCompiledModule : public FixedArray { |
| }; |
| public: |
| - static Handle<WasmCompiledModule> New(Isolate* isolate, |
| - uint32_t min_memory_pages, |
| - uint32_t globals_size, |
| - ModuleOrigin origin); |
| + static Handle<WasmCompiledModule> New( |
| + Isolate* isolate, Handle<Managed<WasmModule>> module_wrapper); |
| static Handle<WasmCompiledModule> Clone(Isolate* isolate, |
| Handle<WasmCompiledModule> module) { |
| Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( |
| isolate->factory()->CopyFixedArray(module)); |
| - ret->Init(); |
| + ret->InitId(); |
| ret->reset_weak_owning_instance(); |
| ret->reset_weak_next_instance(); |
| ret->reset_weak_prev_instance(); |
| return ret; |
| } |
| + void clear_module_wrapper(Isolate* isolate) { |
| + set(kID_module_wrapper, *isolate->factory()->null_value()); |
| + } |
| + |
| + uint32_t min_memory_pages() const; |
| + |
| uint32_t mem_size() const { |
| - DCHECK(has_heap()); |
| - return heap()->byte_length()->Number(); |
| + DCHECK(has_memory()); |
| + return memory()->byte_length()->Number(); |
| } |
| uint32_t default_mem_size() const { |
| @@ -459,8 +456,11 @@ class WasmCompiledModule : public FixedArray { |
| void PrintInstancesChain(); |
| + static void RecreateModuleWrapper(Isolate* isolate, |
| + Handle<FixedArray> compiled_module); |
| + |
| private: |
| - void Init(); |
| + void InitId(); |
| DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); |
| }; |
| @@ -490,22 +490,22 @@ int GetNumberOfFunctions(Handle<JSObject> wasm); |
| // Create and export JSFunction |
| Handle<JSFunction> WrapExportCodeAsJSFunction(Isolate* isolate, |
| Handle<Code> export_code, |
| - Handle<String> name, int arity, |
| - MaybeHandle<ByteArray> signature, |
| + Handle<String> name, |
| + FunctionSig* sig, |
| Handle<JSObject> module_instance); |
| -// Check whether the given object is a wasm object. |
| +// Check whether the given object represents a WebAssembly.Module instance. |
| // This checks the number and type of internal fields, so it's not 100 percent |
| // secure. If it turns out that we need more complete checks, we could add a |
| // special marker as internal field, which will definitely never occur anywhere |
| // else. |
| -bool IsWasmObject(Object* object); |
| +bool IsWasmModule(Object* wasm_module); |
|
Mircea Trofin
2016/10/15 17:38:41
I also think "WasmModule" is a better name than "W
|
| -// Return the compiled module object for this wasm object. |
| -WasmCompiledModule* GetCompiledModule(JSObject* wasm); |
| +// Return the compiled module object for this WASM module. |
| +WasmCompiledModule* GetCompiledModule(Object* wasm_module); |
| // Check whether the wasm module was generated from asm.js code. |
| -bool WasmIsAsmJs(Object* wasm, Isolate* isolate); |
| +bool WasmIsAsmJs(Object* instance, Isolate* isolate); |
| // Get the script for the asm.js origin of the wasm module. |
| Handle<Script> GetAsmWasmScript(Handle<JSObject> wasm); |
| @@ -530,7 +530,7 @@ Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, |
| void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, |
| const std::vector<Handle<Code>>* code_table); |
| -Handle<JSObject> CreateCompiledModuleObject( |
| +Handle<JSObject> CreateWasmModuleObject( |
| Isolate* isolate, Handle<WasmCompiledModule> compiled_module, |
| ModuleOrigin origin); |
| @@ -562,9 +562,9 @@ int32_t GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, |
| namespace testing { |
| -void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, |
| +void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> wasm_module, |
| int instance_count); |
| -void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); |
| +void ValidateModuleState(Isolate* isolate, Handle<JSObject> wasm_module); |
| void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
| } // namespace testing |