ladybird/Libraries/LibJS/Runtime/InterpreterStack.cpp
Andreas Kling 0c5e4ebc18 LibJS: Add InterpreterStack bump allocator for execution contexts
Add a managed bump allocator backed by an 8 MB mmap region to replace
alloca-based execution context allocation. Pages are committed on
demand by the OS, so only the memory actually touched is resident.

The InterpreterStack is stored as a member of VM and provides simple
LIFO allocation and deallocation of ExecutionContext frames.
2026-03-04 18:53:12 +01:00

25 lines
509 B
C++

/*
* Copyright (c) 2026, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/InterpreterStack.h>
#include <sys/mman.h>
namespace JS {
InterpreterStack::InterpreterStack()
{
m_base = mmap(nullptr, stack_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
VERIFY(m_base != MAP_FAILED);
m_top = m_base;
m_limit = static_cast<u8*>(m_base) + stack_size;
}
InterpreterStack::~InterpreterStack()
{
munmap(m_base, stack_size);
}
}