Commit 6e0706bc authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Do not store Counters in compilation units

The Counters are not specific to compilation units, they just happen to
be used in WasmCompilationUnit::ExecuteCompilation.
Remove it from the compilation unit and pass it explicitly where needed.
This saves another field on the compilation units.

R=titzer@chromium.org

Bug: v8:8343
Change-Id: Iad4fd8ae23b022c237535503e0e805db7e67071a
Reviewed-on: https://chromium-review.googlesource.com/c/1304297
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57083}
parent fc100f8e
...@@ -5264,7 +5264,8 @@ Vector<const char> GetDebugName(Zone* zone, int index) { ...@@ -5264,7 +5264,8 @@ Vector<const char> GetDebugName(Zone* zone, int index) {
} // namespace } // namespace
void TurbofanWasmCompilationUnit::ExecuteCompilation( void TurbofanWasmCompilationUnit::ExecuteCompilation(
wasm::CompilationEnv* env, wasm::WasmFeatures* detected) { wasm::CompilationEnv* env, Counters* counters,
wasm::WasmFeatures* detected) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteTurbofanCompilation"); "ExecuteTurbofanCompilation");
double decode_ms = 0; double decode_ms = 0;
...@@ -5321,7 +5322,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -5321,7 +5322,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
const_cast<wasm::WasmModule*>(env->module), wasm_unit_->native_module_, const_cast<wasm::WasmModule*>(env->module), wasm_unit_->native_module_,
wasm_unit_->func_index_, env->module->origin)); wasm_unit_->func_index_, env->module->origin));
if (job->ExecuteJob() == CompilationJob::SUCCEEDED) { if (job->ExecuteJob() == CompilationJob::SUCCEEDED) {
wasm_unit_->SetResult(info.wasm_code()); wasm_unit_->SetResult(info.wasm_code(), counters);
} }
if (FLAG_trace_wasm_decode_time) { if (FLAG_trace_wasm_decode_time) {
double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
...@@ -5333,7 +5334,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -5333,7 +5334,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
decode_ms, node_count, pipeline_ms); decode_ms, node_count, pipeline_ms);
} }
// TODO(bradnelson): Improve histogram handling of size_t. // TODO(bradnelson): Improve histogram handling of size_t.
wasm_unit_->counters_->wasm_compile_function_peak_memory_bytes()->AddSample( counters->wasm_compile_function_peak_memory_bytes()->AddSample(
static_cast<int>(mcgraph->graph()->zone()->allocation_size())); static_cast<int>(mcgraph->graph()->zone()->allocation_size()));
} }
......
...@@ -56,7 +56,7 @@ class TurbofanWasmCompilationUnit { ...@@ -56,7 +56,7 @@ class TurbofanWasmCompilationUnit {
MachineGraph* mcgraph, MachineGraph* mcgraph,
NodeOriginTable* node_origins); NodeOriginTable* node_origins);
void ExecuteCompilation(wasm::CompilationEnv* env, void ExecuteCompilation(wasm::CompilationEnv*, Counters*,
wasm::WasmFeatures* detected); wasm::WasmFeatures* detected);
private: private:
......
...@@ -1873,6 +1873,7 @@ class LiftoffCompiler { ...@@ -1873,6 +1873,7 @@ class LiftoffCompiler {
} // namespace } // namespace
bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env, bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env,
Counters* counters,
WasmFeatures* detected) { WasmFeatures* detected) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteLiftoffCompilation"); "ExecuteLiftoffCompilation");
...@@ -1886,7 +1887,7 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env, ...@@ -1886,7 +1887,7 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env,
auto call_descriptor = auto call_descriptor =
compiler::GetWasmCallDescriptor(&zone, wasm_unit_->func_body_.sig); compiler::GetWasmCallDescriptor(&zone, wasm_unit_->func_body_.sig);
base::Optional<TimedHistogramScope> liftoff_compile_time_scope( base::Optional<TimedHistogramScope> liftoff_compile_time_scope(
base::in_place, wasm_unit_->counters_->liftoff_compile_time()); base::in_place, counters->liftoff_compile_time());
WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder( WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder(
&zone, module, wasm_unit_->native_module_->enabled_features(), detected, &zone, module, wasm_unit_->native_module_->enabled_features(), detected,
wasm_unit_->func_body_, call_descriptor, env, &zone); wasm_unit_->func_body_, call_descriptor, env, &zone);
...@@ -1896,11 +1897,11 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env, ...@@ -1896,11 +1897,11 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env,
if (decoder.failed()) return false; // validation error if (decoder.failed()) return false; // validation error
if (!compiler->ok()) { if (!compiler->ok()) {
// Liftoff compilation failed. // Liftoff compilation failed.
wasm_unit_->counters_->liftoff_unsupported_functions()->Increment(); counters->liftoff_unsupported_functions()->Increment();
return false; return false;
} }
wasm_unit_->counters_->liftoff_compiled_functions()->Increment(); counters->liftoff_compiled_functions()->Increment();
if (FLAG_trace_wasm_decode_time) { if (FLAG_trace_wasm_decode_time) {
double compile_ms = compile_timer.Elapsed().InMillisecondsF(); double compile_ms = compile_timer.Elapsed().InMillisecondsF();
...@@ -1924,7 +1925,7 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env, ...@@ -1924,7 +1925,7 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env,
wasm_unit_->func_index_, desc, frame_slot_count, safepoint_table_offset, wasm_unit_->func_index_, desc, frame_slot_count, safepoint_table_offset,
0, std::move(protected_instructions), std::move(source_positions), 0, std::move(protected_instructions), std::move(source_positions),
WasmCode::kLiftoff); WasmCode::kLiftoff);
wasm_unit_->SetResult(code); wasm_unit_->SetResult(code, counters);
return true; return true;
} }
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class Counters;
namespace wasm { namespace wasm {
struct CompilationEnv; struct CompilationEnv;
...@@ -20,7 +23,7 @@ class LiftoffCompilationUnit final { ...@@ -20,7 +23,7 @@ class LiftoffCompilationUnit final {
explicit LiftoffCompilationUnit(WasmCompilationUnit* wasm_unit) explicit LiftoffCompilationUnit(WasmCompilationUnit* wasm_unit)
: wasm_unit_(wasm_unit) {} : wasm_unit_(wasm_unit) {}
bool ExecuteCompilation(CompilationEnv*, WasmFeatures* detected); bool ExecuteCompilation(CompilationEnv*, Counters*, WasmFeatures* detected);
private: private:
WasmCompilationUnit* const wasm_unit_; WasmCompilationUnit* const wasm_unit_;
......
...@@ -38,10 +38,9 @@ ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier() { ...@@ -38,10 +38,9 @@ ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier() {
WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine,
NativeModule* native_module, NativeModule* native_module,
FunctionBody body, int index, FunctionBody body, int index,
Counters* counters, ExecutionTier mode) ExecutionTier mode)
: wasm_engine_(wasm_engine), : wasm_engine_(wasm_engine),
func_body_(body), func_body_(body),
counters_(counters),
func_index_(index), func_index_(index),
native_module_(native_module), native_module_(native_module),
mode_(mode) { mode_(mode) {
...@@ -64,13 +63,14 @@ WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, ...@@ -64,13 +63,14 @@ WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine,
WasmCompilationUnit::~WasmCompilationUnit() = default; WasmCompilationUnit::~WasmCompilationUnit() = default;
void WasmCompilationUnit::ExecuteCompilation(CompilationEnv* env, void WasmCompilationUnit::ExecuteCompilation(CompilationEnv* env,
Counters* counters,
WasmFeatures* detected) { WasmFeatures* detected) {
const WasmModule* module = native_module_->module(); const WasmModule* module = native_module_->module();
auto size_histogram = auto size_histogram =
SELECT_WASM_COUNTER(counters_, module->origin, wasm, function_size_bytes); SELECT_WASM_COUNTER(counters, module->origin, wasm, function_size_bytes);
size_histogram->AddSample( size_histogram->AddSample(
static_cast<int>(func_body_.end - func_body_.start)); static_cast<int>(func_body_.end - func_body_.start));
auto timed_histogram = SELECT_WASM_COUNTER(counters_, module->origin, auto timed_histogram = SELECT_WASM_COUNTER(counters, module->origin,
wasm_compile, function_time); wasm_compile, function_time);
TimedHistogramScope wasm_compile_function_time_scope(timed_histogram); TimedHistogramScope wasm_compile_function_time_scope(timed_histogram);
...@@ -81,12 +81,12 @@ void WasmCompilationUnit::ExecuteCompilation(CompilationEnv* env, ...@@ -81,12 +81,12 @@ void WasmCompilationUnit::ExecuteCompilation(CompilationEnv* env,
switch (mode_) { switch (mode_) {
case ExecutionTier::kBaseline: case ExecutionTier::kBaseline:
if (liftoff_unit_->ExecuteCompilation(env, detected)) break; if (liftoff_unit_->ExecuteCompilation(env, counters, detected)) break;
// Otherwise, fall back to turbofan. // Otherwise, fall back to turbofan.
SwitchMode(ExecutionTier::kOptimized); SwitchMode(ExecutionTier::kOptimized);
V8_FALLTHROUGH; V8_FALLTHROUGH;
case ExecutionTier::kOptimized: case ExecutionTier::kOptimized:
turbofan_unit_->ExecuteCompilation(env, detected); turbofan_unit_->ExecuteCompilation(env, counters, detected);
break; break;
case ExecutionTier::kInterpreter: case ExecutionTier::kInterpreter:
UNREACHABLE(); // TODO(titzer): compile interpreter entry stub. UNREACHABLE(); // TODO(titzer): compile interpreter entry stub.
...@@ -144,9 +144,9 @@ bool WasmCompilationUnit::CompileWasmFunction( ...@@ -144,9 +144,9 @@ bool WasmCompilationUnit::CompileWasmFunction(
wire_bytes.start() + function->code.end_offset()}; wire_bytes.start() + function->code.end_offset()};
WasmCompilationUnit unit(isolate->wasm_engine(), native_module, function_body, WasmCompilationUnit unit(isolate->wasm_engine(), native_module, function_body,
function->func_index, isolate->counters(), mode); function->func_index, mode);
CompilationEnv env = native_module->CreateCompilationEnv(); CompilationEnv env = native_module->CreateCompilationEnv();
unit.ExecuteCompilation(&env, detected); unit.ExecuteCompilation(&env, isolate->counters(), detected);
if (unit.failed()) { if (unit.failed()) {
unit.ReportError(thrower); unit.ReportError(thrower);
return false; return false;
...@@ -154,15 +154,15 @@ bool WasmCompilationUnit::CompileWasmFunction( ...@@ -154,15 +154,15 @@ bool WasmCompilationUnit::CompileWasmFunction(
return true; return true;
} }
void WasmCompilationUnit::SetResult(WasmCode* code) { void WasmCompilationUnit::SetResult(WasmCode* code, Counters* counters) {
DCHECK(!result_.failed()); DCHECK(!result_.failed());
DCHECK_NULL(result_.value()); DCHECK_NULL(result_.value());
result_ = Result<WasmCode*>(code); result_ = Result<WasmCode*>(code);
native_module()->PublishCode(code); native_module()->PublishCode(code);
counters_->wasm_generated_code_size()->Increment( counters->wasm_generated_code_size()->Increment(
static_cast<int>(code->instructions().size())); static_cast<int>(code->instructions().size()));
counters_->wasm_reloc_size()->Increment( counters->wasm_reloc_size()->Increment(
static_cast<int>(code->reloc_info().size())); static_cast<int>(code->reloc_info().size()));
} }
......
...@@ -38,11 +38,11 @@ class WasmCompilationUnit final { ...@@ -38,11 +38,11 @@ class WasmCompilationUnit final {
// If used exclusively from a foreground thread, Isolate::counters() may be // If used exclusively from a foreground thread, Isolate::counters() may be
// used by callers to pass Counters. // used by callers to pass Counters.
WasmCompilationUnit(WasmEngine*, NativeModule*, FunctionBody, int index, WasmCompilationUnit(WasmEngine*, NativeModule*, FunctionBody, int index,
Counters*, ExecutionTier = GetDefaultExecutionTier()); ExecutionTier = GetDefaultExecutionTier());
~WasmCompilationUnit(); ~WasmCompilationUnit();
void ExecuteCompilation(CompilationEnv*, WasmFeatures* detected); void ExecuteCompilation(CompilationEnv*, Counters*, WasmFeatures* detected);
NativeModule* native_module() const { return native_module_; } NativeModule* native_module() const { return native_module_; }
ExecutionTier mode() const { return mode_; } ExecutionTier mode() const { return mode_; }
...@@ -66,7 +66,6 @@ class WasmCompilationUnit final { ...@@ -66,7 +66,6 @@ class WasmCompilationUnit final {
WasmEngine* wasm_engine_; WasmEngine* wasm_engine_;
FunctionBody func_body_; FunctionBody func_body_;
Counters* counters_;
int func_index_; int func_index_;
NativeModule* native_module_; NativeModule* native_module_;
ExecutionTier mode_; ExecutionTier mode_;
...@@ -80,7 +79,7 @@ class WasmCompilationUnit final { ...@@ -80,7 +79,7 @@ class WasmCompilationUnit final {
void SwitchMode(ExecutionTier new_mode); void SwitchMode(ExecutionTier new_mode);
// Called from {ExecuteCompilation} to set the result of compilation. // Called from {ExecuteCompilation} to set the result of compilation.
void SetResult(WasmCode*); void SetResult(WasmCode*, Counters*);
DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit); DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit);
}; };
......
...@@ -381,10 +381,11 @@ WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module, ...@@ -381,10 +381,11 @@ WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module,
module_start + func->code.end_offset()}; module_start + func->code.end_offset()};
WasmCompilationUnit unit(isolate->wasm_engine(), native_module, body, WasmCompilationUnit unit(isolate->wasm_engine(), native_module, body,
func_index, isolate->counters()); func_index);
CompilationEnv env = native_module->CreateCompilationEnv(); CompilationEnv env = native_module->CreateCompilationEnv();
unit.ExecuteCompilation( unit.ExecuteCompilation(
&env, Impl(native_module->compilation_state())->detected_features()); &env, isolate->counters(),
Impl(native_module->compilation_state())->detected_features());
// If there is a pending error, something really went wrong. The module was // If there is a pending error, something really went wrong. The module was
// verified before starting execution with lazy compilation. // verified before starting execution with lazy compilation.
...@@ -476,8 +477,7 @@ class CompilationUnitBuilder { ...@@ -476,8 +477,7 @@ class CompilationUnitBuilder {
return base::make_unique<WasmCompilationUnit>( return base::make_unique<WasmCompilationUnit>(
wasm_engine_, native_module_, wasm_engine_, native_module_,
FunctionBody{function->sig, buffer_offset, bytes.begin(), bytes.end()}, FunctionBody{function->sig, buffer_offset, bytes.begin(), bytes.end()},
function->func_index, function->func_index, mode);
compilation_state()->isolate()->async_counters().get(), mode);
} }
CompilationStateImpl* compilation_state() const { CompilationStateImpl* compilation_state() const {
...@@ -522,7 +522,8 @@ double MonotonicallyIncreasingTimeInMs() { ...@@ -522,7 +522,8 @@ double MonotonicallyIncreasingTimeInMs() {
// the finisher_is_running_ flag is not set. // the finisher_is_running_ flag is not set.
bool FetchAndExecuteCompilationUnit(CompilationEnv* env, bool FetchAndExecuteCompilationUnit(CompilationEnv* env,
CompilationStateImpl* compilation_state, CompilationStateImpl* compilation_state,
WasmFeatures* detected) { WasmFeatures* detected,
Counters* counters) {
DisallowHeapAccess no_heap_access; DisallowHeapAccess no_heap_access;
std::unique_ptr<WasmCompilationUnit> unit = std::unique_ptr<WasmCompilationUnit> unit =
...@@ -535,7 +536,7 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env, ...@@ -535,7 +536,7 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env,
// later as soon as Liftoff can compile any function. Then, we can directly // later as soon as Liftoff can compile any function. Then, we can directly
// access {unit->mode()} within {ScheduleUnitForFinishing()}. // access {unit->mode()} within {ScheduleUnitForFinishing()}.
ExecutionTier mode = unit->mode(); ExecutionTier mode = unit->mode();
unit->ExecuteCompilation(env, detected); unit->ExecuteCompilation(env, counters, detected);
compilation_state->ScheduleUnitForFinishing(std::move(unit), mode); compilation_state->ScheduleUnitForFinishing(std::move(unit), mode);
return true; return true;
...@@ -635,7 +636,8 @@ void CompileInParallel(Isolate* isolate, NativeModule* native_module, ...@@ -635,7 +636,8 @@ void CompileInParallel(Isolate* isolate, NativeModule* native_module,
WasmFeatures detected_features; WasmFeatures detected_features;
CompilationEnv env = native_module->CreateCompilationEnv(); CompilationEnv env = native_module->CreateCompilationEnv();
while (FetchAndExecuteCompilationUnit(&env, compilation_state, while (FetchAndExecuteCompilationUnit(&env, compilation_state,
&detected_features) && &detected_features,
isolate->counters()) &&
!compilation_state->baseline_compilation_finished()) { !compilation_state->baseline_compilation_finished()) {
// 2.b) If {baseline_finish_units_} contains a compilation unit, the main // 2.b) If {baseline_finish_units_} contains a compilation unit, the main
// thread dequeues it and finishes the compilation unit. Compilation // thread dequeues it and finishes the compilation unit. Compilation
...@@ -846,9 +848,12 @@ class FinishCompileTask : public CancelableTask { ...@@ -846,9 +848,12 @@ class FinishCompileTask : public CancelableTask {
// The runnable task that performs compilations in the background. // The runnable task that performs compilations in the background.
class BackgroundCompileTask : public CancelableTask { class BackgroundCompileTask : public CancelableTask {
public: public:
explicit BackgroundCompileTask(NativeModule* native_module, explicit BackgroundCompileTask(CancelableTaskManager* task_manager,
CancelableTaskManager* task_manager) NativeModule* native_module,
: CancelableTask(task_manager), native_module_(native_module) {} Counters* counters)
: CancelableTask(task_manager),
native_module_(native_module),
counters_(counters) {}
void RunInternal() override { void RunInternal() override {
TRACE_COMPILE("(3b) Compiling...\n"); TRACE_COMPILE("(3b) Compiling...\n");
...@@ -859,7 +864,7 @@ class BackgroundCompileTask : public CancelableTask { ...@@ -859,7 +864,7 @@ class BackgroundCompileTask : public CancelableTask {
WasmFeatures detected_features = kNoWasmFeatures; WasmFeatures detected_features = kNoWasmFeatures;
while (!compilation_state->failed()) { while (!compilation_state->failed()) {
if (!FetchAndExecuteCompilationUnit(&env, compilation_state, if (!FetchAndExecuteCompilationUnit(&env, compilation_state,
&detected_features)) { &detected_features, counters_)) {
break; break;
} }
} }
...@@ -868,6 +873,7 @@ class BackgroundCompileTask : public CancelableTask { ...@@ -868,6 +873,7 @@ class BackgroundCompileTask : public CancelableTask {
private: private:
NativeModule* const native_module_; NativeModule* const native_module_;
Counters* const counters_;
}; };
} // namespace } // namespace
...@@ -3052,7 +3058,7 @@ void CompilationStateImpl::RestartBackgroundTasks(size_t max) { ...@@ -3052,7 +3058,7 @@ void CompilationStateImpl::RestartBackgroundTasks(size_t max) {
for (; num_restart > 0; --num_restart) { for (; num_restart > 0; --num_restart) {
auto task = base::make_unique<BackgroundCompileTask>( auto task = base::make_unique<BackgroundCompileTask>(
native_module_, &background_task_manager_); &background_task_manager_, native_module_, isolate_->counters());
// If --wasm-num-compilation-tasks=0 is passed, do only spawn foreground // If --wasm-num-compilation-tasks=0 is passed, do only spawn foreground
// tasks. This is used to make timing deterministic. // tasks. This is used to make timing deterministic.
......
...@@ -420,9 +420,10 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) { ...@@ -420,9 +420,10 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
NativeModule* native_module = NativeModule* native_module =
builder_->instance_object()->module_object()->native_module(); builder_->instance_object()->module_object()->native_module();
WasmCompilationUnit unit(isolate()->wasm_engine(), native_module, func_body, WasmCompilationUnit unit(isolate()->wasm_engine(), native_module, func_body,
function_->func_index, isolate()->counters(), tier); function_->func_index, tier);
WasmFeatures unused_detected_features; WasmFeatures unused_detected_features;
unit.ExecuteCompilation(&env, &unused_detected_features); unit.ExecuteCompilation(&env, isolate()->counters(),
&unused_detected_features);
CHECK(!unit.failed()); CHECK(!unit.failed());
if (WasmCode::ShouldBeLogged(isolate())) unit.result()->LogCode(isolate()); if (WasmCode::ShouldBeLogged(isolate())) unit.result()->LogCode(isolate());
} }
......
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