Bug 1737199 - Avoid some VLAs when using jemalloc_stats r=glandium

Differential Revision: https://phabricator.services.mozilla.com/D129228
This commit is contained in:
Paul Bone 2021-10-27 08:46:51 +00:00
Родитель c1f80ec803
Коммит 24067c4312
2 изменённых файлов: 11 добавлений и 6 удалений

Просмотреть файл

@ -776,7 +776,11 @@ class Replay {
// Using a variable length array here is a GCC & Clang extension. But it
// allows us to place this on the stack and not alter jemalloc's profiling.
const size_t num_bins = ::jemalloc_stats_num_bins();
jemalloc_bin_stats_t bin_stats[num_bins];
const size_t MAX_NUM_BINS = 100;
if (num_bins > MAX_NUM_BINS) {
die("Exceeded maximum number of jemalloc stats bins");
}
jemalloc_bin_stats_t bin_stats[MAX_NUM_BINS] = {{0}};
::jemalloc_stats_internal(&stats, bin_stats);
#ifdef XP_LINUX
@ -791,8 +795,7 @@ class Replay {
size_t large_used = 0;
size_t huge_slop = 0;
size_t huge_used = 0;
size_t bin_slop[num_bins];
memset(bin_slop, 0, sizeof(size_t) * num_bins);
size_t bin_slop[MAX_NUM_BINS] = {0};
for (size_t slot_id = 0; slot_id < mNumUsedSlots; slot_id++) {
MemSlot& slot = mSlots[slot_id];
@ -869,7 +872,8 @@ class Replay {
FdPrintf(mStdErr, "\n%8s %11s %10s %8s %9s %9s %8s\n", "bin-size",
"unused (c)", "total (c)", "used (c)", "non-full (r)", "total (r)",
"used (r)");
for (auto& bin : bin_stats) {
for (unsigned i = 0; i < num_bins; i++) {
auto& bin = bin_stats[i];
MOZ_ASSERT(bin.size);
FdPrintf(mStdErr, "%8zu %8zuKiB %7zuKiB %7zu%% %12zu %9zu %7zu%%\n",
bin.size, bin.bytes_unused / 1024, bin.bytes_total / 1024,

Просмотреть файл

@ -1207,8 +1207,9 @@ class JemallocHeapReporter final : public nsIMemoryReporter {
nsISupports* aData, bool aAnonymize) override {
jemalloc_stats_t stats;
const size_t num_bins = jemalloc_stats_num_bins();
jemalloc_bin_stats_t bin_stats[num_bins];
jemalloc_stats(&stats, bin_stats);
nsTArray<jemalloc_bin_stats_t> bin_stats(num_bins);
bin_stats.SetLength(num_bins);
jemalloc_stats(&stats, bin_stats.Elements());
// clang-format off
MOZ_COLLECT_REPORT(