LibGC: Add GC::Heap::the()

There's only ever one GC::Heap per process, so let's have a way to find
it even when you have no context.
This commit is contained in:
Andreas Kling 2025-11-01 07:55:29 +01:00 committed by Andreas Kling
parent 8b1f2e4e24
commit d234e9ee71
2 changed files with 10 additions and 0 deletions

View File

@ -30,10 +30,18 @@
namespace GC {
static Heap* s_the;
Heap& Heap::the()
{
return *s_the;
}
Heap::Heap(void* private_data, AK::Function<void(HashMap<Cell*, GC::HeapRoot>&)> gather_embedder_roots)
: HeapBase(private_data)
, m_gather_embedder_roots(move(gather_embedder_roots))
{
s_the = this;
static_assert(HeapBlock::min_possible_cell_size <= 32, "Heap Cell tracking uses too much data!");
m_size_based_cell_allocators.append(make<CellAllocator>(64));
m_size_based_cell_allocators.append(make<CellAllocator>(96));

View File

@ -38,6 +38,8 @@ public:
explicit Heap(void* private_data, AK::Function<void(HashMap<Cell*, GC::HeapRoot>&)> gather_embedder_roots);
~Heap();
static Heap& the();
template<typename T, typename... Args>
Ref<T> allocate(Args&&... args)
{