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

[wasm] Create WasmCompiledModule together with WasmModuleObject

We need to create one {WasmCompiledModule} before creating the
{WasmModuleObject}. This CL refactors the code such that the
{WasmModuleObject} itself creates the {WasmCompiledModule}. This moves
us closer to removing the {WasmCompiledModule}.

R=titzer@chromium.org

Change-Id: I9f85e47f643c39840036f4f1f92df736732c8f74
Reviewed-on: https://chromium-review.googlesource.com/1105762Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53833}
parent 0256c6d0
This diff is collapsed.
......@@ -146,8 +146,8 @@ class AsyncCompileJob {
std::shared_ptr<WasmModule> module_;
std::vector<DeferredHandles*> deferred_handles_;
Handle<WasmCompiledModule> compiled_module_;
Handle<WasmModuleObject> module_object_;
NativeModule* native_module_ = nullptr;
std::unique_ptr<CompileStep> step_;
CancelableTaskManager background_task_manager_;
......
......@@ -272,9 +272,8 @@ enum DispatchTableElements : int {
} // namespace
Handle<WasmModuleObject> WasmModuleObject::New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
Handle<FixedArray> export_wrappers,
std::shared_ptr<wasm::WasmModule> module,
Isolate* isolate, Handle<FixedArray> export_wrappers,
std::shared_ptr<wasm::WasmModule> module, wasm::ModuleEnv& env,
Handle<SeqOneByteString> module_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table) {
// The {managed_module} will take shared ownership of the {WasmModule} object,
......@@ -284,6 +283,12 @@ Handle<WasmModuleObject> WasmModuleObject::New(
Managed<WasmModule>::FromSharedPtr(isolate, module_size,
std::move(module));
// Create the first {WasmCompiledModule} associated with this
// {WasmModuleObject}.
Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate, managed_module->raw(), env);
// Now create the {WasmModuleObject}.
Handle<JSFunction> module_cons(
isolate->native_context()->wasm_module_constructor());
auto module_object = Handle<WasmModuleObject>::cast(
......@@ -303,6 +308,10 @@ Handle<WasmModuleObject> WasmModuleObject::New(
if (!asm_js_offset_table.is_null()) {
module_object->set_asm_js_offset_table(*asm_js_offset_table);
}
// TODO(clemensh): Move the reference to the native module to the module
// object.
compiled_module->GetNativeModule()->SetModuleObject(module_object);
return module_object;
}
......
......@@ -135,12 +135,13 @@ class WasmModuleObject : public JSObject {
WASM_MODULE_OBJECT_FIELDS)
#undef WASM_MODULE_OBJECT_FIELDS
static Handle<WasmModuleObject> New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
Handle<FixedArray> export_wrappers,
std::shared_ptr<wasm::WasmModule> module,
Handle<SeqOneByteString> module_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table);
static Handle<WasmModuleObject> New(Isolate* isolate,
Handle<FixedArray> export_wrappers,
std::shared_ptr<wasm::WasmModule> module,
wasm::ModuleEnv& env,
Handle<SeqOneByteString> module_bytes,
Handle<Script> script,
Handle<ByteArray> asm_js_offset_table);
// Set a breakpoint on the given byte position inside the given module.
// This will affect all live and future instances of the module.
......
......@@ -602,9 +602,14 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler : kNoTrapHandler;
wasm::ModuleEnv env(module, use_trap_handler,
wasm::RuntimeExceptionSupport::kRuntimeExceptionSupport);
Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate, module, env);
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate, export_wrappers, std::move(decode_result.val), env,
Handle<SeqOneByteString>::cast(module_bytes), script,
Handle<ByteArray>::null());
Handle<WasmCompiledModule> compiled_module(module_object->compiled_module(),
isolate);
NativeModule* native_module = compiled_module->GetNativeModule();
if (FLAG_wasm_lazy_compilation) {
native_module->SetLazyBuiltin(BUILTIN_CODE(isolate, WasmCompileLazy));
}
......@@ -613,12 +618,6 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
Reader reader(data + kVersionSize);
if (!deserializer.Read(&reader)) return {};
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate, compiled_module, export_wrappers, std::move(decode_result.val),
Handle<SeqOneByteString>::cast(module_bytes), script,
Handle<ByteArray>::null());
native_module->SetModuleObject(module_object);
// TODO(6792): Wrappers below might be cloned using {Factory::CopyCode}. This
// requires unlocking the code space here. This should eventually be moved
// into the allocator.
......
......@@ -217,12 +217,11 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
script->set_type(Script::TYPE_WASM);
Handle<FixedArray> export_wrappers = isolate_->factory()->NewFixedArray(0);
ModuleEnv env = CreateModuleEnv();
Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate_, test_module_ptr_, env);
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate_, compiled_module, export_wrappers, test_module_, empty_string,
script, Handle<ByteArray>::null());
compiled_module->GetNativeModule()->SetModuleObject(module_object);
Handle<WasmModuleObject> module_object =
WasmModuleObject::New(isolate_, export_wrappers, test_module_, env,
empty_string, script, Handle<ByteArray>::null());
Handle<WasmCompiledModule> compiled_module(module_object->compiled_module(),
isolate_);
// This method is called when we initialize TestEnvironment. We don't
// have a memory yet, so we won't create it here. We'll update the
// interpreter when we get a memory. We do have globals, though.
......
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