From 81a5dcde84cecb2e2be352a606325807abcce2dc Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 29 May 2021 06:24:30 -0600 Subject: [PATCH] LibJS: Expose minimum possible cell size of JS::Heap Use this to avoid creating a 16 byte cell allocator on x86_64, where the size of FreelistEntry is 24 bytes. Every JS::Cell must be at least the size of the FreelistEntry or things start crashing, so the 16 byte allocator was wasted on that platform. --- Userland/Libraries/LibJS/Heap/Heap.cpp | 5 ++++- Userland/Libraries/LibJS/Heap/HeapBlock.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp index 11042ea5e9..0f9501ee44 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.cpp +++ b/Userland/Libraries/LibJS/Heap/Heap.cpp @@ -23,7 +23,10 @@ namespace JS { Heap::Heap(VM& vm) : m_vm(vm) { - m_allocators.append(make(16)); + if constexpr (HeapBlock::min_possible_cell_size <= 16) { + m_allocators.append(make(16)); + } + static_assert(HeapBlock::min_possible_cell_size <= 24, "Heap Cell tracking uses too much data!"); m_allocators.append(make(32)); m_allocators.append(make(64)); m_allocators.append(make(128)); diff --git a/Userland/Libraries/LibJS/Heap/HeapBlock.h b/Userland/Libraries/LibJS/Heap/HeapBlock.h index 85a6307ae3..6b2c1eff12 100644 --- a/Userland/Libraries/LibJS/Heap/HeapBlock.h +++ b/Userland/Libraries/LibJS/Heap/HeapBlock.h @@ -101,6 +101,9 @@ private: size_t m_next_lazy_freelist_index { 0 }; FreelistEntry* m_freelist { nullptr }; alignas(Cell) u8 m_storage[]; + +public: + static constexpr size_t min_possible_cell_size = sizeof(FreelistEntry); }; }