Renaming mem_* identifiers from 'camelCase' to 'underscore_naming'.

This commit is contained in:
Ruben Ayrapetyan
2014-07-23 12:21:07 +04:00
parent 2d4ed154ee
commit b3b4c74cbe
13 changed files with 307 additions and 307 deletions
+8 -8
View File
@@ -25,7 +25,7 @@
/** /**
* Area for heap * Area for heap
*/ */
static uint8_t mem_HeapArea[ MEM_HEAP_AREA_SIZE ] __attribute__((aligned(MEM_ALIGNMENT))); static uint8_t mem_heap_area[ MEM_HEAP_AREA_SIZE ] __attribute__((aligned(MEM_ALIGNMENT)));
/** /**
* Check that heap area is less or equal than 64K. * Check that heap area is less or equal than 64K.
@@ -36,17 +36,17 @@ JERRY_STATIC_ASSERT( MEM_HEAP_AREA_SIZE <= 64 * 1024 );
* Initialize memory allocators. * Initialize memory allocators.
*/ */
void void
mem_Init( void) mem_init( void)
{ {
mem_HeapInit( mem_HeapArea, sizeof (mem_HeapArea)); mem_heap_init( mem_heap_area, sizeof (mem_heap_area));
mem_PoolsInit(); mem_pools_init();
} /* mem_Init */ } /* mem_init */
/** /**
* Get base pointer for allocation area. * Get base pointer for allocation area.
*/ */
uintptr_t uintptr_t
mem_GetBasePointer( void) mem_get_base_pointer( void)
{ {
return (uintptr_t) mem_HeapArea; return (uintptr_t) mem_heap_area;
} /* mem_GetBasePointer */ } /* mem_get_base_pointer */
+2 -2
View File
@@ -36,8 +36,8 @@
*/ */
#define MEM_ALIGNMENT (1 << MEM_ALIGNMENT_LOG) #define MEM_ALIGNMENT (1 << MEM_ALIGNMENT_LOG)
extern void mem_Init(void); extern void mem_init(void);
uintptr_t mem_GetBasePointer(void); uintptr_t mem_get_base_pointer(void);
#endif /* !JERRY_MEM_ALLOCATOR_H */ #endif /* !JERRY_MEM_ALLOCATOR_H */
+155 -155
View File
@@ -36,18 +36,18 @@ typedef enum
{ {
MEM_MAGIC_NUM_OF_FREE_BLOCK = 0x31d7c809, MEM_MAGIC_NUM_OF_FREE_BLOCK = 0x31d7c809,
MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK = 0x59d75b46 MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK = 0x59d75b46
} mem_MagicNumOfBlock_t; } mem_magic_num_of_block_t;
/** /**
* State of the block to initialize (argument of mem_InitBlockHeader) * State of the block to initialize (argument of mem_init_block_header)
* *
* @see mem_InitBlockHeader * @see mem_init_block_header
*/ */
typedef enum typedef enum
{ {
MEM_BLOCK_FREE, /**< initializing free block */ MEM_BLOCK_FREE, /**< initializing free block */
MEM_BLOCK_ALLOCATED /**< initializing allocated block */ MEM_BLOCK_ALLOCATED /**< initializing allocated block */
} mem_BlockState_t; } mem_block_state_t;
/** /**
* Linked list direction descriptors * Linked list direction descriptors
@@ -57,23 +57,23 @@ typedef enum
MEM_DIRECTION_PREV = 0, /**< direction from right to left */ MEM_DIRECTION_PREV = 0, /**< direction from right to left */
MEM_DIRECTION_NEXT = 1, /**< direction from left to right */ MEM_DIRECTION_NEXT = 1, /**< direction from left to right */
MEM_DIRECTION_COUNT = 2 /**< count of possible directions */ MEM_DIRECTION_COUNT = 2 /**< count of possible directions */
} mem_Direction_t; } mem_direction_t;
/** /**
* Description of heap memory block layout * Description of heap memory block layout
*/ */
typedef struct mem_BlockHeader_t typedef struct mem_block_header_t
{ {
mem_MagicNumOfBlock_t MagicNum; /**< magic number - MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK for allocated block mem_magic_num_of_block_t MagicNum; /**< magic number - MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK for allocated block
and MEM_MAGIC_NUM_OF_FREE_BLOCK for free block */ and MEM_MAGIC_NUM_OF_FREE_BLOCK for free block */
struct mem_BlockHeader_t *Neighbours[ MEM_DIRECTION_COUNT ]; /**< neighbour blocks */ struct mem_block_header_t *Neighbours[ MEM_DIRECTION_COUNT ]; /**< neighbour blocks */
size_t allocated_bytes; /**< allocated area size - for allocated blocks; 0 - for free blocks */ size_t allocated_bytes; /**< allocated area size - for allocated blocks; 0 - for free blocks */
} mem_BlockHeader_t; } mem_block_header_t;
/** /**
* Chunk should have enough space for block header * Chunk should have enough space for block header
*/ */
JERRY_STATIC_ASSERT( MEM_HEAP_CHUNK_SIZE >= sizeof (mem_BlockHeader_t) ); JERRY_STATIC_ASSERT( MEM_HEAP_CHUNK_SIZE >= sizeof (mem_block_header_t) );
/** /**
* Chunk size should satisfy the required alignment value * Chunk size should satisfy the required alignment value
@@ -87,43 +87,43 @@ typedef struct
{ {
uint8_t* HeapStart; /**< first address of heap space */ uint8_t* HeapStart; /**< first address of heap space */
size_t HeapSize; /**< heap space size */ size_t HeapSize; /**< heap space size */
mem_BlockHeader_t* pFirstBlock; /**< first block of the heap */ mem_block_header_t* pFirstBlock; /**< first block of the heap */
mem_BlockHeader_t* pLastBlock; /**< last block of the heap */ mem_block_header_t* pLastBlock; /**< last block of the heap */
} mem_HeapState_t; } mem_heap_state_t;
/** /**
* Heap state * Heap state
*/ */
mem_HeapState_t mem_Heap; mem_heap_state_t mem_heap;
static size_t mem_get_block_chunks_count( const mem_BlockHeader_t *block_header_p); static size_t mem_get_block_chunks_count( const mem_block_header_t *block_header_p);
static size_t mem_get_block_data_space_size( const mem_BlockHeader_t *block_header_p); static size_t mem_get_block_data_space_size( const mem_block_header_t *block_header_p);
static size_t mem_get_block_chunks_count_from_data_size( size_t block_allocated_size); static size_t mem_get_block_chunks_count_from_data_size( size_t block_allocated_size);
static void mem_InitBlockHeader( uint8_t *pFirstChunk, static void mem_init_block_header( uint8_t *pFirstChunk,
size_t sizeInChunks, size_t sizeInChunks,
mem_BlockState_t blockState, mem_block_state_t blockState,
mem_BlockHeader_t *pPrevBlock, mem_block_header_t *pPrevBlock,
mem_BlockHeader_t *pNextBlock); mem_block_header_t *pNextBlock);
static void mem_CheckHeap( void); static void mem_check_heap( void);
#ifdef MEM_STATS #ifdef MEM_STATS
/** /**
* Heap's memory usage statistics * Heap's memory usage statistics
*/ */
static mem_HeapStats_t mem_HeapStats; static mem_heap_stats_t mem_heap_stats;
static void mem_HeapStatInit( void); static void mem_heap_stat_init( void);
static void mem_HeapStatAllocBlock( mem_BlockHeader_t *block_header_p); static void mem_heap_stat_alloc_block( mem_block_header_t *block_header_p);
static void mem_HeapStatFreeBlock( mem_BlockHeader_t *block_header_p); static void mem_heap_stat_free_block( mem_block_header_t *block_header_p);
static void mem_HeapStatFreeBlockSplit( void); static void mem_heap_stat_free_block_split( void);
static void mem_HeapStatFreeBlockMerge( void); static void mem_heap_stat_free_block_merge( void);
#else /* !MEM_STATS */ #else /* !MEM_STATS */
# define mem_HeapStatInit() # define mem_heap_stat_init()
# define mem_HeapStatAllocBlock( v) # define mem_heap_stat_alloc_block( v)
# define mem_HeapStatFreeBlock( v) # define mem_heap_stat_free_block( v)
# define mem_HeapStatFreeBlockSplit() # define mem_heap_stat_free_block_split()
# define mem_HeapStatFreeBlockMerge() # define mem_heap_stat_free_block_merge()
#endif /* !MEM_STATS */ #endif /* !MEM_STATS */
/** /**
@@ -132,22 +132,22 @@ static void mem_HeapStatFreeBlockMerge( void);
* @return chunks count * @return chunks count
*/ */
static size_t static size_t
mem_get_block_chunks_count( const mem_BlockHeader_t *block_header_p) /**< block header */ mem_get_block_chunks_count( const mem_block_header_t *block_header_p) /**< block header */
{ {
JERRY_ASSERT( block_header_p != NULL ); JERRY_ASSERT( block_header_p != NULL );
const mem_BlockHeader_t *next_block_p = block_header_p->Neighbours[ MEM_DIRECTION_NEXT ]; const mem_block_header_t *next_block_p = block_header_p->Neighbours[ MEM_DIRECTION_NEXT ];
size_t dist_till_block_end; size_t dist_till_block_end;
if ( next_block_p == NULL ) if ( next_block_p == NULL )
{ {
dist_till_block_end = (size_t) ( mem_Heap.HeapStart + mem_Heap.HeapSize - (uint8_t*) block_header_p ); dist_till_block_end = (size_t) ( mem_heap.HeapStart + mem_heap.HeapSize - (uint8_t*) block_header_p );
} else } else
{ {
dist_till_block_end = (size_t) ( (uint8_t*) next_block_p - (uint8_t*) block_header_p ); dist_till_block_end = (size_t) ( (uint8_t*) next_block_p - (uint8_t*) block_header_p );
} }
JERRY_ASSERT( dist_till_block_end <= mem_Heap.HeapSize ); JERRY_ASSERT( dist_till_block_end <= mem_heap.HeapSize );
JERRY_ASSERT( dist_till_block_end % MEM_HEAP_CHUNK_SIZE == 0 ); JERRY_ASSERT( dist_till_block_end % MEM_HEAP_CHUNK_SIZE == 0 );
return dist_till_block_end / MEM_HEAP_CHUNK_SIZE; return dist_till_block_end / MEM_HEAP_CHUNK_SIZE;
@@ -159,9 +159,9 @@ mem_get_block_chunks_count( const mem_BlockHeader_t *block_header_p) /**< block
* @return size of block area that can be used to store data * @return size of block area that can be used to store data
*/ */
static size_t static size_t
mem_get_block_data_space_size( const mem_BlockHeader_t *block_header_p) /**< block header */ mem_get_block_data_space_size( const mem_block_header_t *block_header_p) /**< block header */
{ {
return mem_get_block_chunks_count( block_header_p) * MEM_HEAP_CHUNK_SIZE - sizeof (mem_BlockHeader_t); return mem_get_block_chunks_count( block_header_p) * MEM_HEAP_CHUNK_SIZE - sizeof (mem_block_header_t);
} /* mem_get_block_data_space_size */ } /* mem_get_block_data_space_size */
/** /**
@@ -172,14 +172,14 @@ mem_get_block_data_space_size( const mem_BlockHeader_t *block_header_p) /**< blo
static size_t static size_t
mem_get_block_chunks_count_from_data_size( size_t block_allocated_size) /**< size of block's allocated area */ mem_get_block_chunks_count_from_data_size( size_t block_allocated_size) /**< size of block's allocated area */
{ {
return JERRY_ALIGNUP( sizeof (mem_BlockHeader_t) + block_allocated_size, MEM_HEAP_CHUNK_SIZE) / MEM_HEAP_CHUNK_SIZE; return JERRY_ALIGNUP( sizeof (mem_block_header_t) + block_allocated_size, MEM_HEAP_CHUNK_SIZE) / MEM_HEAP_CHUNK_SIZE;
} /* mem_get_block_chunks_count_from_data_size */ } /* mem_get_block_chunks_count_from_data_size */
/** /**
* Startup initialization of heap * Startup initialization of heap
*/ */
void void
mem_HeapInit(uint8_t *heapStart, /**< first address of heap space */ mem_heap_init(uint8_t *heapStart, /**< first address of heap space */
size_t heapSize) /**< heap space size */ size_t heapSize) /**< heap space size */
{ {
JERRY_ASSERT( heapStart != NULL ); JERRY_ASSERT( heapStart != NULL );
@@ -187,32 +187,32 @@ mem_HeapInit(uint8_t *heapStart, /**< first address of heap space */
JERRY_ASSERT( heapSize % MEM_HEAP_CHUNK_SIZE == 0 ); JERRY_ASSERT( heapSize % MEM_HEAP_CHUNK_SIZE == 0 );
JERRY_ASSERT( (uintptr_t) heapStart % MEM_ALIGNMENT == 0); JERRY_ASSERT( (uintptr_t) heapStart % MEM_ALIGNMENT == 0);
mem_Heap.HeapStart = heapStart; mem_heap.HeapStart = heapStart;
mem_Heap.HeapSize = heapSize; mem_heap.HeapSize = heapSize;
mem_InitBlockHeader(mem_Heap.HeapStart, mem_init_block_header(mem_heap.HeapStart,
0, 0,
MEM_BLOCK_FREE, MEM_BLOCK_FREE,
NULL, NULL,
NULL); NULL);
mem_Heap.pFirstBlock = (mem_BlockHeader_t*) mem_Heap.HeapStart; mem_heap.pFirstBlock = (mem_block_header_t*) mem_heap.HeapStart;
mem_Heap.pLastBlock = mem_Heap.pFirstBlock; mem_heap.pLastBlock = mem_heap.pFirstBlock;
mem_HeapStatInit(); mem_heap_stat_init();
} /* mem_HeapInit */ } /* mem_heap_init */
/** /**
* Initialize block header * Initialize block header
*/ */
static void static void
mem_InitBlockHeader( uint8_t *pFirstChunk, /**< address of the first chunk to use for the block */ mem_init_block_header( uint8_t *pFirstChunk, /**< address of the first chunk to use for the block */
size_t allocated_bytes, /**< size of block's allocated area */ size_t allocated_bytes, /**< size of block's allocated area */
mem_BlockState_t blockState, /**< state of the block (allocated or free) */ mem_block_state_t blockState, /**< state of the block (allocated or free) */
mem_BlockHeader_t *pPrevBlock, /**< previous block */ mem_block_header_t *pPrevBlock, /**< previous block */
mem_BlockHeader_t *pNextBlock) /**< next block */ mem_block_header_t *pNextBlock) /**< next block */
{ {
mem_BlockHeader_t *pBlockHeader = (mem_BlockHeader_t*) pFirstChunk; mem_block_header_t *pBlockHeader = (mem_block_header_t*) pFirstChunk;
if ( blockState == MEM_BLOCK_FREE ) if ( blockState == MEM_BLOCK_FREE )
{ {
@@ -229,7 +229,7 @@ mem_InitBlockHeader( uint8_t *pFirstChunk, /**< address of the first chu
pBlockHeader->allocated_bytes = allocated_bytes; pBlockHeader->allocated_bytes = allocated_bytes;
JERRY_ASSERT( allocated_bytes <= mem_get_block_data_space_size( pBlockHeader) ); JERRY_ASSERT( allocated_bytes <= mem_get_block_data_space_size( pBlockHeader) );
} /* mem_InitBlockHeader */ } /* mem_init_block_header */
/** /**
* Allocation of memory region. * Allocation of memory region.
@@ -245,21 +245,21 @@ mem_InitBlockHeader( uint8_t *pFirstChunk, /**< address of the first chu
* NULL - if there is not enough memory. * NULL - if there is not enough memory.
*/ */
uint8_t* uint8_t*
mem_HeapAllocBlock( size_t sizeInBytes, /**< size of region to allocate in bytes */ mem_heap_alloc_block( size_t sizeInBytes, /**< size of region to allocate in bytes */
mem_HeapAllocTerm_t allocTerm) /**< expected allocation term */ mem_heap_alloc_term_t allocTerm) /**< expected allocation term */
{ {
mem_BlockHeader_t *pBlock; mem_block_header_t *pBlock;
mem_Direction_t direction; mem_direction_t direction;
mem_CheckHeap(); mem_check_heap();
if ( allocTerm == MEM_HEAP_ALLOC_SHORT_TERM ) if ( allocTerm == MEM_HEAP_ALLOC_SHORT_TERM )
{ {
pBlock = mem_Heap.pFirstBlock; pBlock = mem_heap.pFirstBlock;
direction = MEM_DIRECTION_NEXT; direction = MEM_DIRECTION_NEXT;
} else } else
{ {
pBlock = mem_Heap.pLastBlock; pBlock = mem_heap.pLastBlock;
direction = MEM_DIRECTION_PREV; direction = MEM_DIRECTION_PREV;
} }
@@ -292,66 +292,66 @@ mem_HeapAllocBlock( size_t sizeInBytes, /**< size of region to allocat
JERRY_ASSERT( newBlockSizeInChunks <= foundBlockSizeInChunks ); JERRY_ASSERT( newBlockSizeInChunks <= foundBlockSizeInChunks );
mem_BlockHeader_t *pPrevBlock = pBlock->Neighbours[ MEM_DIRECTION_PREV ]; mem_block_header_t *pPrevBlock = pBlock->Neighbours[ MEM_DIRECTION_PREV ];
mem_BlockHeader_t *pNextBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ]; mem_block_header_t *pNextBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ];
if ( newBlockSizeInChunks < foundBlockSizeInChunks ) if ( newBlockSizeInChunks < foundBlockSizeInChunks )
{ {
mem_HeapStatFreeBlockSplit(); mem_heap_stat_free_block_split();
uint8_t *pNewFreeBlockFirstChunk = (uint8_t*) pBlock + newBlockSizeInChunks * MEM_HEAP_CHUNK_SIZE; uint8_t *pNewFreeBlockFirstChunk = (uint8_t*) pBlock + newBlockSizeInChunks * MEM_HEAP_CHUNK_SIZE;
mem_InitBlockHeader(pNewFreeBlockFirstChunk, mem_init_block_header(pNewFreeBlockFirstChunk,
0, 0,
MEM_BLOCK_FREE, MEM_BLOCK_FREE,
pBlock /* there we will place new allocated block */, pBlock /* there we will place new allocated block */,
pNextBlock); pNextBlock);
mem_BlockHeader_t *pNewFreeBlock = (mem_BlockHeader_t*) pNewFreeBlockFirstChunk; mem_block_header_t *pNewFreeBlock = (mem_block_header_t*) pNewFreeBlockFirstChunk;
if ( pNextBlock == NULL ) if ( pNextBlock == NULL )
{ {
mem_Heap.pLastBlock = pNewFreeBlock; mem_heap.pLastBlock = pNewFreeBlock;
} }
pNextBlock = pNewFreeBlock; pNextBlock = pNewFreeBlock;
} }
mem_InitBlockHeader((uint8_t*) pBlock, mem_init_block_header((uint8_t*) pBlock,
sizeInBytes, sizeInBytes,
MEM_BLOCK_ALLOCATED, MEM_BLOCK_ALLOCATED,
pPrevBlock, pPrevBlock,
pNextBlock); pNextBlock);
mem_HeapStatAllocBlock( pBlock); mem_heap_stat_alloc_block( pBlock);
JERRY_ASSERT( mem_get_block_data_space_size( pBlock) >= sizeInBytes ); JERRY_ASSERT( mem_get_block_data_space_size( pBlock) >= sizeInBytes );
mem_CheckHeap(); mem_check_heap();
/* return data space beginning address */ /* return data space beginning address */
uint8_t *pDataSpace = (uint8_t*) (pBlock + 1); uint8_t *pDataSpace = (uint8_t*) (pBlock + 1);
JERRY_ASSERT( (uintptr_t) pDataSpace % MEM_ALIGNMENT == 0); JERRY_ASSERT( (uintptr_t) pDataSpace % MEM_ALIGNMENT == 0);
return pDataSpace; return pDataSpace;
} /* mem_HeapAllocBlock */ } /* mem_heap_alloc_block */
/** /**
* Free the memory block. * Free the memory block.
*/ */
void void
mem_HeapFreeBlock( uint8_t *ptr) /**< pointer to beginning of data space of the block */ mem_heap_free_block( uint8_t *ptr) /**< pointer to beginning of data space of the block */
{ {
/* checking that ptr points to the heap */ /* checking that ptr points to the heap */
JERRY_ASSERT( ptr >= mem_Heap.HeapStart JERRY_ASSERT( ptr >= mem_heap.HeapStart
&& ptr <= mem_Heap.HeapStart + mem_Heap.HeapSize ); && ptr <= mem_heap.HeapStart + mem_heap.HeapSize );
mem_CheckHeap(); mem_check_heap();
mem_BlockHeader_t *pBlock = (mem_BlockHeader_t*) ptr - 1; mem_block_header_t *pBlock = (mem_block_header_t*) ptr - 1;
mem_BlockHeader_t *pPrevBlock = pBlock->Neighbours[ MEM_DIRECTION_PREV ]; mem_block_header_t *pPrevBlock = pBlock->Neighbours[ MEM_DIRECTION_PREV ];
mem_BlockHeader_t *pNextBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ]; mem_block_header_t *pNextBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ];
mem_HeapStatFreeBlock( pBlock); mem_heap_stat_free_block( pBlock);
/* checking magic nums that are neighbour to data space */ /* checking magic nums that are neighbour to data space */
JERRY_ASSERT( pBlock->MagicNum == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK ); JERRY_ASSERT( pBlock->MagicNum == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
@@ -367,7 +367,7 @@ mem_HeapFreeBlock( uint8_t *ptr) /**< pointer to beginning of data space of the
&& pNextBlock->MagicNum == MEM_MAGIC_NUM_OF_FREE_BLOCK ) && pNextBlock->MagicNum == MEM_MAGIC_NUM_OF_FREE_BLOCK )
{ {
/* merge with the next block */ /* merge with the next block */
mem_HeapStatFreeBlockMerge(); mem_heap_stat_free_block_merge();
pNextBlock = pNextBlock->Neighbours[ MEM_DIRECTION_NEXT ]; pNextBlock = pNextBlock->Neighbours[ MEM_DIRECTION_NEXT ];
pBlock->Neighbours[ MEM_DIRECTION_NEXT ] = pNextBlock; pBlock->Neighbours[ MEM_DIRECTION_NEXT ] = pNextBlock;
@@ -376,7 +376,7 @@ mem_HeapFreeBlock( uint8_t *ptr) /**< pointer to beginning of data space of the
pNextBlock->Neighbours[ MEM_DIRECTION_PREV ] = pBlock; pNextBlock->Neighbours[ MEM_DIRECTION_PREV ] = pBlock;
} else } else
{ {
mem_Heap.pLastBlock = pBlock; mem_heap.pLastBlock = pBlock;
} }
} }
@@ -384,7 +384,7 @@ mem_HeapFreeBlock( uint8_t *ptr) /**< pointer to beginning of data space of the
&& pPrevBlock->MagicNum == MEM_MAGIC_NUM_OF_FREE_BLOCK ) && pPrevBlock->MagicNum == MEM_MAGIC_NUM_OF_FREE_BLOCK )
{ {
/* merge with the previous block */ /* merge with the previous block */
mem_HeapStatFreeBlockMerge(); mem_heap_stat_free_block_merge();
pPrevBlock->Neighbours[ MEM_DIRECTION_NEXT ] = pNextBlock; pPrevBlock->Neighbours[ MEM_DIRECTION_NEXT ] = pNextBlock;
if ( pNextBlock != NULL ) if ( pNextBlock != NULL )
@@ -392,12 +392,12 @@ mem_HeapFreeBlock( uint8_t *ptr) /**< pointer to beginning of data space of the
pNextBlock->Neighbours[ MEM_DIRECTION_PREV ] = pBlock->Neighbours[ MEM_DIRECTION_PREV ]; pNextBlock->Neighbours[ MEM_DIRECTION_PREV ] = pBlock->Neighbours[ MEM_DIRECTION_PREV ];
} else } else
{ {
mem_Heap.pLastBlock = pPrevBlock; mem_heap.pLastBlock = pPrevBlock;
} }
} }
mem_CheckHeap(); mem_check_heap();
} /* mem_HeapFreeBlock */ } /* mem_heap_free_block */
/** /**
* Recommend allocation size based on chunk size. * Recommend allocation size based on chunk size.
@@ -405,30 +405,30 @@ mem_HeapFreeBlock( uint8_t *ptr) /**< pointer to beginning of data space of the
* @return recommended allocation size * @return recommended allocation size
*/ */
size_t size_t
mem_HeapRecommendAllocationSize( size_t minimumAllocationSize) /**< minimum allocation size */ mem_heap_recommend_allocation_size( size_t minimumAllocationSize) /**< minimum allocation size */
{ {
size_t minimumAllocationSizeWithBlockHeader = minimumAllocationSize + sizeof (mem_BlockHeader_t); size_t minimumAllocationSizeWithBlockHeader = minimumAllocationSize + sizeof (mem_block_header_t);
size_t heapChunkAlignedAllocationSize = JERRY_ALIGNUP( minimumAllocationSizeWithBlockHeader, MEM_HEAP_CHUNK_SIZE); size_t heapChunkAlignedAllocationSize = JERRY_ALIGNUP( minimumAllocationSizeWithBlockHeader, MEM_HEAP_CHUNK_SIZE);
return heapChunkAlignedAllocationSize - sizeof (mem_BlockHeader_t); return heapChunkAlignedAllocationSize - sizeof (mem_block_header_t);
} /* mem_HeapRecommendAllocationSize */ } /* mem_heap_recommend_allocation_size */
/** /**
* Print heap * Print heap
*/ */
void void
mem_HeapPrint( bool dumpBlockData) /**< print block with data (true) mem_heap_print( bool dumpBlockData) /**< print block with data (true)
or print only block header (false) */ or print only block header (false) */
{ {
mem_CheckHeap(); mem_check_heap();
__printf("Heap: start=%p size=%lu, first block->%p, last block->%p\n", __printf("Heap: start=%p size=%lu, first block->%p, last block->%p\n",
mem_Heap.HeapStart, mem_heap.HeapStart,
mem_Heap.HeapSize, mem_heap.HeapSize,
(void*) mem_Heap.pFirstBlock, (void*) mem_heap.pFirstBlock,
(void*) mem_Heap.pLastBlock); (void*) mem_heap.pLastBlock);
for ( mem_BlockHeader_t *pBlock = mem_Heap.pFirstBlock; for ( mem_block_header_t *pBlock = mem_heap.pFirstBlock;
pBlock != NULL; pBlock != NULL;
pBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ] ) pBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ] )
{ {
@@ -464,16 +464,16 @@ mem_HeapPrint( bool dumpBlockData) /**< print block with data (true)
" Peak allocated chunks count = %lu\n" " Peak allocated chunks count = %lu\n"
" Peak allocated bytes count = %lu\n" " Peak allocated bytes count = %lu\n"
" Peak waste bytes count = %lu\n", " Peak waste bytes count = %lu\n",
mem_HeapStats.size, mem_heap_stats.size,
mem_HeapStats.blocks, mem_heap_stats.blocks,
mem_HeapStats.allocated_blocks, mem_heap_stats.allocated_blocks,
mem_HeapStats.allocated_chunks, mem_heap_stats.allocated_chunks,
mem_HeapStats.allocated_bytes, mem_heap_stats.allocated_bytes,
mem_HeapStats.waste_bytes, mem_heap_stats.waste_bytes,
mem_HeapStats.peak_allocated_blocks, mem_heap_stats.peak_allocated_blocks,
mem_HeapStats.peak_allocated_chunks, mem_heap_stats.peak_allocated_chunks,
mem_HeapStats.peak_allocated_bytes, mem_heap_stats.peak_allocated_bytes,
mem_HeapStats.peak_waste_bytes); mem_heap_stats.peak_waste_bytes);
#endif /* MEM_STATS */ #endif /* MEM_STATS */
__printf("\n"); __printf("\n");
@@ -483,14 +483,14 @@ mem_HeapPrint( bool dumpBlockData) /**< print block with data (true)
* Check heap consistency * Check heap consistency
*/ */
static void static void
mem_CheckHeap( void) mem_check_heap( void)
{ {
#ifndef JERRY_NDEBUG #ifndef JERRY_NDEBUG
JERRY_ASSERT( (uint8_t*) mem_Heap.pFirstBlock == mem_Heap.HeapStart ); JERRY_ASSERT( (uint8_t*) mem_heap.pFirstBlock == mem_heap.HeapStart );
JERRY_ASSERT( mem_Heap.HeapSize % MEM_HEAP_CHUNK_SIZE == 0 ); JERRY_ASSERT( mem_heap.HeapSize % MEM_HEAP_CHUNK_SIZE == 0 );
bool isLastBlockWasMet = false; bool isLastBlockWasMet = false;
for ( mem_BlockHeader_t *pBlock = mem_Heap.pFirstBlock; for ( mem_block_header_t *pBlock = mem_heap.pFirstBlock;
pBlock != NULL; pBlock != NULL;
pBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ] ) pBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ] )
{ {
@@ -498,8 +498,8 @@ mem_CheckHeap( void)
JERRY_ASSERT( pBlock->MagicNum == MEM_MAGIC_NUM_OF_FREE_BLOCK JERRY_ASSERT( pBlock->MagicNum == MEM_MAGIC_NUM_OF_FREE_BLOCK
|| pBlock->MagicNum == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK ); || pBlock->MagicNum == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
mem_BlockHeader_t *pNextBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ]; mem_block_header_t *pNextBlock = pBlock->Neighbours[ MEM_DIRECTION_NEXT ];
if ( pBlock == mem_Heap.pLastBlock ) if ( pBlock == mem_heap.pLastBlock )
{ {
isLastBlockWasMet = true; isLastBlockWasMet = true;
@@ -512,35 +512,35 @@ mem_CheckHeap( void)
JERRY_ASSERT( isLastBlockWasMet ); JERRY_ASSERT( isLastBlockWasMet );
#endif /* !JERRY_NDEBUG */ #endif /* !JERRY_NDEBUG */
} /* mem_CheckHeap */ } /* mem_check_heap */
#ifdef MEM_STATS #ifdef MEM_STATS
/** /**
* Get heap memory usage statistics * Get heap memory usage statistics
*/ */
void void
mem_HeapGetStats( mem_HeapStats_t *out_heap_stats_p) /**< out: heap stats */ mem_heap_get_stats( mem_heap_stats_t *out_heap_stats_p) /**< out: heap stats */
{ {
*out_heap_stats_p = mem_HeapStats; *out_heap_stats_p = mem_heap_stats;
} /* mem_HeapGetStats */ } /* mem_heap_get_stats */
/** /**
* Initalize heap memory usage statistics account structure * Initalize heap memory usage statistics account structure
*/ */
static void static void
mem_HeapStatInit() mem_heap_stat_init()
{ {
__memset( &mem_HeapStats, 0, sizeof (mem_HeapStats)); __memset( &mem_heap_stats, 0, sizeof (mem_heap_stats));
mem_HeapStats.size = mem_Heap.HeapSize; mem_heap_stats.size = mem_heap.HeapSize;
mem_HeapStats.blocks = 1; mem_heap_stats.blocks = 1;
} /* mem_InitStats */ } /* mem_InitStats */
/** /**
* Account block allocation * Account block allocation
*/ */
static void static void
mem_HeapStatAllocBlock( mem_BlockHeader_t *block_header_p) /**< allocated block */ mem_heap_stat_alloc_block( mem_block_header_t *block_header_p) /**< allocated block */
{ {
JERRY_ASSERT( block_header_p->MagicNum == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK ); JERRY_ASSERT( block_header_p->MagicNum == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
@@ -548,41 +548,41 @@ mem_HeapStatAllocBlock( mem_BlockHeader_t *block_header_p) /**< allocated block
const size_t bytes = block_header_p->allocated_bytes; const size_t bytes = block_header_p->allocated_bytes;
const size_t waste_bytes = chunks * MEM_HEAP_CHUNK_SIZE - bytes; const size_t waste_bytes = chunks * MEM_HEAP_CHUNK_SIZE - bytes;
mem_HeapStats.allocated_blocks++; mem_heap_stats.allocated_blocks++;
mem_HeapStats.allocated_chunks += chunks; mem_heap_stats.allocated_chunks += chunks;
mem_HeapStats.allocated_bytes += bytes; mem_heap_stats.allocated_bytes += bytes;
mem_HeapStats.waste_bytes += waste_bytes; mem_heap_stats.waste_bytes += waste_bytes;
if ( mem_HeapStats.allocated_blocks > mem_HeapStats.peak_allocated_blocks ) if ( mem_heap_stats.allocated_blocks > mem_heap_stats.peak_allocated_blocks )
{ {
mem_HeapStats.peak_allocated_blocks = mem_HeapStats.allocated_blocks; mem_heap_stats.peak_allocated_blocks = mem_heap_stats.allocated_blocks;
} }
if ( mem_HeapStats.allocated_chunks > mem_HeapStats.peak_allocated_chunks ) if ( mem_heap_stats.allocated_chunks > mem_heap_stats.peak_allocated_chunks )
{ {
mem_HeapStats.peak_allocated_chunks = mem_HeapStats.allocated_chunks; mem_heap_stats.peak_allocated_chunks = mem_heap_stats.allocated_chunks;
} }
if ( mem_HeapStats.allocated_bytes > mem_HeapStats.peak_allocated_bytes ) if ( mem_heap_stats.allocated_bytes > mem_heap_stats.peak_allocated_bytes )
{ {
mem_HeapStats.peak_allocated_bytes = mem_HeapStats.allocated_bytes; mem_heap_stats.peak_allocated_bytes = mem_heap_stats.allocated_bytes;
} }
if ( mem_HeapStats.waste_bytes > mem_HeapStats.peak_waste_bytes ) if ( mem_heap_stats.waste_bytes > mem_heap_stats.peak_waste_bytes )
{ {
mem_HeapStats.peak_waste_bytes = mem_HeapStats.waste_bytes; mem_heap_stats.peak_waste_bytes = mem_heap_stats.waste_bytes;
} }
JERRY_ASSERT( mem_HeapStats.allocated_blocks <= mem_HeapStats.blocks ); JERRY_ASSERT( mem_heap_stats.allocated_blocks <= mem_heap_stats.blocks );
JERRY_ASSERT( mem_HeapStats.allocated_bytes <= mem_HeapStats.size ); JERRY_ASSERT( mem_heap_stats.allocated_bytes <= mem_heap_stats.size );
JERRY_ASSERT( mem_HeapStats.allocated_chunks <= mem_HeapStats.size / MEM_HEAP_CHUNK_SIZE ); JERRY_ASSERT( mem_heap_stats.allocated_chunks <= mem_heap_stats.size / MEM_HEAP_CHUNK_SIZE );
} /* mem_HeapStatAllocBlock */ } /* mem_heap_stat_alloc_block */
/** /**
* Account block freeing * Account block freeing
*/ */
static void static void
mem_HeapStatFreeBlock( mem_BlockHeader_t *block_header_p) /**< block to be freed */ mem_heap_stat_free_block( mem_block_header_t *block_header_p) /**< block to be freed */
{ {
JERRY_ASSERT( block_header_p->MagicNum == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK ); JERRY_ASSERT( block_header_p->MagicNum == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
@@ -590,38 +590,38 @@ mem_HeapStatFreeBlock( mem_BlockHeader_t *block_header_p) /**< block to be freed
const size_t bytes = block_header_p->allocated_bytes; const size_t bytes = block_header_p->allocated_bytes;
const size_t waste_bytes = chunks * MEM_HEAP_CHUNK_SIZE - bytes; const size_t waste_bytes = chunks * MEM_HEAP_CHUNK_SIZE - bytes;
JERRY_ASSERT( mem_HeapStats.allocated_blocks <= mem_HeapStats.blocks ); JERRY_ASSERT( mem_heap_stats.allocated_blocks <= mem_heap_stats.blocks );
JERRY_ASSERT( mem_HeapStats.allocated_bytes <= mem_HeapStats.size ); JERRY_ASSERT( mem_heap_stats.allocated_bytes <= mem_heap_stats.size );
JERRY_ASSERT( mem_HeapStats.allocated_chunks <= mem_HeapStats.size / MEM_HEAP_CHUNK_SIZE ); JERRY_ASSERT( mem_heap_stats.allocated_chunks <= mem_heap_stats.size / MEM_HEAP_CHUNK_SIZE );
JERRY_ASSERT( mem_HeapStats.allocated_blocks >= 1 ); JERRY_ASSERT( mem_heap_stats.allocated_blocks >= 1 );
JERRY_ASSERT( mem_HeapStats.allocated_chunks >= chunks ); JERRY_ASSERT( mem_heap_stats.allocated_chunks >= chunks );
JERRY_ASSERT( mem_HeapStats.allocated_bytes >= bytes ); JERRY_ASSERT( mem_heap_stats.allocated_bytes >= bytes );
JERRY_ASSERT( mem_HeapStats.waste_bytes >= waste_bytes ); JERRY_ASSERT( mem_heap_stats.waste_bytes >= waste_bytes );
mem_HeapStats.allocated_blocks--; mem_heap_stats.allocated_blocks--;
mem_HeapStats.allocated_chunks -= chunks; mem_heap_stats.allocated_chunks -= chunks;
mem_HeapStats.allocated_bytes -= bytes; mem_heap_stats.allocated_bytes -= bytes;
mem_HeapStats.waste_bytes -= waste_bytes; mem_heap_stats.waste_bytes -= waste_bytes;
} /* mem_HeapStatFreeBlock */ } /* mem_heap_stat_free_block */
/** /**
* Account free block split * Account free block split
*/ */
static void static void
mem_HeapStatFreeBlockSplit( void) mem_heap_stat_free_block_split( void)
{ {
mem_HeapStats.blocks++; mem_heap_stats.blocks++;
} /* mem_HeapStatFreeBlockSplit */ } /* mem_heap_stat_free_block_split */
/** /**
* Account free block merge * Account free block merge
*/ */
static void static void
mem_HeapStatFreeBlockMerge( void) mem_heap_stat_free_block_merge( void)
{ {
mem_HeapStats.blocks--; mem_heap_stats.blocks--;
} /* mem_HeapStatFreeBlockMerge */ } /* mem_heap_stat_free_block_merge */
#endif /* MEM_STATS */ #endif /* MEM_STATS */
/** /**
+9 -9
View File
@@ -31,18 +31,18 @@
/** /**
* Type of allocation (argument of mem_Alloc) * Type of allocation (argument of mem_Alloc)
* *
* @see mem_HeapAllocBlock * @see mem_heap_alloc_block
*/ */
typedef enum { typedef enum {
MEM_HEAP_ALLOC_SHORT_TERM, /**< allocated region will be freed soon */ MEM_HEAP_ALLOC_SHORT_TERM, /**< allocated region will be freed soon */
MEM_HEAP_ALLOC_LONG_TERM /**< allocated region most likely will not be freed soon */ MEM_HEAP_ALLOC_LONG_TERM /**< allocated region most likely will not be freed soon */
} mem_HeapAllocTerm_t; } mem_heap_alloc_term_t;
extern void mem_HeapInit(uint8_t *heapStart, size_t heapSize); extern void mem_heap_init(uint8_t *heapStart, size_t heapSize);
extern uint8_t* mem_HeapAllocBlock(size_t sizeInBytes, mem_HeapAllocTerm_t allocTerm); extern uint8_t* mem_heap_alloc_block(size_t sizeInBytes, mem_heap_alloc_term_t allocTerm);
extern void mem_HeapFreeBlock(uint8_t *ptr); extern void mem_heap_free_block(uint8_t *ptr);
extern size_t mem_HeapRecommendAllocationSize(size_t minimumAllocationSize); extern size_t mem_heap_recommend_allocation_size(size_t minimumAllocationSize);
extern void mem_HeapPrint(bool dumpBlockData); extern void mem_heap_print(bool dumpBlockData);
#ifdef MEM_STATS #ifdef MEM_STATS
/** /**
@@ -64,9 +64,9 @@ typedef struct {
size_t waste_bytes; /**< bytes waste due to blocks filled partially size_t waste_bytes; /**< bytes waste due to blocks filled partially
and due to block headers */ and due to block headers */
size_t peak_waste_bytes; /**< peak bytes waste */ size_t peak_waste_bytes; /**< peak bytes waste */
} mem_HeapStats_t; } mem_heap_stats_t;
extern void mem_HeapGetStats(mem_HeapStats_t *out_heap_stats_p); extern void mem_heap_get_stats(mem_heap_stats_t *out_heap_stats_p);
#endif /* MEM_STATS */ #endif /* MEM_STATS */
/** /**
+24 -24
View File
@@ -34,14 +34,14 @@
/** /**
* Magic number to fill free chunks in debug version * Magic number to fill free chunks in debug version
*/ */
static const uint8_t mem_PoolFreeChunkMagicNum = 0x71; static const uint8_t mem_pool_free_chunk_magic_num = 0x71;
/** /**
* Number of bits in a single bitmap's bits' block. * Number of bits in a single bitmap's bits' block.
*/ */
static const mword_t mem_BitmapBitsInBlock = sizeof (mword_t) * JERRY_BITSINBYTE; static const mword_t mem_bitmap_bits_in_block = sizeof (mword_t) * JERRY_BITSINBYTE;
static void mem_CheckPool( mem_PoolState_t *pPool); static void mem_check_pool( mem_pool_state_t *pPool);
/** /**
* Initialization of memory pool. * Initialization of memory pool.
@@ -53,7 +53,7 @@ static void mem_CheckPool( mem_PoolState_t *pPool);
* it is incorrect to suppose, that chunk number = poolSize / chunkSize. * it is incorrect to suppose, that chunk number = poolSize / chunkSize.
*/ */
void void
mem_PoolInit(mem_PoolState_t *pPool, /**< pool */ mem_pool_init(mem_pool_state_t *pPool, /**< pool */
size_t chunkSize, /**< size of one chunk */ size_t chunkSize, /**< size of one chunk */
uint8_t *poolStart, /**< start of pool space */ uint8_t *poolStart, /**< start of pool space */
size_t poolSize) /**< pool space size */ size_t poolSize) /**< pool space size */
@@ -114,19 +114,19 @@ mem_PoolInit(mem_PoolState_t *pPool, /**< pool */
__memset( pPool->pBitmap, 0, bitmapAreaSize); __memset( pPool->pBitmap, 0, bitmapAreaSize);
#ifndef JERRY_NDEBUG #ifndef JERRY_NDEBUG
__memset( pPool->pChunks, mem_PoolFreeChunkMagicNum, chunksAreaSize); __memset( pPool->pChunks, mem_pool_free_chunk_magic_num, chunksAreaSize);
#endif /* JERRY_NDEBUG */ #endif /* JERRY_NDEBUG */
mem_CheckPool( pPool); mem_check_pool( pPool);
} /* mem_PoolInit */ } /* mem_pool_init */
/** /**
* Allocate a chunk in the pool * Allocate a chunk in the pool
*/ */
uint8_t* uint8_t*
mem_PoolAllocChunk(mem_PoolState_t *pPool) /**< pool */ mem_pool_alloc_chunk(mem_pool_state_t *pPool) /**< pool */
{ {
mem_CheckPool( pPool); mem_check_pool( pPool);
if ( pPool->FreeChunksNumber == 0 ) if ( pPool->FreeChunksNumber == 0 )
{ {
@@ -144,7 +144,7 @@ mem_PoolAllocChunk(mem_PoolState_t *pPool) /**< pool */
} else } else
{ {
bitmapBlockIndex++; bitmapBlockIndex++;
chunkIndex += mem_BitmapBitsInBlock; chunkIndex += mem_bitmap_bits_in_block;
} }
} }
@@ -158,7 +158,7 @@ mem_PoolAllocChunk(mem_PoolState_t *pPool) /**< pool */
mword_t bit = 1; mword_t bit = 1;
for ( size_t bitIndex = 0; for ( size_t bitIndex = 0;
bitIndex < mem_BitmapBitsInBlock && chunkIndex < pPool->ChunksNumber; bitIndex < mem_bitmap_bits_in_block && chunkIndex < pPool->ChunksNumber;
bitIndex++, chunkIndex++, bit <<= 1 ) bitIndex++, chunkIndex++, bit <<= 1 )
{ {
if ( ~pPool->pBitmap[ bitmapBlockIndex ] & bit ) if ( ~pPool->pBitmap[ bitmapBlockIndex ] & bit )
@@ -169,7 +169,7 @@ mem_PoolAllocChunk(mem_PoolState_t *pPool) /**< pool */
uint8_t *pChunk = &pPool->pChunks[ chunkIndex * pPool->ChunkSize ]; uint8_t *pChunk = &pPool->pChunks[ chunkIndex * pPool->ChunkSize ];
pPool->FreeChunksNumber--; pPool->FreeChunksNumber--;
mem_CheckPool( pPool); mem_check_pool( pPool);
return pChunk; return pChunk;
} }
@@ -177,42 +177,42 @@ mem_PoolAllocChunk(mem_PoolState_t *pPool) /**< pool */
/* that zero bit is at the end of the bitmap and doesn't correspond to any chunk */ /* that zero bit is at the end of the bitmap and doesn't correspond to any chunk */
return NULL; return NULL;
} /* mem_PoolAllocChunk */ } /* mem_pool_alloc_chunk */
/** /**
* Free the chunk in the pool * Free the chunk in the pool
*/ */
void void
mem_PoolFreeChunk(mem_PoolState_t *pPool, /**< pool */ mem_pool_free_chunk(mem_pool_state_t *pPool, /**< pool */
uint8_t *pChunk) /**< chunk pointer */ uint8_t *pChunk) /**< chunk pointer */
{ {
JERRY_ASSERT( pPool->FreeChunksNumber < pPool->ChunksNumber ); JERRY_ASSERT( pPool->FreeChunksNumber < pPool->ChunksNumber );
JERRY_ASSERT( pChunk >= pPool->pChunks && pChunk <= pPool->pChunks + pPool->ChunksNumber * pPool->ChunkSize ); JERRY_ASSERT( pChunk >= pPool->pChunks && pChunk <= pPool->pChunks + pPool->ChunksNumber * pPool->ChunkSize );
JERRY_ASSERT( ( (uintptr_t) pChunk - (uintptr_t) pPool->pChunks ) % pPool->ChunkSize == 0 ); JERRY_ASSERT( ( (uintptr_t) pChunk - (uintptr_t) pPool->pChunks ) % pPool->ChunkSize == 0 );
mem_CheckPool( pPool); mem_check_pool( pPool);
size_t chunkIndex = (size_t) (pChunk - pPool->pChunks) / pPool->ChunkSize; size_t chunkIndex = (size_t) (pChunk - pPool->pChunks) / pPool->ChunkSize;
size_t bitmapBlockIndex = chunkIndex / mem_BitmapBitsInBlock; size_t bitmapBlockIndex = chunkIndex / mem_bitmap_bits_in_block;
size_t bitmapBitInBlock = chunkIndex % mem_BitmapBitsInBlock; size_t bitmapBitInBlock = chunkIndex % mem_bitmap_bits_in_block;
mword_t bitMask = ( 1lu << bitmapBitInBlock ); mword_t bitMask = ( 1lu << bitmapBitInBlock );
#ifndef JERRY_NDEBUG #ifndef JERRY_NDEBUG
__memset( (uint8_t*) pChunk, mem_PoolFreeChunkMagicNum, pPool->ChunkSize); __memset( (uint8_t*) pChunk, mem_pool_free_chunk_magic_num, pPool->ChunkSize);
#endif /* JERRY_NDEBUG */ #endif /* JERRY_NDEBUG */
JERRY_ASSERT( pPool->pBitmap[ bitmapBlockIndex ] & bitMask ); JERRY_ASSERT( pPool->pBitmap[ bitmapBlockIndex ] & bitMask );
pPool->pBitmap[ bitmapBlockIndex ] &= ~bitMask; pPool->pBitmap[ bitmapBlockIndex ] &= ~bitMask;
pPool->FreeChunksNumber++; pPool->FreeChunksNumber++;
mem_CheckPool( pPool); mem_check_pool( pPool);
} /* mem_PoolFreeChunk */ } /* mem_pool_free_chunk */
/** /**
* Check pool state consistency * Check pool state consistency
*/ */
static void static void
mem_CheckPool( mem_PoolState_t __unused *pPool) /**< pool (unused #ifdef JERRY_NDEBUG) */ mem_check_pool( mem_pool_state_t __unused *pPool) /**< pool (unused #ifdef JERRY_NDEBUG) */
{ {
#ifndef JERRY_NDEBUG #ifndef JERRY_NDEBUG
JERRY_ASSERT( pPool->ChunksNumber != 0 ); JERRY_ASSERT( pPool->ChunksNumber != 0 );
@@ -221,7 +221,7 @@ mem_CheckPool( mem_PoolState_t __unused *pPool) /**< pool (unused #ifdef JERRY_N
JERRY_ASSERT( (uint8_t*) pPool->pChunks > pPool->pPoolStart ); JERRY_ASSERT( (uint8_t*) pPool->pChunks > pPool->pPoolStart );
uint8_t freeChunkTemplate[ pPool->ChunkSize ]; uint8_t freeChunkTemplate[ pPool->ChunkSize ];
__memset( &freeChunkTemplate, mem_PoolFreeChunkMagicNum, sizeof (freeChunkTemplate)); __memset( &freeChunkTemplate, mem_pool_free_chunk_magic_num, sizeof (freeChunkTemplate));
size_t metFreeChunksNumber = 0; size_t metFreeChunksNumber = 0;
@@ -235,7 +235,7 @@ mem_CheckPool( mem_PoolState_t __unused *pPool) /**< pool (unused #ifdef JERRY_N
mword_t bitMask = 1; mword_t bitMask = 1;
for ( size_t bitmapBitInBlock = 0; for ( size_t bitmapBitInBlock = 0;
chunkIndex < pPool->ChunksNumber && bitmapBitInBlock < mem_BitmapBitsInBlock; chunkIndex < pPool->ChunksNumber && bitmapBitInBlock < mem_bitmap_bits_in_block;
bitmapBitInBlock++, bitMask <<= 1, chunkIndex++ ) bitmapBitInBlock++, bitMask <<= 1, chunkIndex++ )
{ {
if ( ~bitmapBlock & bitMask ) if ( ~bitmapBlock & bitMask )
@@ -249,7 +249,7 @@ mem_CheckPool( mem_PoolState_t __unused *pPool) /**< pool (unused #ifdef JERRY_N
JERRY_ASSERT( metFreeChunksNumber == pPool->FreeChunksNumber ); JERRY_ASSERT( metFreeChunksNumber == pPool->FreeChunksNumber );
#endif /* !JERRY_NDEBUG */ #endif /* !JERRY_NDEBUG */
} /* mem_CheckPool */ } /* mem_check_pool */
/** /**
* @} * @}
+6 -6
View File
@@ -30,7 +30,7 @@
* TODO: * TODO:
* Compact the struct * Compact the struct
*/ */
typedef struct mem_PoolState_t { typedef struct mem_pool_state_t {
uint8_t *pPoolStart; /**< first address of pool space */ uint8_t *pPoolStart; /**< first address of pool space */
size_t PoolSize; /**< pool space size */ size_t PoolSize; /**< pool space size */
@@ -42,12 +42,12 @@ typedef struct mem_PoolState_t {
size_t ChunksNumber; /**< number of chunks */ size_t ChunksNumber; /**< number of chunks */
size_t FreeChunksNumber; /**< number of free chunks */ size_t FreeChunksNumber; /**< number of free chunks */
struct mem_PoolState_t *pNextPool; /**< pointer to the next pool with same chunk size */ struct mem_pool_state_t *pNextPool; /**< pointer to the next pool with same chunk size */
} mem_PoolState_t; } mem_pool_state_t;
extern void mem_PoolInit(mem_PoolState_t *pPool, size_t chunkSize, uint8_t *poolStart, size_t poolSize); extern void mem_pool_init(mem_pool_state_t *pPool, size_t chunkSize, uint8_t *poolStart, size_t poolSize);
extern uint8_t* mem_PoolAllocChunk(mem_PoolState_t *pPool); extern uint8_t* mem_pool_alloc_chunk(mem_pool_state_t *pPool);
extern void mem_PoolFreeChunk(mem_PoolState_t *pPool, uint8_t *pChunk); extern void mem_pool_free_chunk(mem_pool_state_t *pPool, uint8_t *pChunk);
#endif /* JERRY_MEM_POOL_H */ #endif /* JERRY_MEM_POOL_H */
+84 -84
View File
@@ -36,40 +36,40 @@
/** /**
* Lists of pools for possible chunk sizes * Lists of pools for possible chunk sizes
*/ */
mem_PoolState_t *mem_Pools[ MEM_POOL_CHUNK_TYPE__COUNT ]; mem_pool_state_t *mem_pools[ MEM_POOL_CHUNK_TYPE__COUNT ];
/** /**
* Number of free chunks of possible chunk sizes * Number of free chunks of possible chunk sizes
*/ */
size_t mem_FreeChunksNumber[ MEM_POOL_CHUNK_TYPE__COUNT ]; size_t mem_free_chunks_number[ MEM_POOL_CHUNK_TYPE__COUNT ];
/** /**
* Pool, containing pool headers * Pool, containing pool headers
*/ */
mem_PoolState_t mem_PoolForPoolHeaders; mem_pool_state_t mem_pool_for_pool_headers;
/** /**
* Space for pool, containing pool headers * Space for pool, containing pool headers
*/ */
uint8_t *mem_SpaceForPoolForPoolHeaders; uint8_t *mem_space_for_pool_for_pool_headers;
#ifdef MEM_STATS #ifdef MEM_STATS
/** /**
* Pools' memory usage statistics * Pools' memory usage statistics
*/ */
mem_PoolsStats_t mem_PoolsStats; mem_pools_stats_t mem_pools_stats;
static void mem_PoolsStatInit( void); static void mem_pools_stat_init( void);
static void mem_PoolsStatAllocPool( mem_PoolChunkType_t); static void mem_pools_stat_alloc_pool( mem_pool_chunk_type_t);
static void mem_PoolsStatFreePool( mem_PoolChunkType_t); static void mem_pools_stat_free_pool( mem_pool_chunk_type_t);
static void mem_PoolsStatAllocChunk( mem_PoolChunkType_t); static void mem_pools_stat_alloc_chunk( mem_pool_chunk_type_t);
static void mem_PoolsStatFreeChunk( mem_PoolChunkType_t); static void mem_pools_stat_free_chunk( mem_pool_chunk_type_t);
#else /* !MEM_STATS */ #else /* !MEM_STATS */
# define mem_PoolsStatInit() # define mem_pools_stat_init()
# define mem_PoolsStatAllocPool(v) # define mem_pools_stat_alloc_pool(v)
# define mem_PoolsStatFreePool(v) # define mem_pools_stat_free_pool(v)
# define mem_PoolsStatAllocChunk(v) # define mem_pools_stat_alloc_chunk(v)
# define mem_PoolsStatFreeChunk(v) # define mem_pools_stat_free_chunk(v)
#endif /* !MEM_STATS */ #endif /* !MEM_STATS */
/** /**
@@ -78,25 +78,25 @@ static void mem_PoolsStatFreeChunk( mem_PoolChunkType_t);
* @return size (in bytes) of chunk of specified type * @return size (in bytes) of chunk of specified type
*/ */
size_t size_t
mem_GetChunkSize( mem_PoolChunkType_t chunkType) /**< chunk type */ mem_get_chunk_size( mem_pool_chunk_type_t chunkType) /**< chunk type */
{ {
uint32_t chunkTypeId = (uint32_t) chunkType; uint32_t chunkTypeId = (uint32_t) chunkType;
JERRY_ASSERT( chunkTypeId < MEM_POOL_CHUNK_TYPE__COUNT ); JERRY_ASSERT( chunkTypeId < MEM_POOL_CHUNK_TYPE__COUNT );
return ( 1u << ( chunkTypeId + 2 ) ); return ( 1u << ( chunkTypeId + 2 ) );
} /* mem_GetChunkSize */ } /* mem_get_chunk_size */
/** /**
* Initialize pool manager * Initialize pool manager
*/ */
void void
mem_PoolsInit(void) mem_pools_init(void)
{ {
for ( uint32_t i = 0; i < MEM_POOL_CHUNK_TYPE__COUNT; i++ ) for ( uint32_t i = 0; i < MEM_POOL_CHUNK_TYPE__COUNT; i++ )
{ {
mem_Pools[ i ] = NULL; mem_pools[ i ] = NULL;
mem_FreeChunksNumber[ i ] = 0; mem_free_chunks_number[ i ] = 0;
} }
/** /**
@@ -104,23 +104,23 @@ mem_PoolsInit(void)
* *
* TODO: Research. * TODO: Research.
*/ */
size_t poolSpaceSize = mem_HeapRecommendAllocationSize( 4 * sizeof (mem_PoolState_t) + sizeof (mword_t) ); size_t poolSpaceSize = mem_heap_recommend_allocation_size( 4 * sizeof (mem_pool_state_t) + sizeof (mword_t) );
mem_SpaceForPoolForPoolHeaders = mem_HeapAllocBlock(poolSpaceSize, mem_space_for_pool_for_pool_headers = mem_heap_alloc_block(poolSpaceSize,
MEM_HEAP_ALLOC_LONG_TERM); MEM_HEAP_ALLOC_LONG_TERM);
/* /*
* Get chunk type, checking that there is a type corresponding to specified size. * Get chunk type, checking that there is a type corresponding to specified size.
*/ */
const mem_PoolChunkType_t chunkType = mem_SizeToPoolChunkType( sizeof(mem_PoolState_t)); const mem_pool_chunk_type_t chunkType = mem_size_to_pool_chunk_type( sizeof(mem_pool_state_t));
mem_PoolInit(&mem_PoolForPoolHeaders, mem_pool_init(&mem_pool_for_pool_headers,
mem_GetChunkSize( chunkType), mem_get_chunk_size( chunkType),
mem_SpaceForPoolForPoolHeaders, mem_space_for_pool_for_pool_headers,
poolSpaceSize); poolSpaceSize);
mem_PoolsStatInit(); mem_pools_stat_init();
} /* mem_PoolsInit */ } /* mem_pools_init */
/** /**
* Allocate a chunk of specified size * Allocate a chunk of specified size
@@ -129,16 +129,16 @@ mem_PoolsInit(void)
* or NULL - if not enough memory. * or NULL - if not enough memory.
*/ */
uint8_t* uint8_t*
mem_PoolsAlloc( mem_PoolChunkType_t chunkType) /**< chunk type */ mem_pools_alloc( mem_pool_chunk_type_t chunkType) /**< chunk type */
{ {
size_t chunkSize = mem_GetChunkSize( chunkType); size_t chunkSize = mem_get_chunk_size( chunkType);
/** /**
* If there are no free chunks, allocate new pool. * If there are no free chunks, allocate new pool.
*/ */
if ( mem_FreeChunksNumber[ chunkType ] == 0 ) if ( mem_free_chunks_number[ chunkType ] == 0 )
{ {
mem_PoolState_t *poolState = (mem_PoolState_t*) mem_PoolAllocChunk( &mem_PoolForPoolHeaders); mem_pool_state_t *poolState = (mem_pool_state_t*) mem_pool_alloc_chunk( &mem_pool_for_pool_headers);
if ( poolState == NULL ) if ( poolState == NULL )
{ {
@@ -153,9 +153,9 @@ mem_PoolsAlloc( mem_PoolChunkType_t chunkType) /**< chunk type */
* *
* TODO: Research. * TODO: Research.
*/ */
size_t poolSpaceSize = mem_HeapRecommendAllocationSize( 8 * chunkSize + sizeof (mword_t) ); size_t poolSpaceSize = mem_heap_recommend_allocation_size( 8 * chunkSize + sizeof (mword_t) );
uint8_t *poolSpace = mem_HeapAllocBlock( poolSpaceSize, uint8_t *poolSpace = mem_heap_alloc_block( poolSpaceSize,
MEM_HEAP_ALLOC_LONG_TERM); MEM_HEAP_ALLOC_LONG_TERM);
if ( poolSpace == NULL ) if ( poolSpace == NULL )
@@ -166,17 +166,17 @@ mem_PoolsAlloc( mem_PoolChunkType_t chunkType) /**< chunk type */
return NULL; return NULL;
} }
mem_PoolInit( poolState, mem_pool_init( poolState,
chunkSize, chunkSize,
poolSpace, poolSpace,
poolSpaceSize); poolSpaceSize);
poolState->pNextPool = mem_Pools[ chunkType ]; poolState->pNextPool = mem_pools[ chunkType ];
mem_Pools[ chunkType ] = poolState; mem_pools[ chunkType ] = poolState;
mem_FreeChunksNumber[ chunkType ] += poolState->FreeChunksNumber; mem_free_chunks_number[ chunkType ] += poolState->FreeChunksNumber;
mem_PoolsStatAllocPool( chunkType); mem_pools_stat_alloc_pool( chunkType);
} }
/** /**
@@ -184,7 +184,7 @@ mem_PoolsAlloc( mem_PoolChunkType_t chunkType) /**< chunk type */
* *
* Search for the pool. * Search for the pool.
*/ */
mem_PoolState_t *poolState = mem_Pools[ chunkType ]; mem_pool_state_t *poolState = mem_pools[ chunkType ];
while ( poolState->FreeChunksNumber == 0 ) while ( poolState->FreeChunksNumber == 0 )
{ {
@@ -196,21 +196,21 @@ mem_PoolsAlloc( mem_PoolChunkType_t chunkType) /**< chunk type */
/** /**
* And allocate chunk within it. * And allocate chunk within it.
*/ */
mem_FreeChunksNumber[ chunkType ]--; mem_free_chunks_number[ chunkType ]--;
mem_PoolsStatAllocChunk( chunkType); mem_pools_stat_alloc_chunk( chunkType);
return mem_PoolAllocChunk( poolState); return mem_pool_alloc_chunk( poolState);
} /* mem_PoolsAlloc */ } /* mem_pools_alloc */
/** /**
* Free the chunk * Free the chunk
*/ */
void void
mem_PoolsFree( mem_PoolChunkType_t chunkType, /**< the chunk type */ mem_pools_free( mem_pool_chunk_type_t chunkType, /**< the chunk type */
uint8_t *pChunk) /**< pointer to the chunk */ uint8_t *pChunk) /**< pointer to the chunk */
{ {
mem_PoolState_t *poolState = mem_Pools[ chunkType ], *prevPoolState = NULL; mem_pool_state_t *poolState = mem_pools[ chunkType ], *prevPoolState = NULL;
/** /**
* Search for the pool containing specified chunk. * Search for the pool containing specified chunk.
@@ -227,10 +227,10 @@ mem_PoolsFree( mem_PoolChunkType_t chunkType, /**< the chunk type */
/** /**
* Free the chunk * Free the chunk
*/ */
mem_PoolFreeChunk( poolState, pChunk); mem_pool_free_chunk( poolState, pChunk);
mem_FreeChunksNumber[ chunkType ]++; mem_free_chunks_number[ chunkType ]++;
mem_PoolsStatFreeChunk( chunkType); mem_pools_stat_free_chunk( chunkType);
/** /**
* If all chunks of the pool are free, free the pool itself. * If all chunks of the pool are free, free the pool itself.
@@ -242,95 +242,95 @@ mem_PoolsFree( mem_PoolChunkType_t chunkType, /**< the chunk type */
prevPoolState->pNextPool = poolState->pNextPool; prevPoolState->pNextPool = poolState->pNextPool;
} else } else
{ {
mem_Pools[ chunkType ] = poolState->pNextPool; mem_pools[ chunkType ] = poolState->pNextPool;
} }
mem_FreeChunksNumber[ chunkType ] -= poolState->ChunksNumber; mem_free_chunks_number[ chunkType ] -= poolState->ChunksNumber;
mem_HeapFreeBlock( poolState->pPoolStart); mem_heap_free_block( poolState->pPoolStart);
mem_PoolFreeChunk( &mem_PoolForPoolHeaders, (uint8_t*) poolState); mem_pool_free_chunk( &mem_pool_for_pool_headers, (uint8_t*) poolState);
mem_PoolsStatFreePool( chunkType); mem_pools_stat_free_pool( chunkType);
} }
} /* mem_PoolsFree */ } /* mem_pools_free */
#ifdef MEM_STATS #ifdef MEM_STATS
/** /**
* Get pools memory usage statistics * Get pools memory usage statistics
*/ */
void void
mem_PoolsGetStats( mem_PoolsStats_t *out_pools_stats_p) /**< out: pools' stats */ mem_pools_get_stats( mem_pools_stats_t *out_pools_stats_p) /**< out: pools' stats */
{ {
JERRY_ASSERT( out_pools_stats_p != NULL ); JERRY_ASSERT( out_pools_stats_p != NULL );
*out_pools_stats_p = mem_PoolsStats; *out_pools_stats_p = mem_pools_stats;
} /* mem_PoolsGetStats */ } /* mem_pools_get_stats */
/** /**
* Initalize pools' memory usage statistics account structure * Initalize pools' memory usage statistics account structure
*/ */
static void static void
mem_PoolsStatInit( void) mem_pools_stat_init( void)
{ {
__memset( &mem_PoolsStats, 0, sizeof (mem_PoolsStats)); __memset( &mem_pools_stats, 0, sizeof (mem_pools_stats));
} /* mem_PoolsStatInit */ } /* mem_pools_stat_init */
/** /**
* Account allocation of a pool * Account allocation of a pool
*/ */
static void static void
mem_PoolsStatAllocPool( mem_PoolChunkType_t chunkType) /**< chunk type */ mem_pools_stat_alloc_pool( mem_pool_chunk_type_t chunkType) /**< chunk type */
{ {
mem_PoolsStats.pools_count[ chunkType ]++; mem_pools_stats.pools_count[ chunkType ]++;
mem_PoolsStats.free_chunks[ chunkType ] = mem_FreeChunksNumber[ chunkType ]; mem_pools_stats.free_chunks[ chunkType ] = mem_free_chunks_number[ chunkType ];
if ( mem_PoolsStats.pools_count[ chunkType ] > mem_PoolsStats.peak_pools_count[ chunkType ] ) if ( mem_pools_stats.pools_count[ chunkType ] > mem_pools_stats.peak_pools_count[ chunkType ] )
{ {
mem_PoolsStats.peak_pools_count[ chunkType ] = mem_PoolsStats.pools_count[ chunkType ]; mem_pools_stats.peak_pools_count[ chunkType ] = mem_pools_stats.pools_count[ chunkType ];
} }
} /* mem_PoolsStatAllocPool */ } /* mem_pools_stat_alloc_pool */
/** /**
* Account freeing of a pool * Account freeing of a pool
*/ */
static void static void
mem_PoolsStatFreePool( mem_PoolChunkType_t chunkType) /**< chunk type */ mem_pools_stat_free_pool( mem_pool_chunk_type_t chunkType) /**< chunk type */
{ {
JERRY_ASSERT( mem_PoolsStats.pools_count[ chunkType ] > 0 ); JERRY_ASSERT( mem_pools_stats.pools_count[ chunkType ] > 0 );
mem_PoolsStats.pools_count[ chunkType ]--; mem_pools_stats.pools_count[ chunkType ]--;
mem_PoolsStats.free_chunks[ chunkType ] = mem_FreeChunksNumber[ chunkType ]; mem_pools_stats.free_chunks[ chunkType ] = mem_free_chunks_number[ chunkType ];
} /* mem_PoolsStatFreePool */ } /* mem_pools_stat_free_pool */
/** /**
* Account allocation of chunk in a pool * Account allocation of chunk in a pool
*/ */
static void static void
mem_PoolsStatAllocChunk( mem_PoolChunkType_t chunkType) /**< chunk type */ mem_pools_stat_alloc_chunk( mem_pool_chunk_type_t chunkType) /**< chunk type */
{ {
JERRY_ASSERT( mem_PoolsStats.free_chunks[ chunkType ] > 0 ); JERRY_ASSERT( mem_pools_stats.free_chunks[ chunkType ] > 0 );
mem_PoolsStats.allocated_chunks[ chunkType ]++; mem_pools_stats.allocated_chunks[ chunkType ]++;
mem_PoolsStats.free_chunks[ chunkType ]--; mem_pools_stats.free_chunks[ chunkType ]--;
if ( mem_PoolsStats.allocated_chunks[ chunkType ] > mem_PoolsStats.peak_allocated_chunks[ chunkType ] ) if ( mem_pools_stats.allocated_chunks[ chunkType ] > mem_pools_stats.peak_allocated_chunks[ chunkType ] )
{ {
mem_PoolsStats.peak_allocated_chunks[ chunkType ] = mem_PoolsStats.allocated_chunks[ chunkType ]; mem_pools_stats.peak_allocated_chunks[ chunkType ] = mem_pools_stats.allocated_chunks[ chunkType ];
} }
} /* mem_PoolsStatAllocChunk */ } /* mem_pools_stat_alloc_chunk */
/** /**
* Account freeing of chunk in a pool * Account freeing of chunk in a pool
*/ */
static void static void
mem_PoolsStatFreeChunk( mem_PoolChunkType_t chunkType) /**< chunk type */ mem_pools_stat_free_chunk( mem_pool_chunk_type_t chunkType) /**< chunk type */
{ {
JERRY_ASSERT( mem_PoolsStats.allocated_chunks[ chunkType ] > 0 ); JERRY_ASSERT( mem_pools_stats.allocated_chunks[ chunkType ] > 0 );
mem_PoolsStats.allocated_chunks[ chunkType ]--; mem_pools_stats.allocated_chunks[ chunkType ]--;
mem_PoolsStats.free_chunks[ chunkType ]++; mem_pools_stats.free_chunks[ chunkType ]++;
} /* mem_PoolsStatFreeChunk */ } /* mem_pools_stat_free_chunk */
#endif /* MEM_STATS */ #endif /* MEM_STATS */
/** /**
+8 -8
View File
@@ -39,23 +39,23 @@ typedef enum {
MEM_POOL_CHUNK_TYPE_32, /**< 32-byte chunk */ MEM_POOL_CHUNK_TYPE_32, /**< 32-byte chunk */
MEM_POOL_CHUNK_TYPE_64, /**< 64-byte chunk */ MEM_POOL_CHUNK_TYPE_64, /**< 64-byte chunk */
MEM_POOL_CHUNK_TYPE__COUNT /**< count of possible pool chunks' sizes */ MEM_POOL_CHUNK_TYPE__COUNT /**< count of possible pool chunks' sizes */
} mem_PoolChunkType_t; } mem_pool_chunk_type_t;
/** /**
* Convert size to pool chunk type. * Convert size to pool chunk type.
*/ */
#define mem_SizeToPoolChunkType( size) ((size) == 4 ? MEM_POOL_CHUNK_TYPE_4 : \ #define mem_size_to_pool_chunk_type( size) ((size) == 4 ? MEM_POOL_CHUNK_TYPE_4 : \
((size) == 8 ? MEM_POOL_CHUNK_TYPE_8 : \ ((size) == 8 ? MEM_POOL_CHUNK_TYPE_8 : \
((size) == 16 ? MEM_POOL_CHUNK_TYPE_16 : \ ((size) == 16 ? MEM_POOL_CHUNK_TYPE_16 : \
((size) == 32 ? MEM_POOL_CHUNK_TYPE_32 : \ ((size) == 32 ? MEM_POOL_CHUNK_TYPE_32 : \
((size) == 64 ? MEM_POOL_CHUNK_TYPE_64 : \ ((size) == 64 ? MEM_POOL_CHUNK_TYPE_64 : \
jerry_UnreferencedExpression))))) jerry_UnreferencedExpression)))))
extern size_t mem_GetChunkSize( mem_PoolChunkType_t chunkType); extern size_t mem_get_chunk_size( mem_pool_chunk_type_t chunkType);
extern void mem_PoolsInit(void); extern void mem_pools_init(void);
extern uint8_t* mem_PoolsAlloc(mem_PoolChunkType_t chunkType); extern uint8_t* mem_pools_alloc(mem_pool_chunk_type_t chunkType);
extern void mem_PoolsFree(mem_PoolChunkType_t chunkType, uint8_t *pChunk); extern void mem_pools_free(mem_pool_chunk_type_t chunkType, uint8_t *pChunk);
#ifdef MEM_STATS #ifdef MEM_STATS
/** /**
@@ -77,9 +77,9 @@ typedef struct
/** free chunks count, per type */ /** free chunks count, per type */
size_t free_chunks[ MEM_POOL_CHUNK_TYPE__COUNT ]; size_t free_chunks[ MEM_POOL_CHUNK_TYPE__COUNT ];
} mem_PoolsStats_t; } mem_pools_stats_t;
extern void mem_PoolsGetStats( mem_PoolsStats_t *out_pools_stats_p); extern void mem_pools_get_stats( mem_pools_stats_t *out_pools_stats_p);
#endif /* MEM_STATS */ #endif /* MEM_STATS */
#endif /* JERRY_MEM_POOLMAN_H */ #endif /* JERRY_MEM_POOLMAN_H */
+2 -2
View File
@@ -114,7 +114,7 @@ init_string_literal_copy(T_IDX idx, /**< literal identifier */
ssize_t req_sz = -sz; ssize_t req_sz = -sz;
str_lit_descr_p->str_p = mem_HeapAllocBlock( (size_t)req_sz, str_lit_descr_p->str_p = mem_heap_alloc_block( (size_t)req_sz,
MEM_HEAP_ALLOC_SHORT_TERM); MEM_HEAP_ALLOC_SHORT_TERM);
sz = try_get_string_by_idx( idx, sz = try_get_string_by_idx( idx,
@@ -140,7 +140,7 @@ free_string_literal_copy(string_literal_copy *str_lit_descr_p) /**< string liter
} }
else else
{ {
mem_HeapFreeBlock( str_lit_descr_p->str_p); mem_heap_free_block( str_lit_descr_p->str_p);
} }
str_lit_descr_p->str_p = NULL; str_lit_descr_p->str_p = NULL;
+2 -2
View File
@@ -55,7 +55,7 @@ JERRY_STATIC_ASSERT( sizeof (ecma_CompletionValue_t) == sizeof(uint32_t) );
ecma_Alloc ## ecmaType (void) \ ecma_Alloc ## ecmaType (void) \
{ \ { \
ecma_ ## ecmaType ## _t *p ## ecmaType = (ecma_ ## ecmaType ## _t *) \ ecma_ ## ecmaType ## _t *p ## ecmaType = (ecma_ ## ecmaType ## _t *) \
mem_PoolsAlloc( mem_SizeToPoolChunkType( sizeof(ecma_ ## ecmaType ## _t))); \ mem_pools_alloc( mem_size_to_pool_chunk_type( sizeof(ecma_ ## ecmaType ## _t))); \
\ \
ecma_GCRun(); \ ecma_GCRun(); \
JERRY_ASSERT( p ## ecmaType != NULL ); \ JERRY_ASSERT( p ## ecmaType != NULL ); \
@@ -69,7 +69,7 @@ ecma_Alloc ## ecmaType (void) \
#define DEALLOC( ecmaType) void \ #define DEALLOC( ecmaType) void \
ecma_Dealloc ## ecmaType( ecma_ ## ecmaType ## _t *p ## ecmaType) \ ecma_Dealloc ## ecmaType( ecma_ ## ecmaType ## _t *p ## ecmaType) \
{ \ { \
mem_PoolsFree( mem_SizeToPoolChunkType( sizeof(ecma_ ## ecmaType ## _t)), \ mem_pools_free( mem_size_to_pool_chunk_type( sizeof(ecma_ ## ecmaType ## _t)), \
(uint8_t*) p ## ecmaType); \ (uint8_t*) p ## ecmaType); \
} }
+2 -2
View File
@@ -41,7 +41,7 @@ ecma_CompressPointer(void *pointer) /**< pointer to compress */
JERRY_ASSERT(intPtr % MEM_ALIGNMENT == 0); JERRY_ASSERT(intPtr % MEM_ALIGNMENT == 0);
intPtr -= mem_GetBasePointer(); intPtr -= mem_get_base_pointer();
intPtr >>= MEM_ALIGNMENT_LOG; intPtr >>= MEM_ALIGNMENT_LOG;
JERRY_ASSERT((intPtr & ~((1u << ECMA_POINTER_FIELD_WIDTH) - 1)) == 0); JERRY_ASSERT((intPtr & ~((1u << ECMA_POINTER_FIELD_WIDTH) - 1)) == 0);
@@ -63,7 +63,7 @@ ecma_DecompressPointer(uintptr_t compressedPointer) /**< pointer to decompress *
uintptr_t intPtr = compressedPointer; uintptr_t intPtr = compressedPointer;
intPtr <<= MEM_ALIGNMENT_LOG; intPtr <<= MEM_ALIGNMENT_LOG;
intPtr += mem_GetBasePointer(); intPtr += mem_get_base_pointer();
return (void*) intPtr; return (void*) intPtr;
} /* ecma_DecompressPointer */ } /* ecma_DecompressPointer */
+4 -4
View File
@@ -129,7 +129,7 @@ get_char (size_t i)
if (buffer == NULL) if (buffer == NULL)
{ {
buffer = (char *) mem_HeapAllocBlock (BUFFER_SIZE, MEM_HEAP_ALLOC_SHORT_TERM); buffer = (char *) mem_heap_alloc_block (BUFFER_SIZE, MEM_HEAP_ALLOC_SHORT_TERM);
error = __fread (buffer, 1, BUFFER_SIZE, file); error = __fread (buffer, 1, BUFFER_SIZE, file);
if (error == 0) if (error == 0)
return '\0'; return '\0';
@@ -307,7 +307,7 @@ current_token (void)
JERRY_ASSERT (token_start); JERRY_ASSERT (token_start);
JERRY_ASSERT (token_start <= buffer); JERRY_ASSERT (token_start <= buffer);
size_t length = (size_t) (buffer - token_start); size_t length = (size_t) (buffer - token_start);
char *res = (char *) mem_HeapAllocBlock (length + 1, MEM_HEAP_ALLOC_SHORT_TERM); char *res = (char *) mem_heap_alloc_block (length + 1, MEM_HEAP_ALLOC_SHORT_TERM);
__strncpy (res, token_start, length); __strncpy (res, token_start, length);
res[length] = '\0'; res[length] = '\0';
token_start = NULL; token_start = NULL;
@@ -621,7 +621,7 @@ parse_string (void)
} }
length = (size_t) (buffer - token_start); length = (size_t) (buffer - token_start);
tok = (char *) mem_HeapAllocBlock (length, MEM_HEAP_ALLOC_SHORT_TERM); tok = (char *) mem_heap_alloc_block (length, MEM_HEAP_ALLOC_SHORT_TERM);
index = tok; index = tok;
for (i = token_start; i < buffer; i++) for (i = token_start; i < buffer; i++)
@@ -653,7 +653,7 @@ parse_string (void)
{ {
if (!__strncmp (seen_names[num].str, tok, __strlen (tok))) if (!__strncmp (seen_names[num].str, tok, __strlen (tok)))
{ {
mem_HeapFreeBlock ((uint8_t*) tok); mem_heap_free_block ((uint8_t*) tok);
return seen_names[num].tok; return seen_names[num].tok;
} }
} }
+1 -1
View File
@@ -105,7 +105,7 @@ main (int argc, char **argv)
FILE *file = NULL; FILE *file = NULL;
#endif #endif
mem_Init (); mem_init ();
#ifdef __HOST #ifdef __HOST
if (argc > 0) if (argc > 0)