Commit ec8a5873 authored by Karl Schimpf's avatar Karl Schimpf Committed by Commit Bot

Make wasm memory histograms simple histograms.

This Cl fixes a fundamental misunderstanding when Wasm memory
histograms were added. They were added using
HISTOGRAM_MEMORY_LIST(). This macro implements aggregating memory
histograms that handle cases memory cases that are not module
specific.

The fixed memory histograms are all module specific, and are simple
histograms.

In addition, it removes field is_sync from ModuleCompiler and
WasmCompilationUnit, since the field is no longer needed to make the
fixed memory histograms synchronous.

Bug: v8:6361
Change-Id: I696109b4fd1a4aadc87a6bdbbc4b7daefd58ea51
Reviewed-on: https://chromium-review.googlesource.com/565349Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Commit-Queue: Karl Schimpf <kschimpf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46541}
parent 0a5cbce4
...@@ -3944,7 +3944,6 @@ WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, ...@@ -3944,7 +3944,6 @@ WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate,
func_body_(body), func_body_(body),
func_name_(name), func_name_(name),
counters_(isolate->counters()), counters_(isolate->counters()),
is_sync_(true),
centry_stub_(centry_stub), centry_stub_(centry_stub),
func_index_(index) {} func_index_(index) {}
...@@ -3970,7 +3969,6 @@ WasmCompilationUnit::WasmCompilationUnit( ...@@ -3970,7 +3969,6 @@ WasmCompilationUnit::WasmCompilationUnit(
func_body_(body), func_body_(body),
func_name_(name), func_name_(name),
counters_(async_counters.get()), counters_(async_counters.get()),
is_sync_(false),
centry_stub_(centry_stub), centry_stub_(centry_stub),
func_index_(index) {} func_index_(index) {}
...@@ -4035,9 +4033,6 @@ void WasmCompilationUnit::ExecuteCompilation() { ...@@ -4035,9 +4033,6 @@ void WasmCompilationUnit::ExecuteCompilation() {
&protected_instructions, module_env_->module->origin())); &protected_instructions, module_env_->module->origin()));
ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED;
// TODO(bradnelson): Improve histogram handling of size_t. // TODO(bradnelson): Improve histogram handling of size_t.
if (is_sync_)
// TODO(karlschimpf): Make this work when asynchronous.
// https://bugs.chromium.org/p/v8/issues/detail?id=6361
counters()->wasm_compile_function_peak_memory_bytes()->AddSample( counters()->wasm_compile_function_peak_memory_bytes()->AddSample(
static_cast<int>(jsgraph_->graph()->zone()->allocation_size())); static_cast<int>(jsgraph_->graph()->zone()->allocation_size()));
......
...@@ -87,7 +87,6 @@ class WasmCompilationUnit final { ...@@ -87,7 +87,6 @@ class WasmCompilationUnit final {
wasm::FunctionBody func_body_; wasm::FunctionBody func_body_;
wasm::WasmName func_name_; wasm::WasmName func_name_;
Counters* counters_; Counters* counters_;
bool is_sync_;
// The graph zone is deallocated at the end of ExecuteCompilation by virtue of // The graph zone is deallocated at the end of ExecuteCompilation by virtue of
// it being zone allocated. // it being zone allocated.
JSGraph* jsgraph_ = nullptr; JSGraph* jsgraph_ = nullptr;
......
...@@ -1006,7 +1006,25 @@ class RuntimeCallTimerScope { ...@@ -1006,7 +1006,25 @@ class RuntimeCallTimerScope {
13) \ 13) \
HR(array_buffer_new_size_failures, V8.ArrayBufferNewSizeFailures, 0, 4096, \ HR(array_buffer_new_size_failures, V8.ArrayBufferNewSizeFailures, 0, 4096, \
13) \ 13) \
HR(shared_array_allocations, V8.SharedArrayAllocationSizes, 0, 4096, 13) HR(shared_array_allocations, V8.SharedArrayAllocationSizes, 0, 4096, 13) \
HR(wasm_asm_function_size_bytes, V8.WasmFunctionSizeBytes.asm, 1, GB, 51) \
HR(wasm_wasm_function_size_bytes, V8.WasmFunctionSizeBytes.wasm, 1, GB, 51) \
HR(wasm_asm_module_size_bytes, V8.WasmModuleSizeBytes.asm, 1, GB, 51) \
HR(wasm_wasm_module_size_bytes, V8.WasmModuleSizeBytes.wasm, 1, GB, 51) \
HR(wasm_asm_min_mem_pages_count, V8.WasmMinMemPagesCount.asm, 1, 2 << 16, \
51) \
HR(wasm_wasm_min_mem_pages_count, V8.WasmMinMemPagesCount.wasm, 1, 2 << 16, \
51) \
HR(wasm_wasm_max_mem_pages_count, V8.WasmMaxMemPagesCount.wasm, 1, 2 << 16, \
51) \
HR(wasm_decode_asm_module_peak_memory_bytes, \
V8.WasmDecodeModulePeakMemoryBytes.asm, 1, GB, 51) \
HR(wasm_decode_wasm_module_peak_memory_bytes, \
V8.WasmDecodeModulePeakMemoryBytes.wasm, 1, GB, 51) \
HR(asm_wasm_translation_peak_memory_bytes, \
V8.AsmWasmTranslationPeakMemoryBytes, 1, GB, 51) \
HR(wasm_compile_function_peak_memory_bytes, \
V8.WasmCompileFunctionPeakMemoryBytes, 1, GB, 51)
#define HISTOGRAM_TIMER_LIST(HT) \ #define HISTOGRAM_TIMER_LIST(HT) \
/* Garbage collection timers. */ \ /* Garbage collection timers. */ \
...@@ -1080,6 +1098,7 @@ class RuntimeCallTimerScope { ...@@ -1080,6 +1098,7 @@ class RuntimeCallTimerScope {
HP(heap_fraction_map_space, V8.MemoryHeapFractionMapSpace) \ HP(heap_fraction_map_space, V8.MemoryHeapFractionMapSpace) \
HP(heap_fraction_lo_space, V8.MemoryHeapFractionLoSpace) HP(heap_fraction_lo_space, V8.MemoryHeapFractionLoSpace)
// Note: These use Histogram with options (min=1000, max=500000, buckets=50).
#define HISTOGRAM_LEGACY_MEMORY_LIST(HM) \ #define HISTOGRAM_LEGACY_MEMORY_LIST(HM) \
HM(heap_sample_total_committed, V8.MemoryHeapSampleTotalCommitted) \ HM(heap_sample_total_committed, V8.MemoryHeapSampleTotalCommitted) \
HM(heap_sample_total_used, V8.MemoryHeapSampleTotalUsed) \ HM(heap_sample_total_used, V8.MemoryHeapSampleTotalUsed) \
...@@ -1087,25 +1106,11 @@ class RuntimeCallTimerScope { ...@@ -1087,25 +1106,11 @@ class RuntimeCallTimerScope {
HM(heap_sample_code_space_committed, V8.MemoryHeapSampleCodeSpaceCommitted) \ HM(heap_sample_code_space_committed, V8.MemoryHeapSampleCodeSpaceCommitted) \
HM(heap_sample_maximum_committed, V8.MemoryHeapSampleMaximumCommitted) HM(heap_sample_maximum_committed, V8.MemoryHeapSampleMaximumCommitted)
// Note: These define both Histogram and AggregatedMemoryHistogram<Histogram>
// histograms with options (min=4000, max=2000000, buckets=100).
#define HISTOGRAM_MEMORY_LIST(HM) \ #define HISTOGRAM_MEMORY_LIST(HM) \
HM(memory_heap_committed, V8.MemoryHeapCommitted) \ HM(memory_heap_committed, V8.MemoryHeapCommitted) \
HM(memory_heap_used, V8.MemoryHeapUsed) \ HM(memory_heap_used, V8.MemoryHeapUsed)
/* Asm/Wasm */ \
HM(wasm_decode_asm_module_peak_memory_bytes, \
V8.WasmDecodeModulePeakMemoryBytes.asm) \
HM(wasm_decode_wasm_module_peak_memory_bytes, \
V8.WasmDecodeModulePeakMemoryBytes.wasm) \
HM(wasm_compile_function_peak_memory_bytes, \
V8.WasmCompileFunctionPeakMemoryBytes) \
HM(wasm_asm_min_mem_pages_count, V8.WasmMinMemPagesCount.asm) \
HM(wasm_wasm_min_mem_pages_count, V8.WasmMinMemPagesCount.wasm) \
HM(wasm_wasm_max_mem_pages_count, V8.WasmMaxMemPagesCount.wasm) \
HM(wasm_asm_function_size_bytes, V8.WasmFunctionSizeBytes.asm) \
HM(wasm_wasm_function_size_bytes, V8.WasmFunctionSizeBytes.wasm) \
HM(wasm_asm_module_size_bytes, V8.WasmModuleSizeBytes.asm) \
HM(wasm_wasm_module_size_bytes, V8.WasmModuleSizeBytes.wasm) \
HM(asm_wasm_translation_peak_memory_bytes, \
V8.AsmWasmTranslationPeakMemoryBytes)
// WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC
// Intellisense to crash. It was broken into two macros (each of length 40 // Intellisense to crash. It was broken into two macros (each of length 40
......
...@@ -83,11 +83,10 @@ size_t ModuleCompiler::CodeGenerationSchedule::GetRandomIndexInSchedule() { ...@@ -83,11 +83,10 @@ size_t ModuleCompiler::CodeGenerationSchedule::GetRandomIndexInSchedule() {
} }
ModuleCompiler::ModuleCompiler(Isolate* isolate, ModuleCompiler::ModuleCompiler(Isolate* isolate,
std::unique_ptr<WasmModule> module, bool is_sync) std::unique_ptr<WasmModule> module)
: isolate_(isolate), : isolate_(isolate),
module_(std::move(module)), module_(std::move(module)),
async_counters_(isolate->async_counters()), async_counters_(isolate->async_counters()),
is_sync_(is_sync),
executed_units_( executed_units_(
isolate->random_number_generator(), isolate->random_number_generator(),
(isolate->heap()->memory_allocator()->code_range()->valid() (isolate->heap()->memory_allocator()->code_range()->valid()
...@@ -347,19 +346,12 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObject( ...@@ -347,19 +346,12 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObject(
signature_tables->set(i, *temp_instance.signature_tables[i]); signature_tables->set(i, *temp_instance.signature_tables[i]);
} }
if (is_sync_) {
// TODO(karlschimpf): Make this work when asynchronous.
// https://bugs.chromium.org/p/v8/issues/detail?id=6361
TimedHistogramScope wasm_compile_module_time_scope( TimedHistogramScope wasm_compile_module_time_scope(
module_->is_wasm() ? counters()->wasm_compile_wasm_module_time() module_->is_wasm() ? counters()->wasm_compile_wasm_module_time()
: counters()->wasm_compile_asm_module_time()); : counters()->wasm_compile_asm_module_time());
return CompileToModuleObjectInternal( return CompileToModuleObjectInternal(
thrower, wire_bytes, asm_js_script, asm_js_offset_table_bytes, factory, thrower, wire_bytes, asm_js_script, asm_js_offset_table_bytes, factory,
&temp_instance, &function_tables, &signature_tables); &temp_instance, &function_tables, &signature_tables);
}
return CompileToModuleObjectInternal(
thrower, wire_bytes, asm_js_script, asm_js_offset_table_bytes, factory,
&temp_instance, &function_tables, &signature_tables);
} }
namespace { namespace {
...@@ -591,9 +583,6 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal( ...@@ -591,9 +583,6 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
temp_instance->function_code[i] = init_builtin; temp_instance->function_code[i] = init_builtin;
} }
if (is_sync_)
// TODO(karlschimpf): Make this work when asynchronous.
// https://bugs.chromium.org/p/v8/issues/detail?id=6361
(module_->is_wasm() ? counters()->wasm_functions_per_wasm_module() (module_->is_wasm() ? counters()->wasm_functions_per_wasm_module()
: counters()->wasm_functions_per_asm_module()) : counters()->wasm_functions_per_asm_module())
->AddSample(static_cast<int>(module_->functions.size())); ->AddSample(static_cast<int>(module_->functions.size()));
...@@ -2110,9 +2099,8 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep { ...@@ -2110,9 +2099,8 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
// Transfer ownership of the {WasmModule} to the {ModuleCompiler}, but // Transfer ownership of the {WasmModule} to the {ModuleCompiler}, but
// keep a pointer. // keep a pointer.
WasmModule* module = module_.get(); WasmModule* module = module_.get();
constexpr bool is_sync = true;
job_->compiler_.reset( job_->compiler_.reset(
new ModuleCompiler(job_->isolate_, std::move(module_), !is_sync)); new ModuleCompiler(job_->isolate_, std::move(module_)));
job_->compiler_->EnableThrottling(); job_->compiler_->EnableThrottling();
// Reopen all handles which should survive in the DeferredHandleScope. // Reopen all handles which should survive in the DeferredHandleScope.
......
...@@ -27,8 +27,7 @@ class ModuleCompiler { ...@@ -27,8 +27,7 @@ class ModuleCompiler {
// In {CompileToModuleObject}, it will transfer ownership to the generated // In {CompileToModuleObject}, it will transfer ownership to the generated
// {WasmModuleWrapper}. If this method is not called, ownership may be // {WasmModuleWrapper}. If this method is not called, ownership may be
// reclaimed by explicitely releasing the {module_} field. // reclaimed by explicitely releasing the {module_} field.
ModuleCompiler(Isolate* isolate, std::unique_ptr<WasmModule> module, ModuleCompiler(Isolate* isolate, std::unique_ptr<WasmModule> module);
bool is_sync);
// The actual runnable task that performs compilations in the background. // The actual runnable task that performs compilations in the background.
class CompilationTask : public CancelableTask { class CompilationTask : public CancelableTask {
...@@ -52,13 +51,6 @@ class ModuleCompiler { ...@@ -52,13 +51,6 @@ class ModuleCompiler {
void AddUnit(ModuleEnv* module_env, const WasmFunction* function, void AddUnit(ModuleEnv* module_env, const WasmFunction* function,
uint32_t buffer_offset, Vector<const uint8_t> bytes, uint32_t buffer_offset, Vector<const uint8_t> bytes,
WasmName name) { WasmName name) {
if (compiler_->is_sync_) {
units_.emplace_back(new compiler::WasmCompilationUnit(
compiler_->isolate_, module_env,
wasm::FunctionBody{function->sig, buffer_offset, bytes.begin(),
bytes.end()},
name, function->func_index, compiler_->centry_stub_));
} else {
units_.emplace_back(new compiler::WasmCompilationUnit( units_.emplace_back(new compiler::WasmCompilationUnit(
compiler_->isolate_, module_env, compiler_->isolate_, module_env,
wasm::FunctionBody{function->sig, buffer_offset, bytes.begin(), wasm::FunctionBody{function->sig, buffer_offset, bytes.begin(),
...@@ -66,7 +58,6 @@ class ModuleCompiler { ...@@ -66,7 +58,6 @@ class ModuleCompiler {
name, function->func_index, compiler_->centry_stub_, name, function->func_index, compiler_->centry_stub_,
compiler_->async_counters())); compiler_->async_counters()));
} }
}
void Commit() { void Commit() {
{ {
...@@ -177,7 +168,6 @@ class ModuleCompiler { ...@@ -177,7 +168,6 @@ class ModuleCompiler {
Isolate* isolate_; Isolate* isolate_;
std::unique_ptr<WasmModule> module_; std::unique_ptr<WasmModule> module_;
const std::shared_ptr<Counters> async_counters_; const std::shared_ptr<Counters> async_counters_;
bool is_sync_;
std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> std::vector<std::unique_ptr<compiler::WasmCompilationUnit>>
compilation_units_; compilation_units_;
base::Mutex compilation_units_mutex_; base::Mutex compilation_units_mutex_;
......
...@@ -1336,9 +1336,9 @@ FunctionResult DecodeWasmFunction(Isolate* isolate, Zone* zone, ...@@ -1336,9 +1336,9 @@ FunctionResult DecodeWasmFunction(Isolate* isolate, Zone* zone,
bool is_sync) { bool is_sync) {
size_t size = function_end - function_start; size_t size = function_end - function_start;
bool is_wasm = module_env->module_env.is_wasm(); bool is_wasm = module_env->module_env.is_wasm();
auto size_counter = is_wasm ? counters->wasm_wasm_function_size_bytes() auto size_histogram = is_wasm ? counters->wasm_wasm_function_size_bytes()
: counters->wasm_asm_function_size_bytes(); : counters->wasm_asm_function_size_bytes();
size_counter->AddSample(static_cast<int>(size)); size_histogram->AddSample(static_cast<int>(size));
auto time_counter = is_wasm ? counters->wasm_decode_wasm_function_time() auto time_counter = is_wasm ? counters->wasm_decode_wasm_function_time()
: counters->wasm_decode_asm_function_time(); : counters->wasm_decode_asm_function_time();
TimedHistogramScope wasm_decode_function_time_scope(time_counter); TimedHistogramScope wasm_decode_function_time_scope(time_counter);
......
...@@ -760,8 +760,7 @@ MaybeHandle<WasmModuleObject> wasm::SyncCompileTranslatedAsmJs( ...@@ -760,8 +760,7 @@ MaybeHandle<WasmModuleObject> wasm::SyncCompileTranslatedAsmJs(
// Transfer ownership to the {WasmModuleWrapper} generated in // Transfer ownership to the {WasmModuleWrapper} generated in
// {CompileToModuleObject}. // {CompileToModuleObject}.
constexpr bool is_sync = true; ModuleCompiler helper(isolate, std::move(result.val));
ModuleCompiler helper(isolate, std::move(result.val), is_sync);
return helper.CompileToModuleObject(thrower, bytes, asm_js_script, return helper.CompileToModuleObject(thrower, bytes, asm_js_script,
asm_js_offset_table_bytes); asm_js_offset_table_bytes);
} }
...@@ -783,8 +782,7 @@ MaybeHandle<WasmModuleObject> wasm::SyncCompile(Isolate* isolate, ...@@ -783,8 +782,7 @@ MaybeHandle<WasmModuleObject> wasm::SyncCompile(Isolate* isolate,
// Transfer ownership to the {WasmModuleWrapper} generated in // Transfer ownership to the {WasmModuleWrapper} generated in
// {CompileToModuleObject}. // {CompileToModuleObject}.
constexpr bool is_sync = true; ModuleCompiler helper(isolate, std::move(result.val));
ModuleCompiler helper(isolate, std::move(result.val), is_sync);
return helper.CompileToModuleObject(thrower, bytes, Handle<Script>(), return helper.CompileToModuleObject(thrower, bytes, 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