Commit dfffde4a authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Add proper --turbo-stats-wasm flag.

This gathers TurboFan compilation statistics for WebAssembly separately
from the JavaScript statistics. It is a preparation to having multiple
Isolates trigger TurboFan compilations in a shared engine. By adding
compilation statistics to the engine, their lifetime is independent of
any particular Isolate.

R=ahaas@chromium.org

Change-Id: I1bd0fbe6d6bde65ca813ccfd1154558ea6cddb07
Reviewed-on: https://chromium-review.googlesource.com/1131121
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54357}
parent 8442795a
......@@ -6,7 +6,6 @@
#include "src/compiler/pipeline-statistics.h"
#include "src/compiler/zone-stats.h"
#include "src/isolate.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/string.h"
#include "src/optimized-compilation-info.h"
......@@ -46,11 +45,11 @@ void PipelineStatistics::CommonStats::End(
}
PipelineStatistics::PipelineStatistics(OptimizedCompilationInfo* info,
Isolate* isolate, ZoneStats* zone_stats)
: isolate_(isolate),
outer_zone_(info->zone()),
CompilationStatistics* compilation_stats,
ZoneStats* zone_stats)
: outer_zone_(info->zone()),
zone_stats_(zone_stats),
compilation_stats_(isolate_->GetTurboStatistics()),
compilation_stats_(compilation_stats),
source_size_(0),
phase_kind_name_(nullptr),
phase_name_(nullptr) {
......
......@@ -20,8 +20,8 @@ class PhaseScope;
class PipelineStatistics : public Malloced {
public:
PipelineStatistics(OptimizedCompilationInfo* info, Isolate* isolate,
ZoneStats* zone_stats);
PipelineStatistics(OptimizedCompilationInfo* info,
CompilationStatistics* turbo_stats, ZoneStats* zone_stats);
~PipelineStatistics();
void BeginPhaseKind(const char* phase_kind_name);
......@@ -56,7 +56,6 @@ class PipelineStatistics : public Malloced {
void BeginPhase(const char* name);
void EndPhase();
Isolate* isolate_;
Zone* outer_zone_;
ZoneStats* zone_stats_;
CompilationStatistics* compilation_stats_;
......
......@@ -760,7 +760,8 @@ PipelineStatistics* CreatePipelineStatistics(Handle<Script> script,
PipelineStatistics* pipeline_statistics = nullptr;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics = new PipelineStatistics(info, isolate, zone_stats);
pipeline_statistics =
new PipelineStatistics(info, isolate->GetTurboStatistics(), zone_stats);
pipeline_statistics->BeginPhaseKind("initializing");
}
......@@ -775,15 +776,16 @@ PipelineStatistics* CreatePipelineStatistics(Handle<Script> script,
return pipeline_statistics;
}
PipelineStatistics* CreatePipelineStatistics(wasm::FunctionBody function_body,
PipelineStatistics* CreatePipelineStatistics(wasm::WasmEngine* wasm_engine,
wasm::FunctionBody function_body,
wasm::WasmModule* wasm_module,
OptimizedCompilationInfo* info,
Isolate* isolate,
ZoneStats* zone_stats) {
PipelineStatistics* pipeline_statistics = nullptr;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics = new PipelineStatistics(info, isolate, zone_stats);
if (FLAG_turbo_stats_wasm) {
pipeline_statistics = new PipelineStatistics(
info, wasm_engine->GetOrCreateTurboStatistics(), zone_stats);
pipeline_statistics->BeginPhaseKind("initializing");
}
......@@ -973,16 +975,17 @@ void PipelineCompilationJob::RegisterWeakObjectsInOptimizedCode(
class PipelineWasmCompilationJob final : public OptimizedCompilationJob {
public:
explicit PipelineWasmCompilationJob(
OptimizedCompilationInfo* info, Isolate* isolate, MachineGraph* mcgraph,
CallDescriptor* call_descriptor, SourcePositionTable* source_positions,
NodeOriginTable* node_origins, WasmCompilationData* wasm_compilation_data,
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
Isolate* isolate, MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
wasm::NativeModule* native_module, int function_index, bool asmjs_origin)
: OptimizedCompilationJob(isolate->stack_guard()->real_climit(), info,
"TurboFan", State::kReadyToExecute),
zone_stats_(isolate->allocator()),
pipeline_statistics_(CreatePipelineStatistics(
function_body, wasm_module, info, isolate, &zone_stats_)),
wasm_engine, function_body, wasm_module, info, &zone_stats_)),
data_(&zone_stats_, isolate, info, mcgraph, pipeline_statistics_.get(),
source_positions, node_origins, wasm_compilation_data,
function_index, WasmAssemblerOptions(isolate)),
......@@ -1019,8 +1022,9 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
pipeline_.RunPrintAndVerify("Machine", true);
PipelineData* data = &data_;
PipelineRunScope scope(data, "wasm optimization");
data->BeginPhaseKind("wasm optimization");
if (FLAG_wasm_opt || asmjs_origin_) {
PipelineRunScope scope(data, "wasm full optimization");
GraphReducer graph_reducer(scope.zone(), data->graph(),
data->mcgraph()->Dead());
DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(),
......@@ -1036,6 +1040,7 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
AddReducer(data, &graph_reducer, &value_numbering);
graph_reducer.ReduceGraph();
} else {
PipelineRunScope scope(data, "wasm base optimization");
GraphReducer graph_reducer(scope.zone(), data->graph(),
data->mcgraph()->Dead());
ValueNumberingReducer value_numbering(scope.zone(), data->graph()->zone());
......@@ -2124,8 +2129,8 @@ MaybeHandle<Code> Pipeline::GenerateCodeForCodeStub(
data.set_verify_graph(FLAG_verify_csa);
std::unique_ptr<PipelineStatistics> pipeline_statistics;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics.reset(
new PipelineStatistics(&info, isolate, &zone_stats));
pipeline_statistics.reset(new PipelineStatistics(
&info, isolate->GetTurboStatistics(), &zone_stats));
pipeline_statistics->BeginPhaseKind("stub codegen");
}
......@@ -2195,8 +2200,8 @@ MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
source_positions, node_positions, nullptr, options);
std::unique_ptr<PipelineStatistics> pipeline_statistics;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics.reset(
new PipelineStatistics(info, isolate, &zone_stats));
pipeline_statistics.reset(new PipelineStatistics(
info, isolate->GetTurboStatistics(), &zone_stats));
pipeline_statistics->BeginPhaseKind("test codegen");
}
......@@ -2233,16 +2238,17 @@ OptimizedCompilationJob* Pipeline::NewCompilationJob(
// static
OptimizedCompilationJob* Pipeline::NewWasmCompilationJob(
OptimizedCompilationInfo* info, Isolate* isolate, MachineGraph* mcgraph,
CallDescriptor* call_descriptor, SourcePositionTable* source_positions,
NodeOriginTable* node_origins, WasmCompilationData* wasm_compilation_data,
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
Isolate* isolate, MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
wasm::NativeModule* native_module, int function_index,
wasm::ModuleOrigin asmjs_origin) {
return new PipelineWasmCompilationJob(
info, isolate, mcgraph, call_descriptor, source_positions, node_origins,
wasm_compilation_data, function_body, wasm_module, native_module,
function_index, asmjs_origin);
info, wasm_engine, isolate, mcgraph, call_descriptor, source_positions,
node_origins, wasm_compilation_data, function_body, wasm_module,
native_module, function_index, asmjs_origin);
}
bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config,
......
......@@ -24,6 +24,7 @@ namespace wasm {
enum ModuleOrigin : uint8_t;
struct FunctionBody;
class NativeModule;
class WasmEngine;
struct WasmModule;
} // namespace wasm
......@@ -47,9 +48,10 @@ class Pipeline : public AllStatic {
// Returns a new compilation job for the WebAssembly compilation info.
static OptimizedCompilationJob* NewWasmCompilationJob(
OptimizedCompilationInfo* info, Isolate* isolate, MachineGraph* mcgraph,
CallDescriptor* call_descriptor, SourcePositionTable* source_positions,
NodeOriginTable* node_origins, WasmCompilationData* wasm_compilation_data,
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
Isolate* isolate, MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
wasm::NativeModule* native_module, int function_index,
wasm::ModuleOrigin wasm_origin);
......
......@@ -5211,9 +5211,9 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
}
job_.reset(Pipeline::NewWasmCompilationJob(
info_.get(), wasm_unit_->isolate_, mcgraph_, call_descriptor,
source_positions, node_origins, &wasm_compilation_data_,
wasm_unit_->func_body_,
info_.get(), wasm_unit_->isolate_->wasm_engine(), wasm_unit_->isolate_,
mcgraph_, call_descriptor, source_positions, node_origins,
&wasm_compilation_data_, wasm_unit_->func_body_,
const_cast<wasm::WasmModule*>(wasm_unit_->env_->module),
wasm_unit_->native_module_, wasm_unit_->func_index_,
wasm_unit_->env_->module->origin));
......
......@@ -430,6 +430,8 @@ DEFINE_STRING(csa_trap_on_node, nullptr,
DEFINE_BOOL(turbo_stats, false, "print TurboFan statistics")
DEFINE_BOOL(turbo_stats_nvp, false,
"print TurboFan statistics in machine-readable format")
DEFINE_BOOL(turbo_stats_wasm, false,
"print TurboFan statistics of wasm compilations")
DEFINE_BOOL(turbo_splitting, true, "split nodes during scheduling in TurboFan")
DEFINE_BOOL(function_context_specialization, false,
"enable function context specialization in TurboFan")
......@@ -528,8 +530,6 @@ DEFINE_BOOL(wasm_async_compilation, true,
"enable actual asynchronous compilation for WebAssembly.compile")
DEFINE_BOOL(wasm_test_streaming, false,
"use streaming compilation instead of async compilation for tests")
// Parallel compilation confuses turbo_stats, force single threaded.
DEFINE_VALUE_IMPLICATION(turbo_stats, wasm_num_compilation_tasks, 0)
DEFINE_UINT(wasm_max_mem_pages, v8::internal::wasm::kV8MaxWasmMemoryPages,
"maximum memory size of a wasm instance")
DEFINE_UINT(wasm_max_table_size, v8::internal::wasm::kV8MaxWasmTableSize,
......
......@@ -3233,7 +3233,6 @@ void Isolate::UnlinkDeferredHandles(DeferredHandles* deferred) {
void Isolate::DumpAndResetStats() {
if (turbo_statistics() != nullptr) {
DCHECK(FLAG_turbo_stats || FLAG_turbo_stats_nvp);
StdoutStream os;
if (FLAG_turbo_stats) {
AsPrintableStatistics ps = {*turbo_statistics(), false};
......@@ -3243,9 +3242,14 @@ void Isolate::DumpAndResetStats() {
AsPrintableStatistics ps = {*turbo_statistics(), true};
os << ps << std::endl;
}
}
delete turbo_statistics_;
turbo_statistics_ = nullptr;
}
// TODO(7424): There is no public API for the {WasmEngine} yet. So for now we
// just dump and reset the engines statistics together with the Isolate.
if (FLAG_turbo_stats_wasm) {
wasm_engine()->DumpAndResetTurboStatistics();
}
if (V8_UNLIKELY(FLAG_runtime_stats ==
v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE)) {
counters()->runtime_call_stats()->Print();
......
......@@ -4,6 +4,7 @@
#include "src/wasm/wasm-engine.h"
#include "src/compilation-statistics.h"
#include "src/objects-inl.h"
#include "src/objects/js-promise.h"
#include "src/wasm/module-compiler.h"
......@@ -15,6 +16,11 @@ namespace v8 {
namespace internal {
namespace wasm {
WasmEngine::WasmEngine(std::unique_ptr<WasmCodeManager> code_manager)
: code_manager_(std::move(code_manager)) {}
WasmEngine::~WasmEngine() = default;
bool WasmEngine::SyncValidate(Isolate* isolate, const ModuleWireBytes& bytes) {
// TODO(titzer): remove dependency on the isolate.
if (bytes.start() == nullptr || bytes.length() == 0) return false;
......@@ -151,6 +157,21 @@ std::shared_ptr<StreamingDecoder> WasmEngine::StartStreamingCompilation(
return job->CreateStreamingDecoder();
}
CompilationStatistics* WasmEngine::GetOrCreateTurboStatistics() {
if (compilation_stats_ == nullptr) {
compilation_stats_.reset(new CompilationStatistics());
}
return compilation_stats_.get();
}
void WasmEngine::DumpAndResetTurboStatistics() {
if (compilation_stats_ != nullptr) {
StdoutStream os;
os << AsPrintableStatistics{*compilation_stats_.get(), false} << std::endl;
}
compilation_stats_.reset();
}
void WasmEngine::Register(CancelableTaskManager* task_manager) {
task_managers_.emplace_back(task_manager);
}
......
......@@ -14,6 +14,7 @@
namespace v8 {
namespace internal {
class CompilationStatistics;
class WasmModuleObject;
class WasmInstanceObject;
......@@ -40,8 +41,8 @@ class V8_EXPORT_PRIVATE InstantiationResultResolver {
// loading, instantiating, and executing WASM code.
class V8_EXPORT_PRIVATE WasmEngine {
public:
explicit WasmEngine(std::unique_ptr<WasmCodeManager> code_manager)
: code_manager_(std::move(code_manager)) {}
explicit WasmEngine(std::unique_ptr<WasmCodeManager> code_manager);
~WasmEngine();
// Synchronously validates the given bytes that represent an encoded WASM
// module.
......@@ -92,6 +93,12 @@ class V8_EXPORT_PRIVATE WasmEngine {
AccountingAllocator* allocator() { return &allocator_; }
// Compilation statistics for TurboFan compilations.
CompilationStatistics* GetOrCreateTurboStatistics();
// Prints the gathered compilation statistics, then resets them.
void DumpAndResetTurboStatistics();
// We register and unregister CancelableTaskManagers that run engine-dependent
// tasks. These tasks need to be shutdown if the engine is shut down.
void Register(CancelableTaskManager* task_manager);
......@@ -120,6 +127,7 @@ class V8_EXPORT_PRIVATE WasmEngine {
// job from the map when it is finished.
std::unordered_map<AsyncCompileJob*, std::unique_ptr<AsyncCompileJob>> jobs_;
std::unique_ptr<WasmCodeManager> code_manager_;
std::unique_ptr<CompilationStatistics> compilation_stats_;
WasmMemoryTracker memory_tracker_;
AccountingAllocator allocator_;
......
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