From 2495460f6ed8a29819fe951b6611e215cbfcd8e7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 8 Oct 2021 19:47:25 +0200 Subject: [PATCH] LibJS: Prune WeakContainers before freeing HeapBlocks WeakContainers need to look at the Cell::State bits to know if their weak pointees got swept by garbage collection. So we must do this before potentially freeing one or more HeapBlocks by notifying the allocator that a block became empty. --- Userland/Libraries/LibJS/Heap/Heap.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp index a3aef36e0e..023f0aaf7e 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.cpp +++ b/Userland/Libraries/LibJS/Heap/Heap.cpp @@ -254,6 +254,9 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure return IterationDecision::Continue; }); + for (auto& weak_container : m_weak_containers) + weak_container.remove_dead_cells({}); + for (auto* block : empty_blocks) { dbgln_if(HEAP_DEBUG, " - HeapBlock empty @ {}: cell_size={}", block, block->cell_size()); allocator_for_size(block->cell_size()).block_did_become_empty({}, *block); @@ -264,9 +267,6 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure allocator_for_size(block->cell_size()).block_did_become_usable({}, *block); } - for (auto& weak_container : m_weak_containers) - weak_container.remove_dead_cells({}); - if constexpr (HEAP_DEBUG) { for_each_block([&](auto& block) { dbgln(" > Live HeapBlock @ {}: cell_size={}", &block, block.cell_size());