From a293e21147f6b9bbd5410082b67f5b27ba90f69c Mon Sep 17 00:00:00 2001 From: Andrey Shitov Date: Mon, 15 Jun 2015 17:04:44 +0300 Subject: [PATCH] Introduce JERRY_DISABLE_HEAVY_DEBUG preprocessor definiton to speed up debug version of the engine. Heavy debug is enabled only for unit tests. JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com --- jerry-core/CMakeLists.txt | 4 ++-- jerry-core/jrt/jrt-fatals.cpp | 6 +++--- jerry-core/jrt/jrt.h | 6 +++--- jerry-core/mem/mem-heap.cpp | 4 ++-- jerry-core/mem/mem-pool.cpp | 8 +++++--- jerry-core/rcs/rcs-chunked-list.cpp | 10 +++++----- jerry-core/rcs/rcs-recordset.cpp | 4 ++-- plugins/CMakeLists.txt | 2 +- tests/unit/test-common.h | 7 +++++++ 9 files changed, 30 insertions(+), 21 deletions(-) diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index b20965dda2..1cbb98ab4d 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -37,10 +37,10 @@ project (JerryCore CXX C ASM) # Build modes # Debug - set(DEFINES_JERRY_DEBUG JERRY_ENABLE_PRETTY_PRINTER) + set(DEFINES_JERRY_DEBUG JERRY_ENABLE_PRETTY_PRINTER JERRY_DISABLE_HEAVY_DEBUG) # Release - set(DEFINES_JERRY_RELEASE JERRY_NDEBUG) + set(DEFINES_JERRY_RELEASE JERRY_NDEBUG JERRY_DISABLE_HEAVY_DEBUG) # Unit tests set(DEFINES_JERRY_UNITTESTS JERRY_ENABLE_PRETTY_PRINTER) diff --git a/jerry-core/jrt/jrt-fatals.cpp b/jerry-core/jrt/jrt-fatals.cpp index 3ada6946b2..2dcc761ba8 100644 --- a/jerry-core/jrt/jrt-fatals.cpp +++ b/jerry-core/jrt/jrt-fatals.cpp @@ -84,15 +84,15 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */ const char *function, /**< function name */ const uint32_t line) /** line */ { -#ifndef JERRY_NDEBUG +#if !defined (JERRY_NDEBUG) || !defined (JERRY_DISABLE_HEAVY_DEBUG) printf ("ICE: Assertion '%s' failed at %s(%s):%lu.\n", assertion, file, function, (unsigned long) line); -#else /* !JERRY_NDEBUG */ +#else /* !JERRY_NDEBUG || !JERRY_DISABLE_HEAVY_DEBUG */ (void) assertion; (void) file; (void) function; (void) line; -#endif /* JERRY_NDEBUG */ +#endif /* JERRY_NDEBUG && JERRY_DISABLE_HEAVY_DEBUG */ jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION); } /* jerry_assert_fail */ diff --git a/jerry-core/jrt/jrt.h b/jerry-core/jrt/jrt.h index 45fa13affb..8ced0a61ef 100644 --- a/jerry-core/jrt/jrt.h +++ b/jerry-core/jrt/jrt.h @@ -86,12 +86,12 @@ extern void __noreturn jerry_unreachable (const char *comment, const char *file, extern void __noreturn jerry_unimplemented (const char *comment, const char *file, const char *function, const uint32_t line); -#ifndef JERRY_NDEBUG +#if !defined (JERRY_NDEBUG) || !defined (JERRY_DISABLE_HEAVY_DEBUG) #define JERRY_ASSERT(x) do { if (__builtin_expect (!(x), 0)) { \ jerry_assert_fail (#x, __FILE__, __func__, __LINE__); } } while (0) -#else /* !JERRY_NDEBUG */ +#else /* !JERRY_NDEBUG || !JERRY_DISABLE_HEAVY_DEBUG*/ #define JERRY_ASSERT(x) do { if (false) { (void)(x); } } while (0) -#endif /* !JERRY_NDEBUG */ +#endif /* JERRY_NDEBUG && JERRY_DISABLE_HEAVY_NEBUG */ #ifdef JERRY_ENABLE_LOG #define JERRY_LOG(lvl, ...) \ diff --git a/jerry-core/mem/mem-heap.cpp b/jerry-core/mem/mem-heap.cpp index 1f41333aca..3fc35bc513 100644 --- a/jerry-core/mem/mem-heap.cpp +++ b/jerry-core/mem/mem-heap.cpp @@ -1058,7 +1058,7 @@ mem_heap_print (bool dump_block_headers, /**< print block headers */ static void mem_check_heap (void) { -#ifndef JERRY_NDEBUG +#ifndef JERRY_DISABLE_HEAVY_DEBUG JERRY_ASSERT ((uint8_t*) mem_heap.first_block_p == mem_heap.heap_start); JERRY_ASSERT (mem_heap.heap_size % MEM_HEAP_CHUNK_SIZE == 0); @@ -1131,7 +1131,7 @@ mem_check_heap (void) JERRY_ASSERT (chunk_sizes_sum * MEM_HEAP_CHUNK_SIZE == mem_heap.heap_size); JERRY_ASSERT (is_first_block_was_met); -#endif /* !JERRY_NDEBUG */ +#endif /* !JERRY_DISABLE_HEAVY_DEBUG */ } /* mem_check_heap */ #ifdef MEM_STATS diff --git a/jerry-core/mem/mem-pool.cpp b/jerry-core/mem/mem-pool.cpp index cd7d500d62..1acd32bf0b 100644 --- a/jerry-core/mem/mem-pool.cpp +++ b/jerry-core/mem/mem-pool.cpp @@ -181,9 +181,9 @@ mem_pool_free_chunk (mem_pool_state_t *pool_p, /**< pool */ * Check pool state consistency */ static void -mem_check_pool (mem_pool_state_t __attr_unused___ *pool_p) /**< pool (unused #ifdef JERRY_NDEBUG) */ +mem_check_pool (mem_pool_state_t __attr_unused___ *pool_p) /**< pool (unused #ifdef JERRY_DISABLE_HEAVY_DEBUG) */ { -#ifndef JERRY_NDEBUG +#ifndef JERRY_DISABLE_HEAVY_DEBUG JERRY_ASSERT (pool_p->free_chunks_number <= MEM_POOL_CHUNKS_NUMBER); size_t met_free_chunks_number = 0; @@ -204,7 +204,9 @@ mem_check_pool (mem_pool_state_t __attr_unused___ *pool_p) /**< pool (unused #if } JERRY_ASSERT (met_free_chunks_number == pool_p->free_chunks_number); -#endif /* !JERRY_NDEBUG */ +#else /* !JERRY_DISABLE_HEAVY_DEBUG */ + (void) pool_p; +#endif /* JERRY_DISABLE_HEAVY_DEBUG */ } /* mem_check_pool */ /** diff --git a/jerry-core/rcs/rcs-chunked-list.cpp b/jerry-core/rcs/rcs-chunked-list.cpp index def0ada18c..9ef4bb8d14 100644 --- a/jerry-core/rcs/rcs-chunked-list.cpp +++ b/jerry-core/rcs/rcs-chunked-list.cpp @@ -289,7 +289,7 @@ void rcs_chunked_list_t::assert_list_is_correct (void) const { -#ifndef JERRY_NDEBUG +#ifndef JERRY_DISABLE_HEAVY_DEBUG for (node_t *node_iter_p = get_first (); node_iter_p != NULL; node_iter_p = get_next (node_iter_p)) @@ -308,7 +308,7 @@ const && next_node_p != NULL && get_prev (next_node_p) == node_iter_p)); } -#endif /* !JERRY_NDEBUG */ +#endif /* !JERRY_DISABLE_HEAVY_DEBUG */ } /* rcs_chunked_list_t::assert_list_is_correct */ /** @@ -318,7 +318,7 @@ void rcs_chunked_list_t::assert_node_is_correct (const rcs_chunked_list_t::node_t* node_p) /**< the node */ const { -#ifndef JERRY_NDEBUG +#ifndef JERRY_DISABLE_HEAVY_DEBUG JERRY_ASSERT (node_p != NULL); assert_list_is_correct (); @@ -337,7 +337,7 @@ const } JERRY_ASSERT (is_in_list); -#else /* JERRY_NDEBUG */ +#else /* !JERRY_DISABLE_HEAVY_DEBUG */ (void) node_p; -#endif /* JERRY_NDEBUG */ +#endif /* JERRY_DISABLE_HEAVY_DEBUG */ } /* rcs_chunked_list_t::assert_node_is_correct */ diff --git a/jerry-core/rcs/rcs-recordset.cpp b/jerry-core/rcs/rcs-recordset.cpp index 4bab26b1bc..d3a07e012c 100644 --- a/jerry-core/rcs/rcs-recordset.cpp +++ b/jerry-core/rcs/rcs-recordset.cpp @@ -613,7 +613,7 @@ rcs_recordset_t::get_record_size (rcs_record_t* rec_p) /**< record */ void rcs_recordset_t::assert_state_is_correct (void) { -#ifndef JERRY_NDEBUG +#ifndef JERRY_DISABLE_HEAVY_DEBUG size_t node_size_sum = 0; size_t record_size_sum = 0; @@ -658,7 +658,7 @@ rcs_recordset_t::assert_state_is_correct (void) } JERRY_ASSERT (node_size_sum == record_size_sum); -#endif /* !JERRY_NDEBUG */ +#endif /* !JERRY_DISABLE_HEAVY_DEBUG */ } /* rcs_recordset_t::assert_state_is_correct */ /** diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index a26e7260d1..aeec865859 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -23,7 +23,7 @@ project (Jerry_Plugins CXX ASM) set(DEFINES_PLUGINS_DEBUG ) # Release - set(DEFINES_PLUGINS_RELEASE JERRY_NDEBUG) + set(DEFINES_PLUGINS_RELEASE JERRY_NDEBUG JERRY_DISABLE_HEAVY_DEBUG) # Platform-specific # Linux diff --git a/tests/unit/test-common.h b/tests/unit/test-common.h index c56f71c048..3b32553fc0 100644 --- a/tests/unit/test-common.h +++ b/tests/unit/test-common.h @@ -26,6 +26,13 @@ using namespace std; +/** + * Verify that unit tests are built with all debug checks enabled + */ +#if defined (JERRY_NDEBUG) || defined (JERRY_DISABLE_HEAVY_DEBUG) +# error "defined (JERRY_NDEBUG) || defined (JERRY_DISABLE_HEAVY_DEBUG) in a unit test" +#endif /* JERRY_NDEBUG || JERRY_DISABLE_HEAVY_DEBUG */ + #define TEST_RANDOMIZE() \ do \ { \