1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

LibJS: GC: Remove clear_all_mark_bits()

Clearing all marked flags has been integrated into the sweep function,
saving an additional full iteration over the heap.
This commit is contained in:
Stephan Unverwerth 2020-03-08 23:17:34 +01:00 committed by Andreas Kling
parent b956e2d939
commit 1207187e97
2 changed files with 7 additions and 14 deletions

View file

@ -66,7 +66,6 @@ void Heap::collect_garbage()
HashTable<Cell*> live_cells; HashTable<Cell*> live_cells;
visit_live_cells(roots, live_cells); visit_live_cells(roots, live_cells);
clear_all_mark_bits();
mark_live_cells(live_cells); mark_live_cells(live_cells);
sweep_dead_cells(); sweep_dead_cells();
} }
@ -114,15 +113,6 @@ void Heap::visit_live_cells(const HashTable<Cell*>& roots, HashTable<Cell*>& liv
#endif #endif
} }
void Heap::clear_all_mark_bits()
{
for (auto& block : m_blocks) {
block->for_each_cell([&](Cell* cell) {
cell->set_marked(false);
});
}
}
void Heap::mark_live_cells(const HashTable<Cell*>& live_cells) void Heap::mark_live_cells(const HashTable<Cell*>& live_cells)
{ {
#ifdef HEAP_DEBUG #ifdef HEAP_DEBUG
@ -147,11 +137,15 @@ void Heap::sweep_dead_cells()
#endif #endif
for (auto& block : m_blocks) { for (auto& block : m_blocks) {
block->for_each_cell([&](Cell* cell) { block->for_each_cell([&](Cell* cell) {
if (cell->is_live() && !cell->is_marked()) { if (cell->is_live()) {
if (!cell->is_marked()) {
#ifdef HEAP_DEBUG #ifdef HEAP_DEBUG
dbg() << " ~ " << cell; dbg() << " ~ " << cell;
#endif #endif
block->deallocate(cell); block->deallocate(cell);
} else {
cell->set_marked(false);
}
} }
}); });
} }

View file

@ -58,7 +58,6 @@ private:
void collect_roots(HashTable<Cell*>&); void collect_roots(HashTable<Cell*>&);
void visit_live_cells(const HashTable<Cell*>& roots, HashTable<Cell*>& live_cells); void visit_live_cells(const HashTable<Cell*>& roots, HashTable<Cell*>& live_cells);
void clear_all_mark_bits();
void mark_live_cells(const HashTable<Cell*>& live_cells); void mark_live_cells(const HashTable<Cell*>& live_cells);
void sweep_dead_cells(); void sweep_dead_cells();