mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-03 04:50:29 +00:00
LibJS: Delete fully-empty HeapBlocks after garbage collection
We now deallocate GC blocks when they are found to have no live cells inside them.
This commit is contained in:
parent
bc002f807a
commit
2106dafd62
Notes:
sideshowbarker
2024-07-19 08:12:27 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2106dafd628
2 changed files with 23 additions and 0 deletions
8
Base/home/anon/js/gc-strings.js
Normal file
8
Base/home/anon/js/gc-strings.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
function foo() {
|
||||
var a = [];
|
||||
for (var i = 0; i < 4000; ++i) {
|
||||
a.push("string" + i);
|
||||
}
|
||||
}
|
||||
|
||||
foo();
|
|
@ -185,7 +185,10 @@ void Heap::sweep_dead_cells()
|
|||
#ifdef HEAP_DEBUG
|
||||
dbg() << "sweep_dead_cells:";
|
||||
#endif
|
||||
Vector<HeapBlock*, 32> empty_blocks;
|
||||
|
||||
for (auto& block : m_blocks) {
|
||||
bool block_has_live_cells = false;
|
||||
block->for_each_cell([&](Cell* cell) {
|
||||
if (cell->is_live()) {
|
||||
if (!cell->is_marked()) {
|
||||
|
@ -195,9 +198,21 @@ void Heap::sweep_dead_cells()
|
|||
block->deallocate(cell);
|
||||
} else {
|
||||
cell->set_marked(false);
|
||||
block_has_live_cells = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!block_has_live_cells)
|
||||
empty_blocks.append(block);
|
||||
}
|
||||
|
||||
for (auto* block : empty_blocks) {
|
||||
dbg() << " - Reclaim HeapBlock @ " << block << ": cell_size=" << block->cell_size();
|
||||
m_blocks.remove_first_matching([block](auto& entry) { return entry == block; });
|
||||
}
|
||||
|
||||
for (auto& block : m_blocks) {
|
||||
dbg() << " > Live HeapBlock @ " << block << ": cell_size=" << block->cell_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue