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.
This commit is contained in:
Andreas Kling 2021-10-08 19:47:25 +02:00
parent 13138811df
commit 2495460f6e
Notes: sideshowbarker 2024-07-18 02:55:33 +09:00

View file

@ -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());