Commit b9401e42 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Create managed together with the module object

We currently create a managed object holding a shared reference to the
WasmModule, and pass this to the factory method for the
WasmModuleObject. Instead, we can just create it inside that factory
method, removing code duplication.

R=herhut@chromium.org

Change-Id: I3cea858ba445971dc8dbeb693061ef5684bc02da
Reviewed-on: https://chromium-review.googlesource.com/1102336
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarStephan Herhut <herhut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53763}
parent 16f18697
......@@ -1366,13 +1366,6 @@ MaybeHandle<WasmModuleObject> CompileToModuleObjectInternal(
.ToHandleChecked();
DCHECK(module_bytes->IsSeqOneByteString());
// The {managed_module} will take ownership of the {WasmModule} object,
// and it will be destroyed when the GC reclaims the wrapper object.
size_t module_size = EstimateWasmModuleSize(module.get());
Handle<Managed<WasmModule>> managed_module =
Managed<WasmModule>::FromUniquePtr(isolate, module_size,
std::move(module));
// Create the module object.
// TODO(clemensh): For the same module (same bytes / same hash), we should
// only have one WasmModuleObject. Otherwise, we might only set
......@@ -1395,7 +1388,7 @@ MaybeHandle<WasmModuleObject> CompileToModuleObjectInternal(
Handle<WasmCompiledModule> compiled_module =
NewCompiledModule(isolate, wasm_module, env);
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate, compiled_module, export_wrappers, managed_module,
isolate, compiled_module, export_wrappers, std::move(module),
Handle<SeqOneByteString>::cast(module_bytes), script,
asm_js_offset_table);
compiled_module->GetNativeModule()->SetModuleObject(module_object);
......@@ -2910,20 +2903,13 @@ void AsyncCompileJob::FinishCompile() {
Handle<FixedArray> export_wrappers =
isolate_->factory()->NewFixedArray(export_wrapper_size, TENURED);
// The {managed_module} will take ownership of the {WasmModule} object,
// and it will be destroyed when the GC reclaims the wrapper object.
size_t module_size = EstimateWasmModuleSize(module_.get());
Handle<Managed<WasmModule>> managed_module =
Managed<WasmModule>::FromUniquePtr(isolate_, module_size,
std::move(module_));
// Create the module object.
// TODO(clemensh): For the same module (same bytes / same hash), we should
// only have one {WasmModuleObject}. Otherwise, we might only set
// breakpoints on a (potentially empty) subset of the instances.
// Create the module object.
module_object_ = WasmModuleObject::New(
isolate_, compiled_module_, export_wrappers, managed_module,
isolate_, compiled_module_, export_wrappers, std::move(module_),
Handle<SeqOneByteString>::cast(module_bytes), script,
asm_js_offset_table);
compiled_module_->GetNativeModule()->SetModuleObject(module_object_);
......
......@@ -274,9 +274,16 @@ enum DispatchTableElements : int {
Handle<WasmModuleObject> WasmModuleObject::New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
Handle<FixedArray> export_wrappers,
Handle<Managed<wasm::WasmModule>> managed_module,
std::shared_ptr<wasm::WasmModule> module,
Handle<SeqOneByteString> module_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table) {
// The {managed_module} will take shared ownership of the {WasmModule} object,
// and release it when the GC reclaim the managed.
size_t module_size = EstimateWasmModuleSize(module.get());
Handle<Managed<WasmModule>> managed_module =
Managed<WasmModule>::FromSharedPtr(isolate, module_size,
std::move(module));
Handle<JSFunction> module_cons(
isolate->native_context()->wasm_module_constructor());
auto module_object = Handle<WasmModuleObject>::cast(
......
......@@ -138,7 +138,7 @@ class WasmModuleObject : public JSObject {
static Handle<WasmModuleObject> New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
Handle<FixedArray> export_wrappers,
Handle<Managed<wasm::WasmModule>> managed_module,
std::shared_ptr<wasm::WasmModule> module,
Handle<SeqOneByteString> module_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table);
......
......@@ -581,6 +581,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
i::wasm::kWasmOrigin);
if (!decode_result.ok()) return {};
CHECK_NOT_NULL(decode_result.val);
WasmModule* module = decode_result.val.get();
Handle<String> module_bytes =
isolate->factory()
->NewStringFromOneByte(
......@@ -588,13 +589,6 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
TENURED)
.ToHandleChecked();
DCHECK(module_bytes->IsSeqOneByteString());
// The {managed_module} will take ownership of the {WasmModule} object,
// and it will be destroyed when the GC reclaims it.
WasmModule* module = decode_result.val.get();
size_t module_size = EstimateWasmModuleSize(module);
Handle<Managed<WasmModule>> managed_module =
Managed<WasmModule>::FromUniquePtr(isolate, module_size,
std::move(decode_result.val));
Handle<Script> script = CreateWasmScript(isolate, wire_bytes);
int export_wrappers_size = static_cast<int>(module->num_exported_functions);
Handle<FixedArray> export_wrappers = isolate->factory()->NewFixedArray(
......@@ -618,7 +612,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
if (!deserializer.Read(&reader)) return {};
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate, compiled_module, export_wrappers, managed_module,
isolate, compiled_module, export_wrappers, std::move(decode_result.val),
Handle<SeqOneByteString>::cast(module_bytes), script,
Handle<ByteArray>::null());
native_module->SetModuleObject(module_object);
......
......@@ -210,10 +210,6 @@ const WasmGlobal* TestingModuleBuilder::AddGlobal(ValueType type) {
Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
Handle<SeqOneByteString> empty_string = Handle<SeqOneByteString>::cast(
isolate_->factory()->NewStringFromOneByte({}).ToHandleChecked());
size_t module_size = 0;
auto managed_module =
Managed<WasmModule>::FromSharedPtr(isolate_, module_size, test_module_);
DCHECK_EQ(test_module_ptr_, managed_module->raw());
Handle<Script> script =
isolate_->factory()->NewScript(isolate_->factory()->empty_string());
script->set_type(Script::TYPE_WASM);
......@@ -222,7 +218,7 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate_, test_module_ptr_, env);
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate_, compiled_module, export_wrappers, managed_module, empty_string,
isolate_, compiled_module, export_wrappers, test_module_, empty_string,
script, Handle<ByteArray>::null());
compiled_module->GetNativeModule()->SetModuleObject(module_object);
// This method is called when we initialize TestEnvironment. We don't
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment