Commit e453f722 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][gc] Add counters for amount of freed code

This adds two counters for collecting the absolute size of freed code,
and the percent of total generated code per module.

R=titzer@chromium.org

Bug: v8:8217
Change-Id: Ia065081104fbff6459791c919e0b18677ba45cc3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1573698
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60948}
parent b2942ae9
......@@ -74,14 +74,19 @@ namespace internal {
HR(wasm_memory_allocation_result, V8.WasmMemoryAllocationResult, 0, 3, 4) \
HR(wasm_address_space_usage_mb, V8.WasmAddressSpaceUsageMiB, 0, 1 << 20, \
128) \
/* code size of live modules, collected on GC */ \
/* committed code size per module, collected on GC */ \
HR(wasm_module_code_size_mb, V8.WasmModuleCodeSizeMiB, 0, 1024, 64) \
/* code size of modules after baseline compilation */ \
/* code size per module after baseline compilation */ \
HR(wasm_module_code_size_mb_after_baseline, \
V8.WasmModuleCodeSizeBaselineMiB, 0, 1024, 64) \
/* code size of modules after top-tier compilation */ \
/* code size per module after top-tier compilation */ \
HR(wasm_module_code_size_mb_after_top_tier, V8.WasmModuleCodeSizeTopTierMiB, \
0, 1024, 64)
0, 1024, 64) \
/* freed code size per module, collected on GC */ \
HR(wasm_module_freed_code_size_mb, V8.WasmModuleCodeSizeFreed, 0, 1024, 64) \
/* percent of freed code size per module, collected on GC */ \
HR(wasm_module_freed_code_size_percent, V8.WasmModuleCodeSizePercentFreed, \
0, 100, 32)
#define HISTOGRAM_TIMER_LIST(HT) \
/* Timer histograms, not thread safe: HT(name, caption, max, unit) */ \
......
......@@ -1329,9 +1329,17 @@ void NativeModule::SampleCodeSize(
case kAfterTopTier:
histogram = counters->wasm_module_code_size_mb_after_top_tier();
break;
case kSampling:
case kSampling: {
histogram = counters->wasm_module_code_size_mb();
// Also, add a sample of freed code size, absolute and relative.
size_t freed_size = freed_code_size_.load(std::memory_order_relaxed);
int total_freed_mb = static_cast<int>(freed_size / MB);
counters->wasm_module_freed_code_size_mb()->AddSample(total_freed_mb);
int freed_percent =
static_cast<int>(100 * freed_code_size_ / generated_code_size_);
counters->wasm_module_freed_code_size_percent()->AddSample(freed_percent);
break;
}
}
histogram->AddSample(code_size_mb);
}
......@@ -1386,11 +1394,14 @@ void NativeModule::FreeCode(Vector<WasmCode* const> codes) {
// For now, we neither free the {WasmCode} objects, nor do we free any code.
// We just zap the code to ensure it's not executed any more.
// TODO(clemensh): Actually free the {WasmCode} objects and the code pages.
size_t code_size = 0;
for (WasmCode* code : codes) {
ZapCode(code->instruction_start(), code->instructions().size());
FlushInstructionCache(code->instruction_start(),
code->instructions().size());
code_size += code->instructions().size();
}
freed_code_size_.fetch_add(code_size);
}
void WasmCodeManager::FreeNativeModule(NativeModule* native_module) {
......
......@@ -523,6 +523,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmEngine* const engine_;
std::atomic<size_t> committed_code_space_{0};
std::atomic<size_t> generated_code_size_{0};
std::atomic<size_t> freed_code_size_{0};
int modification_scope_depth_ = 0;
bool can_request_more_memory_;
UseTrapHandler use_trap_handler_ = kNoTrapHandler;
......
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