Przeglądaj źródła

LibJS: Show class in SerenityOS mmap name for type-specific allocators

Andreas Kling 1 rok temu
rodzic
commit
ee3d09f225

+ 4 - 3
Userland/Libraries/LibJS/Heap/CellAllocator.cpp

@@ -12,8 +12,9 @@
 
 
 namespace JS {
 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);
         heap.register_cell_allocator({}, *this);
 
 
     if (m_usable_blocks.is_empty()) {
     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());
         m_usable_blocks.append(*block.leak_ptr());
     }
     }
 
 

+ 9 - 3
Userland/Libraries/LibJS/Heap/CellAllocator.h

@@ -17,13 +17,13 @@
     static JS::TypeIsolatingCellAllocator<ClassName> cell_allocator;
     static JS::TypeIsolatingCellAllocator<ClassName> cell_allocator;
 
 
 #define JS_DEFINE_ALLOCATOR(ClassName) \
 #define JS_DEFINE_ALLOCATOR(ClassName) \
-    JS::TypeIsolatingCellAllocator<ClassName> ClassName::cell_allocator;
+    JS::TypeIsolatingCellAllocator<ClassName> ClassName::cell_allocator { #ClassName };
 
 
 namespace JS {
 namespace JS {
 
 
 class CellAllocator {
 class CellAllocator {
 public:
 public:
-    explicit CellAllocator(size_t cell_size);
+    CellAllocator(size_t cell_size, char const* class_name = nullptr);
     ~CellAllocator() = default;
     ~CellAllocator() = default;
 
 
     size_t cell_size() const { return m_cell_size; }
     size_t cell_size() const { return m_cell_size; }
@@ -53,6 +53,7 @@ public:
     BlockAllocator& block_allocator() { return m_block_allocator; }
     BlockAllocator& block_allocator() { return m_block_allocator; }
 
 
 private:
 private:
+    char const* const m_class_name { nullptr };
     size_t const m_cell_size;
     size_t const m_cell_size;
 
 
     BlockAllocator m_block_allocator;
     BlockAllocator m_block_allocator;
@@ -67,7 +68,12 @@ class TypeIsolatingCellAllocator {
 public:
 public:
     using CellType = T;
     using CellType = T;
 
 
-    NeverDestroyed<CellAllocator> allocator { sizeof(T) };
+    TypeIsolatingCellAllocator(char const* class_name)
+        : allocator(sizeof(T), class_name)
+    {
+    }
+
+    NeverDestroyed<CellAllocator> allocator;
 };
 };
 
 
 }
 }

+ 5 - 2
Userland/Libraries/LibJS/Heap/HeapBlock.cpp

@@ -18,11 +18,14 @@
 
 
 namespace JS {
 namespace JS {
 
 
-NonnullOwnPtr<HeapBlock> HeapBlock::create_with_cell_size(Heap& heap, CellAllocator& cell_allocator, size_t cell_size)
+NonnullOwnPtr<HeapBlock> HeapBlock::create_with_cell_size(Heap& heap, CellAllocator& cell_allocator, size_t cell_size, [[maybe_unused]] char const* class_name)
 {
 {
 #ifdef AK_OS_SERENITY
 #ifdef AK_OS_SERENITY
     char name[64];
     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
 #else
     char const* name = nullptr;
     char const* name = nullptr;
 #endif
 #endif

+ 1 - 1
Userland/Libraries/LibJS/Heap/HeapBlock.h

@@ -26,7 +26,7 @@ class HeapBlock : public HeapBlockBase {
 
 
 public:
 public:
     using HeapBlockBase::block_size;
     using HeapBlockBase::block_size;
-    static NonnullOwnPtr<HeapBlock> create_with_cell_size(Heap&, CellAllocator&, size_t);
+    static NonnullOwnPtr<HeapBlock> 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_size() const { return m_cell_size; }
     size_t cell_count() const { return (block_size - sizeof(HeapBlock)) / m_cell_size; }
     size_t cell_count() const { return (block_size - sizeof(HeapBlock)) / m_cell_size; }