Commit 407fd479 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Reduce number of WasmCompilationUnit constructors

Instead of four different constructors, we actually just need one. You
either pass a Counters*, or we will get it from the isolate (which is
only allowed to happen on the main thread).
This change makes refactoring this data structure for the baseline
compiler much easier.

R=mtrofin@chromium.org
CC=kschimpf@chromium.org

Bug: v8:6600
Change-Id: I56fb47005861dd4a203373776901930a02e09deb
Reviewed-on: https://chromium-review.googlesource.com/657979Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47964}
parent 745ae2d8
...@@ -4232,50 +4232,16 @@ Vector<const char> GetDebugName(Zone* zone, wasm::WasmName name, int index) { ...@@ -4232,50 +4232,16 @@ Vector<const char> GetDebugName(Zone* zone, wasm::WasmName name, int index) {
} }
} // namespace } // namespace
WasmCompilationUnit::WasmCompilationUnit(
Isolate* isolate, const wasm::ModuleWireBytes& wire_bytes, ModuleEnv* env,
const wasm::WasmFunction* function, Handle<Code> centry_stub)
: WasmCompilationUnit(
isolate, env,
wasm::FunctionBody{function->sig, function->code.offset(),
wire_bytes.start() + function->code.offset(),
wire_bytes.start() + function->code.end_offset()},
wire_bytes.GetNameOrNull(function), function->func_index,
centry_stub) {}
WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, ModuleEnv* env, WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, ModuleEnv* env,
wasm::FunctionBody body, wasm::FunctionBody body,
wasm::WasmName name, int index, wasm::WasmName name, int index,
Handle<Code> centry_stub) Handle<Code> centry_stub,
: isolate_(isolate), Counters* counters)
env_(env),
func_body_(body),
func_name_(name),
counters_(isolate->counters()),
centry_stub_(centry_stub),
func_index_(index) {}
WasmCompilationUnit::WasmCompilationUnit(
Isolate* isolate, const wasm::ModuleWireBytes& wire_bytes, ModuleEnv* env,
const wasm::WasmFunction* function, Handle<Code> centry_stub,
const std::shared_ptr<Counters>& async_counters)
: WasmCompilationUnit(
isolate, env,
wasm::FunctionBody{function->sig, function->code.offset(),
wire_bytes.start() + function->code.offset(),
wire_bytes.start() + function->code.end_offset()},
wire_bytes.GetNameOrNull(function), function->func_index, centry_stub,
async_counters) {}
WasmCompilationUnit::WasmCompilationUnit(
Isolate* isolate, ModuleEnv* env, wasm::FunctionBody body,
wasm::WasmName name, int index, Handle<Code> centry_stub,
const std::shared_ptr<Counters>& async_counters)
: isolate_(isolate), : isolate_(isolate),
env_(env), env_(env),
func_body_(body), func_body_(body),
func_name_(name), func_name_(name),
counters_(async_counters.get()), counters_(counters ? counters : isolate->counters()),
centry_stub_(centry_stub), centry_stub_(centry_stub),
func_index_(index) {} func_index_(index) {}
...@@ -4412,8 +4378,13 @@ MaybeHandle<Code> WasmCompilationUnit::CompileWasmFunction( ...@@ -4412,8 +4378,13 @@ MaybeHandle<Code> WasmCompilationUnit::CompileWasmFunction(
wasm::ErrorThrower* thrower, Isolate* isolate, wasm::ErrorThrower* thrower, Isolate* isolate,
const wasm::ModuleWireBytes& wire_bytes, ModuleEnv* env, const wasm::ModuleWireBytes& wire_bytes, ModuleEnv* env,
const wasm::WasmFunction* function) { const wasm::WasmFunction* function) {
WasmCompilationUnit unit(isolate, wire_bytes, env, function, wasm::FunctionBody function_body{
CEntryStub(isolate, 1).GetCode()); function->sig, function->code.offset(),
wire_bytes.start() + function->code.offset(),
wire_bytes.start() + function->code.end_offset()};
WasmCompilationUnit unit(
isolate, env, function_body, wire_bytes.GetNameOrNull(function),
function->func_index, CEntryStub(isolate, 1).GetCode());
unit.ExecuteCompilation(); unit.ExecuteCompilation();
return unit.FinishCompilation(thrower); return unit.FinishCompilation(thrower);
} }
......
...@@ -80,22 +80,13 @@ struct ModuleEnv { ...@@ -80,22 +80,13 @@ struct ModuleEnv {
class WasmCompilationUnit final { class WasmCompilationUnit final {
public: public:
// Use the following constructors if you know you are running on the // If constructing from a background thread, pass in a Counters*, and ensure
// foreground thread. // that the Counters live at least as long as this compilation unit (which
WasmCompilationUnit(Isolate* isolate, const wasm::ModuleWireBytes& wire_bytes, // typically means to hold a std::shared_ptr<Counters>).
ModuleEnv* env, const wasm::WasmFunction* function, // If no such pointer is passed, Isolate::counters() will be called. This is
Handle<Code> centry_stub); // only allowed to happen on the foreground thread.
WasmCompilationUnit(Isolate* isolate, ModuleEnv* env, wasm::FunctionBody body, WasmCompilationUnit(Isolate*, ModuleEnv*, wasm::FunctionBody, wasm::WasmName,
wasm::WasmName name, int index, Handle<Code> centry_stub); int index, Handle<Code> centry_stub, Counters* = nullptr);
// Use the following constructors if the compilation may run on a background
// thread.
WasmCompilationUnit(Isolate* isolate, const wasm::ModuleWireBytes& wire_bytes,
ModuleEnv* env, const wasm::WasmFunction* function,
Handle<Code> centry_stub,
const std::shared_ptr<Counters>& async_counters);
WasmCompilationUnit(Isolate* isolate, ModuleEnv* env, wasm::FunctionBody body,
wasm::WasmName name, int index, Handle<Code> centry_stub,
const std::shared_ptr<Counters>& async_counters);
int func_index() const { return func_index_; } int func_index() const { return func_index_; }
......
...@@ -57,7 +57,7 @@ class ModuleCompiler { ...@@ -57,7 +57,7 @@ class ModuleCompiler {
wasm::FunctionBody{function->sig, buffer_offset, bytes.begin(), wasm::FunctionBody{function->sig, buffer_offset, bytes.begin(),
bytes.end()}, bytes.end()},
name, function->func_index, compiler_->centry_stub_, name, function->func_index, compiler_->centry_stub_,
compiler_->async_counters())); compiler_->counters()));
} }
void Commit() { void Commit() {
...@@ -105,10 +105,7 @@ class ModuleCompiler { ...@@ -105,10 +105,7 @@ class ModuleCompiler {
base::AtomicNumber<size_t> allocated_memory_{0}; base::AtomicNumber<size_t> allocated_memory_{0};
}; };
const std::shared_ptr<Counters>& async_counters() const { Counters* counters() const { return async_counters_.get(); }
return async_counters_;
}
Counters* counters() const { return async_counters().get(); }
// Run by each compilation task and by the main thread (i.e. in both // Run by each compilation task and by the main thread (i.e. in both
// foreground and background threads). The no_finisher_callback is called // foreground and background threads). The no_finisher_callback is called
......
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