diff --git a/Userland/Libraries/LibJS/Heap/CellAllocator.cpp b/Userland/Libraries/LibJS/Heap/CellAllocator.cpp index 6289c738011..7ba90f062cf 100644 --- a/Userland/Libraries/LibJS/Heap/CellAllocator.cpp +++ b/Userland/Libraries/LibJS/Heap/CellAllocator.cpp @@ -12,8 +12,9 @@ namespace JS { -CellAllocator::CellAllocator(size_t cell_size) - : m_cell_size(cell_size) +CellAllocator::CellAllocator(size_t cell_size, char const* class_name) + : m_class_name(class_name) + , m_cell_size(cell_size) { } @@ -23,7 +24,7 @@ Cell* CellAllocator::allocate_cell(Heap& heap) heap.register_cell_allocator({}, *this); if (m_usable_blocks.is_empty()) { - auto block = HeapBlock::create_with_cell_size(heap, *this, m_cell_size); + auto block = HeapBlock::create_with_cell_size(heap, *this, m_cell_size, m_class_name); m_usable_blocks.append(*block.leak_ptr()); } diff --git a/Userland/Libraries/LibJS/Heap/CellAllocator.h b/Userland/Libraries/LibJS/Heap/CellAllocator.h index cd835cc4b76..a7822e16c18 100644 --- a/Userland/Libraries/LibJS/Heap/CellAllocator.h +++ b/Userland/Libraries/LibJS/Heap/CellAllocator.h @@ -17,13 +17,13 @@ static JS::TypeIsolatingCellAllocator cell_allocator; #define JS_DEFINE_ALLOCATOR(ClassName) \ - JS::TypeIsolatingCellAllocator ClassName::cell_allocator; + JS::TypeIsolatingCellAllocator ClassName::cell_allocator { #ClassName }; namespace JS { class CellAllocator { public: - explicit CellAllocator(size_t cell_size); + CellAllocator(size_t cell_size, char const* class_name = nullptr); ~CellAllocator() = default; size_t cell_size() const { return m_cell_size; } @@ -53,6 +53,7 @@ public: BlockAllocator& block_allocator() { return m_block_allocator; } private: + char const* const m_class_name { nullptr }; size_t const m_cell_size; BlockAllocator m_block_allocator; @@ -67,7 +68,12 @@ class TypeIsolatingCellAllocator { public: using CellType = T; - NeverDestroyed allocator { sizeof(T) }; + TypeIsolatingCellAllocator(char const* class_name) + : allocator(sizeof(T), class_name) + { + } + + NeverDestroyed allocator; }; } diff --git a/Userland/Libraries/LibJS/Heap/HeapBlock.cpp b/Userland/Libraries/LibJS/Heap/HeapBlock.cpp index 8f5637be6c3..6f978e4a388 100644 --- a/Userland/Libraries/LibJS/Heap/HeapBlock.cpp +++ b/Userland/Libraries/LibJS/Heap/HeapBlock.cpp @@ -18,11 +18,14 @@ namespace JS { -NonnullOwnPtr HeapBlock::create_with_cell_size(Heap& heap, CellAllocator& cell_allocator, size_t cell_size) +NonnullOwnPtr HeapBlock::create_with_cell_size(Heap& heap, CellAllocator& cell_allocator, size_t cell_size, [[maybe_unused]] char const* class_name) { #ifdef AK_OS_SERENITY char name[64]; - snprintf(name, sizeof(name), "LibJS: HeapBlock(%zu)", cell_size); + if (class_name) + snprintf(name, sizeof(name), "LibJS: HeapBlock(%zu): %s", cell_size, class_name); + else + snprintf(name, sizeof(name), "LibJS: HeapBlock(%zu)", cell_size); #else char const* name = nullptr; #endif diff --git a/Userland/Libraries/LibJS/Heap/HeapBlock.h b/Userland/Libraries/LibJS/Heap/HeapBlock.h index b8e26338107..b0644dc3f60 100644 --- a/Userland/Libraries/LibJS/Heap/HeapBlock.h +++ b/Userland/Libraries/LibJS/Heap/HeapBlock.h @@ -26,7 +26,7 @@ class HeapBlock : public HeapBlockBase { public: using HeapBlockBase::block_size; - static NonnullOwnPtr create_with_cell_size(Heap&, CellAllocator&, size_t); + static NonnullOwnPtr create_with_cell_size(Heap&, CellAllocator&, size_t cell_size, char const* class_name); size_t cell_size() const { return m_cell_size; } size_t cell_count() const { return (block_size - sizeof(HeapBlock)) / m_cell_size; }