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) {
}
} // 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,
wasm::FunctionBody body,
wasm::WasmName name, int index,
Handle<Code> centry_stub)
: isolate_(isolate),
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)
Handle<Code> centry_stub,
Counters* counters)
: isolate_(isolate),
env_(env),
func_body_(body),
func_name_(name),
counters_(async_counters.get()),
counters_(counters ? counters : isolate->counters()),
centry_stub_(centry_stub),
func_index_(index) {}
......@@ -4412,8 +4378,13 @@ MaybeHandle<Code> WasmCompilationUnit::CompileWasmFunction(
wasm::ErrorThrower* thrower, Isolate* isolate,
const wasm::ModuleWireBytes& wire_bytes, ModuleEnv* env,
const wasm::WasmFunction* function) {
WasmCompilationUnit unit(isolate, wire_bytes, env, function,
CEntryStub(isolate, 1).GetCode());
wasm::FunctionBody function_body{
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();
return unit.FinishCompilation(thrower);
}
......
......@@ -80,22 +80,13 @@ struct ModuleEnv {
class WasmCompilationUnit final {
public:
// Use the following constructors if you know you are running on the
// foreground thread.
WasmCompilationUnit(Isolate* isolate, const wasm::ModuleWireBytes& wire_bytes,
ModuleEnv* env, const wasm::WasmFunction* function,
Handle<Code> centry_stub);
WasmCompilationUnit(Isolate* isolate, ModuleEnv* env, wasm::FunctionBody body,
wasm::WasmName name, int index, Handle<Code> centry_stub);
// 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);
// If constructing from a background thread, pass in a Counters*, and ensure
// that the Counters live at least as long as this compilation unit (which
// typically means to hold a std::shared_ptr<Counters>).
// If no such pointer is passed, Isolate::counters() will be called. This is
// only allowed to happen on the foreground thread.
WasmCompilationUnit(Isolate*, ModuleEnv*, wasm::FunctionBody, wasm::WasmName,
int index, Handle<Code> centry_stub, Counters* = nullptr);
int func_index() const { return func_index_; }
......
......@@ -57,7 +57,7 @@ class ModuleCompiler {
wasm::FunctionBody{function->sig, buffer_offset, bytes.begin(),
bytes.end()},
name, function->func_index, compiler_->centry_stub_,
compiler_->async_counters()));
compiler_->counters()));
}
void Commit() {
......@@ -105,10 +105,7 @@ class ModuleCompiler {
base::AtomicNumber<size_t> allocated_memory_{0};
};
const std::shared_ptr<Counters>& async_counters() const {
return async_counters_;
}
Counters* counters() const { return async_counters().get(); }
Counters* counters() const { return async_counters_.get(); }
// Run by each compilation task and by the main thread (i.e. in both
// 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