aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Langó <llango.u-szeged@partner.samsung.com>2017-01-30 11:04:25 +0100
committerGitHub <noreply@github.com>2017-01-30 11:04:25 +0100
commit7b59c80e185e52cfd33c0bb5b733261eca0b5ae3 (patch)
tree2bc3b5749e03785e0ca73c325d3ad0edcf581f6f
parent0c3ef892c0f346f017a40725fb0f7fa210bc9802 (diff)
Use default system allocator on 32bit systems, if JERRY_SYSTEM_ALLOCATOR is defined. (#1541)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
-rw-r--r--jerry-core/CMakeLists.txt37
-rw-r--r--jerry-core/jcontext/jcontext.c2
-rw-r--r--jerry-core/jcontext/jcontext.h4
-rw-r--r--jerry-core/jmem/jmem-heap.c33
-rwxr-xr-xtools/build.py2
5 files changed, 61 insertions, 17 deletions
diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt
index d4f6107b..c3bcaa1a 100644
--- a/jerry-core/CMakeLists.txt
+++ b/jerry-core/CMakeLists.txt
@@ -17,19 +17,24 @@ set(JERRY_CORE_NAME jerry-core)
project (${JERRY_CORE_NAME} C)
# Optional features
-set(FEATURE_CPOINTER_32_BIT OFF CACHE BOOL "Enable 32 bit compressed pointers?")
-set(FEATURE_ERROR_MESSAGES OFF CACHE BOOL "Enable error messages?")
-set(FEATURE_JS_PARSER ON CACHE BOOL "Enable js-parser?")
-set(FEATURE_MEM_STATS OFF CACHE BOOL "Enable memory statistics?")
-set(FEATURE_MEM_STRESS_TEST OFF CACHE BOOL "Enable mem-stress test?")
-set(FEATURE_PARSER_DUMP OFF CACHE BOOL "Enable parser byte-code dumps?")
-set(FEATURE_PROFILE "es5.1" CACHE STRING "Use default or other profile?")
-set(FEATURE_REGEXP_DUMP OFF CACHE BOOL "Enable regexp byte-code dumps?")
-set(FEATURE_SNAPSHOT_EXEC OFF CACHE BOOL "Enable executing snapshot files?")
-set(FEATURE_SNAPSHOT_SAVE OFF CACHE BOOL "Enable saving snapshot files?")
-set(FEATURE_VALGRIND OFF CACHE BOOL "Enable Valgrind support?")
-set(FEATURE_VALGRIND_FREYA OFF CACHE BOOL "Enable Valgrind-Freya support?")
-set(MEM_HEAP_SIZE_KB "512" CACHE STRING "Size of memory heap, in kilobytes")
+set(FEATURE_CPOINTER_32_BIT OFF CACHE BOOL "Enable 32 bit compressed pointers?")
+set(FEATURE_ERROR_MESSAGES OFF CACHE BOOL "Enable error messages?")
+set(FEATURE_JS_PARSER ON CACHE BOOL "Enable js-parser?")
+set(FEATURE_MEM_STATS OFF CACHE BOOL "Enable memory statistics?")
+set(FEATURE_MEM_STRESS_TEST OFF CACHE BOOL "Enable mem-stress test?")
+set(FEATURE_PARSER_DUMP OFF CACHE BOOL "Enable parser byte-code dumps?")
+set(FEATURE_PROFILE "es5.1" CACHE STRING "Use default or other profile?")
+set(FEATURE_REGEXP_DUMP OFF CACHE BOOL "Enable regexp byte-code dumps?")
+set(FEATURE_SNAPSHOT_EXEC OFF CACHE BOOL "Enable executing snapshot files?")
+set(FEATURE_SNAPSHOT_SAVE OFF CACHE BOOL "Enable saving snapshot files?")
+set(FEATURE_SYSTEM_ALLOCATOR OFF CACHE BOOL "Enable system allocator?")
+set(FEATURE_VALGRIND OFF CACHE BOOL "Enable Valgrind support?")
+set(FEATURE_VALGRIND_FREYA OFF CACHE BOOL "Enable Valgrind-Freya support?")
+set(MEM_HEAP_SIZE_KB "512" CACHE STRING "Size of memory heap, in kilobytes")
+
+if(FEATURE_SYSTEM_ALLOCATOR)
+ set(FEATURE_CPOINTER_32_BIT ON)
+endif()
# Status messages
message(STATUS "FEATURE_CPOINTER_32_BIT " ${FEATURE_CPOINTER_32_BIT})
@@ -42,6 +47,7 @@ message(STATUS "FEATURE_PROFILE " ${FEATURE_PROFILE})
message(STATUS "FEATURE_REGEXP_DUMP " ${FEATURE_REGEXP_DUMP})
message(STATUS "FEATURE_SNAPSHOT_EXEC " ${FEATURE_SNAPSHOT_EXEC})
message(STATUS "FEATURE_SNAPSHOT_SAVE " ${FEATURE_SNAPSHOT_SAVE})
+message(STATUS "FEATURE_SYSTEM_ALLOCATOR " ${FEATURE_SYSTEM_ALLOCATOR})
message(STATUS "FEATURE_VALGRIND " ${FEATURE_VALGRIND})
message(STATUS "FEATURE_VALGRIND_FREYA " ${FEATURE_VALGRIND_FREYA})
message(STATUS "MEM_HEAP_SIZE_KB " ${MEM_HEAP_SIZE_KB})
@@ -194,6 +200,11 @@ if(FEATURE_SNAPSHOT_SAVE)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_SNAPSHOT_SAVE)
endif()
+# Enable system allocator
+if(FEATURE_SYSTEM_ALLOCATOR)
+ set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_SYSTEM_ALLOCATOR)
+endif()
+
# Valgrind
if(FEATURE_VALGRIND)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_VALGRIND)
diff --git a/jerry-core/jcontext/jcontext.c b/jerry-core/jcontext/jcontext.c
index 627de7f9..42241302 100644
--- a/jerry-core/jcontext/jcontext.c
+++ b/jerry-core/jcontext/jcontext.c
@@ -33,10 +33,12 @@ jerry_context_t jerry_global_context;
#define JERRY_GLOBAL_HEAP_SECTION __attribute__ ((section (JERRY_HEAP_SECTION_ATTR)))
#endif /* !JERRY_HEAP_SECTION_ATTR */
+#ifndef JERRY_SYSTEM_ALLOCATOR
/**
* Global heap.
*/
jmem_heap_t jerry_global_heap __attribute__ ((aligned (JMEM_ALIGNMENT))) JERRY_GLOBAL_HEAP_SECTION;
+#endif /* !JERRY_SYSTEM_ALLOCATOR */
#ifndef CONFIG_ECMA_LCACHE_DISABLE
diff --git a/jerry-core/jcontext/jcontext.h b/jerry-core/jcontext/jcontext.h
index b9acd4a9..a19954f2 100644
--- a/jerry-core/jcontext/jcontext.h
+++ b/jerry-core/jcontext/jcontext.h
@@ -135,10 +135,12 @@ typedef struct
*/
extern jerry_context_t jerry_global_context;
+#ifndef JERRY_SYSTEM_ALLOCATOR
/**
* Global heap.
*/
extern jmem_heap_t jerry_global_heap;
+#endif /* !JERRY_SYSTEM_ALLOCATOR */
#ifndef CONFIG_ECMA_LCACHE_DISABLE
@@ -154,10 +156,12 @@ extern jerry_hash_table_t jerry_global_hash_table;
*/
#define JERRY_CONTEXT(field) (jerry_global_context.field)
+#ifndef JERRY_SYSTEM_ALLOCATOR
/**
* Provides a reference to the area field of the heap.
*/
#define JERRY_HEAP_CONTEXT(field) (jerry_global_heap.field)
+#endif /* !JERRY_SYSTEM_ALLOCATOR */
#ifndef CONFIG_ECMA_LCACHE_DISABLE
diff --git a/jerry-core/jmem/jmem-heap.c b/jerry-core/jmem/jmem-heap.c
index 2699d70a..775e0e94 100644
--- a/jerry-core/jmem/jmem-heap.c
+++ b/jerry-core/jmem/jmem-heap.c
@@ -108,6 +108,12 @@ JERRY_STATIC_ASSERT (sizeof (jmem_heap_t) <= JMEM_HEAP_SIZE,
size_of_mem_heap_must_be_less_than_or_equal_to_MEM_HEAP_SIZE);
#ifdef JMEM_STATS
+
+#ifdef JERRY_SYSTEM_ALLOCATOR
+/* TODO: Implement mem-stat support for system allocator */
+#error Memory statistics (JMEM_STATS) are not supported
+#endif
+
static void jmem_heap_stat_init (void);
static void jmem_heap_stat_alloc (size_t num);
static void jmem_heap_stat_free (size_t num);
@@ -144,6 +150,7 @@ jmem_heap_init (void)
maximum_heap_size_for_16_bit_compressed_pointers_is_512K);
#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;
@@ -160,16 +167,20 @@ jmem_heap_init (void)
VALGRIND_NOACCESS_SPACE (JERRY_HEAP_CONTEXT (area), JMEM_HEAP_AREA_SIZE);
+#endif /* !JERRY_SYSTEM_ALLOCATOR */
JMEM_HEAP_STAT_INIT ();
} /* jmem_heap_init */
/**
* Finalize heap
*/
-void jmem_heap_finalize (void)
+void
+jmem_heap_finalize (void)
{
JERRY_ASSERT (JERRY_CONTEXT (jmem_heap_allocated_size) == 0);
+#ifndef JERRY_SYSTEM_ALLOCATOR
VALGRIND_NOACCESS_SPACE (&JERRY_HEAP_CONTEXT (first), sizeof (jmem_heap_t));
+#endif /* !JERRY_SYSTEM_ALLOCATOR */
} /* jmem_heap_finalize */
/**
@@ -181,9 +192,10 @@ void jmem_heap_finalize (void)
* @return pointer to allocated memory block - if allocation is successful,
* NULL - if there is not enough memory.
*/
-static __attr_hot___
-void *jmem_heap_alloc_block_internal (const size_t size)
+static __attr_hot___ void *
+jmem_heap_alloc_block_internal (const size_t size)
{
+#ifndef JERRY_SYSTEM_ALLOCATOR
/* Align size. */
const size_t required_size = ((size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT) * JMEM_ALIGNMENT;
jmem_heap_free_t *data_space_p = NULL;
@@ -306,7 +318,10 @@ void *jmem_heap_alloc_block_internal (const size_t size)
JMEM_HEAP_STAT_ALLOC (size);
return (void *) data_space_p;
-} /* jmem_heap_finalize */
+#else /* JERRY_SYSTEM_ALLOCATOR */
+ return malloc (size);
+#endif /* !JERRY_SYSTEM_ALLOCATOR */
+} /* jmem_heap_alloc_block_internal */
/**
* Allocation of memory block, running 'try to give memory back' callbacks, if there is not enough memory.
@@ -412,6 +427,7 @@ void __attr_hot___
jmem_heap_free_block (void *ptr, /**< pointer to beginning of data space of the block */
const size_t size) /**< size of allocated region */
{
+#ifndef JERRY_SYSTEM_ALLOCATOR
VALGRIND_FREYA_CHECK_MEMPOOL_REQUEST;
/* checking that ptr points to the heap */
@@ -515,6 +531,10 @@ jmem_heap_free_block (void *ptr, /**< pointer to beginning of data space of the
VALGRIND_NOACCESS_SPACE (&JERRY_HEAP_CONTEXT (first), sizeof (jmem_heap_free_t));
JERRY_ASSERT (JERRY_CONTEXT (jmem_heap_limit) >= JERRY_CONTEXT (jmem_heap_allocated_size));
JMEM_HEAP_STAT_FREE (size);
+#else /* JERRY_SYSTEM_ALLOCATOR */
+ JERRY_UNUSED (size);
+ free (ptr);
+#endif /* !JERRY_SYSTEM_ALLOCATOR */
} /* jmem_heap_free_block */
#ifndef JERRY_NDEBUG
@@ -530,8 +550,13 @@ jmem_heap_free_block (void *ptr, /**< pointer to beginning of data space of the
bool
jmem_is_heap_pointer (const void *pointer) /**< pointer */
{
+#ifndef JERRY_SYSTEM_ALLOCATOR
return ((uint8_t *) pointer >= JERRY_HEAP_CONTEXT (area)
&& (uint8_t *) pointer <= (JERRY_HEAP_CONTEXT (area) + JMEM_HEAP_AREA_SIZE));
+#else /* JERRY_SYSTEM_ALLOCATOR */
+ JERRY_UNUSED (pointer);
+ return true;
+#endif /* !JERRY_SYSTEM_ALLOCATOR */
} /* jmem_is_heap_pointer */
#endif /* !JERRY_NDEBUG */
diff --git a/tools/build.py b/tools/build.py
index 19b6551d..e5c3db29 100755
--- a/tools/build.py
+++ b/tools/build.py
@@ -67,6 +67,7 @@ def get_arguments():
parser.add_argument('--profile', metavar='FILE', action='store', default=DEFAULT_PROFILE, help='specify profile file (default: %(default)s)')
parser.add_argument('--snapshot-exec', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable executing snapshot files (%(choices)s; default: %(default)s)')
parser.add_argument('--snapshot-save', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable saving snapshot files (%(choices)s; default: %(default)s)')
+ parser.add_argument('--system-allocator', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable system allocator (%(choices)s; default: %(default)s)')
parser.add_argument('--static-link', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='enable static linking of binaries (%(choices)s; default: %(default)s)')
parser.add_argument('--strip', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='strip release binaries (%(choices)s; default: %(default)s)')
parser.add_argument('--toolchain', metavar='FILE', action='store', default=default_toolchain(), help='add toolchain file (default: %(default)s)')
@@ -118,6 +119,7 @@ def generate_build_options(arguments):
build_options.append('-DFEATURE_SNAPSHOT_EXEC=%s' % arguments.snapshot_exec)
build_options.append('-DFEATURE_SNAPSHOT_SAVE=%s' % arguments.snapshot_save)
+ build_options.append('-DFEATURE_SYSTEM_ALLOCATOR=%s' % arguments.system_allocator)
build_options.append('-DENABLE_STATIC_LINK=%s' % arguments.static_link)
build_options.append('-DENABLE_STRIP=%s' % arguments.strip)