1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibJS: Make it possible to go from a Cell* to its Heap&

This patch makes all HeapBlock allocations aligned to their block size,
enabling us to find the HeapBlock* for a given Cell* by simply masking
bits off of the cell address.

Use this to make a simple Heap& getter for Cell, which lets us avoid
plumbing the Heap& everywhere.
This commit is contained in:
Andreas Kling 2020-03-13 11:01:44 +01:00
parent d9c7009604
commit 6089d6566b
5 changed files with 44 additions and 7 deletions

View file

@ -53,10 +53,10 @@ Cell* Heap::allocate_cell(size_t size)
return cell;
}
auto* block = (HeapBlock*)malloc(HeapBlock::block_size);
new (block) HeapBlock(size);
m_blocks.append(NonnullOwnPtr<HeapBlock>(NonnullOwnPtr<HeapBlock>::Adopt, *block));
return block->allocate();
auto block = HeapBlock::create_with_cell_size(*this, size);
auto* cell = block->allocate();
m_blocks.append(move(block));
return cell;
}
void Heap::collect_garbage()