mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:48:11 +00:00
LibJS: Add Cell::must_survive_garbage_collection() mechanism
This allows cells to prevent themselves from being garbage collected, even when there are no references to them.
This commit is contained in:
parent
8ace6b4f1d
commit
51579810bd
3 changed files with 24 additions and 4 deletions
|
@ -232,11 +232,18 @@ void Heap::mark_live_cells(HashTable<Cell*> const& roots)
|
|||
m_uprooted_cells.clear();
|
||||
}
|
||||
|
||||
bool Heap::cell_must_survive_garbage_collection(Cell const& cell)
|
||||
{
|
||||
if (!cell.overrides_must_survive_garbage_collection({}))
|
||||
return false;
|
||||
return cell.must_survive_garbage_collection();
|
||||
}
|
||||
|
||||
void Heap::finalize_unmarked_cells()
|
||||
{
|
||||
for_each_block([&](auto& block) {
|
||||
block.template for_each_cell_in_state<Cell::State::Live>([](Cell* cell) {
|
||||
if (!cell->is_marked())
|
||||
if (!cell->is_marked() && !cell_must_survive_garbage_collection(*cell))
|
||||
cell->finalize();
|
||||
});
|
||||
return IterationDecision::Continue;
|
||||
|
@ -258,7 +265,7 @@ void Heap::sweep_dead_cells(bool print_report, Core::ElapsedTimer const& measure
|
|||
bool block_has_live_cells = false;
|
||||
bool block_was_full = block.is_full();
|
||||
block.template for_each_cell_in_state<Cell::State::Live>([&](Cell* cell) {
|
||||
if (!cell->is_marked()) {
|
||||
if (!cell->is_marked() && !cell_must_survive_garbage_collection(*cell)) {
|
||||
dbgln_if(HEAP_DEBUG, " ~ {}", cell);
|
||||
block.deallocate(cell);
|
||||
++collected_cells;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue