| Index: src/wasm/wasm-module.cc
|
| diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
|
| index e82ffcd4626ded3bdf65fae7ca6282ce9bfdd6d9..03d10bffe47bc557f986129cef58fb3fc1882a0c 100644
|
| --- a/src/wasm/wasm-module.cc
|
| +++ b/src/wasm/wasm-module.cc
|
| @@ -172,43 +172,14 @@ enum WasmInstanceFields {
|
| kWasmModuleInternalFieldCount
|
| };
|
|
|
| -// TODO(mtrofin): Unnecessary once we stop using JS Heap for wasm code.
|
| -// For now, each field is expected to have the type commented by its side.
|
| -// The elements typed as "maybe" are optional. The others are mandatory. Since
|
| -// the compiled module is either obtained from the current v8 instance, or from
|
| -// a snapshot produced by a compatible (==identical) v8 instance, we simply
|
| -// fail at instantiation time, in the face of invalid data.
|
| -enum CompiledWasmObjectFields {
|
| - kFunctions, // FixedArray of Code
|
| - kImportData, // maybe FixedArray of FixedArray respecting the
|
| - // WasmImportMetadata structure.
|
| - kImportMap, // FixedArray. The i-th element is the Code object used for
|
| - // import i
|
| - kExports, // maybe FixedArray of FixedArray of WasmExportMetadata
|
| - // structure
|
| - kStartupFunction, // maybe FixedArray of WasmExportMetadata structure
|
| - kTableOfIndirectFunctionTables, // maybe FixedArray of FixedArray of
|
| - // WasmIndirectFunctionTableMetadata
|
| - kModuleBytes, // maybe String
|
| - kFunctionNameTable, // maybe ByteArray
|
| - kMinRequiredMemory, // Smi. an uint32_t
|
| - // The following 2 are either together present or absent:
|
| - kDataSegmentsInfo, // maybe FixedArray of FixedArray respecting the
|
| - // WasmSegmentInfo structure
|
| - kDataSegments, // maybe ByteArray.
|
| -
|
| - kGlobalsSize, // Smi. an uint32_t
|
| - kMemSize, // Smi.an uint32_t
|
| - kMemStart, // MaybeHandle<ArrayBuffer>
|
| - kExportMem, // Smi. bool
|
| - kOrigin, // Smi. ModuleOrigin
|
| - kNextInstance, // WeakCell. See compiled code cloning.
|
| - kPrevInstance, // WeakCell. See compiled code cloning.
|
| - kOwningInstance, // WeakCell, pointing to the owning instance.
|
| - kModuleObject, // WeakCell, pointing to the module object.
|
| - kCompiledWasmObjectTableSize // Sentinel value.
|
| -};
|
| -
|
| +// // TODO(mtrofin): Unnecessary once we stop using JS Heap for wasm code.
|
| +// // For now, each field is expected to have the type commented by its side.
|
| +// // The elements typed as "maybe" are optional. The others are mandatory.
|
| +// Since
|
| +// // the compiled module is either obtained from the current v8 instance, or
|
| +// from
|
| +// // a snapshot produced by a compatible (==identical) v8 instance, we simply
|
| +// // fail at instantiation time, in the face of invalid data.
|
| enum WasmImportMetadata {
|
| kModuleName, // String
|
| kFunctionName, // maybe String
|
| @@ -242,21 +213,18 @@ uint32_t GetMinModuleMemSize(const WasmModule* module) {
|
| return WasmModule::kPageSize * module->min_mem_pages;
|
| }
|
|
|
| -void LoadDataSegments(Handle<FixedArray> compiled_module, Address mem_addr,
|
| - size_t mem_size) {
|
| +void LoadDataSegments(Handle<WasmCompiledModule> compiled_module,
|
| + Address mem_addr, size_t mem_size) {
|
| Isolate* isolate = compiled_module->GetIsolate();
|
| - MaybeHandle<ByteArray> maybe_data =
|
| - compiled_module->GetValue<ByteArray>(isolate, kDataSegments);
|
| - MaybeHandle<FixedArray> maybe_segments =
|
| - compiled_module->GetValue<FixedArray>(isolate, kDataSegmentsInfo);
|
|
|
| // We either have both or neither.
|
| - CHECK(maybe_data.is_null() == maybe_segments.is_null());
|
| + CHECK(compiled_module->has_data_segments() ==
|
| + compiled_module->has_data_segments_info());
|
| // If we have neither, we're done.
|
| - if (maybe_data.is_null()) return;
|
| + if (!compiled_module->has_data_segments()) return;
|
|
|
| - Handle<ByteArray> data = maybe_data.ToHandleChecked();
|
| - Handle<FixedArray> segments = maybe_segments.ToHandleChecked();
|
| + Handle<ByteArray> data = compiled_module->data_segments();
|
| + Handle<FixedArray> segments = compiled_module->data_segments_info();
|
|
|
| uint32_t last_extraction_pos = 0;
|
| for (int i = 0; i < segments->length(); ++i) {
|
| @@ -274,7 +242,7 @@ void LoadDataSegments(Handle<FixedArray> compiled_module, Address mem_addr,
|
| }
|
|
|
| void SaveDataSegmentInfo(Factory* factory, const WasmModule* module,
|
| - Handle<FixedArray> compiled_module) {
|
| + Handle<WasmCompiledModule> compiled_module) {
|
| Handle<FixedArray> segments = factory->NewFixedArray(
|
| static_cast<int>(module->data_segments.size()), TENURED);
|
| uint32_t data_size = 0;
|
| @@ -300,8 +268,8 @@ void SaveDataSegmentInfo(Factory* factory, const WasmModule* module,
|
| segment.source_size);
|
| last_insertion_pos += segment.source_size;
|
| }
|
| - compiled_module->set(kDataSegmentsInfo, *segments);
|
| - compiled_module->set(kDataSegments, *data);
|
| + compiled_module->set_data_segments_info(segments);
|
| + compiled_module->set_data_segments(data);
|
| }
|
|
|
| void PatchFunctionTable(Handle<Code> code,
|
| @@ -910,29 +878,25 @@ void CompileSequentially(Isolate* isolate, const WasmModule* module,
|
| }
|
| }
|
|
|
| -void SetDebugSupport(Factory* factory, Handle<FixedArray> compiled_module,
|
| +void SetDebugSupport(Factory* factory,
|
| + Handle<WasmCompiledModule> compiled_module,
|
| Handle<JSObject> js_object) {
|
| Isolate* isolate = compiled_module->GetIsolate();
|
| - MaybeHandle<String> module_bytes_string =
|
| - compiled_module->GetValue<String>(isolate, kModuleBytes);
|
| - if (!module_bytes_string.is_null()) {
|
| + if (compiled_module->has_module_bytes()) {
|
| js_object->SetInternalField(kWasmModuleBytesString,
|
| - *module_bytes_string.ToHandleChecked());
|
| + *compiled_module->module_bytes());
|
| }
|
|
|
| - MaybeHandle<ByteArray> function_name_table =
|
| - compiled_module->GetValue<ByteArray>(isolate, kFunctionNameTable);
|
| - if (!function_name_table.is_null()) {
|
| + if (compiled_module->has_function_names()) {
|
| js_object->SetInternalField(kWasmFunctionNamesArray,
|
| - *function_name_table.ToHandleChecked());
|
| + *compiled_module->function_names());
|
| }
|
| }
|
|
|
| bool SetupGlobals(Isolate* isolate, MaybeHandle<JSObject> template_owner,
|
| - Handle<FixedArray> compiled_module, Handle<JSObject> instance,
|
| - ErrorThrower* thrower) {
|
| - uint32_t globals_size = static_cast<uint32_t>(
|
| - Smi::cast(compiled_module->get(kGlobalsSize))->value());
|
| + Handle<WasmCompiledModule> compiled_module,
|
| + Handle<JSObject> instance, ErrorThrower* thrower) {
|
| + uint32_t globals_size = compiled_module->globals_size();
|
| if (globals_size > 0) {
|
| Handle<JSArrayBuffer> globals_buffer =
|
| NewArrayBuffer(isolate, globals_size);
|
| @@ -953,11 +917,11 @@ bool SetupGlobals(Isolate* isolate, MaybeHandle<JSObject> template_owner,
|
| return true;
|
| }
|
|
|
| -bool SetupInstanceHeap(Isolate* isolate, Handle<FixedArray> compiled_module,
|
| +bool SetupInstanceHeap(Isolate* isolate,
|
| + Handle<WasmCompiledModule> compiled_module,
|
| Handle<JSObject> instance, Handle<JSArrayBuffer> memory,
|
| ErrorThrower* thrower) {
|
| - uint32_t min_mem_pages = static_cast<uint32_t>(
|
| - Smi::cast(compiled_module->get(kMinRequiredMemory))->value());
|
| + uint32_t min_mem_pages = compiled_module->min_required_memory();
|
| isolate->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages);
|
| // TODO(wasm): re-enable counter for max_mem_pages when we use that field.
|
|
|
| @@ -972,21 +936,17 @@ bool SetupInstanceHeap(Isolate* isolate, Handle<FixedArray> compiled_module,
|
| instance->SetInternalField(kWasmMemArrayBuffer, *memory);
|
| Address mem_start = static_cast<Address>(memory->backing_store());
|
| uint32_t mem_size = static_cast<uint32_t>(memory->byte_length()->Number());
|
| - uint32_t old_mem_size = static_cast<uint32_t>(
|
| - compiled_module->GetValueChecked<HeapNumber>(isolate, kMemSize)
|
| - ->value());
|
| - MaybeHandle<JSArrayBuffer> old_mem =
|
| - compiled_module->GetValue<JSArrayBuffer>(isolate, kMemStart);
|
| + uint32_t old_mem_size = compiled_module->mem_size();
|
| Address old_mem_start =
|
| - old_mem.is_null()
|
| - ? nullptr
|
| - : static_cast<Address>(old_mem.ToHandleChecked()->backing_store());
|
| + compiled_module->has_mem_start()
|
| + ? static_cast<Address>(
|
| + compiled_module->mem_start()->backing_store())
|
| + : nullptr;
|
| RelocateInstanceCode(instance, old_mem_start, mem_start, old_mem_size,
|
| mem_size);
|
| LoadDataSegments(compiled_module, mem_start, mem_size);
|
| - compiled_module->GetValueChecked<HeapNumber>(isolate, kMemSize)
|
| - ->set_value(static_cast<double>(mem_size));
|
| - compiled_module->set(kMemStart, *memory);
|
| + compiled_module->set_mem_size(mem_size);
|
| + compiled_module->set_mem_start(memory);
|
| }
|
| return true;
|
| }
|
| @@ -1038,19 +998,17 @@ void FixupFunctionsAndImports(Handle<FixedArray> old_functions,
|
| }
|
| }
|
|
|
| -bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module,
|
| +bool SetupImports(Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
|
| Handle<JSObject> instance, ErrorThrower* thrower,
|
| Handle<JSReceiver> ffi) {
|
| //-------------------------------------------------------------------------
|
| // Compile wrappers to imported functions.
|
| //-------------------------------------------------------------------------
|
| std::vector<Handle<Code>> import_code;
|
| - MaybeHandle<FixedArray> maybe_import_data =
|
| - compiled_module->GetValue<FixedArray>(isolate, kImportData);
|
| - Handle<FixedArray> import_data;
|
| - if (maybe_import_data.ToHandle(&import_data)) {
|
| + if (compiled_module->has_import_data()) {
|
| if (!CompileWrappersToImportedFunctions(isolate, ffi, import_code,
|
| - import_data, thrower)) {
|
| + compiled_module->import_data(),
|
| + thrower)) {
|
| return false;
|
| }
|
| }
|
| @@ -1063,21 +1021,18 @@ bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module,
|
| for (int i = 0; i < new_imports->length(); ++i) {
|
| new_imports->set(i, *import_code[i]);
|
| }
|
| - compiled_module->set(kImportMap, *new_imports);
|
| + compiled_module->set_import_map(new_imports);
|
| return true;
|
| }
|
|
|
| -bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate,
|
| - Handle<JSObject> instance, ErrorThrower* thrower) {
|
| +bool SetupExportsObject(Handle<WasmCompiledModule> compiled_module,
|
| + Isolate* isolate, Handle<JSObject> instance,
|
| + ErrorThrower* thrower) {
|
| Factory* factory = isolate->factory();
|
| - bool mem_export =
|
| - static_cast<bool>(Smi::cast(compiled_module->get(kExportMem))->value());
|
| - ModuleOrigin origin = static_cast<ModuleOrigin>(
|
| - Smi::cast(compiled_module->get(kOrigin))->value());
|
| -
|
| - MaybeHandle<FixedArray> maybe_exports =
|
| - compiled_module->GetValue<FixedArray>(isolate, kExports);
|
| - if (!maybe_exports.is_null() || mem_export) {
|
| + bool mem_export = compiled_module->export_memory();
|
| + ModuleOrigin origin = compiled_module->origin();
|
| +
|
| + if (compiled_module->has_exports() || mem_export) {
|
| PropertyDescriptor desc;
|
| desc.set_writable(false);
|
|
|
| @@ -1090,8 +1045,8 @@ bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate,
|
| Handle<String> exports_name = factory->InternalizeUtf8String("exports");
|
| JSObject::AddProperty(instance, exports_name, exports_object, READ_ONLY);
|
| }
|
| - Handle<FixedArray> exports;
|
| - if (maybe_exports.ToHandle(&exports)) {
|
| + if (compiled_module->has_exports()) {
|
| + Handle<FixedArray> exports = compiled_module->exports();
|
| int exports_size = exports->length();
|
| for (int i = 0; i < exports_size; ++i) {
|
| if (thrower->error()) return false;
|
| @@ -1128,30 +1083,11 @@ bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate,
|
| return true;
|
| }
|
|
|
| -#define GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(Field) \
|
| - WeakCell* Get##Field(const FixedArray* compiled_module) { \
|
| - Object* obj = compiled_module->get(k##Field); \
|
| - DCHECK_NOT_NULL(obj); \
|
| - if (obj->IsWeakCell()) { \
|
| - return WeakCell::cast(obj); \
|
| - } else { \
|
| - return nullptr; \
|
| - } \
|
| - }
|
| -
|
| -GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(NextInstance)
|
| -GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(PrevInstance)
|
| -GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(OwningInstance)
|
| -GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(ModuleObject)
|
| -
|
| static void ResetCompiledModule(Isolate* isolate, JSObject* owner,
|
| - FixedArray* compiled_module) {
|
| + WasmCompiledModule* compiled_module) {
|
| Object* undefined = *isolate->factory()->undefined_value();
|
| - Object* mem_size_obj = compiled_module->get(kMemSize);
|
| - DCHECK(mem_size_obj->IsMutableHeapNumber());
|
| - uint32_t old_mem_size =
|
| - static_cast<uint32_t>(HeapNumber::cast(mem_size_obj)->value());
|
| - Object* mem_start = compiled_module->get(kMemStart);
|
| + uint32_t old_mem_size = compiled_module->mem_size();
|
| + Object* mem_start = compiled_module->ptr_to_mem_start();
|
| Address old_mem_address = nullptr;
|
| Address globals_start =
|
| GetGlobalStartAddressFromCodeTemplate(undefined, owner);
|
| @@ -1165,7 +1101,7 @@ static void ResetCompiledModule(Isolate* isolate, JSObject* owner,
|
| RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE) |
|
| RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_REFERENCE);
|
|
|
| - Object* fct_obj = compiled_module->get(kFunctions);
|
| + Object* fct_obj = compiled_module->ptr_to_functions();
|
| if (fct_obj != nullptr && fct_obj != undefined &&
|
| (old_mem_size > 0 || globals_start != nullptr)) {
|
| FixedArray* functions = FixedArray::cast(fct_obj);
|
| @@ -1191,29 +1127,29 @@ static void ResetCompiledModule(Isolate* isolate, JSObject* owner,
|
| }
|
| }
|
| }
|
| - compiled_module->set(kOwningInstance, undefined);
|
| - compiled_module->set(kMemStart, undefined);
|
| + compiled_module->reset_weak_owning_instance(isolate);
|
| + compiled_module->reset_mem_start(isolate);
|
| }
|
|
|
| static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
|
| JSObject** p = reinterpret_cast<JSObject**>(data.GetParameter());
|
| JSObject* owner = *p;
|
| - FixedArray* compiled_module =
|
| - FixedArray::cast(owner->GetInternalField(kWasmCompiledModule));
|
| + WasmCompiledModule* compiled_module =
|
| + WasmCompiledModule::cast(owner->GetInternalField(kWasmCompiledModule));
|
| Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
|
| Object* undefined = *isolate->factory()->undefined_value();
|
| - WeakCell* weak_module_obj = GetModuleObject(compiled_module);
|
| - DCHECK_NOT_NULL(weak_module_obj);
|
| + DCHECK(compiled_module->has_weak_module_object());
|
| + WeakCell* weak_module_obj = compiled_module->ptr_to_weak_module_object();
|
| // weak_module_obj may have been cleared, meaning the module object
|
| // was GC-ed. In that case, there won't be any new instances created,
|
| // and we don't need to maintain the links between instances.
|
| if (!weak_module_obj->cleared()) {
|
| JSObject* module_obj = JSObject::cast(weak_module_obj->value());
|
| - FixedArray* current_template =
|
| - FixedArray::cast(module_obj->GetInternalField(0));
|
| - DCHECK_NULL(GetPrevInstance(current_template));
|
| - WeakCell* next = GetNextInstance(compiled_module);
|
| - WeakCell* prev = GetPrevInstance(compiled_module);
|
| + WasmCompiledModule* current_template =
|
| + WasmCompiledModule::cast(module_obj->GetInternalField(0));
|
| + DCHECK(!current_template->has_weak_prev_instance());
|
| + WeakCell* next = compiled_module->ptr_to_weak_next_instance();
|
| + WeakCell* prev = compiled_module->ptr_to_weak_prev_instance();
|
|
|
| if (current_template == compiled_module) {
|
| if (next == nullptr) {
|
| @@ -1222,7 +1158,8 @@ static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
|
| DCHECK(next->value()->IsFixedArray());
|
| module_obj->SetInternalField(0, next->value());
|
| DCHECK_NULL(prev);
|
| - FixedArray::cast(next->value())->set(kPrevInstance, undefined);
|
| + WasmCompiledModule::cast(next->value())
|
| + ->reset_weak_prev_instance(isolate);
|
| }
|
| } else {
|
| DCHECK(!(prev == nullptr && next == nullptr));
|
| @@ -1231,13 +1168,23 @@ static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
|
| // we would have relinked the list.
|
| if (prev != nullptr) {
|
| DCHECK(!prev->cleared());
|
| - FixedArray::cast(prev->value())
|
| - ->set(kNextInstance, next == nullptr ? undefined : next);
|
| + if (next == nullptr) {
|
| + WasmCompiledModule::cast(prev->value())
|
| + ->reset_weak_next_instance(isolate);
|
| + } else {
|
| + WasmCompiledModule::cast(prev->value())
|
| + ->set_ptr_to_weak_next_instance(next);
|
| + }
|
| }
|
| if (next != nullptr) {
|
| DCHECK(!next->cleared());
|
| - FixedArray::cast(next->value())
|
| - ->set(kPrevInstance, prev == nullptr ? undefined : prev);
|
| + if (prev == nullptr) {
|
| + WasmCompiledModule::cast(next->value())
|
| + ->reset_weak_prev_instance(isolate);
|
| + } else {
|
| + WasmCompiledModule::cast(next->value())
|
| + ->set_ptr_to_weak_prev_instance(prev);
|
| + }
|
| }
|
| }
|
| }
|
| @@ -1246,11 +1193,11 @@ static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
|
|
|
| } // namespace
|
|
|
| -MaybeHandle<FixedArray> WasmModule::CompileFunctions(
|
| +MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions(
|
| Isolate* isolate, ErrorThrower* thrower) const {
|
| Factory* factory = isolate->factory();
|
|
|
| - MaybeHandle<FixedArray> nothing;
|
| + MaybeHandle<WasmCompiledModule> nothing;
|
|
|
| WasmModuleInstance temp_instance_for_compilation(this);
|
| temp_instance_for_compilation.context = isolate->native_context();
|
| @@ -1328,17 +1275,17 @@ MaybeHandle<FixedArray> WasmModule::CompileFunctions(
|
| // and information needed at instantiation time. This object needs to be
|
| // serializable. Instantiation may occur off a deserialized version of this
|
| // object.
|
| - Handle<FixedArray> ret =
|
| - factory->NewFixedArray(kCompiledWasmObjectTableSize, TENURED);
|
| - ret->set(kFunctions, *compiled_functions);
|
| + Handle<WasmCompiledModule> ret = WasmCompiledModule::New(isolate);
|
| +
|
| + ret->set_functions(compiled_functions);
|
| if (!indirect_table.is_null()) {
|
| - ret->set(kTableOfIndirectFunctionTables, *indirect_table.ToHandleChecked());
|
| + ret->set_indirect_function_tables(indirect_table.ToHandleChecked());
|
| }
|
| if (!maybe_imports.is_null()) {
|
| - ret->set(kImportMap, *maybe_imports.ToHandleChecked());
|
| + ret->set_import_map(maybe_imports.ToHandleChecked());
|
| }
|
| Handle<FixedArray> import_data = GetImportsMetadata(factory, this);
|
| - ret->set(kImportData, *import_data);
|
| + ret->set_import_data(import_data);
|
|
|
| // Compile export functions.
|
| int export_size = static_cast<int>(export_table.size());
|
| @@ -1377,7 +1324,7 @@ MaybeHandle<FixedArray> WasmModule::CompileFunctions(
|
| startup_fct = export_code;
|
| }
|
| }
|
| - ret->set(kExports, *exports);
|
| + ret->set_exports(exports);
|
| }
|
|
|
| // Compile startup function, if we haven't already.
|
| @@ -1395,7 +1342,7 @@ MaybeHandle<FixedArray> WasmModule::CompileFunctions(
|
| metadata->set(kExportCode, *startup_fct);
|
| metadata->set(kExportArity, Smi::FromInt(0));
|
| metadata->set(kExportedFunctionIndex, Smi::FromInt(start_function_index));
|
| - ret->set(kStartupFunction, *metadata);
|
| + ret->set_startup_function(metadata);
|
| }
|
|
|
| // TODO(wasm): saving the module bytes for debugging is wasteful. We should
|
| @@ -1408,21 +1355,18 @@ MaybeHandle<FixedArray> WasmModule::CompileFunctions(
|
| Handle<String> module_bytes_string =
|
| factory->NewStringFromOneByte(module_bytes_vec, TENURED)
|
| .ToHandleChecked();
|
| - ret->set(kModuleBytes, *module_bytes_string);
|
| + ret->set_module_bytes(module_bytes_string);
|
| }
|
|
|
| Handle<ByteArray> function_name_table =
|
| BuildFunctionNamesTable(isolate, module_env.module);
|
| - ret->set(kFunctionNameTable, *function_name_table);
|
| - ret->set(kMinRequiredMemory, Smi::FromInt(min_mem_pages));
|
| + ret->set_function_names(function_name_table);
|
| + ret->set_min_required_memory(min_mem_pages);
|
| if (data_segments.size() > 0) SaveDataSegmentInfo(factory, this, ret);
|
| - ret->set(kGlobalsSize, Smi::FromInt(globals_size));
|
| - ret->set(kExportMem, Smi::FromInt(mem_export));
|
| - ret->set(kOrigin, Smi::FromInt(origin));
|
| - Handle<HeapNumber> size_as_object = factory->NewHeapNumber(
|
| - static_cast<double>(temp_instance_for_compilation.mem_size), MUTABLE,
|
| - TENURED);
|
| - ret->set(kMemSize, *size_as_object);
|
| + ret->set_globals_size(globals_size);
|
| + ret->set_export_memory(mem_export);
|
| + ret->set_origin(origin);
|
| + ret->set_mem_size(temp_instance_for_compilation.mem_size);
|
| return ret;
|
| }
|
|
|
| @@ -1475,16 +1419,16 @@ Handle<FixedArray> SetupIndirectFunctionTable(
|
| return cloned_indirect_tables;
|
| }
|
|
|
| -Handle<FixedArray> CloneModuleForInstance(Isolate* isolate,
|
| - Handle<JSObject> module_object,
|
| - bool* template_is_owned,
|
| - Handle<FixedArray>* module_template) {
|
| +Handle<WasmCompiledModule> CloneModuleForInstance(
|
| + Isolate* isolate, Handle<JSObject> module_object, bool* template_is_owned,
|
| + Handle<WasmCompiledModule>* module_template) {
|
| Factory* factory = isolate->factory();
|
|
|
| - Handle<FixedArray> original;
|
| + Handle<WasmCompiledModule> original;
|
| for (int i = 0; i < 2; ++i) {
|
| - original = handle(FixedArray::cast(module_object->GetInternalField(0)));
|
| - if (GetOwningInstance(*original) == nullptr) {
|
| + original =
|
| + handle(WasmCompiledModule::cast(module_object->GetInternalField(0)));
|
| + if (!original->has_weak_owning_instance()) {
|
| *template_is_owned = false;
|
| *module_template = original;
|
| return original;
|
| @@ -1498,23 +1442,22 @@ Handle<FixedArray> CloneModuleForInstance(Isolate* isolate,
|
| *module_template = original;
|
|
|
| // We insert the latest clone in front.
|
| - Handle<FixedArray> clone = factory->CopyFixedArray(original);
|
| - Handle<WeakCell> weak_link_to_wasm_obj =
|
| - original->GetValueChecked<WeakCell>(isolate, kModuleObject);
|
| + Handle<WasmCompiledModule> clone =
|
| + Handle<WasmCompiledModule>::cast(factory->CopyFixedArray(original));
|
| + Handle<WeakCell> weak_link_to_wasm_obj = original->weak_module_object();
|
|
|
| - clone->set(kModuleObject, *weak_link_to_wasm_obj);
|
| + clone->set_weak_module_object(weak_link_to_wasm_obj);
|
| Handle<WeakCell> link_to_original = factory->NewWeakCell(original);
|
| - clone->set(kNextInstance, *link_to_original);
|
| + clone->set_weak_next_instance(link_to_original);
|
| Handle<WeakCell> link_to_clone = factory->NewWeakCell(clone);
|
| - original->set(kPrevInstance, *link_to_clone);
|
| + original->set_weak_prev_instance(link_to_clone);
|
| JSObject::cast(weak_link_to_wasm_obj->value())->SetInternalField(0, *clone);
|
|
|
| // Clone each wasm code object.
|
| - Handle<FixedArray> orig_wasm_functions =
|
| - original->GetValueChecked<FixedArray>(isolate, kFunctions);
|
| + Handle<FixedArray> orig_wasm_functions = original->functions();
|
| Handle<FixedArray> clone_wasm_functions =
|
| factory->CopyFixedArray(orig_wasm_functions);
|
| - clone->set(kFunctions, *clone_wasm_functions);
|
| + clone->set_functions(clone_wasm_functions);
|
| for (int i = 0; i < clone_wasm_functions->length(); ++i) {
|
| Handle<Code> orig_code =
|
| clone_wasm_functions->GetValueChecked<Code>(isolate, i);
|
| @@ -1522,12 +1465,10 @@ Handle<FixedArray> CloneModuleForInstance(Isolate* isolate,
|
| clone_wasm_functions->set(i, *cloned_code);
|
| }
|
|
|
| - MaybeHandle<FixedArray> maybe_orig_exports =
|
| - original->GetValue<FixedArray>(isolate, kExports);
|
| - Handle<FixedArray> orig_exports;
|
| - if (maybe_orig_exports.ToHandle(&orig_exports)) {
|
| + if (original->has_exports()) {
|
| + Handle<FixedArray> orig_exports = original->exports();
|
| Handle<FixedArray> cloned_exports = factory->CopyFixedArray(orig_exports);
|
| - clone->set(kExports, *cloned_exports);
|
| + clone->set_exports(cloned_exports);
|
| for (int i = 0; i < orig_exports->length(); ++i) {
|
| Handle<FixedArray> export_metadata =
|
| orig_exports->GetValueChecked<FixedArray>(isolate, i);
|
| @@ -1550,15 +1491,13 @@ Handle<FixedArray> CloneModuleForInstance(Isolate* isolate,
|
| }
|
| }
|
|
|
| - MaybeHandle<FixedArray> maybe_startup =
|
| - original->GetValue<FixedArray>(isolate, kStartupFunction);
|
| - if (!maybe_startup.is_null()) {
|
| + if (original->has_startup_function()) {
|
| Handle<FixedArray> startup_metadata =
|
| - factory->CopyFixedArray(maybe_startup.ToHandleChecked());
|
| + factory->CopyFixedArray(original->startup_function());
|
| Handle<Code> startup_fct_clone = factory->CopyCode(
|
| startup_metadata->GetValueChecked<Code>(isolate, kExportCode));
|
| startup_metadata->set(kExportCode, *startup_fct_clone);
|
| - clone->set(kStartupFunction, *startup_metadata);
|
| + clone->set_startup_function(startup_metadata);
|
| // TODO(wasm): see todo above about int vs size_t indexing in FixedArray.
|
| int startup_fct_index =
|
| Smi::cast(startup_metadata->get(kExportedFunctionIndex))->value();
|
| @@ -1568,7 +1507,7 @@ Handle<FixedArray> CloneModuleForInstance(Isolate* isolate,
|
| clone_wasm_functions->GetValueChecked<Code>(isolate, startup_fct_index);
|
| PatchJSWrapper(isolate, startup_fct_clone, new_target);
|
| }
|
| - clone->set(kImportMap, *isolate->factory()->undefined_value());
|
| + clone->reset_import_map(isolate);
|
| return clone;
|
| }
|
|
|
| @@ -1587,21 +1526,16 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
|
| Factory* factory = isolate->factory();
|
|
|
| bool template_is_owned = false;
|
| - Handle<FixedArray> compiled_module_template;
|
| - Handle<FixedArray> compiled_module = CloneModuleForInstance(
|
| + Handle<WasmCompiledModule> compiled_module_template;
|
| + Handle<WasmCompiledModule> compiled_module = CloneModuleForInstance(
|
| isolate, module_object, &template_is_owned, &compiled_module_template);
|
|
|
| MaybeHandle<JSObject> template_owner;
|
| if (template_is_owned) {
|
| - Handle<WeakCell> weak_owner =
|
| - compiled_module_template->GetValueChecked<WeakCell>(isolate,
|
| - kOwningInstance);
|
| - template_owner = handle(JSObject::cast(weak_owner->value()));
|
| + template_owner = compiled_module_template->owning_instance();
|
| }
|
| // These fields are compulsory.
|
| - Handle<FixedArray> code_table =
|
| - compiled_module->GetValueChecked<FixedArray>(isolate, kFunctions);
|
| -
|
| + Handle<FixedArray> code_table = compiled_module->functions();
|
| RecordStats(isolate, code_table);
|
|
|
| MaybeHandle<JSObject> nothing;
|
| @@ -1615,7 +1549,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
|
| // Remember the old imports, for the case when we are at the first instance -
|
| // they will be replaced with the instance's actual imports in SetupImports.
|
| MaybeHandle<FixedArray> old_imports =
|
| - compiled_module_template->GetValue<FixedArray>(isolate, kImportMap);
|
| + compiled_module_template->maybe_import_map();
|
| if (!(SetupInstanceHeap(isolate, compiled_module, js_object, memory,
|
| &thrower) &&
|
| SetupGlobals(isolate, template_owner, compiled_module, js_object,
|
| @@ -1625,11 +1559,8 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
|
| return nothing;
|
| }
|
|
|
| - FixupFunctionsAndImports(
|
| - compiled_module_template->GetValueChecked<FixedArray>(isolate,
|
| - kFunctions),
|
| - code_table, old_imports,
|
| - compiled_module->GetValue<FixedArray>(isolate, kImportMap));
|
| + FixupFunctionsAndImports(compiled_module_template->functions(), code_table,
|
| + old_imports, compiled_module->maybe_import_map());
|
|
|
| SetDebugSupport(factory, compiled_module, js_object);
|
| SetRuntimeSupport(isolate, js_object);
|
| @@ -1644,11 +1575,9 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
|
| code_table->GetValueChecked<Code>(isolate, i);
|
| }
|
|
|
| - MaybeHandle<FixedArray> maybe_indirect_tables =
|
| - compiled_module->GetValue<FixedArray>(isolate,
|
| - kTableOfIndirectFunctionTables);
|
| - Handle<FixedArray> indirect_tables_template;
|
| - if (maybe_indirect_tables.ToHandle(&indirect_tables_template)) {
|
| + if (compiled_module->has_indirect_function_tables()) {
|
| + Handle<FixedArray> indirect_tables_template =
|
| + compiled_module->indirect_function_tables();
|
| Handle<FixedArray> to_replace =
|
| template_owner.is_null()
|
| ? indirect_tables_template
|
| @@ -1670,10 +1599,8 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
|
| }
|
|
|
| // Run the start function if one was specified.
|
| - MaybeHandle<FixedArray> maybe_startup_fct =
|
| - compiled_module->GetValue<FixedArray>(isolate, kStartupFunction);
|
| - Handle<FixedArray> metadata;
|
| - if (maybe_startup_fct.ToHandle(&metadata)) {
|
| + if (compiled_module->has_startup_function()) {
|
| + Handle<FixedArray> metadata = compiled_module->startup_function();
|
| HandleScope scope(isolate);
|
| Handle<Code> startup_code =
|
| metadata->GetValueChecked<Code>(isolate, kExportCode);
|
| @@ -1697,10 +1624,10 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
|
|
|
| DCHECK(wasm::IsWasmObject(*js_object));
|
|
|
| - if (!compiled_module->GetValue<WeakCell>(isolate, kModuleObject).is_null()) {
|
| + if (compiled_module->has_weak_module_object()) {
|
| js_object->SetInternalField(kWasmCompiledModule, *compiled_module);
|
| Handle<WeakCell> link_to_owner = factory->NewWeakCell(js_object);
|
| - compiled_module->set(kOwningInstance, *link_to_owner);
|
| + compiled_module->set_weak_owning_instance(link_to_owner);
|
|
|
| Handle<Object> global_handle =
|
| isolate->global_handles()->Create(*js_object);
|
| @@ -1897,7 +1824,8 @@ Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate,
|
| Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check();
|
| }
|
| Handle<WeakCell> link_to_module = isolate->factory()->NewWeakCell(module_obj);
|
| - compiled_module->set(kModuleObject, *link_to_module);
|
| + WasmCompiledModule::cast(*compiled_module)
|
| + ->set_weak_module_object(link_to_module);
|
| return module_obj;
|
| }
|
|
|
| @@ -1937,8 +1865,8 @@ void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer) {
|
| instance->SetInternalField(kWasmMemArrayBuffer, buffer);
|
| Object* module = instance->GetInternalField(kWasmCompiledModule);
|
| if (module->IsFixedArray()) {
|
| - HeapNumber::cast(FixedArray::cast(module)->get(kMemSize))
|
| - ->set_value(buffer->byte_length()->Number());
|
| + WasmCompiledModule::cast(module)->set_mem_size(
|
| + buffer->byte_length()->Number());
|
| }
|
| }
|
|
|
| @@ -1948,21 +1876,24 @@ void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj,
|
| int instance_count) {
|
| CHECK_GE(instance_count, 0);
|
| DisallowHeapAllocation no_gc;
|
| - FixedArray* compiled_module =
|
| - FixedArray::cast(module_obj->GetInternalField(0));
|
| - CHECK_EQ(JSObject::cast(GetModuleObject(compiled_module)->value()),
|
| - *module_obj);
|
| + WasmCompiledModule* compiled_module =
|
| + WasmCompiledModule::cast(module_obj->GetInternalField(0));
|
| + CHECK_EQ(
|
| + JSObject::cast(compiled_module->ptr_to_weak_module_object()->value()),
|
| + *module_obj);
|
| Object* prev = nullptr;
|
| - int found_instances = GetOwningInstance(compiled_module) == nullptr ? 0 : 1;
|
| - FixedArray* current_instance = compiled_module;
|
| - while (GetNextInstance(current_instance) != nullptr) {
|
| - CHECK((prev == nullptr && GetPrevInstance(current_instance) == nullptr) ||
|
| - GetPrevInstance(current_instance)->value() == prev);
|
| - CHECK_EQ(GetModuleObject(current_instance)->value(), *module_obj);
|
| - CHECK(IsWasmObject(GetOwningInstance(current_instance)->value()));
|
| + int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0;
|
| + WasmCompiledModule* current_instance = compiled_module;
|
| + while (current_instance->has_weak_next_instance()) {
|
| + CHECK((prev == nullptr && !current_instance->has_weak_prev_instance()) ||
|
| + current_instance->ptr_to_weak_prev_instance()->value() == prev);
|
| + CHECK_EQ(current_instance->ptr_to_weak_module_object()->value(),
|
| + *module_obj);
|
| + CHECK(
|
| + IsWasmObject(current_instance->ptr_to_weak_owning_instance()->value()));
|
| prev = current_instance;
|
| - current_instance =
|
| - FixedArray::cast(GetNextInstance(current_instance)->value());
|
| + current_instance = WasmCompiledModule::cast(
|
| + current_instance->ptr_to_weak_next_instance()->value());
|
| ++found_instances;
|
| CHECK_LE(found_instances, instance_count);
|
| }
|
| @@ -1971,22 +1902,22 @@ void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj,
|
|
|
| void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj) {
|
| DisallowHeapAllocation no_gc;
|
| - FixedArray* compiled_module =
|
| - FixedArray::cast(module_obj->GetInternalField(0));
|
| - CHECK_NOT_NULL(GetModuleObject(compiled_module));
|
| - CHECK_EQ(GetModuleObject(compiled_module)->value(), *module_obj);
|
| - CHECK_NULL(GetPrevInstance(compiled_module));
|
| - CHECK_NULL(GetNextInstance(compiled_module));
|
| - CHECK_NULL(GetOwningInstance(compiled_module));
|
| + WasmCompiledModule* compiled_module =
|
| + WasmCompiledModule::cast(module_obj->GetInternalField(0));
|
| + CHECK(compiled_module->has_weak_module_object());
|
| + CHECK_EQ(compiled_module->ptr_to_weak_module_object()->value(), *module_obj);
|
| + CHECK(!compiled_module->has_weak_prev_instance());
|
| + CHECK(!compiled_module->has_weak_next_instance());
|
| + CHECK(!compiled_module->has_weak_owning_instance());
|
| }
|
|
|
| void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance) {
|
| DisallowHeapAllocation no_gc;
|
| CHECK(IsWasmObject(*instance));
|
| - FixedArray* compiled_module =
|
| - FixedArray::cast(instance->GetInternalField(kWasmCompiledModule));
|
| - CHECK_NOT_NULL(GetModuleObject(compiled_module));
|
| - CHECK(GetModuleObject(compiled_module)->cleared());
|
| + WasmCompiledModule* compiled_module =
|
| + WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule));
|
| + CHECK(compiled_module->has_weak_module_object());
|
| + CHECK(compiled_module->ptr_to_weak_module_object()->cleared());
|
| }
|
|
|
| } // namespace testing
|
|
|