mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:57:34 +00:00
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:
parent
13138811df
commit
2495460f6e
1 changed files with 3 additions and 3 deletions
|
@ -254,6 +254,9 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (auto& weak_container : m_weak_containers)
|
||||||
|
weak_container.remove_dead_cells({});
|
||||||
|
|
||||||
for (auto* block : empty_blocks) {
|
for (auto* block : empty_blocks) {
|
||||||
dbgln_if(HEAP_DEBUG, " - HeapBlock empty @ {}: cell_size={}", block, block->cell_size());
|
dbgln_if(HEAP_DEBUG, " - HeapBlock empty @ {}: cell_size={}", block, block->cell_size());
|
||||||
allocator_for_size(block->cell_size()).block_did_become_empty({}, *block);
|
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);
|
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) {
|
if constexpr (HEAP_DEBUG) {
|
||||||
for_each_block([&](auto& block) {
|
for_each_block([&](auto& block) {
|
||||||
dbgln(" > Live HeapBlock @ {}: cell_size={}", &block, block.cell_size());
|
dbgln(" > Live HeapBlock @ {}: cell_size={}", &block, block.cell_size());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue