mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:12:43 +00:00 
			
		
		
		
	LibJS: Show class in SerenityOS mmap name for type-specific allocators
This commit is contained in:
		
							parent
							
								
									b6d4eea7ac
								
							
						
					
					
						commit
						ee3d09f225
					
				
					 4 changed files with 19 additions and 9 deletions
				
			
		|  | @ -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()); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -17,13 +17,13 @@ | |||
|     static JS::TypeIsolatingCellAllocator<ClassName> cell_allocator; | ||||
| 
 | ||||
| #define JS_DEFINE_ALLOCATOR(ClassName) \ | ||||
|     JS::TypeIsolatingCellAllocator<ClassName> ClassName::cell_allocator; | ||||
|     JS::TypeIsolatingCellAllocator<ClassName> 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<CellAllocator> allocator { sizeof(T) }; | ||||
|     TypeIsolatingCellAllocator(char const* class_name) | ||||
|         : allocator(sizeof(T), class_name) | ||||
|     { | ||||
|     } | ||||
| 
 | ||||
|     NeverDestroyed<CellAllocator> allocator; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -18,10 +18,13 @@ | |||
| 
 | ||||
| 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 | ||||
|     char name[64]; | ||||
|     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; | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ class HeapBlock : public HeapBlockBase { | |||
| 
 | ||||
| public: | ||||
|     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_count() const { return (block_size - sizeof(HeapBlock)) / m_cell_size; } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling