mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 23:12:08 +00:00
LibJS: Implement basic conservative garbage collection
We now scan the stack and CPU registers for potential pointers into the GC heap, and include any valid Cell pointers in the set of roots. This works pretty well but we'll also need to solve marking of things passed to native functions, since those are currently in Vector<Value> and the Vector storage is on the heap (not scanned.)
This commit is contained in:
parent
ad92a1e4bc
commit
ab404a2f88
3 changed files with 81 additions and 2 deletions
|
@ -61,6 +61,14 @@ public:
|
|||
return reinterpret_cast<HeapBlock*>((FlatPtr)cell & ~(block_size - 1));
|
||||
}
|
||||
|
||||
Cell* cell_from_possible_pointer(FlatPtr pointer)
|
||||
{
|
||||
if (pointer < reinterpret_cast<FlatPtr>(m_storage))
|
||||
return nullptr;
|
||||
size_t cell_index = (pointer - reinterpret_cast<FlatPtr>(m_storage)) / m_cell_size;
|
||||
return cell(cell_index);
|
||||
}
|
||||
|
||||
private:
|
||||
HeapBlock(Heap&, size_t cell_size);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue