diff options
author | Akos Kiss <akiss@inf.u-szeged.hu> | 2018-08-31 14:58:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-31 14:58:11 +0200 |
commit | c3b6bfe8b64668236b59fc745bad6d37c6990c6f (patch) | |
tree | 696a500009e4312a1cb8e3ff5bd5ceca876c8f21 | |
parent | 6049c0378dd5b4c146ad785c86a4200ce1ccb343 (diff) |
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
-rw-r--r-- | jerry-core/jcontext/jcontext.c | 11 | ||||
-rw-r--r-- | jerry-core/jcontext/jcontext.h | 85 | ||||
-rw-r--r-- | jerry-core/jmem/jmem-heap.c | 25 | ||||
-rw-r--r-- | jerry-core/jmem/jmem.h | 7 |
4 files changed, 59 insertions, 69 deletions
diff --git a/jerry-core/jcontext/jcontext.c b/jerry-core/jcontext/jcontext.c index 959e0c78..199b871d 100644 --- a/jerry-core/jcontext/jcontext.c +++ b/jerry-core/jcontext/jcontext.c @@ -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 */ diff --git a/jerry-core/jcontext/jcontext.h b/jerry-core/jcontext/jcontext.h index 24c9c050..6d07ffe4 100644 --- a/jerry-core/jcontext/jcontext.h +++ b/jerry-core/jcontext/jcontext.h @@ -13,7 +13,7 @@ * limitations under the License. */ -/** +/* * Memory context for JerryScript */ #ifndef JCONTEXT_H @@ -34,11 +34,6 @@ */ /** - * First member of the jerry context - */ -#define JERRY_CONTEXT_FIRST_MEMBER ecma_builtin_objects - -/** * User context item */ typedef struct jerry_context_data_header @@ -51,6 +46,11 @@ typedef struct jerry_context_data_header ((uint8_t *) (item_p + 1)) /** + * First member of the jerry context + */ +#define JERRY_CONTEXT_FIRST_MEMBER ecma_builtin_objects + +/** * JerryScript context * * The purpose of this header is storing @@ -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) - -#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 */ +#else /* !JERRY_ENABLE_EXTERNAL_CONTEXT */ -#define JMEM_HEAP_SIZE (JERRY_GET_CURRENT_INSTANCE ()->heap_size) +/* + * This part is for JerryScript which uses default context. + */ -#define JMEM_HEAP_AREA_SIZE (JERRY_GET_CURRENT_INSTANCE ()->heap_size - JMEM_ALIGNMENT) +/** + * Global context. + */ +extern jerry_context_t jerry_global_context; -#endif /* !JERRY_SYSTEM_ALLOCATOR */ +/** + * Provides a reference to a field in the current context. + */ +#define JERRY_CONTEXT(field) (jerry_global_context.field) -#else /* !JERRY_ENABLE_EXTERNAL_CONTEXT */ +#ifndef JERRY_SYSTEM_ALLOCATOR /** - * 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 @@ -223,25 +229,12 @@ typedef struct } 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) diff --git a/jerry-core/jmem/jmem-heap.c b/jerry-core/jmem/jmem-heap.c index 0511a88a..2fe973c1 100644 --- a/jerry-core/jmem/jmem-heap.c +++ b/jerry-core/jmem/jmem-heap.c @@ -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 */ /** diff --git a/jerry-core/jmem/jmem.h b/jerry-core/jmem/jmem.h index a6caa093..8665e52f 100644 --- a/jerry-core/jmem/jmem.h +++ b/jerry-core/jmem/jmem.h @@ -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 */ |