diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2021-05-29 06:24:30 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-29 17:47:29 +0100 |
commit | 81a5dcde84cecb2e2be352a606325807abcce2dc (patch) | |
tree | af9e4fefbed3079090e545006398f95e8bda0a34 /Userland/Libraries | |
parent | 07c62f9f42f0591f6358f71b8e971550d1a183af (diff) | |
download | serenity-81a5dcde84cecb2e2be352a606325807abcce2dc.zip |
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Heap/Heap.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Heap/HeapBlock.h | 3 |
2 files changed, 7 insertions, 1 deletions
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<CellAllocator>(16)); + if constexpr (HeapBlock::min_possible_cell_size <= 16) { + m_allocators.append(make<CellAllocator>(16)); + } + static_assert(HeapBlock::min_possible_cell_size <= 24, "Heap Cell tracking uses too much data!"); m_allocators.append(make<CellAllocator>(32)); m_allocators.append(make<CellAllocator>(64)); m_allocators.append(make<CellAllocator>(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); }; } |