Commit 4061f6ee authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Simplify allocation of export wrappers array.

R=clemensh@chromium.org

Change-Id: I4fb79b1b694c89f348dba71dae0ad68e82b614dc
Reviewed-on: https://chromium-review.googlesource.com/1127051
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54267}
parent 70cc29ca
......@@ -919,7 +919,6 @@ MaybeHandle<WasmModuleObject> CompileToModuleObject(
base::Optional<CodeSpaceMemoryModificationScope> modification_scope(
base::in_place_t(), isolate->heap());
Factory* factory = isolate->factory();
// Create heap objects for script, module bytes and asm.js offset table to
// be stored in the module object.
Handle<Script> script;
......@@ -943,14 +942,6 @@ MaybeHandle<WasmModuleObject> CompileToModuleObject(
// only have one WasmModuleObject. Otherwise, we might only set
// breakpoints on a (potentially empty) subset of the instances.
int export_wrappers_size =
static_cast<int>(wasm_module->num_exported_functions);
Handle<FixedArray> export_wrappers =
factory->NewFixedArray(static_cast<int>(export_wrappers_size), TENURED);
Handle<Code> init_builtin = BUILTIN_CODE(isolate, Illegal);
for (int i = 0, e = export_wrappers->length(); i < e; ++i) {
export_wrappers->set(i, *init_builtin);
}
ModuleEnv env = CreateDefaultModuleEnv(wasm_module);
// Create the compiled module object and populate with compiled functions
......@@ -958,8 +949,8 @@ MaybeHandle<WasmModuleObject> CompileToModuleObject(
// serializable. Instantiation may occur off a deserialized version of this
// object.
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate, export_wrappers, std::move(module), env,
std::move(wire_bytes_copy), script, asm_js_offset_table);
isolate, std::move(module), env, std::move(wire_bytes_copy), script,
asm_js_offset_table);
CompileNativeModule(isolate, thrower, module_object, wasm_module, &env);
if (thrower->error()) return {};
......@@ -2457,9 +2448,6 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
const WasmModule* module = job_->module_.get();
ModuleEnv env = CreateDefaultModuleEnv(module);
int export_wrapper_size = static_cast<int>(module->num_exported_functions);
Handle<FixedArray> export_wrappers =
job_->isolate_->factory()->NewFixedArray(export_wrapper_size, TENURED);
// TODO(wasm): Improve efficiency of storing module wire bytes. Only store
// relevant sections, not function bodies
......@@ -2470,7 +2458,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
// breakpoints on a (potentially empty) subset of the instances.
// Create the module object.
job_->module_object_ = WasmModuleObject::New(
job_->isolate_, export_wrappers, job_->module_, env,
job_->isolate_, job_->module_, env,
{std::move(job_->bytes_copy_), job_->wire_bytes_.length()}, script,
asm_js_offset_table);
job_->native_module_ = job_->module_object_->native_module();
......
......@@ -176,10 +176,9 @@ enum DispatchTableElements : int {
// static
Handle<WasmModuleObject> WasmModuleObject::New(
Isolate* isolate, Handle<FixedArray> export_wrappers,
std::shared_ptr<const wasm::WasmModule> shared_module, wasm::ModuleEnv& env,
OwnedVector<const uint8_t> wire_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table) {
Isolate* isolate, std::shared_ptr<const wasm::WasmModule> shared_module,
wasm::ModuleEnv& env, OwnedVector<const uint8_t> wire_bytes,
Handle<Script> script, Handle<ByteArray> asm_js_offset_table) {
DCHECK_EQ(shared_module.get(), env.module);
// Create a new {NativeModule} first.
......@@ -195,7 +194,7 @@ Handle<WasmModuleObject> WasmModuleObject::New(
// Delegate to the shared {WasmModuleObject::New} allocator.
Handle<WasmModuleObject> module_object =
New(isolate, export_wrappers, std::move(native_module), script);
New(isolate, std::move(native_module), script);
if (!asm_js_offset_table.is_null()) {
module_object->set_asm_js_offset_table(*asm_js_offset_table);
}
......@@ -204,8 +203,12 @@ Handle<WasmModuleObject> WasmModuleObject::New(
// static
Handle<WasmModuleObject> WasmModuleObject::New(
Isolate* isolate, Handle<FixedArray> export_wrappers,
std::shared_ptr<wasm::NativeModule> native_module, Handle<Script> script) {
Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
Handle<Script> script) {
int export_wrapper_size =
static_cast<int>(native_module->module()->num_exported_functions);
Handle<FixedArray> export_wrappers =
isolate->factory()->NewFixedArray(export_wrapper_size, TENURED);
Handle<WasmModuleObject> module_object = Handle<WasmModuleObject>::cast(
isolate->factory()->NewJSObject(isolate->wasm_module_constructor()));
module_object->set_export_wrappers(*export_wrappers);
......
......@@ -134,16 +134,15 @@ class WasmModuleObject : public JSObject {
// Creates a new {WasmModuleObject} with a new {NativeModule} underneath.
static Handle<WasmModuleObject> New(
Isolate* isolate, Handle<FixedArray> export_wrappers,
std::shared_ptr<const wasm::WasmModule> module, wasm::ModuleEnv& env,
OwnedVector<const uint8_t> wire_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table);
Isolate* isolate, std::shared_ptr<const wasm::WasmModule> module,
wasm::ModuleEnv& env, OwnedVector<const uint8_t> wire_bytes,
Handle<Script> script, Handle<ByteArray> asm_js_offset_table);
// Creates a new {WasmModuleObject} for an existing {NativeModule} that is
// reference counted and might be shared between multiple Isolates.
static Handle<WasmModuleObject> New(
Isolate* isolate, Handle<FixedArray> export_wrappers,
std::shared_ptr<wasm::NativeModule> native_module, Handle<Script> script);
Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
Handle<Script> script);
// Set a breakpoint on the given byte position inside the given module.
// This will affect all live and future instances of the module.
......
......@@ -541,9 +541,6 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
CHECK_NOT_NULL(decode_result.val);
WasmModule* module = decode_result.val.get();
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(
static_cast<int>(export_wrappers_size), TENURED);
// TODO(eholk): We need to properly preserve the flag whether the trap
// handler was used or not when serializing.
......@@ -555,8 +552,8 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
OwnedVector<uint8_t> wire_bytes_copy = OwnedVector<uint8_t>::Of(wire_bytes);
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate, export_wrappers, std::move(decode_result.val), env,
std::move(wire_bytes_copy), script, Handle<ByteArray>::null());
isolate, std::move(decode_result.val), env, std::move(wire_bytes_copy),
script, Handle<ByteArray>::null());
NativeModule* native_module = module_object->native_module();
if (FLAG_wasm_lazy_compilation) {
......
......@@ -88,12 +88,8 @@ class SharedEngineIsolate {
Handle<WasmInstanceObject> ImportInstance(SharedModule shared_module) {
Vector<const byte> wire_bytes = shared_module->wire_bytes();
Handle<Script> script = CreateWasmScript(isolate(), wire_bytes);
int export_wrappers_size =
static_cast<int>(shared_module->module()->num_exported_functions);
Handle<FixedArray> export_wrappers =
isolate()->factory()->NewFixedArray(export_wrappers_size, TENURED);
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate(), export_wrappers, shared_module, script);
Handle<WasmModuleObject> module_object =
WasmModuleObject::New(isolate(), shared_module, script);
// TODO(6792): Wrappers below might be cloned using {Factory::CopyCode}.
// This requires unlocking the code space here. This should eventually be
......
......@@ -213,11 +213,9 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
Handle<Script> script =
isolate_->factory()->NewScript(isolate_->factory()->empty_string());
script->set_type(Script::TYPE_WASM);
Handle<FixedArray> export_wrappers = isolate_->factory()->NewFixedArray(0);
ModuleEnv env = CreateModuleEnv();
Handle<WasmModuleObject> module_object =
WasmModuleObject::New(isolate_, export_wrappers, test_module_, env, {},
script, Handle<ByteArray>::null());
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate_, test_module_, env, {}, script, Handle<ByteArray>::null());
// 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