Chromium Code Reviews| Index: src/wasm/wasm-module.h | 
| diff --git a/src/wasm/wasm-module.h b/src/wasm/wasm-module.h | 
| index 3ee5e597894b59a6f46d1f7bda5608cc459f8c32..1d7c9485c2518c9c75062a88fb692c01ba5d9975 100644 | 
| --- a/src/wasm/wasm-module.h | 
| +++ b/src/wasm/wasm-module.h | 
| @@ -12,6 +12,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" | 
| @@ -176,22 +177,23 @@ struct V8_EXPORT_PRIVATE 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. | 
| @@ -208,8 +210,11 @@ struct V8_EXPORT_PRIVATE 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 { | 
| @@ -248,17 +253,17 @@ struct V8_EXPORT_PRIVATE WasmModule { | 
| // Creates a new instantiation of the module in the given isolate. | 
| static MaybeHandle<JSObject> Instantiate(Isolate* isolate, | 
| ErrorThrower* thrower, | 
| - Handle<JSObject> module_object, | 
| + 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. | 
| @@ -270,18 +275,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 | 
| @@ -379,7 +381,8 @@ class WasmCompiledModule : public FixedArray { | 
| #define WCM_SMALL_NUMBER(TYPE, NAME) \ | 
| TYPE NAME() const { \ | 
| return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ | 
| - } | 
| + } \ | 
| + void set_##NAME(TYPE value) { set(kID_##NAME, Smi::FromInt(value)); } | 
| #define WCM_WEAK_LINK(TYPE, NAME) \ | 
| WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ | 
| @@ -390,25 +393,18 @@ 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) \ | 
| MACRO(OBJECT, SeqOneByteString, module_bytes) \ | 
| - MACRO(OBJECT, ByteArray, function_names) \ | 
| MACRO(OBJECT, Script, asm_js_script) \ | 
| + MACRO(OBJECT, FixedArray, function_tables) \ | 
| + MACRO(OBJECT, FixedArray, empty_function_tables) \ | 
| 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(SMALL_NUMBER, uint32_t, min_mem_pages) \ | 
| 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) | 
| @@ -429,16 +425,14 @@ 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(); | 
| @@ -446,12 +440,14 @@ class WasmCompiledModule : public FixedArray { | 
| } | 
| uint32_t mem_size() const { | 
| - DCHECK(has_heap()); | 
| - return heap()->byte_length()->Number(); | 
| + if (has_memory()) { | 
| + return memory()->byte_length()->Number(); | 
| + } | 
| + return min_mem_pages() * WasmModule::kPageSize; | 
| 
 
rossberg
2016/10/19 09:19:16
return default_mem_size() ?
 
titzer
2016/10/19 09:54:41
Done.
 
 | 
| } | 
| uint32_t default_mem_size() const { | 
| - return min_memory_pages() * WasmModule::kPageSize; | 
| + return min_mem_pages() * WasmModule::kPageSize; | 
| } | 
| #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) | 
| @@ -462,8 +458,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); | 
| }; | 
| @@ -493,22 +492,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, int func_index, | 
| Handle<JSObject> module_instance); | 
| -// Check whether the given object is a wasm object. | 
| +// Check whether the given object represents a WebAssembly.Instance 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 IsWasmInstance(Object* instance); | 
| -// Return the compiled module object for this wasm object. | 
| -WasmCompiledModule* GetCompiledModule(JSObject* wasm); | 
| +// Return the compiled module object for this WASM instance. | 
| +WasmCompiledModule* GetCompiledModule(Object* wasm_instance); | 
| // 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); | 
| @@ -528,7 +527,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); | 
| @@ -560,9 +559,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 |