mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Reorganize heap context related elements (#2500)
- Moved global context's `JMEM_HEAP_SIZE` to jcontext.h as external context's heap size is declared there, too. - Moved the assert on `jmem_heap_t` vs `JMEM_HEAP_SIZE` to jcontext.c, as both entities are declared in the corresponding header. - Removed superfluous checks on `JMEM_HEAP_SIZE` as it is not a publicly configurable macro (opposed to `CONFIG_MEM_HEAP_AREA_SIZE`). - Ensured that all definitions of and references to `jmem_heap_t`, `JERRY_HEAP_CONTEXT`, `JERRY_HEAP_SIZE`, and `JERRY_HEAP_AREA_SIZE` are guarded by `#ifndef JERRY_SYSTEM_ALLOCATOR`, as they are meaningless if the system allocator is used. The commit also contains some stylistic changes in jcontext.h JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
parent
6049c0378d
commit
c3b6bfe8b6
@ -20,11 +20,20 @@
|
||||
*/
|
||||
|
||||
#ifndef JERRY_ENABLE_EXTERNAL_CONTEXT
|
||||
|
||||
/**
|
||||
* Global context.
|
||||
*/
|
||||
jerry_context_t jerry_global_context;
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
|
||||
/**
|
||||
* Check size of heap is corresponding to configuration
|
||||
*/
|
||||
JERRY_STATIC_ASSERT (sizeof (jmem_heap_t) <= JMEM_HEAP_SIZE,
|
||||
size_of_mem_heap_must_be_less_than_or_equal_to_JMEM_HEAP_SIZE);
|
||||
|
||||
/**
|
||||
* Jerry global heap section attribute.
|
||||
*/
|
||||
@ -34,11 +43,11 @@ jerry_context_t jerry_global_context;
|
||||
#define JERRY_GLOBAL_HEAP_SECTION JERRY_ATTR_SECTION (JERRY_HEAP_SECTION_ATTR)
|
||||
#endif /* !JERRY_HEAP_SECTION_ATTR */
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
/**
|
||||
* Global heap.
|
||||
*/
|
||||
jmem_heap_t jerry_global_heap JERRY_ATTR_ALIGNED (JMEM_ALIGNMENT) JERRY_GLOBAL_HEAP_SECTION;
|
||||
|
||||
#endif /* !JERRY_SYSTEM_ALLOCATOR */
|
||||
|
||||
#endif /* !JERRY_ENABLE_EXTERNAL_CONTEXT */
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
/*
|
||||
* Memory context for JerryScript
|
||||
*/
|
||||
#ifndef JCONTEXT_H
|
||||
@ -33,11 +33,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* First member of the jerry context
|
||||
*/
|
||||
#define JERRY_CONTEXT_FIRST_MEMBER ecma_builtin_objects
|
||||
|
||||
/**
|
||||
* User context item
|
||||
*/
|
||||
@ -50,6 +45,11 @@ typedef struct jerry_context_data_header
|
||||
#define JERRY_CONTEXT_DATA_HEADER_USER_DATA(item_p) \
|
||||
((uint8_t *) (item_p + 1))
|
||||
|
||||
/**
|
||||
* First member of the jerry context
|
||||
*/
|
||||
#define JERRY_CONTEXT_FIRST_MEMBER ecma_builtin_objects
|
||||
|
||||
/**
|
||||
* JerryScript context
|
||||
*
|
||||
@ -141,24 +141,35 @@ typedef struct
|
||||
|
||||
#ifdef JERRY_ENABLE_EXTERNAL_CONTEXT
|
||||
|
||||
#ifndef JERRY_GET_CURRENT_INSTANCE
|
||||
/*
|
||||
* This part is for JerryScript which uses external context.
|
||||
*/
|
||||
|
||||
#ifndef JERRY_GET_CURRENT_INSTANCE
|
||||
/**
|
||||
* Default function if JERRY_GET_CURRENT_INSTANCE is not defined.
|
||||
*/
|
||||
#define JERRY_GET_CURRENT_INSTANCE() (jerry_port_get_current_instance ())
|
||||
|
||||
#endif /* !JERRY_GET_CURRENT_INSTANCE */
|
||||
|
||||
/**
|
||||
* This part is for Jerry which enable external context.
|
||||
*/
|
||||
#define JERRY_CONTEXT(field) (JERRY_GET_CURRENT_INSTANCE ()->context.field)
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
|
||||
#define JMEM_HEAP_SIZE (JERRY_GET_CURRENT_INSTANCE ()->heap_size)
|
||||
|
||||
#define JMEM_HEAP_AREA_SIZE (JMEM_HEAP_SIZE - JMEM_ALIGNMENT)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
jmem_heap_free_t first; /**< first node in free region list */
|
||||
uint8_t area[]; /**< heap area */
|
||||
} jmem_heap_t;
|
||||
|
||||
#define JERRY_HEAP_CONTEXT(field) (JERRY_GET_CURRENT_INSTANCE ()->heap_p->field)
|
||||
|
||||
#endif /* !JERRY_SYSTEM_ALLOCATOR */
|
||||
|
||||
/**
|
||||
* Description of jerry instance which is the header of the context space.
|
||||
*/
|
||||
@ -171,33 +182,28 @@ struct jerry_instance_t
|
||||
#endif /* !JERRY_SYSTEM_ALLOCATOR */
|
||||
};
|
||||
|
||||
#define JERRY_CONTEXT(field) (JERRY_GET_CURRENT_INSTANCE ()->context.field)
|
||||
#else /* !JERRY_ENABLE_EXTERNAL_CONTEXT */
|
||||
|
||||
/*
|
||||
* This part is for JerryScript which uses default context.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Global context.
|
||||
*/
|
||||
extern jerry_context_t jerry_global_context;
|
||||
|
||||
/**
|
||||
* Provides a reference to a field in the current context.
|
||||
*/
|
||||
#define JERRY_CONTEXT(field) (jerry_global_context.field)
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
|
||||
static inline jmem_heap_t * JERRY_ATTR_ALWAYS_INLINE
|
||||
jerry_context_get_current_heap (void)
|
||||
{
|
||||
return JERRY_GET_CURRENT_INSTANCE ()->heap_p;
|
||||
} /* jerry_context_get_current_heap */
|
||||
|
||||
#define JERRY_HEAP_CONTEXT(field) (jerry_context_get_current_heap ()->field)
|
||||
|
||||
#ifdef JMEM_HEAP_SIZE
|
||||
#error "JMEM_HEAP_SIZE must not be defined if JERRY_ENABLE_EXTERNAL_CONTEXT is defined"
|
||||
#endif /* JMEM_HEAP_SIZE */
|
||||
|
||||
#define JMEM_HEAP_SIZE (JERRY_GET_CURRENT_INSTANCE ()->heap_size)
|
||||
|
||||
#define JMEM_HEAP_AREA_SIZE (JERRY_GET_CURRENT_INSTANCE ()->heap_size - JMEM_ALIGNMENT)
|
||||
|
||||
#endif /* !JERRY_SYSTEM_ALLOCATOR */
|
||||
|
||||
#else /* !JERRY_ENABLE_EXTERNAL_CONTEXT */
|
||||
|
||||
/**
|
||||
* This part is for Jerry which use default context.
|
||||
*/
|
||||
* Size of heap
|
||||
*/
|
||||
#define JMEM_HEAP_SIZE ((size_t) (CONFIG_MEM_HEAP_AREA_SIZE))
|
||||
|
||||
/**
|
||||
* Calculate heap area size, leaving space for a pointer to the free list
|
||||
@ -222,26 +228,13 @@ typedef struct
|
||||
uint8_t area[JMEM_HEAP_AREA_SIZE]; /**< heap area */
|
||||
} jmem_heap_t;
|
||||
|
||||
/**
|
||||
* Global context.
|
||||
*/
|
||||
extern jerry_context_t jerry_global_context;
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
/**
|
||||
* Global heap.
|
||||
*/
|
||||
extern jmem_heap_t jerry_global_heap;
|
||||
#endif /* !JERRY_SYSTEM_ALLOCATOR */
|
||||
|
||||
/**
|
||||
* Provides a reference to a field in the current context.
|
||||
*/
|
||||
#define JERRY_CONTEXT(field) (jerry_global_context.field)
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
/**
|
||||
* Provides a reference to the area field of the heap.
|
||||
* Provides a reference to a field of the heap.
|
||||
*/
|
||||
#define JERRY_HEAP_CONTEXT(field) (jerry_global_heap.field)
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
/**
|
||||
* End of list marker.
|
||||
*/
|
||||
@ -52,7 +53,6 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
/**
|
||||
* Get end of region
|
||||
*
|
||||
@ -65,14 +65,6 @@ jmem_heap_get_region_end (jmem_heap_free_t *curr_p) /**< current region */
|
||||
} /* jmem_heap_get_region_end */
|
||||
#endif /* !JERRY_SYSTEM_ALLOCATOR */
|
||||
|
||||
#ifndef JERRY_ENABLE_EXTERNAL_CONTEXT
|
||||
/**
|
||||
* Check size of heap is corresponding to configuration
|
||||
*/
|
||||
JERRY_STATIC_ASSERT (sizeof (jmem_heap_t) <= JMEM_HEAP_SIZE,
|
||||
size_of_mem_heap_must_be_less_than_or_equal_to_MEM_HEAP_SIZE);
|
||||
#endif /* !JERRY_ENABLE_EXTERNAL_CONTEXT */
|
||||
|
||||
#ifdef JMEM_STATS
|
||||
static void jmem_heap_stat_init (void);
|
||||
static void jmem_heap_stat_alloc (size_t num);
|
||||
@ -117,12 +109,11 @@ static void jmem_heap_stat_free_iter (void);
|
||||
void
|
||||
jmem_heap_init (void)
|
||||
{
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
#ifndef JERRY_CPOINTER_32_BIT
|
||||
/* the maximum heap size for 16bit compressed pointers should be 512K */
|
||||
JERRY_ASSERT (((UINT16_MAX + 1) << JMEM_ALIGNMENT_LOG) >= JMEM_HEAP_SIZE);
|
||||
#endif /* !JERRY_CPOINTER_32_BIT */
|
||||
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
JERRY_ASSERT ((uintptr_t) JERRY_HEAP_CONTEXT (area) % JMEM_ALIGNMENT == 0);
|
||||
|
||||
JERRY_CONTEXT (jmem_heap_limit) = CONFIG_MEM_HEAP_DESIRED_LIMIT;
|
||||
@ -547,9 +538,12 @@ jmem_heap_stats_print (void)
|
||||
{
|
||||
jmem_heap_stats_t *heap_stats = &JERRY_CONTEXT (jmem_heap_stats);
|
||||
|
||||
JERRY_DEBUG_MSG ("Heap stats:\n"
|
||||
" Heap size = %zu bytes\n"
|
||||
" Allocated = %zu bytes\n"
|
||||
JERRY_DEBUG_MSG ("Heap stats:\n");
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
JERRY_DEBUG_MSG (" Heap size = %zu bytes\n",
|
||||
heap_stats->size);
|
||||
#endif /* !JERRY_SYSTEM_ALLOCATOR */
|
||||
JERRY_DEBUG_MSG (" Allocated = %zu bytes\n"
|
||||
" Peak allocated = %zu bytes\n"
|
||||
" Waste = %zu bytes\n"
|
||||
" Peak waste = %zu bytes\n"
|
||||
@ -561,7 +555,6 @@ jmem_heap_stats_print (void)
|
||||
" Peak allocated object data = %zu bytes\n"
|
||||
" Allocated property data = %zu bytes\n"
|
||||
" Peak allocated property data = %zu bytes\n",
|
||||
heap_stats->size,
|
||||
heap_stats->allocated_bytes,
|
||||
heap_stats->peak_allocated_bytes,
|
||||
heap_stats->waste_bytes,
|
||||
@ -593,7 +586,9 @@ jmem_heap_stats_print (void)
|
||||
static void
|
||||
jmem_heap_stat_init (void)
|
||||
{
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
JERRY_CONTEXT (jmem_heap_stats).size = JMEM_HEAP_AREA_SIZE;
|
||||
#endif /* !JERRY_SYSTEM_ALLOCATOR */
|
||||
} /* jmem_heap_stat_init */
|
||||
|
||||
/**
|
||||
|
||||
@ -25,13 +25,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef JERRY_ENABLE_EXTERNAL_CONTEXT
|
||||
/**
|
||||
* Size of heap
|
||||
*/
|
||||
#define JMEM_HEAP_SIZE ((size_t) (CONFIG_MEM_HEAP_AREA_SIZE))
|
||||
#endif /* !JERRY_ENABLE_EXTERNAL_CONTEXT */
|
||||
|
||||
/**
|
||||
* Logarithm of required alignment for allocated units/blocks
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user