mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Remove heap allocator's block headers, replacing them with bitmap at start of heap.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
parent
4c67403f15
commit
10e5f3530d
@ -23,9 +23,9 @@
|
||||
*/
|
||||
uint64_t __attr_const___
|
||||
jrt_extract_bit_field (uint64_t container, /**< container to extract bit-field from */
|
||||
uint32_t lsb, /**< least significant bit of the value
|
||||
* to be extracted */
|
||||
uint32_t width) /**< width of the bit-field to be extracted */
|
||||
size_t lsb, /**< least significant bit of the value
|
||||
* to be extracted */
|
||||
size_t width) /**< width of the bit-field to be extracted */
|
||||
{
|
||||
JERRY_ASSERT (lsb < JERRY_BITSINBYTE * sizeof (uint64_t));
|
||||
JERRY_ASSERT (width < JERRY_BITSINBYTE * sizeof (uint64_t));
|
||||
@ -45,9 +45,9 @@ jrt_extract_bit_field (uint64_t container, /**< container to extract bit-field f
|
||||
uint64_t __attr_const___
|
||||
jrt_set_bit_field_value (uint64_t container, /**< container to insert bit-field to */
|
||||
uint64_t new_bit_field_value, /**< value of bit-field to insert */
|
||||
uint32_t lsb, /**< least significant bit of the value
|
||||
* to be extracted */
|
||||
uint32_t width) /**< width of the bit-field to be extracted */
|
||||
size_t lsb, /**< least significant bit of the value
|
||||
* to be extracted */
|
||||
size_t width) /**< width of the bit-field to be extracted */
|
||||
{
|
||||
JERRY_ASSERT (lsb < JERRY_BITSINBYTE * sizeof (uint64_t));
|
||||
JERRY_ASSERT (width < JERRY_BITSINBYTE * sizeof (uint64_t));
|
||||
|
||||
@ -16,9 +16,8 @@
|
||||
#ifndef JERRY_BIT_FIELDS_H
|
||||
#define JERRY_BIT_FIELDS_H
|
||||
|
||||
extern uint64_t __attr_const___ jrt_extract_bit_field (uint64_t value, uint32_t lsb,
|
||||
uint32_t width);
|
||||
extern uint64_t __attr_const___ jrt_extract_bit_field (uint64_t value, size_t lsb, size_t width);
|
||||
extern uint64_t __attr_const___ jrt_set_bit_field_value (uint64_t value, uint64_t bit_field_value,
|
||||
uint32_t lsb, uint32_t width);
|
||||
size_t lsb, size_t width);
|
||||
|
||||
#endif /* !JERRY_BIT_FIELDS_H */
|
||||
|
||||
@ -27,12 +27,6 @@
|
||||
|
||||
#include "mem-allocator-internal.h"
|
||||
|
||||
/**
|
||||
* Area for heap
|
||||
*/
|
||||
static uint8_t mem_heap_area[ MEM_HEAP_AREA_SIZE ] __attribute__ ((aligned (JERRY_MAX (MEM_ALIGNMENT,
|
||||
MEM_HEAP_CHUNK_SIZE))));
|
||||
|
||||
/**
|
||||
* The 'try to give memory back' callback
|
||||
*/
|
||||
@ -44,7 +38,7 @@ static mem_try_give_memory_back_callback_t mem_try_give_memory_back_callback = N
|
||||
void
|
||||
mem_init (void)
|
||||
{
|
||||
mem_heap_init (mem_heap_area, sizeof (mem_heap_area));
|
||||
mem_heap_init ();
|
||||
mem_pools_init ();
|
||||
} /* mem_init */
|
||||
|
||||
@ -85,50 +79,27 @@ mem_finalize (bool is_show_mem_stats) /**< show heap memory stats
|
||||
} /* mem_finalize */
|
||||
|
||||
/**
|
||||
* Get base pointer for allocation area.
|
||||
*/
|
||||
static uintptr_t
|
||||
mem_get_base_pointer (void)
|
||||
{
|
||||
return (uintptr_t) mem_heap_area;
|
||||
} /* mem_get_base_pointer */
|
||||
|
||||
/**
|
||||
* Compress pointer.
|
||||
* Compress pointer
|
||||
*
|
||||
* @return packed pointer
|
||||
*/
|
||||
uintptr_t
|
||||
mem_compress_pointer (const void *pointer) /**< pointer to compress */
|
||||
mem_compress_pointer (const void *pointer_p) /**< pointer to compress */
|
||||
{
|
||||
JERRY_ASSERT (pointer != NULL);
|
||||
JERRY_ASSERT (mem_is_heap_pointer (pointer_p));
|
||||
|
||||
uintptr_t int_ptr = (uintptr_t) pointer;
|
||||
|
||||
JERRY_ASSERT (int_ptr % MEM_ALIGNMENT == 0);
|
||||
|
||||
int_ptr -= mem_get_base_pointer ();
|
||||
int_ptr >>= MEM_ALIGNMENT_LOG;
|
||||
|
||||
JERRY_ASSERT ((int_ptr & ~((1u << MEM_HEAP_OFFSET_LOG) - 1)) == 0);
|
||||
|
||||
JERRY_ASSERT (int_ptr != MEM_CP_NULL);
|
||||
|
||||
return int_ptr;
|
||||
return mem_heap_compress_pointer (pointer_p);
|
||||
} /* mem_compress_pointer */
|
||||
|
||||
/**
|
||||
* Decompress pointer.
|
||||
* Decompress pointer
|
||||
*
|
||||
* @return unpacked pointer
|
||||
*/
|
||||
void*
|
||||
mem_decompress_pointer (uintptr_t compressed_pointer) /**< pointer to decompress */
|
||||
{
|
||||
JERRY_ASSERT (compressed_pointer != MEM_CP_NULL);
|
||||
|
||||
uintptr_t int_ptr = compressed_pointer;
|
||||
|
||||
int_ptr <<= MEM_ALIGNMENT_LOG;
|
||||
int_ptr += mem_get_base_pointer ();
|
||||
|
||||
return (void*) int_ptr;
|
||||
return mem_heap_decompress_pointer (compressed_pointer);
|
||||
} /* mem_decompress_pointer */
|
||||
|
||||
/**
|
||||
@ -170,25 +141,6 @@ mem_run_try_to_give_memory_back_callbacks (mem_try_give_memory_back_severity_t s
|
||||
mem_pools_collect_empty ();
|
||||
} /* mem_run_try_to_give_memory_back_callbacks */
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
/**
|
||||
* Check whether the pointer points to the heap
|
||||
*
|
||||
* Note:
|
||||
* the routine should be used only for assertion checks
|
||||
*
|
||||
* @return true - if pointer points to the heap,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
mem_is_heap_pointer (void *pointer) /**< pointer */
|
||||
{
|
||||
uint8_t *uint8_pointer = (uint8_t*) pointer;
|
||||
|
||||
return (uint8_pointer >= mem_heap_area && uint8_pointer <= (mem_heap_area + MEM_HEAP_AREA_SIZE));
|
||||
} /* mem_is_heap_pointer */
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
#ifdef MEM_STATS
|
||||
/**
|
||||
* Reset peak values in memory usage statistics
|
||||
|
||||
@ -128,10 +128,6 @@ extern void* mem_decompress_pointer (uintptr_t compressed_pointer);
|
||||
extern void mem_register_a_try_give_memory_back_callback (mem_try_give_memory_back_callback_t callback);
|
||||
extern void mem_unregister_a_try_give_memory_back_callback (mem_try_give_memory_back_callback_t callback);
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
extern bool mem_is_heap_pointer (void *pointer);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
#ifdef MEM_STATS
|
||||
extern void mem_stats_reset_peak (void);
|
||||
extern void mem_stats_print (void);
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
/**
|
||||
* Size of heap
|
||||
*/
|
||||
#define MEM_HEAP_AREA_SIZE ((size_t) (CONFIG_MEM_HEAP_AREA_SIZE))
|
||||
#define MEM_HEAP_SIZE ((size_t) (CONFIG_MEM_HEAP_AREA_SIZE))
|
||||
|
||||
/**
|
||||
* Size of heap chunk
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -39,13 +39,16 @@ typedef enum
|
||||
MEM_HEAP_ALLOC_LONG_TERM /**< allocated region most likely will not be freed soon */
|
||||
} mem_heap_alloc_term_t;
|
||||
|
||||
extern void mem_heap_init (uint8_t *heap_start, size_t heap_size);
|
||||
extern void mem_heap_init (void);
|
||||
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 void* mem_heap_alloc_chunked_block (mem_heap_alloc_term_t alloc_term);
|
||||
extern void mem_heap_free_block (void *ptr);
|
||||
extern void* mem_heap_get_chunked_block_start (void *ptr);
|
||||
extern size_t mem_heap_get_chunked_block_data_size (void);
|
||||
extern uintptr_t mem_heap_compress_pointer (const void *pointer);
|
||||
extern void* mem_heap_decompress_pointer (uintptr_t compressed_pointer);
|
||||
extern bool mem_is_heap_pointer (const void *pointer);
|
||||
extern size_t __attr_pure___ mem_heap_recommend_allocation_size (size_t minimum_allocation_size);
|
||||
extern void mem_heap_print (bool dump_block_headers, bool dump_block_data, bool dump_stats);
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
#define test_heap_size (32 * 1024)
|
||||
|
||||
// Iterations count
|
||||
#define test_iters (64 * 1024)
|
||||
#define test_iters (4 * 1024)
|
||||
|
||||
// Subiterations count
|
||||
#define test_sub_iters 32
|
||||
@ -75,16 +75,13 @@ test_heap_give_some_memory_back (mem_try_give_memory_back_severity_t severity)
|
||||
}
|
||||
} /* test_heap_give_some_memory_back */
|
||||
|
||||
uint8_t test_native_heap[test_heap_size] __attribute__ ((aligned (JERRY_MAX (MEM_ALIGNMENT,
|
||||
MEM_HEAP_CHUNK_SIZE))));
|
||||
|
||||
int
|
||||
main (int __attr_unused___ argc,
|
||||
char __attr_unused___ **argv)
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
mem_heap_init (test_native_heap, sizeof (test_native_heap));
|
||||
mem_heap_init ();
|
||||
|
||||
mem_register_a_try_give_memory_back_callback (test_heap_give_some_memory_back);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user