Commit 9ab9fbf1 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Make ModuleCompiler::CompileToModuleObject static

The current usage pattern is always to allocate a {ModuleCompiler}, then
call {CompileToModuleObject}, then deallocate the {ModuleCompiler}.
Hence, the method can be made static and allocate the {ModuleCompiler}
internally.
This also gives back a reason for the existence of
{CompileToModuleObjectInternal}.

R=ahaas@chromium.org

Change-Id: Iac1ba28421ade6728046c0b9a6e9fc249a349491
Reviewed-on: https://chromium-review.googlesource.com/650386Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47834}
parent f9cbfafa
...@@ -323,16 +323,15 @@ void ModuleCompiler::ValidateSequentially(const ModuleWireBytes& wire_bytes, ...@@ -323,16 +323,15 @@ void ModuleCompiler::ValidateSequentially(const ModuleWireBytes& wire_bytes,
} }
} }
// static
MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObject( MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObject(
ErrorThrower* thrower, const ModuleWireBytes& wire_bytes, Isolate* isolate, ErrorThrower* thrower, std::unique_ptr<WasmModule> module,
Handle<Script> asm_js_script, const ModuleWireBytes& wire_bytes, Handle<Script> asm_js_script,
Vector<const byte> asm_js_offset_table_bytes) { Vector<const byte> asm_js_offset_table_bytes) {
Handle<Code> centry_stub = CEntryStub(isolate, 1).GetCode();
TimedHistogramScope wasm_compile_module_time_scope( ModuleCompiler compiler(isolate, std::move(module), centry_stub);
module_->is_wasm() ? counters()->wasm_compile_wasm_module_time() return compiler.CompileToModuleObjectInternal(
: counters()->wasm_compile_asm_module_time()); thrower, wire_bytes, asm_js_script, asm_js_offset_table_bytes);
return CompileToModuleObjectInternal(
isolate_, thrower, wire_bytes, asm_js_script, asm_js_offset_table_bytes);
} }
namespace { namespace {
...@@ -576,10 +575,14 @@ void ReopenHandles(Isolate* isolate, const std::vector<Handle<T>>& vec) { ...@@ -576,10 +575,14 @@ void ReopenHandles(Isolate* isolate, const std::vector<Handle<T>>& vec) {
} // namespace } // namespace
MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal( MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& wire_bytes, ErrorThrower* thrower, const ModuleWireBytes& wire_bytes,
Handle<Script> asm_js_script, Handle<Script> asm_js_script,
Vector<const byte> asm_js_offset_table_bytes) { Vector<const byte> asm_js_offset_table_bytes) {
Factory* factory = isolate->factory(); TimedHistogramScope wasm_compile_module_time_scope(
module_->is_wasm() ? counters()->wasm_compile_wasm_module_time()
: counters()->wasm_compile_asm_module_time());
Factory* factory = isolate_->factory();
// Check whether lazy compilation is enabled for this module. // Check whether lazy compilation is enabled for this module.
bool lazy_compile = compile_lazy(module_.get()); bool lazy_compile = compile_lazy(module_.get());
...@@ -591,7 +594,7 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal( ...@@ -591,7 +594,7 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
: BUILTIN_CODE(isolate_, Illegal); : BUILTIN_CODE(isolate_, Illegal);
GlobalHandleLifetimeManager globals_manager; GlobalHandleLifetimeManager globals_manager;
auto env = CreateDefaultModuleEnv(isolate, module_.get(), init_builtin, auto env = CreateDefaultModuleEnv(isolate_, module_.get(), init_builtin,
&globals_manager); &globals_manager);
// The {code_table} array contains import wrappers and functions (which // The {code_table} array contains import wrappers and functions (which
......
...@@ -155,8 +155,9 @@ class ModuleCompiler { ...@@ -155,8 +155,9 @@ class ModuleCompiler {
compiler::ModuleEnv* module_env, compiler::ModuleEnv* module_env,
ErrorThrower* thrower); ErrorThrower* thrower);
MaybeHandle<WasmModuleObject> CompileToModuleObject( static MaybeHandle<WasmModuleObject> CompileToModuleObject(
ErrorThrower* thrower, const ModuleWireBytes& wire_bytes, Isolate* isolate, ErrorThrower* thrower,
std::unique_ptr<WasmModule> module, const ModuleWireBytes& wire_bytes,
Handle<Script> asm_js_script, Handle<Script> asm_js_script,
Vector<const byte> asm_js_offset_table_bytes); Vector<const byte> asm_js_offset_table_bytes);
...@@ -164,8 +165,8 @@ class ModuleCompiler { ...@@ -164,8 +165,8 @@ class ModuleCompiler {
private: private:
MaybeHandle<WasmModuleObject> CompileToModuleObjectInternal( MaybeHandle<WasmModuleObject> CompileToModuleObjectInternal(
Isolate* isolate, ErrorThrower* thrower, ErrorThrower* thrower, const ModuleWireBytes& wire_bytes,
const ModuleWireBytes& wire_bytes, Handle<Script> asm_js_script, Handle<Script> asm_js_script,
Vector<const byte> asm_js_offset_table_bytes); Vector<const byte> asm_js_offset_table_bytes);
Isolate* isolate_; Isolate* isolate_;
......
...@@ -791,11 +791,10 @@ MaybeHandle<WasmModuleObject> SyncCompileTranslatedAsmJs( ...@@ -791,11 +791,10 @@ MaybeHandle<WasmModuleObject> SyncCompileTranslatedAsmJs(
return {}; return {};
} }
// Transfer ownership to the {WasmModuleWrapper} generated in // Transfer ownership of the WasmModule to the {WasmModuleWrapper} generated
// {CompileToModuleObject}. // in {CompileToModuleObject}.
Handle<Code> centry_stub = CEntryStub(isolate, 1).GetCode(); return ModuleCompiler::CompileToModuleObject(
ModuleCompiler compiler(isolate, std::move(result.val), centry_stub); isolate, thrower, std::move(result.val), bytes, asm_js_script,
return compiler.CompileToModuleObject(thrower, bytes, asm_js_script,
asm_js_offset_table_bytes); asm_js_offset_table_bytes);
} }
...@@ -819,11 +818,10 @@ MaybeHandle<WasmModuleObject> SyncCompile(Isolate* isolate, ...@@ -819,11 +818,10 @@ MaybeHandle<WasmModuleObject> SyncCompile(Isolate* isolate,
return {}; return {};
} }
// Transfer ownership to the {WasmModuleWrapper} generated in // Transfer ownership of the WasmModule to the {WasmModuleWrapper} generated
// {CompileToModuleObject}. // in {CompileToModuleObject}.
Handle<Code> centry_stub = CEntryStub(isolate, 1).GetCode(); return ModuleCompiler::CompileToModuleObject(
ModuleCompiler compiler(isolate, std::move(result.val), centry_stub); isolate, thrower, std::move(result.val), bytes_copy, Handle<Script>(),
return compiler.CompileToModuleObject(thrower, bytes_copy, Handle<Script>(),
Vector<const byte>()); Vector<const byte>());
} }
......
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