Replace vera++ with clang-format (#4518)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
Robert Fancsik
2021-11-05 14:15:47 +01:00
committed by GitHub
parent bc091e1742
commit badfdf4dba
564 changed files with 10195 additions and 15090 deletions
+17 -17
View File
@@ -17,7 +17,7 @@
#define JMEM_ALLOCATOR_INTERNAL_H
#ifndef JMEM_ALLOCATOR_INTERNAL
# error "The header is for internal routines of memory allocator component. Please, don't use the routines directly."
#error "The header is for internal routines of memory allocator component. Please, don't use the routines directly."
#endif /* !JMEM_ALLOCATOR_INTERNAL */
/** \addtogroup mem Memory allocation
@@ -29,21 +29,21 @@
* Valgrind-related options and headers
*/
#if JERRY_VALGRIND
# include "memcheck.h"
#include "memcheck.h"
# define JMEM_VALGRIND_NOACCESS_SPACE(p, s) VALGRIND_MAKE_MEM_NOACCESS((p), (s))
# define JMEM_VALGRIND_UNDEFINED_SPACE(p, s) VALGRIND_MAKE_MEM_UNDEFINED((p), (s))
# define JMEM_VALGRIND_DEFINED_SPACE(p, s) VALGRIND_MAKE_MEM_DEFINED((p), (s))
# define JMEM_VALGRIND_MALLOCLIKE_SPACE(p, s) VALGRIND_MALLOCLIKE_BLOCK((p), (s), 0, 0)
# define JMEM_VALGRIND_RESIZE_SPACE(p, o, n) VALGRIND_RESIZEINPLACE_BLOCK((p), (o), (n), 0)
# define JMEM_VALGRIND_FREELIKE_SPACE(p) VALGRIND_FREELIKE_BLOCK((p), 0)
#define JMEM_VALGRIND_NOACCESS_SPACE(p, s) VALGRIND_MAKE_MEM_NOACCESS ((p), (s))
#define JMEM_VALGRIND_UNDEFINED_SPACE(p, s) VALGRIND_MAKE_MEM_UNDEFINED ((p), (s))
#define JMEM_VALGRIND_DEFINED_SPACE(p, s) VALGRIND_MAKE_MEM_DEFINED ((p), (s))
#define JMEM_VALGRIND_MALLOCLIKE_SPACE(p, s) VALGRIND_MALLOCLIKE_BLOCK ((p), (s), 0, 0)
#define JMEM_VALGRIND_RESIZE_SPACE(p, o, n) VALGRIND_RESIZEINPLACE_BLOCK ((p), (o), (n), 0)
#define JMEM_VALGRIND_FREELIKE_SPACE(p) VALGRIND_FREELIKE_BLOCK ((p), 0)
#else /* !JERRY_VALGRIND */
# define JMEM_VALGRIND_NOACCESS_SPACE(p, s)
# define JMEM_VALGRIND_UNDEFINED_SPACE(p, s)
# define JMEM_VALGRIND_DEFINED_SPACE(p, s)
# define JMEM_VALGRIND_MALLOCLIKE_SPACE(p, s)
# define JMEM_VALGRIND_RESIZE_SPACE(p, o, n)
# define JMEM_VALGRIND_FREELIKE_SPACE(p)
#define JMEM_VALGRIND_NOACCESS_SPACE(p, s)
#define JMEM_VALGRIND_UNDEFINED_SPACE(p, s)
#define JMEM_VALGRIND_DEFINED_SPACE(p, s)
#define JMEM_VALGRIND_MALLOCLIKE_SPACE(p, s)
#define JMEM_VALGRIND_RESIZE_SPACE(p, o, n)
#define JMEM_VALGRIND_FREELIKE_SPACE(p)
#endif /* JERRY_VALGRIND */
/** @} */
@@ -74,13 +74,13 @@ void jmem_heap_stat_init (void);
void jmem_heap_stat_alloc (size_t num);
void jmem_heap_stat_free (size_t num);
#define JMEM_HEAP_STAT_INIT() jmem_heap_stat_init ()
#define JMEM_HEAP_STAT_INIT() jmem_heap_stat_init ()
#define JMEM_HEAP_STAT_ALLOC(v1) jmem_heap_stat_alloc (v1)
#define JMEM_HEAP_STAT_FREE(v1) jmem_heap_stat_free (v1)
#define JMEM_HEAP_STAT_FREE(v1) jmem_heap_stat_free (v1)
#else /* !JERRY_MEM_STATS */
#define JMEM_HEAP_STAT_INIT()
#define JMEM_HEAP_STAT_ALLOC(v1) JERRY_UNUSED (v1)
#define JMEM_HEAP_STAT_FREE(v1) JERRY_UNUSED (v1)
#define JMEM_HEAP_STAT_FREE(v1) JERRY_UNUSED (v1)
#endif /* JERRY_MEM_STATS */
/** @} */
+4 -3
View File
@@ -17,6 +17,7 @@
* Allocator implementation
*/
#include "ecma-globals.h"
#include "jcontext.h"
#include "jmem.h"
#include "jrt-libc-includes.h"
@@ -185,7 +186,7 @@ jmem_compress_pointer (const void *pointer_p) /**< pointer to compress */
JERRY_ASSERT (uint_ptr % JMEM_ALIGNMENT == 0);
#if defined (ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY) && JERRY_CPOINTER_32_BIT
#if defined(ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY) && JERRY_CPOINTER_32_BIT
JERRY_ASSERT (((jmem_cpointer_t) uint_ptr) == uint_ptr);
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY || !JERRY_CPOINTER_32_BIT */
const uintptr_t heap_start = (uintptr_t) &JERRY_HEAP_CONTEXT (first);
@@ -209,7 +210,7 @@ jmem_compress_pointer (const void *pointer_p) /**< pointer to compress */
*
* @return unpacked pointer
*/
extern inline void * JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
extern inline void *JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
jmem_decompress_pointer (uintptr_t compressed_pointer) /**< pointer to decompress */
{
JERRY_ASSERT (compressed_pointer != JMEM_CP_NULL);
@@ -218,7 +219,7 @@ jmem_decompress_pointer (uintptr_t compressed_pointer) /**< pointer to decompres
JERRY_ASSERT (((jmem_cpointer_t) uint_ptr) == uint_ptr);
#if defined (ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY) && JERRY_CPOINTER_32_BIT
#if defined(ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY) && JERRY_CPOINTER_32_BIT
JERRY_ASSERT (uint_ptr % JMEM_ALIGNMENT == 0);
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY || !JERRY_CPOINTER_32_BIT */
const uintptr_t heap_start = (uintptr_t) &JERRY_HEAP_CONTEXT (first);
+14 -15
View File
@@ -18,6 +18,7 @@
*/
#include "ecma-gc.h"
#include "jcontext.h"
#include "jmem.h"
#include "jrt-bit-fields.h"
@@ -47,7 +48,7 @@
#define JMEM_HEAP_GET_OFFSET_FROM_ADDR(p) ((uint32_t) (p))
#define JMEM_HEAP_GET_ADDR_FROM_OFFSET(u) ((jmem_heap_free_t *) (u))
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
#define JMEM_HEAP_GET_OFFSET_FROM_ADDR(p) ((uint32_t) ((uint8_t *) (p) - JERRY_HEAP_CONTEXT (area)))
#define JMEM_HEAP_GET_OFFSET_FROM_ADDR(p) ((uint32_t) ((uint8_t *) (p) -JERRY_HEAP_CONTEXT (area)))
#define JMEM_HEAP_GET_ADDR_FROM_OFFSET(u) ((jmem_heap_free_t *) (JERRY_HEAP_CONTEXT (area) + (u)))
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
/**
@@ -59,7 +60,7 @@
*
* @return pointer to the end of the region
*/
static inline jmem_heap_free_t * JERRY_ATTR_ALWAYS_INLINE JERRY_ATTR_PURE
static inline jmem_heap_free_t *JERRY_ATTR_ALWAYS_INLINE JERRY_ATTR_PURE
jmem_heap_get_region_end (jmem_heap_free_t *curr_p) /**< current region */
{
return (jmem_heap_free_t *) ((uint8_t *) curr_p + curr_p->size);
@@ -119,7 +120,7 @@ jmem_heap_finalize (void)
* @return pointer to allocated memory block - if allocation is successful,
* NULL - if there is not enough memory.
*/
static void * JERRY_ATTR_HOT
static void *JERRY_ATTR_HOT
jmem_heap_alloc (const size_t size) /**< size of requested block */
{
#if !JERRY_SYSTEM_ALLOCATOR
@@ -130,8 +131,7 @@ jmem_heap_alloc (const size_t size) /**< size of requested block */
JMEM_VALGRIND_DEFINED_SPACE (&JERRY_HEAP_CONTEXT (first), sizeof (jmem_heap_free_t));
/* Fast path for 8 byte chunks, first region is guaranteed to be sufficient. */
if (required_size == JMEM_ALIGNMENT
&& JERRY_LIKELY (JERRY_HEAP_CONTEXT (first).next_offset != JMEM_HEAP_END_OF_LIST))
if (required_size == JMEM_ALIGNMENT && JERRY_LIKELY (JERRY_HEAP_CONTEXT (first).next_offset != JMEM_HEAP_END_OF_LIST))
{
data_space_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (JERRY_HEAP_CONTEXT (first).next_offset);
JERRY_ASSERT (jmem_is_heap_pointer (data_space_p));
@@ -303,7 +303,7 @@ jmem_heap_gc_and_alloc_block (const size_t size, /**< required memory size */
/**
* Internal method for allocating a memory block.
*/
extern inline void * JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
extern inline void *JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
jmem_heap_alloc_block_internal (const size_t size) /**< required memory size */
{
return jmem_heap_gc_and_alloc_block (size, JMEM_PRESSURE_FULL);
@@ -318,7 +318,7 @@ jmem_heap_alloc_block_internal (const size_t size) /**< required memory size */
* @return NULL, if the required memory is 0
* pointer to allocated memory block, otherwise
*/
extern inline void * JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
extern inline void *JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
jmem_heap_alloc_block (const size_t size) /**< required memory size */
{
void *block_p = jmem_heap_gc_and_alloc_block (size, JMEM_PRESSURE_FULL);
@@ -336,7 +336,7 @@ jmem_heap_alloc_block (const size_t size) /**< required memory size */
* also NULL, if the allocation has failed
* pointer to the allocated memory block, otherwise
*/
extern inline void * JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
extern inline void *JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
jmem_heap_alloc_block_null_on_error (const size_t size) /**< required memory size */
{
void *block_p = jmem_heap_gc_and_alloc_block (size, JMEM_PRESSURE_HIGH);
@@ -358,7 +358,7 @@ jmem_heap_alloc_block_null_on_error (const size_t size) /**< required memory siz
* @return pointer to the preceeding block
*/
static jmem_heap_free_t *
jmem_heap_find_prev (const jmem_heap_free_t * const block_p) /**< which memory block's predecessor we're looking for */
jmem_heap_find_prev (const jmem_heap_free_t *const block_p) /**< which memory block's predecessor we're looking for */
{
const jmem_heap_free_t *prev_p;
@@ -378,7 +378,7 @@ jmem_heap_find_prev (const jmem_heap_free_t * const block_p) /**< which memory b
/* Find position of region in the list. */
while (prev_p->next_offset < block_offset)
{
const jmem_heap_free_t * const next_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (prev_p->next_offset);
const jmem_heap_free_t *const next_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (prev_p->next_offset);
JERRY_ASSERT (jmem_is_heap_pointer (next_p));
JMEM_VALGRIND_DEFINED_SPACE (next_p, sizeof (jmem_heap_free_t));
@@ -489,7 +489,7 @@ jmem_heap_free_block_internal (void *ptr, /**< pointer to beginning of data spac
*
* @return pointer to the reallocated region
*/
void * JERRY_ATTR_HOT
void *JERRY_ATTR_HOT
jmem_heap_realloc_block (void *ptr, /**< memory region to reallocate */
const size_t old_size, /**< current size of the region */
const size_t new_size) /**< desired new size */
@@ -500,7 +500,7 @@ jmem_heap_realloc_block (void *ptr, /**< memory region to reallocate */
JERRY_ASSERT (old_size != 0);
JERRY_ASSERT (new_size != 0);
jmem_heap_free_t * const block_p = (jmem_heap_free_t *) ptr;
jmem_heap_free_t *const block_p = (jmem_heap_free_t *) ptr;
const size_t aligned_new_size = (new_size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT;
const size_t aligned_old_size = (old_size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT;
@@ -544,7 +544,7 @@ jmem_heap_realloc_block (void *ptr, /**< memory region to reallocate */
jmem_heap_free_t *prev_p = jmem_heap_find_prev (block_p);
JMEM_VALGRIND_DEFINED_SPACE (prev_p, sizeof (jmem_heap_free_t));
jmem_heap_free_t * const next_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (prev_p->next_offset);
jmem_heap_free_t *const next_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (prev_p->next_offset);
/* Check if block can be extended at the end */
if (((jmem_heap_free_t *) ((uint8_t *) block_p + aligned_old_size)) == next_p)
@@ -738,8 +738,7 @@ jmem_heap_stats_print (void)
JERRY_DEBUG_MSG ("Heap stats:\n");
#if !JERRY_SYSTEM_ALLOCATOR
JERRY_DEBUG_MSG (" Heap size = %zu bytes\n",
heap_stats->size);
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"
+3 -3
View File
@@ -55,7 +55,7 @@ jmem_pools_finalize (void)
* @return pointer to allocated chunk, if allocation was successful,
* or NULL - if not enough memory.
*/
extern inline void * JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
extern inline void *JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
jmem_pools_alloc (size_t size) /**< size of the chunk */
{
#if JERRY_MEM_GC_BEFORE_EACH_ALLOC
@@ -66,7 +66,7 @@ jmem_pools_alloc (size_t size) /**< size of the chunk */
if (size <= 8)
{
#else /* !JERRY_CPOINTER_32_BIT */
JERRY_ASSERT (size <= 8);
JERRY_ASSERT (size <= 8);
#endif /* JERRY_CPOINTER_32_BIT */
if (JERRY_CONTEXT (jmem_free_8_byte_chunk_p) != NULL)
@@ -130,7 +130,7 @@ jmem_pools_free (void *chunk_p, /**< pointer to the chunk */
if (size <= 8)
{
#else /* !JERRY_CPOINTER_32_BIT */
JERRY_ASSERT (size <= 8);
JERRY_ASSERT (size <= 8);
#endif /* JERRY_CPOINTER_32_BIT */
chunk_to_free_p->next_p = JERRY_CONTEXT (jmem_free_8_byte_chunk_p);
+47 -46
View File
@@ -28,7 +28,7 @@
/**
* Logarithm of required alignment for allocated units/blocks
*/
#define JMEM_ALIGNMENT_LOG 3
#define JMEM_ALIGNMENT_LOG 3
/**
* Representation of NULL value for compressed pointers
@@ -55,7 +55,7 @@
/**
* Shift for tag part in jmem_cpointer_tag_t
*/
#if defined (JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY) && JERRY_CPOINTER_32_BIT
#if defined(JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY) && JERRY_CPOINTER_32_BIT
#define JMEM_TAG_SHIFT 0
#else /* !JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY || !JERRY_CPOINTER_32_BIT */
#define JMEM_TAG_SHIFT 3
@@ -66,9 +66,9 @@
*/
enum
{
JMEM_FIRST_TAG_BIT_MASK = (1u << 0), /**< first tag bit mask **/
JMEM_SECOND_TAG_BIT_MASK = (1u << 1), /**< second tag bit mask **/
JMEM_THIRD_TAG_BIT_MASK = (1u << 2), /**< third tag bit mask **/
JMEM_FIRST_TAG_BIT_MASK = (1u << 0), /**< first tag bit mask **/
JMEM_SECOND_TAG_BIT_MASK = (1u << 1), /**< second tag bit mask **/
JMEM_THIRD_TAG_BIT_MASK = (1u << 2), /**< third tag bit mask **/
};
/**
@@ -117,7 +117,7 @@ typedef uint32_t jmem_cpointer_tag_t;
typedef enum
{
JMEM_PRESSURE_NONE, /**< no memory pressure */
JMEM_PRESSURE_LOW, /**< low memory pressure */
JMEM_PRESSURE_LOW, /**< low memory pressure */
JMEM_PRESSURE_HIGH, /**< high memory pressure */
JMEM_PRESSURE_FULL, /**< memory full */
} jmem_pressure_t;
@@ -189,7 +189,7 @@ void jmem_heap_stats_print (void);
#endif /* JERRY_MEM_STATS */
jmem_cpointer_t JERRY_ATTR_PURE jmem_compress_pointer (const void *pointer_p);
void * JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer);
void *JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer);
/**
* Define a local array variable and allocate memory for the array on the heap.
@@ -199,33 +199,32 @@ void * JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer);
* Warning:
* if there is not enough memory on the heap, shutdown engine with ERR_OUT_OF_MEMORY.
*/
#define JMEM_DEFINE_LOCAL_ARRAY(var_name, number, type) \
{ \
size_t var_name ## ___size = (size_t) (number) * sizeof (type); \
type *var_name = (type *) (jmem_heap_alloc_block (var_name ## ___size));
#define JMEM_DEFINE_LOCAL_ARRAY(var_name, number, type) \
{ \
size_t var_name##___size = (size_t) (number) * sizeof (type); \
type *var_name = (type *) (jmem_heap_alloc_block (var_name##___size));
/**
* Free the previously defined local array variable, freeing corresponding block on the heap,
* if it was allocated (i.e. if the array's size was non-zero).
*/
#define JMEM_FINALIZE_LOCAL_ARRAY(var_name) \
if (var_name != NULL) \
{ \
JERRY_ASSERT (var_name ## ___size != 0); \
\
jmem_heap_free_block (var_name, var_name ## ___size); \
} \
else \
{ \
JERRY_ASSERT (var_name ## ___size == 0); \
} \
}
#define JMEM_FINALIZE_LOCAL_ARRAY(var_name) \
if (var_name != NULL) \
{ \
JERRY_ASSERT (var_name##___size != 0); \
\
jmem_heap_free_block (var_name, var_name##___size); \
} \
else \
{ \
JERRY_ASSERT (var_name##___size == 0); \
} \
}
/**
* Get value of pointer from specified non-null compressed pointer value
*/
#define JMEM_CP_GET_NON_NULL_POINTER(type, cp_value) \
((type *) (jmem_decompress_pointer (cp_value)))
#define JMEM_CP_GET_NON_NULL_POINTER(type, cp_value) ((type *) (jmem_decompress_pointer (cp_value)))
/**
* Get value of pointer from specified compressed pointer value
@@ -245,29 +244,29 @@ void * JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer);
* to specified non_compressed_pointer
*/
#define JMEM_CP_SET_POINTER(cp_value, non_compressed_pointer) \
do \
{ \
void *ptr_value = (void *) non_compressed_pointer; \
\
if (JERRY_UNLIKELY ((ptr_value) == NULL)) \
{ \
(cp_value) = JMEM_CP_NULL; \
} \
else \
{ \
JMEM_CP_SET_NON_NULL_POINTER (cp_value, ptr_value); \
} \
do \
{ \
void *ptr_value = (void *) non_compressed_pointer; \
\
if (JERRY_UNLIKELY ((ptr_value) == NULL)) \
{ \
(cp_value) = JMEM_CP_NULL; \
} \
else \
{ \
JMEM_CP_SET_NON_NULL_POINTER (cp_value, ptr_value); \
} \
} while (false);
/**
* Set value of pointer-tag value so that it will correspond
* to specified non_compressed_pointer along with tag
*/
#define JMEM_CP_SET_NON_NULL_POINTER_TAG(cp_value, pointer, tag) \
do \
{ \
JERRY_ASSERT ((uintptr_t) tag < (uintptr_t) (JMEM_ALIGNMENT)); \
jmem_cpointer_tag_t compressed_ptr = jmem_compress_pointer (pointer); \
#define JMEM_CP_SET_NON_NULL_POINTER_TAG(cp_value, pointer, tag) \
do \
{ \
JERRY_ASSERT ((uintptr_t) tag < (uintptr_t) (JMEM_ALIGNMENT)); \
jmem_cpointer_tag_t compressed_ptr = jmem_compress_pointer (pointer); \
(cp_value) = (jmem_cpointer_tag_t) ((compressed_ptr << JMEM_TAG_SHIFT) | tag); \
} while (false);
@@ -286,12 +285,14 @@ void * JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer);
/**
* Get value of each tag from specified pointer-tag value
*/
#define JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG(cp_value) \
(cp_value & JMEM_FIRST_TAG_BIT_MASK) /**< get first tag bit **/
#define JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG(cp_value) \
(cp_value & JMEM_FIRST_TAG_BIT_MASK) /**< get first tag bit \
**/
#define JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG(cp_value) \
(cp_value & JMEM_SECOND_TAG_BIT_MASK) /**< get second tag bit **/
#define JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG(cp_value) \
(cp_value & JMEM_THIRD_TAG_BIT_MASK) /**< get third tag bit **/
#define JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG(cp_value) \
(cp_value & JMEM_THIRD_TAG_BIT_MASK) /**< get third tag bit \
**/
/**
* Set value of each tag to specified pointer-tag value