Removing mem_heap_try_to_resize_block interface.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -652,142 +652,6 @@ mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to a
|
||||
}
|
||||
} /* mem_heap_alloc_block */
|
||||
|
||||
/**
|
||||
* Try to resize memory region.
|
||||
*
|
||||
* @return true - if resize is successful,
|
||||
* false - if there is not enough memory in front of the block.
|
||||
*/
|
||||
bool
|
||||
mem_heap_try_resize_block (void *ptr, /**< pointer to beginning of data space of the block to resize */
|
||||
size_t size_in_bytes) /**< new block size */
|
||||
{
|
||||
uint8_t *uint8_ptr = (uint8_t*) ptr;
|
||||
|
||||
/* checking that uint8_ptr points to the heap */
|
||||
JERRY_ASSERT(uint8_ptr >= mem_heap.heap_start
|
||||
&& uint8_ptr <= mem_heap.heap_start + mem_heap.heap_size);
|
||||
|
||||
mem_check_heap ();
|
||||
|
||||
mem_block_header_t *block_p = (mem_block_header_t*) uint8_ptr - 1;
|
||||
|
||||
VALGRIND_DEFINED_STRUCT(block_p);
|
||||
|
||||
JERRY_ASSERT(block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
|
||||
|
||||
/* For heap statistics unit we show what is going on as though
|
||||
* the block is freed and then new block (the same or resized)
|
||||
* is allocated */
|
||||
MEM_HEAP_STAT_FREE_BLOCK (block_p);
|
||||
|
||||
size_t current_block_may_expand_up_to = mem_get_block_data_space_size (block_p);
|
||||
|
||||
bool is_resized = false;
|
||||
|
||||
if (current_block_may_expand_up_to >= size_in_bytes)
|
||||
{
|
||||
is_resized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t need_additional_bytes = size_in_bytes - current_block_may_expand_up_to;
|
||||
|
||||
mem_block_header_t *next_block_p = mem_get_next_block_by_direction (block_p, MEM_DIRECTION_NEXT);
|
||||
|
||||
if (next_block_p != NULL)
|
||||
{
|
||||
VALGRIND_DEFINED_STRUCT (next_block_p);
|
||||
|
||||
if (next_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK)
|
||||
{
|
||||
size_t next_block_data_space_size = mem_get_block_data_space_size (next_block_p);
|
||||
|
||||
if (next_block_data_space_size >= need_additional_bytes)
|
||||
{
|
||||
/* next block is free and contains enough space */
|
||||
|
||||
is_resized = true;
|
||||
|
||||
size_t new_block_chunks_count = mem_get_block_chunks_count_from_data_size (size_in_bytes);
|
||||
size_t current_block_chunks_count = mem_get_block_chunks_count (block_p);
|
||||
size_t next_block_chunks_count = mem_get_block_chunks_count (next_block_p);
|
||||
|
||||
JERRY_ASSERT (new_block_chunks_count <= current_block_chunks_count + next_block_chunks_count);
|
||||
|
||||
size_t diff_in_chunks = (size_t) ((current_block_chunks_count +
|
||||
next_block_chunks_count) - new_block_chunks_count);
|
||||
|
||||
mem_block_header_t *block_after_next_p = mem_get_next_block_by_direction (next_block_p,
|
||||
MEM_DIRECTION_NEXT);
|
||||
mem_block_header_t *new_next_of_current_block_p;
|
||||
mem_block_header_t *new_prev_of_block_after_next_p;
|
||||
|
||||
if (diff_in_chunks > 0)
|
||||
{
|
||||
mem_block_header_t *new_free_block_p = (mem_block_header_t*) ((uint8_t*) block_p +
|
||||
new_block_chunks_count * MEM_HEAP_CHUNK_SIZE);
|
||||
|
||||
mem_init_block_header ((uint8_t*) new_free_block_p,
|
||||
0,
|
||||
MEM_BLOCK_FREE,
|
||||
block_p,
|
||||
block_after_next_p);
|
||||
|
||||
new_prev_of_block_after_next_p = new_free_block_p;
|
||||
new_next_of_current_block_p = new_free_block_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_prev_of_block_after_next_p = block_p;
|
||||
new_next_of_current_block_p = block_after_next_p;
|
||||
}
|
||||
|
||||
mem_set_block_next (block_p, new_next_of_current_block_p);
|
||||
if (block_after_next_p != NULL)
|
||||
{
|
||||
VALGRIND_DEFINED_STRUCT (block_after_next_p);
|
||||
|
||||
mem_set_block_prev (block_after_next_p, new_prev_of_block_after_next_p);
|
||||
|
||||
VALGRIND_NOACCESS_STRUCT (block_after_next_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
mem_heap.last_block_p = new_prev_of_block_after_next_p;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (next_block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
|
||||
}
|
||||
|
||||
VALGRIND_NOACCESS_STRUCT (next_block_p);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_resized)
|
||||
{
|
||||
JERRY_ASSERT ((mem_heap_offset_t) size_in_bytes == size_in_bytes);
|
||||
|
||||
if (size_in_bytes >= block_p->allocated_bytes)
|
||||
{
|
||||
VALGRIND_UNDEFINED_SPACE (uint8_ptr + block_p->allocated_bytes, size_in_bytes - block_p->allocated_bytes);
|
||||
}
|
||||
|
||||
mem_set_block_allocated_bytes (block_p, size_in_bytes);
|
||||
}
|
||||
|
||||
MEM_HEAP_STAT_ALLOC_BLOCK (block_p);
|
||||
|
||||
VALGRIND_NOACCESS_STRUCT(block_p);
|
||||
|
||||
mem_check_heap ();
|
||||
|
||||
return is_resized;
|
||||
} /* mem_heap_try_resize_block */
|
||||
|
||||
/**
|
||||
* Free the memory block.
|
||||
*/
|
||||
|
||||
@@ -42,7 +42,6 @@ typedef enum
|
||||
extern void mem_heap_init (uint8_t *heap_start, size_t heap_size);
|
||||
extern void mem_heap_finalize (void);
|
||||
extern void* mem_heap_alloc_block (size_t size_in_bytes, mem_heap_alloc_term_t alloc_term);
|
||||
extern bool mem_heap_try_resize_block (void *ptr, size_t size_in_bytes);
|
||||
extern void mem_heap_free_block (void *ptr);
|
||||
extern void* mem_heap_get_block_start (void *ptr);
|
||||
extern size_t __attr_pure___ mem_heap_recommend_allocation_size (size_t minimum_allocation_size);
|
||||
|
||||
@@ -118,28 +118,6 @@ main (int __attr_unused___ argc,
|
||||
|
||||
// mem_heap_print (true);
|
||||
|
||||
for (uint32_t j = 0; j < test_sub_iters; j++)
|
||||
{
|
||||
if (ptrs[j] != NULL && (rand () % 2) == 0)
|
||||
{
|
||||
for (size_t k = 0; k < sizes[j]; k++)
|
||||
{
|
||||
JERRY_ASSERT(ptrs[j][k] == 0);
|
||||
}
|
||||
|
||||
size_t new_size = (size_t) rand () % (test_threshold_block_size);
|
||||
|
||||
if (mem_heap_try_resize_block (ptrs[j], new_size))
|
||||
{
|
||||
sizes[j] = new_size;
|
||||
memset (ptrs[j], 0, sizes[j]);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (sizes [j] == 0
|
||||
|| mem_heap_get_block_start (ptrs[j] + (size_t) rand () % sizes [j]) == ptrs[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t j = 0; j < test_sub_iters; j++)
|
||||
{
|
||||
if (ptrs[j] != NULL)
|
||||
|
||||
Reference in New Issue
Block a user