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

LibJS: Split Heap into per-cell-size allocators

Instead of keeping all the HeapBlocks in one big list, we now split it
into two levels:

- Heap has a set of Allocators, each with a specific cell size.
- Allocators have two lists of blocks, "full" and "usable".

Allocating a new cell no longer has to scan the entire set of blocks,
but instead just needs to find the right allocator and then pop a cell
from its freelist. If all the blocks in the allocator are full, a new
block will be created.

Blocks are moved from the "full" to "usable" list after sweeping has
determined that they are not completely empty and not completely full.

There are certainly many ways we can improve on this. This patch is
mostly about getting the new allocator architecture in place. :^)
This commit is contained in:
Andreas Kling 2020-10-06 18:50:47 +02:00
parent d3d3b25e1c
commit 48f13b7c3f
7 changed files with 226 additions and 27 deletions

View file

@ -33,6 +33,7 @@
#include <AK/Vector.h>
#include <LibCore/Forward.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Allocator.h>
#include <LibJS/Heap/Handle.h>
#include <LibJS/Runtime/Cell.h>
#include <LibJS/Runtime/Object.h>
@ -101,13 +102,25 @@ private:
Cell* cell_from_possible_pointer(FlatPtr);
Allocator& allocator_for_size(size_t);
template<typename Callback>
void for_each_block(Callback callback)
{
for (auto& allocator : m_allocators) {
if (allocator->for_each_block(callback) == IterationDecision::Break)
return;
}
}
size_t m_max_allocations_between_gc { 10000 };
size_t m_allocations_since_last_gc { false };
bool m_should_collect_on_every_allocation { false };
VM& m_vm;
Vector<NonnullOwnPtr<HeapBlock>> m_blocks;
Vector<NonnullOwnPtr<Allocator>> m_allocators;
HashTable<HandleImpl*> m_handles;
HashTable<MarkedValueList*> m_marked_value_lists;