From 7baaa3f7537a513e3050141df84378d0af8e2339 Mon Sep 17 00:00:00 2001 From: Ted Campbell Date: Wed, 11 Apr 2018 15:49:36 -0400 Subject: [PATCH] Bug 1448563 - Part 6: Add memory reporting for off-thread WASM. r=luke MozReview-Commit-ID: 1lXRj1JUJk2 --- js/public/MemoryMetrics.h | 3 ++- js/src/vm/HelperThreads.cpp | 7 +++++++ js/src/wasm/WasmGenerator.cpp | 25 +++++++++++++++++++++++++ js/src/wasm/WasmGenerator.h | 10 ++++++++++ js/xpconnect/src/XPCJSRuntime.cpp | 4 ++++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/js/public/MemoryMetrics.h b/js/public/MemoryMetrics.h index ec8066797b19..a96d697a1ccf 100644 --- a/js/public/MemoryMetrics.h +++ b/js/public/MemoryMetrics.h @@ -509,7 +509,8 @@ struct HelperThreadStats #define FOR_EACH_SIZE(macro) \ macro(_, MallocHeap, stateData) \ macro(_, MallocHeap, parseTask) \ - macro(_, MallocHeap, ionBuilder) + macro(_, MallocHeap, ionBuilder) \ + macro(_, MallocHeap, wasmCompile) explicit HelperThreadStats() : FOR_EACH_SIZE(ZERO_SIZE) diff --git a/js/src/vm/HelperThreads.cpp b/js/src/vm/HelperThreads.cpp index b106c8402e5f..75a1b58f227c 100644 --- a/js/src/vm/HelperThreads.cpp +++ b/js/src/vm/HelperThreads.cpp @@ -23,6 +23,7 @@ #include "vm/Time.h" #include "vm/TraceLogging.h" #include "vm/Xdr.h" +#include "wasm/WasmGenerator.h" #include "gc/PrivateIterators-inl.h" #include "vm/JSCompartment-inl.h" @@ -1176,6 +1177,12 @@ GlobalHelperThreadState::addSizeOfIncludingThis(JS::GlobalStats* stats, for (auto builder : ionFreeList_) htStats.ionBuilder += builder->sizeOfIncludingThis(mallocSizeOf); + // Report wasm::CompileTasks on wait lists + for (auto task : wasmWorklist_tier1_) + htStats.wasmCompile += task->sizeOfIncludingThis(mallocSizeOf); + for (auto task : wasmWorklist_tier2_) + htStats.wasmCompile += task->sizeOfIncludingThis(mallocSizeOf); + // Report number of helper threads. MOZ_ASSERT(htStats.idleThreadCount == 0); if (threads) { diff --git a/js/src/wasm/WasmGenerator.cpp b/js/src/wasm/WasmGenerator.cpp index 185b76483c44..536490b86936 100644 --- a/js/src/wasm/WasmGenerator.cpp +++ b/js/src/wasm/WasmGenerator.cpp @@ -1025,3 +1025,28 @@ ModuleGenerator::finishTier2(Module& module) return module.finishTier2(Move(linkDataTier_), Move(tier2), env_); } + +size_t +CompiledCode::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const +{ + size_t trapSitesSize = 0; + for (const TrapSiteVector& vec : trapSites) + trapSitesSize += vec.sizeOfExcludingThis(mallocSizeOf); + + return bytes.sizeOfExcludingThis(mallocSizeOf) + + codeRanges.sizeOfExcludingThis(mallocSizeOf) + + callSites.sizeOfExcludingThis(mallocSizeOf) + + callSiteTargets.sizeOfExcludingThis(mallocSizeOf) + + trapSitesSize + + callFarJumps.sizeOfExcludingThis(mallocSizeOf) + + symbolicAccesses.sizeOfExcludingThis(mallocSizeOf) + + codeLabels.sizeOfExcludingThis(mallocSizeOf); +} + +size_t +CompileTask::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const +{ + return lifo.sizeOfExcludingThis(mallocSizeOf) + + inputs.sizeOfExcludingThis(mallocSizeOf) + + output.sizeOfExcludingThis(mallocSizeOf); +} diff --git a/js/src/wasm/WasmGenerator.h b/js/src/wasm/WasmGenerator.h index 78d5783d5c09..c55bb8c0d3ce 100644 --- a/js/src/wasm/WasmGenerator.h +++ b/js/src/wasm/WasmGenerator.h @@ -19,6 +19,8 @@ #ifndef wasm_generator_h #define wasm_generator_h +#include "mozilla/MemoryReporting.h" + #include "jit/MacroAssembler.h" #include "wasm/WasmCompile.h" #include "wasm/WasmModule.h" @@ -93,6 +95,8 @@ struct CompiledCode symbolicAccesses.empty() && codeLabels.empty(); } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const; }; // The CompileTaskState of a ModuleGenerator contains the mutable state shared @@ -128,6 +132,12 @@ struct CompileTask state(state), lifo(defaultChunkSize) {} + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const; + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const + { + return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + } }; // A ModuleGenerator encapsulates the creation of a wasm module. During the diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 8b62c6af87e6..69ee0ec485f1 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -2499,6 +2499,10 @@ JSReporter::CollectReports(WindowPaths* windowPaths, REPORT_BYTES(NS_LITERAL_CSTRING("explicit/js-non-window/helper-thread/ion-builder"), KIND_HEAP, gStats.helperThread.ionBuilder, "The memory used by IonBuilders waiting in HelperThreadState."); + + REPORT_BYTES(NS_LITERAL_CSTRING("explicit/js-non-window/helper-thread/wasm-compile"), + KIND_HEAP, gStats.helperThread.parseTask, + "The memory used by Wasm compilations waiting in HelperThreadState."); } static nsresult