diff --git a/CMakeLists.txt b/CMakeLists.txt index 963b6166c..52ab6eccc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,10 +252,6 @@ project (Jerry CXX C ASM) set(LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} ${LINKER_FLAGS_COMMON_${PLATFORM_EXT}}") set(SOURCE_JERRY_STANDALONE_MAIN ${SOURCE_JERRY_STANDALONE_MAIN_${PLATFORM_EXT}}) -# Definitions - # Memory statistics - set(DEFINES_MEMORY_STATISTICS MEM_STATS) - # Component targets # Jerry's libc if(NOT ${USE_EXTERNAL_LIBC}) @@ -278,15 +274,16 @@ project (Jerry CXX C ASM) set(LIBC_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.jerry-libc.${PLATFORM_L}.lib) function(declare_target_with_modifiers ) # modifiers are passed in ARGN implicit argument - set(DEFINES_JERRY) set(CORE_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}) foreach(MODIFIER ${ARGN}) set(TARGET_NAME ${TARGET_NAME}${MODIFIER_SUFFIX_${MODIFIER}}) + set(CORE_TARGET_NAME ${CORE_TARGET_NAME}${MODIFIER_SUFFIX_${MODIFIER}}) - set(DEFINES_JERRY ${DEFINES_JERRY} ${DEFINES_${MODIFIER}}) endforeach() set(CORE_TARGET_NAME ${CORE_TARGET_NAME}.jerry-core) + set(DEFINES_JERRY ) + if(NOT ${EXTERNAL_BUILD}) add_executable(${TARGET_NAME} ${SOURCE_JERRY_STANDALONE_MAIN}) diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index c48dd94b8..27a0ab2b1 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -66,6 +66,9 @@ project (JerryCore CXX C ASM) CONFIG_ECMA_COMPACT_PROFILE_DISABLE_JSON_BUILTIN CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN) + # Memory statistics + set(DEFINES_MEMORY_STATISTICS MEM_STATS) + # Valgrind set(DEFINES_JERRY_VALGRIND JERRY_VALGRIND) diff --git a/jerry-core/jerry.cpp b/jerry-core/jerry.cpp index 7462ffd54..42ff14d41 100644 --- a/jerry-core/jerry.cpp +++ b/jerry-core/jerry.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include + #include "deserializer.h" #include "ecma-extension.h" #include "ecma-gc.h" @@ -269,6 +271,13 @@ jerry_init (jerry_flag_t flags) /**< combination of Jerry flags */ { jerry_flags = flags; +#ifndef MEM_STATS + if (flags & JERRY_FLAG_MEM_STATS) + { + printf ("Ignoring memory statistics option because of '!MEM_STATS' build configuration.\n"); + } +#endif /* !MEM_STATS */ + mem_init (); deserializer_init (); ecma_init (); diff --git a/jerry-core/mem/mem-allocator.cpp b/jerry-core/mem/mem-allocator.cpp index 146607591..254c1ea1a 100644 --- a/jerry-core/mem/mem-allocator.cpp +++ b/jerry-core/mem/mem-allocator.cpp @@ -65,18 +65,18 @@ mem_finalize (bool is_show_mem_stats) /**< show heap memory stats mem_pools_get_stats (&stats); printf ("Pools stats:\n"); - printf (" Chunk size: %u\n" - " Pools: %lu\n" - " Allocated chunks: %lu\n" - " Free chunks: %lu\n" - " Peak pools: %lu\n" - " Peak allocated chunks: %lu\n\n", + printf (" Chunk size: %zu\n" + " Pools: %zu\n" + " Allocated chunks: %zu\n" + " Free chunks: %zu\n" + " Peak pools: %zu\n" + " Peak allocated chunks: %zu\n\n", MEM_POOL_CHUNK_SIZE, - (unsigned long) stats.pools_count, - (unsigned long) stats.allocated_chunks, - (unsigned long) stats.free_chunks, - (unsigned long) stats.peak_pools_count, - (unsigned long) stats.peak_allocated_chunks); + stats.pools_count, + stats.allocated_chunks, + stats.free_chunks, + stats.peak_pools_count, + stats.peak_allocated_chunks); #endif /* MEM_STATS */ } diff --git a/jerry-core/mem/mem-config.h b/jerry-core/mem/mem-config.h index 23afc8d25..828252479 100644 --- a/jerry-core/mem/mem-config.h +++ b/jerry-core/mem/mem-config.h @@ -26,17 +26,17 @@ /** * Size of heap */ -#define MEM_HEAP_AREA_SIZE (CONFIG_MEM_HEAP_AREA_SIZE) +#define MEM_HEAP_AREA_SIZE ((size_t) (CONFIG_MEM_HEAP_AREA_SIZE)) /** * Size of heap chunk */ -#define MEM_HEAP_CHUNK_SIZE (CONFIG_MEM_HEAP_CHUNK_SIZE) +#define MEM_HEAP_CHUNK_SIZE ((size_t) (CONFIG_MEM_HEAP_CHUNK_SIZE)) /** * Size of pool chunk */ -#define MEM_POOL_CHUNK_SIZE (CONFIG_MEM_POOL_CHUNK_SIZE) +#define MEM_POOL_CHUNK_SIZE ((size_t) (CONFIG_MEM_POOL_CHUNK_SIZE)) /** * Log2 of maximum number of chunks in a pool diff --git a/jerry-core/mem/mem-heap.cpp b/jerry-core/mem/mem-heap.cpp index d4939c5c5..3cc0b3835 100644 --- a/jerry-core/mem/mem-heap.cpp +++ b/jerry-core/mem/mem-heap.cpp @@ -962,28 +962,28 @@ mem_heap_print (bool dump_block_headers, /**< print block headers */ if (dump_stats) { printf ("Heap stats:\n"); - printf (" Heap size = %lu bytes\n" - " Chunk size = %lu bytes\n" - " Blocks count = %lu\n" - " Allocated blocks count = %lu\n" - " Allocated chunks count = %lu\n" - " Allocated = %lu bytes\n" - " Waste = %lu bytes\n" - " Peak allocated blocks count = %lu\n" - " Peak allocated chunks count = %lu\n" - " Peak allocated= %lu bytes\n" - " Peak waste = %lu bytes\n", - (uint64_t) mem_heap_stats.size, - (uint64_t) MEM_HEAP_CHUNK_SIZE, - (uint64_t) mem_heap_stats.blocks, - (uint64_t) mem_heap_stats.allocated_blocks, - (uint64_t) mem_heap_stats.allocated_chunks, - (uint64_t) mem_heap_stats.allocated_bytes, - (uint64_t) mem_heap_stats.waste_bytes, - (uint64_t) mem_heap_stats.peak_allocated_blocks, - (uint64_t) mem_heap_stats.peak_allocated_chunks, - (uint64_t) mem_heap_stats.peak_allocated_bytes, - (uint64_t) mem_heap_stats.peak_waste_bytes); + printf (" Heap size = %zu bytes\n" + " Chunk size = %zu bytes\n" + " Blocks count = %zu\n" + " Allocated blocks count = %zu\n" + " Allocated chunks count = %zu\n" + " Allocated = %zu bytes\n" + " Waste = %zu bytes\n" + " Peak allocated blocks count = %zu\n" + " Peak allocated chunks count = %zu\n" + " Peak allocated= %zu bytes\n" + " Peak waste = %zu bytes\n", + mem_heap_stats.size, + MEM_HEAP_CHUNK_SIZE, + mem_heap_stats.blocks, + mem_heap_stats.allocated_blocks, + mem_heap_stats.allocated_chunks, + mem_heap_stats.allocated_bytes, + mem_heap_stats.waste_bytes, + mem_heap_stats.peak_allocated_blocks, + mem_heap_stats.peak_allocated_chunks, + mem_heap_stats.peak_allocated_bytes, + mem_heap_stats.peak_waste_bytes); } #else /* MEM_STATS */ (void) dump_stats; diff --git a/main-linux.cpp b/main-linux.cpp index 093727cb8..6e1a07f66 100644 --- a/main-linux.cpp +++ b/main-linux.cpp @@ -141,11 +141,7 @@ main (int argc, } else if (!strcmp ("--mem-stats", argv[i])) { -#ifdef MEM_STATS flags |= JERRY_FLAG_MEM_STATS; -#else /* MEM_STATS */ - printf ("Ignoring --mem-stats because of '!MEM_STATS' build configuration.\n"); -#endif /* !MEM_STATS */ } else if (!strcmp ("--parse-only", argv[i])) { diff --git a/main-nuttx.cpp b/main-nuttx.cpp index 3ca67c3e3..04fbaf945 100644 --- a/main-nuttx.cpp +++ b/main-nuttx.cpp @@ -148,11 +148,7 @@ int jerry_main (int argc, char *argv[]) } else if (!strcmp ("--mem-stats", argv[i])) { -#ifdef MEM_STATS flags |= JERRY_FLAG_MEM_STATS; -#else /* MEM_STATS */ - printf ("Ignoring --mem-stats because of '!MEM_STATS' build configuration.\n"); -#endif /* !MEM_STATS */ } else if (!strcmp ("--parse-only", argv[i])) {