Style fixes in liballocator, libecmaobjects, libecmaoperations: space between function name and opening parenthesis, no space after opening parenthesis/before closing parenthesis.

This commit is contained in:
Ruben Ayrapetyan
2014-08-11 19:27:07 +04:00
parent e53be2b441
commit b02eefd4ae
16 changed files with 761 additions and 761 deletions
+20 -20
View File
@@ -26,42 +26,42 @@
/**
* Area for heap
*/
static uint8_t mem_heap_area[ MEM_HEAP_AREA_SIZE ] __attribute__((aligned(MEM_ALIGNMENT)));
static uint8_t mem_heap_area[ MEM_HEAP_AREA_SIZE ] __attribute__ ((aligned (MEM_ALIGNMENT)));
/**
* Check that heap area is less or equal than 64K.
*/
JERRY_STATIC_ASSERT( MEM_HEAP_AREA_SIZE <= 64 * 1024 );
JERRY_STATIC_ASSERT(MEM_HEAP_AREA_SIZE <= 64 * 1024);
/**
* Initialize memory allocators.
*/
void
mem_init( void)
mem_init (void)
{
mem_heap_init( mem_heap_area, sizeof (mem_heap_area));
mem_pools_init();
mem_heap_init (mem_heap_area, sizeof (mem_heap_area));
mem_pools_init ();
} /* mem_init */
/**
* Finalize memory allocators.
*/
void
mem_finalize( bool is_show_mem_stats) /**< show heap memory stats
mem_finalize (bool is_show_mem_stats) /**< show heap memory stats
before finalization? */
{
mem_pools_finalize();
mem_pools_finalize ();
if (is_show_mem_stats)
{
mem_heap_print( false, false, true);
mem_heap_print (false, false, true);
#ifdef MEM_STATS
mem_pools_stats_t stats;
mem_pools_get_stats( &stats);
mem_pools_get_stats (&stats);
__printf("Pools stats:\n");
__printf(" Chunk size: %u\n"
__printf ("Pools stats:\n");
__printf (" Chunk size: %u\n"
" Pools: %lu\n"
" Allocated chunks: %lu\n"
" Free chunks: %lu\n"
@@ -76,14 +76,14 @@ mem_finalize( bool is_show_mem_stats) /**< show heap memory stats
#endif /* MEM_STATS */
}
mem_heap_finalize();
mem_heap_finalize ();
} /* mem_finalize */
/**
* Get base pointer for allocation area.
*/
static uintptr_t
mem_get_base_pointer( void)
mem_get_base_pointer (void)
{
return (uintptr_t) mem_heap_area;
} /* mem_get_base_pointer */
@@ -92,20 +92,20 @@ mem_get_base_pointer( void)
* Compress pointer.
*/
uintptr_t
mem_compress_pointer(void *pointer) /**< pointer to compress */
mem_compress_pointer (void *pointer) /**< pointer to compress */
{
JERRY_ASSERT( pointer != NULL );
JERRY_ASSERT(pointer != NULL);
uintptr_t int_ptr = (uintptr_t) pointer;
JERRY_ASSERT(int_ptr % MEM_ALIGNMENT == 0);
int_ptr -= mem_get_base_pointer();
int_ptr -= mem_get_base_pointer ();
int_ptr >>= MEM_ALIGNMENT_LOG;
JERRY_ASSERT((int_ptr & ~((1u << MEM_HEAP_OFFSET_LOG) - 1)) == 0);
JERRY_ASSERT( int_ptr != MEM_COMPRESSED_POINTER_NULL );
JERRY_ASSERT(int_ptr != MEM_COMPRESSED_POINTER_NULL);
return int_ptr;
} /* mem_compress_pointer */
@@ -114,14 +114,14 @@ mem_compress_pointer(void *pointer) /**< pointer to compress */
* Decompress pointer.
*/
void*
mem_decompress_pointer(uintptr_t compressed_pointer) /**< pointer to decompress */
mem_decompress_pointer (uintptr_t compressed_pointer) /**< pointer to decompress */
{
JERRY_ASSERT( compressed_pointer != MEM_COMPRESSED_POINTER_NULL );
JERRY_ASSERT(compressed_pointer != MEM_COMPRESSED_POINTER_NULL);
uintptr_t int_ptr = compressed_pointer;
int_ptr <<= MEM_ALIGNMENT_LOG;
int_ptr += mem_get_base_pointer();
int_ptr += mem_get_base_pointer ();
return (void*) int_ptr;
} /* mem_decompress_pointer */
+5 -5
View File
@@ -40,13 +40,13 @@
/**
* Width of compressed memory pointer
*/
#define MEM_COMPRESSED_POINTER_WIDTH ( MEM_HEAP_OFFSET_LOG - MEM_ALIGNMENT_LOG )
#define MEM_COMPRESSED_POINTER_WIDTH (MEM_HEAP_OFFSET_LOG - MEM_ALIGNMENT_LOG)
extern void mem_init(void);
extern void mem_finalize(bool is_show_mem_stats);
extern void mem_init (void);
extern void mem_finalize (bool is_show_mem_stats);
extern uintptr_t mem_compress_pointer(void *pointer);
extern void* mem_decompress_pointer(uintptr_t compressed_pointer);
extern uintptr_t mem_compress_pointer (void *pointer);
extern void* mem_decompress_pointer (uintptr_t compressed_pointer);
#endif /* !JERRY_MEM_ALLOCATOR_H */
+194 -194
View File
@@ -36,19 +36,19 @@
#ifndef JERRY_NVALGRIND
# include "memcheck.h"
# define VALGRIND_NOACCESS_STRUCT( s) (void)VALGRIND_MAKE_MEM_NOACCESS( ( s ), sizeof( *( s ) ) )
# define VALGRIND_UNDEFINED_STRUCT( s) (void)VALGRIND_MAKE_MEM_UNDEFINED( ( s ), sizeof( *( s ) ) )
# define VALGRIND_DEFINED_STRUCT( s) (void)VALGRIND_MAKE_MEM_DEFINED( ( s ), sizeof( *( s ) ) )
# define VALGRIND_NOACCESS_SPACE( p, s) (void)VALGRIND_MAKE_MEM_NOACCESS( ( p ), ( s ) )
# define VALGRIND_UNDEFINED_SPACE( p, s) (void)VALGRIND_MAKE_MEM_UNDEFINED( ( p ), ( s ) )
# define VALGRIND_DEFINED_SPACE( p, s) (void)VALGRIND_MAKE_MEM_DEFINED( ( p ), ( s ) )
# define VALGRIND_NOACCESS_STRUCT(s) (void)VALGRIND_MAKE_MEM_NOACCESS((s), sizeof (*(s)))
# define VALGRIND_UNDEFINED_STRUCT(s) (void)VALGRIND_MAKE_MEM_UNDEFINED((s), sizeof (*(s)))
# define VALGRIND_DEFINED_STRUCT(s) (void)VALGRIND_MAKE_MEM_DEFINED((s), sizeof (*(s)))
# define VALGRIND_NOACCESS_SPACE(p, s) (void)VALGRIND_MAKE_MEM_NOACCESS((p), (s))
# define VALGRIND_UNDEFINED_SPACE(p, s) (void)VALGRIND_MAKE_MEM_UNDEFINED((p), (s))
# define VALGRIND_DEFINED_SPACE(p, s) (void)VALGRIND_MAKE_MEM_DEFINED((p), (s))
#else /* !JERRRY_NVALGRIND */
# define VALGRIND_NOACCESS_STRUCT( s)
# define VALGRIND_UNDEFINED_STRUCT( s)
# define VALGRIND_DEFINED_STRUCT( s)
# define VALGRIND_NOACCESS_SPACE( p, s)
# define VALGRIND_UNDEFINED_SPACE( p, s)
# define VALGRIND_DEFINED_SPACE( p, s)
# define VALGRIND_NOACCESS_STRUCT(s)
# define VALGRIND_UNDEFINED_STRUCT(s)
# define VALGRIND_DEFINED_STRUCT(s)
# define VALGRIND_NOACCESS_SPACE(p, s)
# define VALGRIND_UNDEFINED_SPACE(p, s)
# define VALGRIND_DEFINED_SPACE(p, s)
#endif /* !JERRY_NVALGRIND */
/**
@@ -95,12 +95,12 @@ typedef struct mem_block_header_t
/**
* Chunk should have enough space for block header
*/
JERRY_STATIC_ASSERT( MEM_HEAP_CHUNK_SIZE >= sizeof (mem_block_header_t) );
JERRY_STATIC_ASSERT(MEM_HEAP_CHUNK_SIZE >= sizeof (mem_block_header_t));
/**
* Chunk size should satisfy the required alignment value
*/
JERRY_STATIC_ASSERT( MEM_HEAP_CHUNK_SIZE % MEM_ALIGNMENT == 0 );
JERRY_STATIC_ASSERT(MEM_HEAP_CHUNK_SIZE % MEM_ALIGNMENT == 0);
/**
* Description of heap state
@@ -118,16 +118,16 @@ typedef struct
*/
mem_heap_state_t mem_heap;
static size_t mem_get_block_chunks_count( const mem_block_header_t *block_header_p);
static size_t mem_get_block_data_space_size( const mem_block_header_t *block_header_p);
static size_t mem_get_block_chunks_count_from_data_size( size_t block_allocated_size);
static size_t mem_get_block_chunks_count (const mem_block_header_t *block_header_p);
static size_t mem_get_block_data_space_size (const mem_block_header_t *block_header_p);
static size_t mem_get_block_chunks_count_from_data_size (size_t block_allocated_size);
static void mem_init_block_header( uint8_t *first_chunk_p,
static void mem_init_block_header (uint8_t *first_chunk_p,
size_t size_in_chunks,
mem_block_state_t block_state,
mem_block_header_t *prev_block_p,
mem_block_header_t *next_block_p);
static void mem_check_heap( void);
static void mem_check_heap (void);
#ifdef MEM_STATS
/**
@@ -135,17 +135,17 @@ static void mem_check_heap( void);
*/
static mem_heap_stats_t mem_heap_stats;
static void mem_heap_stat_init( void);
static void mem_heap_stat_alloc_block( mem_block_header_t *block_header_p);
static void mem_heap_stat_free_block( mem_block_header_t *block_header_p);
static void mem_heap_stat_free_block_split( void);
static void mem_heap_stat_free_block_merge( void);
static void mem_heap_stat_init (void);
static void mem_heap_stat_alloc_block (mem_block_header_t *block_header_p);
static void mem_heap_stat_free_block (mem_block_header_t *block_header_p);
static void mem_heap_stat_free_block_split (void);
static void mem_heap_stat_free_block_merge (void);
#else /* !MEM_STATS */
# define mem_heap_stat_init()
# define mem_heap_stat_alloc_block( v)
# define mem_heap_stat_free_block( v)
# define mem_heap_stat_free_block_split()
# define mem_heap_stat_free_block_merge()
# define mem_heap_stat_init ()
# define mem_heap_stat_alloc_block (v)
# define mem_heap_stat_free_block (v)
# define mem_heap_stat_free_block_split ()
# define mem_heap_stat_free_block_merge ()
#endif /* !MEM_STATS */
/**
@@ -154,23 +154,23 @@ static void mem_heap_stat_free_block_merge( void);
* @return chunks count
*/
static size_t
mem_get_block_chunks_count( const mem_block_header_t *block_header_p) /**< block header */
mem_get_block_chunks_count (const mem_block_header_t *block_header_p) /**< block header */
{
JERRY_ASSERT( block_header_p != NULL );
JERRY_ASSERT(block_header_p != NULL);
const mem_block_header_t *next_block_p = block_header_p->neighbours[ MEM_DIRECTION_NEXT ];
size_t dist_till_block_end;
if ( next_block_p == NULL )
if (next_block_p == NULL)
{
dist_till_block_end = (size_t) ( mem_heap.heap_start + mem_heap.heap_size - (uint8_t*) block_header_p );
dist_till_block_end = (size_t) (mem_heap.heap_start + mem_heap.heap_size - (uint8_t*) block_header_p);
} else
{
dist_till_block_end = (size_t) ( (uint8_t*) next_block_p - (uint8_t*) block_header_p );
dist_till_block_end = (size_t) ((uint8_t*) next_block_p - (uint8_t*) block_header_p);
}
JERRY_ASSERT( dist_till_block_end <= mem_heap.heap_size );
JERRY_ASSERT( dist_till_block_end % MEM_HEAP_CHUNK_SIZE == 0 );
JERRY_ASSERT(dist_till_block_end <= mem_heap.heap_size);
JERRY_ASSERT(dist_till_block_end % MEM_HEAP_CHUNK_SIZE == 0);
return dist_till_block_end / MEM_HEAP_CHUNK_SIZE;
} /* mem_get_block_chunks_count */
@@ -181,9 +181,9 @@ mem_get_block_chunks_count( const mem_block_header_t *block_header_p) /**< block
* @return size of block area that can be used to store data
*/
static size_t
mem_get_block_data_space_size( const mem_block_header_t *block_header_p) /**< block header */
mem_get_block_data_space_size (const mem_block_header_t *block_header_p) /**< block header */
{
return mem_get_block_chunks_count( block_header_p) * MEM_HEAP_CHUNK_SIZE - sizeof (mem_block_header_t);
return mem_get_block_chunks_count (block_header_p) * MEM_HEAP_CHUNK_SIZE - sizeof (mem_block_header_t);
} /* mem_get_block_data_space_size */
/**
@@ -192,30 +192,30 @@ mem_get_block_data_space_size( const mem_block_header_t *block_header_p) /**< bl
* @return chunks count
*/
static size_t
mem_get_block_chunks_count_from_data_size( size_t block_allocated_size) /**< size of block's allocated area */
mem_get_block_chunks_count_from_data_size (size_t block_allocated_size) /**< size of block's allocated area */
{
return JERRY_ALIGNUP( sizeof (mem_block_header_t) + block_allocated_size, MEM_HEAP_CHUNK_SIZE) / MEM_HEAP_CHUNK_SIZE;
return JERRY_ALIGNUP(sizeof (mem_block_header_t) + block_allocated_size, MEM_HEAP_CHUNK_SIZE) / MEM_HEAP_CHUNK_SIZE;
} /* mem_get_block_chunks_count_from_data_size */
/**
* Startup initialization of heap
*/
void
mem_heap_init(uint8_t *heap_start, /**< first address of heap space */
mem_heap_init (uint8_t *heap_start, /**< first address of heap space */
size_t heap_size) /**< heap space size */
{
JERRY_ASSERT( heap_start != NULL );
JERRY_ASSERT( heap_size != 0 );
JERRY_ASSERT( heap_size % MEM_HEAP_CHUNK_SIZE == 0 );
JERRY_ASSERT( (uintptr_t) heap_start % MEM_ALIGNMENT == 0);
JERRY_ASSERT( heap_size <= ( 1u << MEM_HEAP_OFFSET_LOG ) );
JERRY_ASSERT(heap_start != NULL);
JERRY_ASSERT(heap_size != 0);
JERRY_ASSERT(heap_size % MEM_HEAP_CHUNK_SIZE == 0);
JERRY_ASSERT((uintptr_t) heap_start % MEM_ALIGNMENT == 0);
JERRY_ASSERT(heap_size <= (1u << MEM_HEAP_OFFSET_LOG));
mem_heap.heap_start = heap_start;
mem_heap.heap_size = heap_size;
VALGRIND_NOACCESS_SPACE( heap_start, heap_size);
VALGRIND_NOACCESS_SPACE(heap_start, heap_size);
mem_init_block_header(mem_heap.heap_start,
mem_init_block_header (mem_heap.heap_start,
0,
MEM_BLOCK_FREE,
NULL,
@@ -224,30 +224,30 @@ mem_heap_init(uint8_t *heap_start, /**< first address of heap space */
mem_heap.first_block_p = (mem_block_header_t*) mem_heap.heap_start;
mem_heap.last_block_p = mem_heap.first_block_p;
mem_heap_stat_init();
mem_heap_stat_init ();
} /* mem_heap_init */
/**
* Finalize heap
*/
void
mem_heap_finalize(void)
mem_heap_finalize (void)
{
VALGRIND_DEFINED_SPACE( mem_heap.heap_start, mem_heap.heap_size);
VALGRIND_DEFINED_SPACE(mem_heap.heap_start, mem_heap.heap_size);
JERRY_ASSERT( mem_heap.first_block_p == mem_heap.last_block_p );
JERRY_ASSERT( mem_heap.first_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK );
JERRY_ASSERT(mem_heap.first_block_p == mem_heap.last_block_p);
JERRY_ASSERT(mem_heap.first_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK);
VALGRIND_NOACCESS_SPACE( mem_heap.heap_start, mem_heap.heap_size);
VALGRIND_NOACCESS_SPACE(mem_heap.heap_start, mem_heap.heap_size);
__memset( &mem_heap, 0, sizeof(mem_heap));
__memset (&mem_heap, 0, sizeof (mem_heap));
} /* mem_heap_finalize */
/**
* Initialize block header
*/
static void
mem_init_block_header( uint8_t *first_chunk_p, /**< address of the first chunk to use for the block */
mem_init_block_header (uint8_t *first_chunk_p, /**< address of the first chunk to use for the block */
size_t allocated_bytes, /**< size of block's allocated area */
mem_block_state_t block_state, /**< state of the block (allocated or free) */
mem_block_header_t *prev_block_p, /**< previous block */
@@ -255,13 +255,13 @@ mem_init_block_header( uint8_t *first_chunk_p, /**< address of the first
{
mem_block_header_t *block_header_p = (mem_block_header_t*) first_chunk_p;
VALGRIND_UNDEFINED_STRUCT( block_header_p);
VALGRIND_UNDEFINED_STRUCT(block_header_p);
if ( block_state == MEM_BLOCK_FREE )
if (block_state == MEM_BLOCK_FREE)
{
block_header_p->magic_num = MEM_MAGIC_NUM_OF_FREE_BLOCK;
JERRY_ASSERT( allocated_bytes == 0 );
JERRY_ASSERT(allocated_bytes == 0);
} else
{
block_header_p->magic_num = MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK;
@@ -271,9 +271,9 @@ mem_init_block_header( uint8_t *first_chunk_p, /**< address of the first
block_header_p->neighbours[ MEM_DIRECTION_NEXT ] = next_block_p;
block_header_p->allocated_bytes = allocated_bytes;
JERRY_ASSERT( allocated_bytes <= mem_get_block_data_space_size( block_header_p) );
JERRY_ASSERT(allocated_bytes <= mem_get_block_data_space_size (block_header_p));
VALGRIND_NOACCESS_STRUCT( block_header_p);
VALGRIND_NOACCESS_STRUCT(block_header_p);
} /* mem_init_block_header */
/**
@@ -290,15 +290,15 @@ mem_init_block_header( uint8_t *first_chunk_p, /**< address of the first
* NULL - if there is not enough memory.
*/
uint8_t*
mem_heap_alloc_block( size_t size_in_bytes, /**< size of region to allocate in bytes */
mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to allocate in bytes */
mem_heap_alloc_term_t alloc_term) /**< expected allocation term */
{
mem_block_header_t *block_p;
mem_direction_t direction;
mem_check_heap();
mem_check_heap ();
if ( alloc_term == MEM_HEAP_ALLOC_SHORT_TERM )
if (alloc_term == MEM_HEAP_ALLOC_SHORT_TERM)
{
block_p = mem_heap.first_block_p;
direction = MEM_DIRECTION_NEXT;
@@ -309,49 +309,49 @@ mem_heap_alloc_block( size_t size_in_bytes, /**< size of region to all
}
/* searching for appropriate block */
while ( block_p != NULL )
while (block_p != NULL)
{
VALGRIND_DEFINED_STRUCT( block_p);
VALGRIND_DEFINED_STRUCT(block_p);
if ( block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK )
if (block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK)
{
if ( mem_get_block_data_space_size( block_p) >= size_in_bytes )
if (mem_get_block_data_space_size (block_p) >= size_in_bytes)
{
break;
}
} else
{
JERRY_ASSERT( block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
JERRY_ASSERT(block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
}
mem_block_header_t *next_block_p = block_p->neighbours[ direction ];
VALGRIND_NOACCESS_STRUCT( block_p);
VALGRIND_NOACCESS_STRUCT(block_p);
block_p = next_block_p;
}
if ( block_p == NULL )
if (block_p == NULL)
{
/* not enough free space */
return NULL;
}
/* appropriate block found, allocating space */
size_t new_block_size_in_chunks = mem_get_block_chunks_count_from_data_size( size_in_bytes);
size_t found_block_size_in_chunks = mem_get_block_chunks_count( block_p);
size_t new_block_size_in_chunks = mem_get_block_chunks_count_from_data_size (size_in_bytes);
size_t found_block_size_in_chunks = mem_get_block_chunks_count (block_p);
JERRY_ASSERT( new_block_size_in_chunks <= found_block_size_in_chunks );
JERRY_ASSERT(new_block_size_in_chunks <= found_block_size_in_chunks);
mem_block_header_t *prev_block_p = block_p->neighbours[ MEM_DIRECTION_PREV ];
mem_block_header_t *next_block_p = block_p->neighbours[ MEM_DIRECTION_NEXT ];
if ( new_block_size_in_chunks < found_block_size_in_chunks )
if (new_block_size_in_chunks < found_block_size_in_chunks)
{
mem_heap_stat_free_block_split();
mem_heap_stat_free_block_split ();
uint8_t *new_free_block_first_chunk_p = (uint8_t*) block_p + new_block_size_in_chunks * MEM_HEAP_CHUNK_SIZE;
mem_init_block_header(new_free_block_first_chunk_p,
mem_init_block_header (new_free_block_first_chunk_p,
0,
MEM_BLOCK_FREE,
block_p /* there we will place new allocated block */,
@@ -359,43 +359,43 @@ mem_heap_alloc_block( size_t size_in_bytes, /**< size of region to all
mem_block_header_t *new_free_block_p = (mem_block_header_t*) new_free_block_first_chunk_p;
if ( next_block_p == NULL )
if (next_block_p == NULL)
{
mem_heap.last_block_p = new_free_block_p;
}
else
{
VALGRIND_DEFINED_STRUCT( next_block_p);
VALGRIND_DEFINED_STRUCT(next_block_p);
next_block_p->neighbours[ MEM_DIRECTION_PREV ] = (mem_block_header_t*) new_free_block_first_chunk_p;
VALGRIND_NOACCESS_STRUCT( next_block_p);
VALGRIND_NOACCESS_STRUCT(next_block_p);
}
next_block_p = new_free_block_p;
}
mem_init_block_header((uint8_t*) block_p,
mem_init_block_header ((uint8_t*) block_p,
size_in_bytes,
MEM_BLOCK_ALLOCATED,
prev_block_p,
next_block_p);
VALGRIND_DEFINED_STRUCT( block_p);
VALGRIND_DEFINED_STRUCT(block_p);
mem_heap_stat_alloc_block( block_p);
mem_heap_stat_alloc_block (block_p);
JERRY_ASSERT( mem_get_block_data_space_size( block_p) >= size_in_bytes );
JERRY_ASSERT(mem_get_block_data_space_size (block_p) >= size_in_bytes);
VALGRIND_NOACCESS_STRUCT( block_p);
VALGRIND_NOACCESS_STRUCT(block_p);
mem_check_heap();
mem_check_heap ();
/* return data space beginning address */
uint8_t *data_space_p = (uint8_t*) (block_p + 1);
JERRY_ASSERT( (uintptr_t) data_space_p % MEM_ALIGNMENT == 0);
JERRY_ASSERT((uintptr_t) data_space_p % MEM_ALIGNMENT == 0);
VALGRIND_UNDEFINED_SPACE( data_space_p, size_in_bytes);
VALGRIND_UNDEFINED_SPACE(data_space_p, size_in_bytes);
return data_space_p;
} /* mem_heap_alloc_block */
@@ -404,58 +404,58 @@ mem_heap_alloc_block( size_t size_in_bytes, /**< size of region to all
* Free the memory block.
*/
void
mem_heap_free_block( uint8_t *ptr) /**< pointer to beginning of data space of the block */
mem_heap_free_block (uint8_t *ptr) /**< pointer to beginning of data space of the block */
{
/* checking that ptr points to the heap */
JERRY_ASSERT( ptr >= mem_heap.heap_start
&& ptr <= mem_heap.heap_start + mem_heap.heap_size );
JERRY_ASSERT(ptr >= mem_heap.heap_start
&& ptr <= mem_heap.heap_start + mem_heap.heap_size);
mem_check_heap();
mem_check_heap ();
mem_block_header_t *block_p = (mem_block_header_t*) ptr - 1;
VALGRIND_DEFINED_STRUCT( block_p);
VALGRIND_DEFINED_STRUCT(block_p);
mem_block_header_t *prev_block_p = block_p->neighbours[ MEM_DIRECTION_PREV ];
mem_block_header_t *next_block_p = block_p->neighbours[ MEM_DIRECTION_NEXT ];
mem_heap_stat_free_block( block_p);
mem_heap_stat_free_block (block_p);
VALGRIND_NOACCESS_SPACE( ptr, block_p->allocated_bytes);
VALGRIND_NOACCESS_SPACE(ptr, block_p->allocated_bytes);
/* checking magic nums that are neighbour to data space */
JERRY_ASSERT( block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
if ( next_block_p != NULL )
JERRY_ASSERT(block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
if (next_block_p != NULL)
{
VALGRIND_DEFINED_STRUCT( next_block_p);
VALGRIND_DEFINED_STRUCT(next_block_p);
JERRY_ASSERT( next_block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK
|| next_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK );
JERRY_ASSERT(next_block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK
|| next_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK);
VALGRIND_NOACCESS_STRUCT( next_block_p);
VALGRIND_NOACCESS_STRUCT(next_block_p);
}
block_p->magic_num = MEM_MAGIC_NUM_OF_FREE_BLOCK;
if ( next_block_p != NULL )
if (next_block_p != NULL)
{
VALGRIND_DEFINED_STRUCT( next_block_p);
VALGRIND_DEFINED_STRUCT(next_block_p);
if (next_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK )
if (next_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK)
{
/* merge with the next block */
mem_heap_stat_free_block_merge();
mem_heap_stat_free_block_merge ();
mem_block_header_t *next_next_block_p = next_block_p->neighbours[ MEM_DIRECTION_NEXT ];
VALGRIND_NOACCESS_STRUCT( next_block_p);
VALGRIND_NOACCESS_STRUCT(next_block_p);
next_block_p = next_next_block_p;
VALGRIND_DEFINED_STRUCT( next_block_p);
VALGRIND_DEFINED_STRUCT(next_block_p);
block_p->neighbours[ MEM_DIRECTION_NEXT ] = next_block_p;
if ( next_block_p != NULL )
if (next_block_p != NULL)
{
next_block_p->neighbours[ MEM_DIRECTION_PREV ] = block_p;
}
@@ -465,26 +465,26 @@ mem_heap_free_block( uint8_t *ptr) /**< pointer to beginning of data space of th
}
}
VALGRIND_NOACCESS_STRUCT( next_block_p);
VALGRIND_NOACCESS_STRUCT(next_block_p);
}
if ( prev_block_p != NULL )
if (prev_block_p != NULL)
{
VALGRIND_DEFINED_STRUCT( prev_block_p);
VALGRIND_DEFINED_STRUCT(prev_block_p);
if ( prev_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK )
if (prev_block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK)
{
/* merge with the previous block */
mem_heap_stat_free_block_merge();
mem_heap_stat_free_block_merge ();
prev_block_p->neighbours[ MEM_DIRECTION_NEXT ] = next_block_p;
if ( next_block_p != NULL )
if (next_block_p != NULL)
{
VALGRIND_DEFINED_STRUCT( next_block_p);
VALGRIND_DEFINED_STRUCT(next_block_p);
next_block_p->neighbours[ MEM_DIRECTION_PREV ] = block_p->neighbours[ MEM_DIRECTION_PREV ];
VALGRIND_NOACCESS_STRUCT( next_block_p);
VALGRIND_NOACCESS_STRUCT(next_block_p);
}
else
{
@@ -492,12 +492,12 @@ mem_heap_free_block( uint8_t *ptr) /**< pointer to beginning of data space of th
}
}
VALGRIND_NOACCESS_STRUCT( prev_block_p);
VALGRIND_NOACCESS_STRUCT(prev_block_p);
}
VALGRIND_NOACCESS_STRUCT( block_p);
VALGRIND_NOACCESS_STRUCT(block_p);
mem_check_heap();
mem_check_heap ();
} /* mem_heap_free_block */
/**
@@ -506,10 +506,10 @@ mem_heap_free_block( uint8_t *ptr) /**< pointer to beginning of data space of th
* @return recommended allocation size
*/
size_t
mem_heap_recommend_allocation_size( size_t minimum_allocation_size) /**< minimum allocation size */
mem_heap_recommend_allocation_size (size_t minimum_allocation_size) /**< minimum allocation size */
{
size_t minimum_allocation_size_with_block_header = minimum_allocation_size + sizeof (mem_block_header_t);
size_t heap_chunk_aligned_allocation_size = JERRY_ALIGNUP( minimum_allocation_size_with_block_header, MEM_HEAP_CHUNK_SIZE);
size_t heap_chunk_aligned_allocation_size = JERRY_ALIGNUP(minimum_allocation_size_with_block_header, MEM_HEAP_CHUNK_SIZE);
return heap_chunk_aligned_allocation_size - sizeof (mem_block_header_t);
} /* mem_heap_recommend_allocation_size */
@@ -518,59 +518,59 @@ mem_heap_recommend_allocation_size( size_t minimum_allocation_size) /**< minimum
* Print heap
*/
void
mem_heap_print( bool dump_block_headers, /**< print block headers */
mem_heap_print (bool dump_block_headers, /**< print block headers */
bool dump_block_data, /**< print block with data (true)
or print only block header (false) */
bool dump_stats) /**< print heap stats */
{
mem_check_heap();
mem_check_heap ();
JERRY_ASSERT( !dump_block_data || dump_block_headers );
JERRY_ASSERT(!dump_block_data || dump_block_headers);
if ( dump_block_headers )
if (dump_block_headers)
{
__printf("Heap: start=%p size=%lu, first block->%p, last block->%p\n",
__printf ("Heap: start=%p size=%lu, first block->%p, last block->%p\n",
mem_heap.heap_start,
mem_heap.heap_size,
(void*) mem_heap.first_block_p,
(void*) mem_heap.last_block_p);
for ( mem_block_header_t *block_p = mem_heap.first_block_p, *next_block_p;
for (mem_block_header_t *block_p = mem_heap.first_block_p, *next_block_p;
block_p != NULL;
block_p = next_block_p )
block_p = next_block_p)
{
VALGRIND_DEFINED_STRUCT( block_p);
VALGRIND_DEFINED_STRUCT(block_p);
__printf("Block (%p): magic num=0x%08x, size in chunks=%lu, previous block->%p next block->%p\n",
__printf ("Block (%p): magic num=0x%08x, size in chunks=%lu, previous block->%p next block->%p\n",
(void*) block_p,
block_p->magic_num,
mem_get_block_chunks_count( block_p),
mem_get_block_chunks_count (block_p),
(void*) block_p->neighbours[ MEM_DIRECTION_PREV ],
(void*) block_p->neighbours[ MEM_DIRECTION_NEXT ]);
if ( dump_block_data )
if (dump_block_data)
{
uint8_t *block_data_p = (uint8_t*) (block_p + 1);
for ( uint32_t offset = 0;
offset < mem_get_block_data_space_size( block_p);
offset++ )
for (uint32_t offset = 0;
offset < mem_get_block_data_space_size (block_p);
offset++)
{
__printf("%02x ", block_data_p[ offset ]);
__printf ("%02x ", block_data_p[ offset ]);
}
__printf("\n");
__printf ("\n");
}
next_block_p = block_p->neighbours[ MEM_DIRECTION_NEXT ];
VALGRIND_NOACCESS_STRUCT( block_p);
VALGRIND_NOACCESS_STRUCT(block_p);
}
}
#ifdef MEM_STATS
if ( dump_stats )
if (dump_stats)
{
__printf("Heap stats:\n");
__printf(" Heap size = %lu bytes\n"
__printf ("Heap stats:\n");
__printf (" Heap size = %lu bytes\n"
" Chunk size = %lu bytes\n"
" Blocks count = %lu\n"
" Allocated blocks count = %lu\n"
@@ -595,80 +595,80 @@ mem_heap_print( bool dump_block_headers, /**< print block headers */
}
#endif /* MEM_STATS */
__printf("\n");
__printf ("\n");
} /* mem_heap_print */
/**
* Check heap consistency
*/
static void
mem_check_heap( void)
mem_check_heap (void)
{
#ifndef JERRY_NDEBUG
JERRY_ASSERT( (uint8_t*) mem_heap.first_block_p == mem_heap.heap_start );
JERRY_ASSERT( mem_heap.heap_size % MEM_HEAP_CHUNK_SIZE == 0 );
JERRY_ASSERT((uint8_t*) mem_heap.first_block_p == mem_heap.heap_start);
JERRY_ASSERT(mem_heap.heap_size % MEM_HEAP_CHUNK_SIZE == 0);
bool is_last_block_was_met = false;
size_t chunk_sizes_sum = 0;
for ( mem_block_header_t *block_p = mem_heap.first_block_p, *next_block_p;
for (mem_block_header_t *block_p = mem_heap.first_block_p, *next_block_p;
block_p != NULL;
block_p = next_block_p )
block_p = next_block_p)
{
VALGRIND_DEFINED_STRUCT( block_p);
VALGRIND_DEFINED_STRUCT(block_p);
JERRY_ASSERT( block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK
|| block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
chunk_sizes_sum += mem_get_block_chunks_count( block_p);
JERRY_ASSERT(block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK
|| block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
chunk_sizes_sum += mem_get_block_chunks_count (block_p);
next_block_p = block_p->neighbours[ MEM_DIRECTION_NEXT ];
if ( block_p == mem_heap.last_block_p )
if (block_p == mem_heap.last_block_p)
{
is_last_block_was_met = true;
JERRY_ASSERT( next_block_p == NULL );
JERRY_ASSERT(next_block_p == NULL);
} else
{
JERRY_ASSERT( next_block_p != NULL );
JERRY_ASSERT(next_block_p != NULL);
}
VALGRIND_NOACCESS_STRUCT( block_p);
VALGRIND_NOACCESS_STRUCT(block_p);
}
JERRY_ASSERT( chunk_sizes_sum * MEM_HEAP_CHUNK_SIZE == mem_heap.heap_size );
JERRY_ASSERT( is_last_block_was_met );
JERRY_ASSERT(chunk_sizes_sum * MEM_HEAP_CHUNK_SIZE == mem_heap.heap_size);
JERRY_ASSERT(is_last_block_was_met);
bool is_first_block_was_met = false;
chunk_sizes_sum = 0;
for ( mem_block_header_t *block_p = mem_heap.last_block_p, *prev_block_p;
for (mem_block_header_t *block_p = mem_heap.last_block_p, *prev_block_p;
block_p != NULL;
block_p = prev_block_p )
block_p = prev_block_p)
{
VALGRIND_DEFINED_STRUCT( block_p);
VALGRIND_DEFINED_STRUCT(block_p);
JERRY_ASSERT( block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK
|| block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
chunk_sizes_sum += mem_get_block_chunks_count( block_p);
JERRY_ASSERT(block_p->magic_num == MEM_MAGIC_NUM_OF_FREE_BLOCK
|| block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
chunk_sizes_sum += mem_get_block_chunks_count (block_p);
prev_block_p = block_p->neighbours[ MEM_DIRECTION_PREV ];
if ( block_p == mem_heap.first_block_p )
if (block_p == mem_heap.first_block_p)
{
is_first_block_was_met = true;
JERRY_ASSERT( prev_block_p == NULL );
JERRY_ASSERT(prev_block_p == NULL);
} else
{
JERRY_ASSERT( prev_block_p != NULL );
JERRY_ASSERT(prev_block_p != NULL);
}
VALGRIND_NOACCESS_STRUCT( block_p);
VALGRIND_NOACCESS_STRUCT(block_p);
}
JERRY_ASSERT( chunk_sizes_sum * MEM_HEAP_CHUNK_SIZE == mem_heap.heap_size );
JERRY_ASSERT( is_first_block_was_met );
JERRY_ASSERT(chunk_sizes_sum * MEM_HEAP_CHUNK_SIZE == mem_heap.heap_size);
JERRY_ASSERT(is_first_block_was_met);
#endif /* !JERRY_NDEBUG */
} /* mem_check_heap */
@@ -677,7 +677,7 @@ mem_check_heap( void)
* Get heap memory usage statistics
*/
void
mem_heap_get_stats( mem_heap_stats_t *out_heap_stats_p) /**< out: heap stats */
mem_heap_get_stats (mem_heap_stats_t *out_heap_stats_p) /**< out: heap stats */
{
*out_heap_stats_p = mem_heap_stats;
} /* mem_heap_get_stats */
@@ -686,9 +686,9 @@ mem_heap_get_stats( mem_heap_stats_t *out_heap_stats_p) /**< out: heap stats */
* Initalize heap memory usage statistics account structure
*/
static void
mem_heap_stat_init()
mem_heap_stat_init ()
{
__memset( &mem_heap_stats, 0, sizeof (mem_heap_stats));
__memset (&mem_heap_stats, 0, sizeof (mem_heap_stats));
mem_heap_stats.size = mem_heap.heap_size;
mem_heap_stats.blocks = 1;
@@ -698,11 +698,11 @@ mem_heap_stat_init()
* Account block allocation
*/
static void
mem_heap_stat_alloc_block( mem_block_header_t *block_header_p) /**< allocated block */
mem_heap_stat_alloc_block (mem_block_header_t *block_header_p) /**< allocated block */
{
JERRY_ASSERT( block_header_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
JERRY_ASSERT(block_header_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
const size_t chunks = mem_get_block_chunks_count( block_header_p);
const size_t chunks = mem_get_block_chunks_count (block_header_p);
const size_t bytes = block_header_p->allocated_bytes;
const size_t waste_bytes = chunks * MEM_HEAP_CHUNK_SIZE - bytes;
@@ -711,51 +711,51 @@ mem_heap_stat_alloc_block( mem_block_header_t *block_header_p) /**< allocated bl
mem_heap_stats.allocated_bytes += bytes;
mem_heap_stats.waste_bytes += waste_bytes;
if ( mem_heap_stats.allocated_blocks > mem_heap_stats.peak_allocated_blocks )
if (mem_heap_stats.allocated_blocks > mem_heap_stats.peak_allocated_blocks)
{
mem_heap_stats.peak_allocated_blocks = mem_heap_stats.allocated_blocks;
}
if ( mem_heap_stats.allocated_chunks > mem_heap_stats.peak_allocated_chunks )
if (mem_heap_stats.allocated_chunks > mem_heap_stats.peak_allocated_chunks)
{
mem_heap_stats.peak_allocated_chunks = mem_heap_stats.allocated_chunks;
}
if ( mem_heap_stats.allocated_bytes > mem_heap_stats.peak_allocated_bytes )
if (mem_heap_stats.allocated_bytes > mem_heap_stats.peak_allocated_bytes)
{
mem_heap_stats.peak_allocated_bytes = mem_heap_stats.allocated_bytes;
}
if ( mem_heap_stats.waste_bytes > mem_heap_stats.peak_waste_bytes )
if (mem_heap_stats.waste_bytes > mem_heap_stats.peak_waste_bytes)
{
mem_heap_stats.peak_waste_bytes = mem_heap_stats.waste_bytes;
}
JERRY_ASSERT( mem_heap_stats.allocated_blocks <= mem_heap_stats.blocks );
JERRY_ASSERT( mem_heap_stats.allocated_bytes <= mem_heap_stats.size );
JERRY_ASSERT( mem_heap_stats.allocated_chunks <= mem_heap_stats.size / MEM_HEAP_CHUNK_SIZE );
JERRY_ASSERT(mem_heap_stats.allocated_blocks <= mem_heap_stats.blocks);
JERRY_ASSERT(mem_heap_stats.allocated_bytes <= mem_heap_stats.size);
JERRY_ASSERT(mem_heap_stats.allocated_chunks <= mem_heap_stats.size / MEM_HEAP_CHUNK_SIZE);
} /* mem_heap_stat_alloc_block */
/**
* Account block freeing
*/
static void
mem_heap_stat_free_block( mem_block_header_t *block_header_p) /**< block to be freed */
mem_heap_stat_free_block (mem_block_header_t *block_header_p) /**< block to be freed */
{
JERRY_ASSERT( block_header_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK );
JERRY_ASSERT(block_header_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
const size_t chunks = mem_get_block_chunks_count( block_header_p);
const size_t chunks = mem_get_block_chunks_count (block_header_p);
const size_t bytes = block_header_p->allocated_bytes;
const size_t waste_bytes = chunks * MEM_HEAP_CHUNK_SIZE - bytes;
JERRY_ASSERT( mem_heap_stats.allocated_blocks <= mem_heap_stats.blocks );
JERRY_ASSERT( mem_heap_stats.allocated_bytes <= mem_heap_stats.size );
JERRY_ASSERT( mem_heap_stats.allocated_chunks <= mem_heap_stats.size / MEM_HEAP_CHUNK_SIZE );
JERRY_ASSERT(mem_heap_stats.allocated_blocks <= mem_heap_stats.blocks);
JERRY_ASSERT(mem_heap_stats.allocated_bytes <= mem_heap_stats.size);
JERRY_ASSERT(mem_heap_stats.allocated_chunks <= mem_heap_stats.size / MEM_HEAP_CHUNK_SIZE);
JERRY_ASSERT( mem_heap_stats.allocated_blocks >= 1 );
JERRY_ASSERT( mem_heap_stats.allocated_chunks >= chunks );
JERRY_ASSERT( mem_heap_stats.allocated_bytes >= bytes );
JERRY_ASSERT( mem_heap_stats.waste_bytes >= waste_bytes );
JERRY_ASSERT(mem_heap_stats.allocated_blocks >= 1);
JERRY_ASSERT(mem_heap_stats.allocated_chunks >= chunks);
JERRY_ASSERT(mem_heap_stats.allocated_bytes >= bytes);
JERRY_ASSERT(mem_heap_stats.waste_bytes >= waste_bytes);
mem_heap_stats.allocated_blocks--;
mem_heap_stats.allocated_chunks -= chunks;
@@ -767,7 +767,7 @@ mem_heap_stat_free_block( mem_block_header_t *block_header_p) /**< block to be f
* Account free block split
*/
static void
mem_heap_stat_free_block_split( void)
mem_heap_stat_free_block_split (void)
{
mem_heap_stats.blocks++;
} /* mem_heap_stat_free_block_split */
@@ -776,7 +776,7 @@ mem_heap_stat_free_block_split( void)
* Account free block merge
*/
static void
mem_heap_stat_free_block_merge( void)
mem_heap_stat_free_block_merge (void)
{
mem_heap_stats.blocks--;
} /* mem_heap_stat_free_block_merge */
+7 -7
View File
@@ -38,12 +38,12 @@ typedef enum {
MEM_HEAP_ALLOC_LONG_TERM /**< allocated region most likely will not be freed soon */
} mem_heap_alloc_term_t;
extern void mem_heap_init(uint8_t *heap_start, size_t heap_size);
extern void mem_heap_finalize(void);
extern uint8_t* mem_heap_alloc_block(size_t size_in_bytes, mem_heap_alloc_term_t alloc_term);
extern void mem_heap_free_block(uint8_t *ptr);
extern size_t mem_heap_recommend_allocation_size(size_t minimum_allocation_size);
extern void mem_heap_print(bool dump_block_headers, bool dump_block_data, bool dump_stats);
extern void mem_heap_init (uint8_t *heap_start, size_t heap_size);
extern void mem_heap_finalize (void);
extern uint8_t* mem_heap_alloc_block (size_t size_in_bytes, mem_heap_alloc_term_t alloc_term);
extern void mem_heap_free_block (uint8_t *ptr);
extern size_t mem_heap_recommend_allocation_size (size_t minimum_allocation_size);
extern void mem_heap_print (bool dump_block_headers, bool dump_block_data, bool dump_stats);
#ifdef MEM_STATS
/**
@@ -67,7 +67,7 @@ typedef struct {
size_t peak_waste_bytes; /**< peak bytes waste */
} mem_heap_stats_t;
extern void mem_heap_get_stats(mem_heap_stats_t *out_heap_stats_p);
extern void mem_heap_get_stats (mem_heap_stats_t *out_heap_stats_p);
#endif /* MEM_STATS */
/**
+35 -35
View File
@@ -31,13 +31,13 @@
#include "mem-allocator.h"
#include "mem-pool.h"
static void mem_check_pool( mem_pool_state_t *pool_p);
static void mem_check_pool (mem_pool_state_t *pool_p);
/**
* Get address of pool chunk with specified index
*/
#define MEM_POOL_CHUNK_ADDRESS( pool_header_p, chunk_index) ( (uint8_t*) ( MEM_POOL_SPACE_START( pool_p) + \
MEM_POOL_CHUNK_SIZE * chunk_index ) )
#define MEM_POOL_CHUNK_ADDRESS(pool_header_p, chunk_index) ((uint8_t*) (MEM_POOL_SPACE_START(pool_p) + \
MEM_POOL_CHUNK_SIZE * chunk_index))
/**
* Initialization of memory pool.
@@ -46,20 +46,20 @@ static void mem_check_pool( mem_pool_state_t *pool_p);
* Part of pool space will be used for bitmap and the rest will store chunks.
*/
void
mem_pool_init(mem_pool_state_t *pool_p, /**< pool */
mem_pool_init (mem_pool_state_t *pool_p, /**< pool */
size_t pool_size) /**< pool size */
{
JERRY_ASSERT( pool_p != NULL );
JERRY_ASSERT( (size_t)MEM_POOL_SPACE_START( pool_p) % MEM_ALIGNMENT == 0);
JERRY_ASSERT(pool_p != NULL);
JERRY_ASSERT((size_t)MEM_POOL_SPACE_START(pool_p) % MEM_ALIGNMENT == 0);
JERRY_STATIC_ASSERT( MEM_POOL_CHUNK_SIZE % MEM_ALIGNMENT == 0 );
JERRY_STATIC_ASSERT( MEM_POOL_MAX_CHUNKS_NUMBER_LOG <= sizeof(mem_pool_chunk_index_t) * JERRY_BITSINBYTE );
JERRY_ASSERT( sizeof(mem_pool_chunk_index_t) <= MEM_POOL_CHUNK_SIZE );
JERRY_STATIC_ASSERT(MEM_POOL_CHUNK_SIZE % MEM_ALIGNMENT == 0);
JERRY_STATIC_ASSERT(MEM_POOL_MAX_CHUNKS_NUMBER_LOG <= sizeof (mem_pool_chunk_index_t) * JERRY_BITSINBYTE);
JERRY_ASSERT(sizeof (mem_pool_chunk_index_t) <= MEM_POOL_CHUNK_SIZE);
const size_t pool_space_size = pool_size - sizeof(mem_pool_state_t);
const size_t pool_space_size = pool_size - sizeof (mem_pool_state_t);
const size_t chunks_number = pool_space_size / MEM_POOL_CHUNK_SIZE;
JERRY_ASSERT( ( (mem_pool_chunk_index_t) chunks_number ) == chunks_number );
JERRY_ASSERT(((mem_pool_chunk_index_t) chunks_number) == chunks_number);
pool_p->chunks_number = (mem_pool_chunk_index_t) chunks_number;
@@ -73,44 +73,44 @@ mem_pool_init(mem_pool_state_t *pool_p, /**< pool */
*/
pool_p->first_free_chunk = 0;
for ( mem_pool_chunk_index_t chunk_index = 0;
for (mem_pool_chunk_index_t chunk_index = 0;
chunk_index < chunks_number;
chunk_index++ )
chunk_index++)
{
mem_pool_chunk_index_t *next_free_chunk_index_p =
(mem_pool_chunk_index_t*) MEM_POOL_CHUNK_ADDRESS( pool_p, chunk_index);
(mem_pool_chunk_index_t*) MEM_POOL_CHUNK_ADDRESS(pool_p, chunk_index);
*next_free_chunk_index_p = (mem_pool_chunk_index_t) (chunk_index + 1u);
}
mem_check_pool( pool_p);
mem_check_pool (pool_p);
} /* mem_pool_init */
/**
* Allocate a chunk in the pool
*/
uint8_t*
mem_pool_alloc_chunk(mem_pool_state_t *pool_p) /**< pool */
mem_pool_alloc_chunk (mem_pool_state_t *pool_p) /**< pool */
{
mem_check_pool( pool_p);
mem_check_pool (pool_p);
if ( unlikely( pool_p->free_chunks_number == 0 ) )
if (unlikely (pool_p->free_chunks_number == 0))
{
JERRY_ASSERT( pool_p->first_free_chunk == pool_p->chunks_number );
JERRY_ASSERT(pool_p->first_free_chunk == pool_p->chunks_number);
return NULL;
}
JERRY_ASSERT( pool_p->first_free_chunk < pool_p->chunks_number );
JERRY_ASSERT(pool_p->first_free_chunk < pool_p->chunks_number);
mem_pool_chunk_index_t chunk_index = pool_p->first_free_chunk;
uint8_t *chunk_p = MEM_POOL_CHUNK_ADDRESS( pool_p, chunk_index);
uint8_t *chunk_p = MEM_POOL_CHUNK_ADDRESS(pool_p, chunk_index);
mem_pool_chunk_index_t *next_free_chunk_index_p = (mem_pool_chunk_index_t*) chunk_p;
pool_p->first_free_chunk = *next_free_chunk_index_p;
pool_p->free_chunks_number--;
mem_check_pool( pool_p);
mem_check_pool (pool_p);
return chunk_p;
} /* mem_pool_alloc_chunk */
@@ -119,16 +119,16 @@ mem_pool_alloc_chunk(mem_pool_state_t *pool_p) /**< pool */
* Free the chunk in the pool
*/
void
mem_pool_free_chunk(mem_pool_state_t *pool_p, /**< pool */
mem_pool_free_chunk (mem_pool_state_t *pool_p, /**< pool */
uint8_t *chunk_p) /**< chunk pointer */
{
JERRY_ASSERT( pool_p->free_chunks_number < pool_p->chunks_number );
JERRY_ASSERT( chunk_p >= MEM_POOL_SPACE_START( pool_p) && chunk_p <= MEM_POOL_SPACE_START( pool_p) + pool_p->chunks_number * MEM_POOL_CHUNK_SIZE );
JERRY_ASSERT( ( (uintptr_t) chunk_p - (uintptr_t) MEM_POOL_SPACE_START( pool_p) ) % MEM_POOL_CHUNK_SIZE == 0 );
JERRY_ASSERT(pool_p->free_chunks_number < pool_p->chunks_number);
JERRY_ASSERT(chunk_p >= MEM_POOL_SPACE_START(pool_p) && chunk_p <= MEM_POOL_SPACE_START(pool_p) + pool_p->chunks_number * MEM_POOL_CHUNK_SIZE);
JERRY_ASSERT(((uintptr_t) chunk_p - (uintptr_t) MEM_POOL_SPACE_START(pool_p)) % MEM_POOL_CHUNK_SIZE == 0);
mem_check_pool( pool_p);
mem_check_pool (pool_p);
const size_t chunk_byte_offset = (size_t) (chunk_p - MEM_POOL_SPACE_START( pool_p));
const size_t chunk_byte_offset = (size_t) (chunk_p - MEM_POOL_SPACE_START(pool_p));
const mem_pool_chunk_index_t chunk_index = (mem_pool_chunk_index_t) (chunk_byte_offset / MEM_POOL_CHUNK_SIZE);
mem_pool_chunk_index_t *next_free_chunk_index_p = (mem_pool_chunk_index_t*) chunk_p;
@@ -138,25 +138,25 @@ mem_pool_free_chunk(mem_pool_state_t *pool_p, /**< pool */
pool_p->first_free_chunk = chunk_index;
pool_p->free_chunks_number++;
mem_check_pool( pool_p);
mem_check_pool (pool_p);
} /* mem_pool_free_chunk */
/**
* Check pool state consistency
*/
static void
mem_check_pool( mem_pool_state_t __unused *pool_p) /**< pool (unused #ifdef JERRY_NDEBUG) */
mem_check_pool (mem_pool_state_t __unused *pool_p) /**< pool (unused #ifdef JERRY_NDEBUG) */
{
#ifndef JERRY_NDEBUG
JERRY_ASSERT( pool_p->chunks_number != 0 );
JERRY_ASSERT( pool_p->free_chunks_number <= pool_p->chunks_number );
JERRY_ASSERT(pool_p->chunks_number != 0);
JERRY_ASSERT(pool_p->free_chunks_number <= pool_p->chunks_number);
size_t met_free_chunks_number = 0;
mem_pool_chunk_index_t chunk_index = pool_p->first_free_chunk;
while ( chunk_index != pool_p->chunks_number )
while (chunk_index != pool_p->chunks_number)
{
uint8_t *chunk_p = MEM_POOL_CHUNK_ADDRESS( pool_p, chunk_index);
uint8_t *chunk_p = MEM_POOL_CHUNK_ADDRESS(pool_p, chunk_index);
mem_pool_chunk_index_t *next_free_chunk_index_p = (mem_pool_chunk_index_t*) chunk_p;
met_free_chunks_number++;
@@ -164,7 +164,7 @@ mem_check_pool( mem_pool_state_t __unused *pool_p) /**< pool (unused #ifdef JERR
chunk_index = *next_free_chunk_index_p;
}
JERRY_ASSERT( met_free_chunks_number == pool_p->free_chunks_number );
JERRY_ASSERT(met_free_chunks_number == pool_p->free_chunks_number);
#endif /* !JERRY_NDEBUG */
} /* mem_check_pool */
+4 -4
View File
@@ -29,7 +29,7 @@
/**
* Get pool's space size
*/
#define MEM_POOL_SPACE_START( pool_header_p) ( (uint8_t*) ( (mem_pool_state_t*) pool_header_p + 1 ) )
#define MEM_POOL_SPACE_START(pool_header_p) ((uint8_t*) ((mem_pool_state_t*) pool_header_p + 1))
/**
* Index of chunk in a pool
@@ -50,9 +50,9 @@ typedef struct mem_pool_state_t {
unsigned int next_pool_cp : MEM_HEAP_OFFSET_LOG; /**< pointer to the next pool with same chunk size */
} mem_pool_state_t;
extern void mem_pool_init(mem_pool_state_t *pool_p, size_t pool_size);
extern uint8_t* mem_pool_alloc_chunk(mem_pool_state_t *pool_p);
extern void mem_pool_free_chunk(mem_pool_state_t *pool_p, uint8_t *chunk_p);
extern void mem_pool_init (mem_pool_state_t *pool_p, size_t pool_size);
extern uint8_t* mem_pool_alloc_chunk (mem_pool_state_t *pool_p);
extern void mem_pool_free_chunk (mem_pool_state_t *pool_p, uint8_t *chunk_p);
/**
* @}
+55 -55
View File
@@ -49,39 +49,39 @@ size_t mem_free_chunks_number;
*/
mem_pools_stats_t mem_pools_stats;
static void mem_pools_stat_init( void);
static void mem_pools_stat_alloc_pool( void);
static void mem_pools_stat_free_pool( void);
static void mem_pools_stat_alloc_chunk(void );
static void mem_pools_stat_free_chunk( void);
static void mem_pools_stat_init (void);
static void mem_pools_stat_alloc_pool (void);
static void mem_pools_stat_free_pool (void);
static void mem_pools_stat_alloc_chunk (void);
static void mem_pools_stat_free_chunk (void);
#else /* !MEM_STATS */
# define mem_pools_stat_init()
# define mem_pools_stat_alloc_pool()
# define mem_pools_stat_free_pool()
# define mem_pools_stat_alloc_chunk()
# define mem_pools_stat_free_chunk()
# define mem_pools_stat_init ()
# define mem_pools_stat_alloc_pool ()
# define mem_pools_stat_free_pool ()
# define mem_pools_stat_alloc_chunk ()
# define mem_pools_stat_free_chunk ()
#endif /* !MEM_STATS */
/**
* Initialize pool manager
*/
void
mem_pools_init( void)
mem_pools_init (void)
{
mem_pools = NULL;
mem_free_chunks_number = 0;
mem_pools_stat_init();
mem_pools_stat_init ();
} /* mem_pools_init */
/**
* Finalize pool manager
*/
void
mem_pools_finalize( void)
mem_pools_finalize (void)
{
JERRY_ASSERT( mem_pools == NULL );
JERRY_ASSERT( mem_free_chunks_number == 0 );
JERRY_ASSERT(mem_pools == NULL);
JERRY_ASSERT(mem_free_chunks_number == 0);
} /* mem_pools_finalize */
/**
@@ -91,23 +91,23 @@ mem_pools_finalize( void)
* or NULL - if not enough memory.
*/
uint8_t*
mem_pools_alloc( void)
mem_pools_alloc (void)
{
/**
* If there are no free chunks, allocate new pool.
*/
if ( mem_free_chunks_number == 0 )
if (mem_free_chunks_number == 0)
{
/**
* Space, at least for header and eight chunks.
*
* TODO: Config.
*/
size_t pool_size = mem_heap_recommend_allocation_size( sizeof(mem_pool_state_t) + 8 * MEM_POOL_CHUNK_SIZE );
size_t pool_size = mem_heap_recommend_allocation_size (sizeof (mem_pool_state_t) + 8 * MEM_POOL_CHUNK_SIZE);
mem_pool_state_t *pool_state = (mem_pool_state_t*) mem_heap_alloc_block( pool_size, MEM_HEAP_ALLOC_LONG_TERM);
mem_pool_state_t *pool_state = (mem_pool_state_t*) mem_heap_alloc_block (pool_size, MEM_HEAP_ALLOC_LONG_TERM);
if ( pool_state == NULL )
if (pool_state == NULL)
{
/**
* Not enough space for new pool.
@@ -115,15 +115,15 @@ mem_pools_alloc( void)
return NULL;
}
mem_pool_init( pool_state, pool_size);
mem_pool_init (pool_state, pool_size);
pool_state->next_pool_cp = ( mem_pools == NULL ) ? MEM_COMPRESSED_POINTER_NULL
: (uint16_t) mem_compress_pointer( mem_pools);
pool_state->next_pool_cp = (mem_pools == NULL) ? MEM_COMPRESSED_POINTER_NULL
: (uint16_t) mem_compress_pointer (mem_pools);
mem_pools = pool_state;
mem_free_chunks_number += pool_state->chunks_number;
mem_pools_stat_alloc_pool();
mem_pools_stat_alloc_pool ();
}
/**
@@ -133,11 +133,11 @@ mem_pools_alloc( void)
*/
mem_pool_state_t *pool_state = mem_pools;
while ( pool_state->first_free_chunk == pool_state->chunks_number )
while (pool_state->first_free_chunk == pool_state->chunks_number)
{
pool_state = mem_decompress_pointer( pool_state->next_pool_cp);
pool_state = mem_decompress_pointer (pool_state->next_pool_cp);
JERRY_ASSERT( pool_state != NULL );
JERRY_ASSERT(pool_state != NULL);
}
/**
@@ -145,64 +145,64 @@ mem_pools_alloc( void)
*/
mem_free_chunks_number--;
mem_pools_stat_alloc_chunk();
mem_pools_stat_alloc_chunk ();
return mem_pool_alloc_chunk( pool_state);
return mem_pool_alloc_chunk (pool_state);
} /* mem_pools_alloc */
/**
* Free the chunk
*/
void
mem_pools_free( uint8_t *chunk_p) /**< pointer to the chunk */
mem_pools_free (uint8_t *chunk_p) /**< pointer to the chunk */
{
mem_pool_state_t *pool_state = mem_pools, *prev_pool_state = NULL;
/**
* Search for the pool containing specified chunk.
*/
while ( !( chunk_p >= MEM_POOL_SPACE_START( pool_state)
&& chunk_p <= MEM_POOL_SPACE_START( pool_state) + pool_state->chunks_number * MEM_POOL_CHUNK_SIZE ) )
while (!(chunk_p >= MEM_POOL_SPACE_START(pool_state)
&& chunk_p <= MEM_POOL_SPACE_START(pool_state) + pool_state->chunks_number * MEM_POOL_CHUNK_SIZE))
{
prev_pool_state = pool_state;
pool_state = mem_decompress_pointer( pool_state->next_pool_cp);
pool_state = mem_decompress_pointer (pool_state->next_pool_cp);
JERRY_ASSERT( pool_state != NULL );
JERRY_ASSERT(pool_state != NULL);
}
/**
* Free the chunk
*/
mem_pool_free_chunk( pool_state, chunk_p);
mem_pool_free_chunk (pool_state, chunk_p);
mem_free_chunks_number++;
mem_pools_stat_free_chunk();
mem_pools_stat_free_chunk ();
/**
* If all chunks of the pool are free, free the pool itself.
*/
if ( pool_state->free_chunks_number == pool_state->chunks_number )
if (pool_state->free_chunks_number == pool_state->chunks_number)
{
if ( prev_pool_state != NULL )
if (prev_pool_state != NULL)
{
prev_pool_state->next_pool_cp = pool_state->next_pool_cp;
} else
{
if ( pool_state->next_pool_cp == MEM_COMPRESSED_POINTER_NULL )
if (pool_state->next_pool_cp == MEM_COMPRESSED_POINTER_NULL)
{
mem_pools = NULL;
}
else
{
mem_pools = mem_decompress_pointer( pool_state->next_pool_cp);
mem_pools = mem_decompress_pointer (pool_state->next_pool_cp);
}
}
mem_free_chunks_number -= pool_state->chunks_number;
mem_heap_free_block( (uint8_t*)pool_state);
mem_heap_free_block ((uint8_t*)pool_state);
mem_pools_stat_free_pool();
mem_pools_stat_free_pool ();
}
} /* mem_pools_free */
@@ -211,9 +211,9 @@ mem_pools_free( uint8_t *chunk_p) /**< pointer to the chunk */
* Get pools memory usage statistics
*/
void
mem_pools_get_stats( mem_pools_stats_t *out_pools_stats_p) /**< out: pools' stats */
mem_pools_get_stats (mem_pools_stats_t *out_pools_stats_p) /**< out: pools' stats */
{
JERRY_ASSERT( out_pools_stats_p != NULL );
JERRY_ASSERT(out_pools_stats_p != NULL);
*out_pools_stats_p = mem_pools_stats;
} /* mem_pools_get_stats */
@@ -222,21 +222,21 @@ mem_pools_get_stats( mem_pools_stats_t *out_pools_stats_p) /**< out: pools' stat
* Initalize pools' memory usage statistics account structure
*/
static void
mem_pools_stat_init( void)
mem_pools_stat_init (void)
{
__memset( &mem_pools_stats, 0, sizeof (mem_pools_stats));
__memset (&mem_pools_stats, 0, sizeof (mem_pools_stats));
} /* mem_pools_stat_init */
/**
* Account allocation of a pool
*/
static void
mem_pools_stat_alloc_pool( void)
mem_pools_stat_alloc_pool (void)
{
mem_pools_stats.pools_count++;
mem_pools_stats.free_chunks = mem_free_chunks_number;
if ( mem_pools_stats.pools_count > mem_pools_stats.peak_pools_count )
if (mem_pools_stats.pools_count > mem_pools_stats.peak_pools_count)
{
mem_pools_stats.peak_pools_count = mem_pools_stats.pools_count;
}
@@ -246,9 +246,9 @@ mem_pools_stat_alloc_pool( void)
* Account freeing of a pool
*/
static void
mem_pools_stat_free_pool( void)
mem_pools_stat_free_pool (void)
{
JERRY_ASSERT( mem_pools_stats.pools_count > 0 );
JERRY_ASSERT(mem_pools_stats.pools_count > 0);
mem_pools_stats.pools_count--;
mem_pools_stats.free_chunks = mem_free_chunks_number;
@@ -258,14 +258,14 @@ mem_pools_stat_free_pool( void)
* Account allocation of chunk in a pool
*/
static void
mem_pools_stat_alloc_chunk(void)
mem_pools_stat_alloc_chunk (void)
{
JERRY_ASSERT( mem_pools_stats.free_chunks > 0 );
JERRY_ASSERT(mem_pools_stats.free_chunks > 0);
mem_pools_stats.allocated_chunks++;
mem_pools_stats.free_chunks--;
if ( mem_pools_stats.allocated_chunks > mem_pools_stats.peak_allocated_chunks )
if (mem_pools_stats.allocated_chunks > mem_pools_stats.peak_allocated_chunks)
{
mem_pools_stats.peak_allocated_chunks = mem_pools_stats.allocated_chunks;
}
@@ -275,9 +275,9 @@ mem_pools_stat_alloc_chunk(void)
* Account freeing of chunk in a pool
*/
static void
mem_pools_stat_free_chunk(void)
mem_pools_stat_free_chunk (void)
{
JERRY_ASSERT( mem_pools_stats.allocated_chunks > 0 );
JERRY_ASSERT(mem_pools_stats.allocated_chunks > 0);
mem_pools_stats.allocated_chunks--;
mem_pools_stats.free_chunks++;
+5 -5
View File
@@ -29,10 +29,10 @@
#include "globals.h"
extern void mem_pools_init(void);
extern void mem_pools_finalize(void);
extern uint8_t* mem_pools_alloc(void);
extern void mem_pools_free(uint8_t *chunk_p);
extern void mem_pools_init (void);
extern void mem_pools_finalize (void);
extern uint8_t* mem_pools_alloc (void);
extern void mem_pools_free (uint8_t *chunk_p);
#ifdef MEM_STATS
/**
@@ -56,7 +56,7 @@ typedef struct
size_t free_chunks;
} mem_pools_stats_t;
extern void mem_pools_get_stats( mem_pools_stats_t *out_pools_stats_p);
extern void mem_pools_get_stats (mem_pools_stats_t *out_pools_stats_p);
#endif /* MEM_STATS */
#endif /* JERRY_MEM_POOLMAN_H */
+22 -22
View File
@@ -38,43 +38,43 @@
#include "ecma-gc.h"
#include "mem-poolman.h"
JERRY_STATIC_ASSERT( sizeof (ecma_value_t) <= sizeof (uint16_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_property_t) <= sizeof (uint64_t) );
JERRY_STATIC_ASSERT(sizeof (ecma_value_t) <= sizeof (uint16_t));
JERRY_STATIC_ASSERT(sizeof (ecma_property_t) <= sizeof (uint64_t));
FIXME( Pack ecma_object_t )
JERRY_STATIC_ASSERT( sizeof (ecma_object_t) <= 2 * sizeof (uint64_t) );
FIXME(Pack ecma_object_t)
JERRY_STATIC_ASSERT(sizeof (ecma_object_t) <= 2 * sizeof (uint64_t));
JERRY_STATIC_ASSERT( sizeof (ecma_array_header_t) <= sizeof (uint32_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_array_first_chunk_t) == sizeof(uint64_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_array_non_first_chunk_t) == sizeof(uint64_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_completion_value_t) == sizeof(uint32_t) );
JERRY_STATIC_ASSERT(sizeof (ecma_array_header_t) <= sizeof (uint32_t));
JERRY_STATIC_ASSERT(sizeof (ecma_array_first_chunk_t) == sizeof (uint64_t));
JERRY_STATIC_ASSERT(sizeof (ecma_array_non_first_chunk_t) == sizeof (uint64_t));
JERRY_STATIC_ASSERT(sizeof (ecma_completion_value_t) == sizeof (uint32_t));
/**
* Template of an allocation routine.
*
* FIXME: Run GC only if allocation failed.
*/
#define ALLOC( ecma_type) ecma_ ## ecma_type ## _t * \
#define ALLOC(ecma_type) ecma_ ## ecma_type ## _t * \
ecma_alloc_ ## ecma_type (void) \
{ \
ecma_ ## ecma_type ## _t *p ## ecma_type = (ecma_ ## ecma_type ## _t *) \
mem_pools_alloc(); \
mem_pools_alloc (); \
\
if ( likely( p ## ecma_type != NULL ) ) \
if (likely (p ## ecma_type != NULL)) \
{ \
return p ## ecma_type; \
} \
\
for ( ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; \
for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; \
gen_id < ECMA_GC_GEN_COUNT; \
gen_id++ ) \
gen_id++) \
{ \
ecma_gc_run( gen_id ); \
ecma_gc_run (gen_id); \
\
p ## ecma_type = (ecma_ ## ecma_type ## _t *) \
mem_pools_alloc(); \
mem_pools_alloc (); \
\
if ( likely( p ## ecma_type != NULL ) ) \
if (likely (p ## ecma_type != NULL)) \
{ \
return p ## ecma_type; \
} \
@@ -85,18 +85,18 @@ ecma_alloc_ ## ecma_type (void) \
/**
* Deallocation routine template
*/
#define DEALLOC( ecma_type) void \
ecma_dealloc_ ## ecma_type( ecma_ ## ecma_type ## _t *p ## ecma_type) \
#define DEALLOC(ecma_type) void \
ecma_dealloc_ ## ecma_type (ecma_ ## ecma_type ## _t *p ## ecma_type) \
{ \
mem_pools_free( (uint8_t*) p ## ecma_type); \
mem_pools_free ((uint8_t*) p ## ecma_type); \
}
/**
* Declaration of alloc/free routine for specified ecma-type.
*/
#define DECLARE_ROUTINES_FOR( ecma_type) \
ALLOC( ecma_type) \
DEALLOC( ecma_type)
#define DECLARE_ROUTINES_FOR(ecma_type) \
ALLOC(ecma_type) \
DEALLOC(ecma_type)
DECLARE_ROUTINES_FOR (object)
DECLARE_ROUTINES_FOR (property)
+11 -11
View File
@@ -21,7 +21,7 @@
*/
#ifndef JERRY_ECMA_ALLOC_H
#define JERRY_ECMA_ALLOC_H
#define JERRY_ECMA_ALLOC_H
#include "ecma-globals.h"
@@ -30,60 +30,60 @@
*
* @return pointer to allocated memory
*/
extern ecma_object_t *ecma_alloc_object(void);
extern ecma_object_t *ecma_alloc_object (void);
/**
* Dealloc memory from an ecma-object
*/
extern void ecma_dealloc_object( ecma_object_t *object_p);
extern void ecma_dealloc_object (ecma_object_t *object_p);
/**
* Allocate memory for ecma-property
*
* @return pointer to allocated memory
*/
extern ecma_property_t *ecma_alloc_property(void);
extern ecma_property_t *ecma_alloc_property (void);
/**
* Dealloc memory from an ecma-property
*/
extern void ecma_dealloc_property( ecma_property_t *property_p);
extern void ecma_dealloc_property (ecma_property_t *property_p);
/**
* Allocate memory for ecma-number
*
* @return pointer to allocated memory
*/
extern ecma_number_t *ecma_alloc_number(void);
extern ecma_number_t *ecma_alloc_number (void);
/**
* Dealloc memory from an ecma-number
*/
extern void ecma_dealloc_number( ecma_number_t *number_p);
extern void ecma_dealloc_number (ecma_number_t *number_p);
/**
* Allocate memory for first chunk of an ecma-array
*
* @return pointer to allocated memory
*/
extern ecma_array_first_chunk_t *ecma_alloc_array_first_chunk(void);
extern ecma_array_first_chunk_t *ecma_alloc_array_first_chunk (void);
/**
* Dealloc memory from first chunk of an ecma-array
*/
extern void ecma_dealloc_array_first_chunk( ecma_array_first_chunk_t *first_chunk_p);
extern void ecma_dealloc_array_first_chunk (ecma_array_first_chunk_t *first_chunk_p);
/**
* Allocate memory for non-first chunk of an ecma-array
*
* @return pointer to allocated memory
*/
extern ecma_array_non_first_chunk_t *ecma_alloc_array_non_first_chunk(void);
extern ecma_array_non_first_chunk_t *ecma_alloc_array_non_first_chunk (void);
/**
* Dealloc memory from non-first chunk of an ecma-array
*/
extern void ecma_dealloc_array_non_first_chunk( ecma_array_non_first_chunk_t *number_p);
extern void ecma_dealloc_array_non_first_chunk (ecma_array_non_first_chunk_t *number_p);
#endif /* JERRY_ECMA_ALLOC_H */
+99 -99
View File
@@ -36,19 +36,19 @@
*/
static ecma_object_t *ecma_gc_objects_lists[ ECMA_GC_GEN_COUNT ];
static void ecma_gc_mark( ecma_object_t *object_p, ecma_gc_gen_t maximum_gen_to_traverse);
static void ecma_gc_sweep( ecma_object_t *object_p);
static void ecma_gc_mark (ecma_object_t *object_p, ecma_gc_gen_t maximum_gen_to_traverse);
static void ecma_gc_sweep (ecma_object_t *object_p);
/**
* Initialize GC information for the object
*/
void
ecma_init_gc_info(ecma_object_t *object_p) /**< object */
ecma_init_gc_info (ecma_object_t *object_p) /**< object */
{
object_p->gc_info.refs = 1;
object_p->gc_info.generation = ECMA_GC_GEN_0;
ECMA_SET_POINTER( object_p->gc_info.next, ecma_gc_objects_lists[ ECMA_GC_GEN_0 ]);
ECMA_SET_POINTER(object_p->gc_info.next, ecma_gc_objects_lists[ ECMA_GC_GEN_0 ]);
ecma_gc_objects_lists[ ECMA_GC_GEN_0 ] = object_p;
/* Should be set to false at the beginning of garbage collection */
@@ -61,7 +61,7 @@ ecma_init_gc_info(ecma_object_t *object_p) /**< object */
* Increase reference counter of an object
*/
void
ecma_ref_object(ecma_object_t *object_p) /**< object */
ecma_ref_object (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT(object_p != NULL);
object_p->gc_info.refs++;
@@ -71,7 +71,7 @@ ecma_ref_object(ecma_object_t *object_p) /**< object */
*/
JERRY_ASSERT(object_p->gc_info.refs > 0);
if ( unlikely( object_p->gc_info.refs == 0 ) )
if (unlikely (object_p->gc_info.refs == 0))
{
JERRY_UNREACHABLE();
}
@@ -81,7 +81,7 @@ ecma_ref_object(ecma_object_t *object_p) /**< object */
* Decrease reference counter of an object
*/
void
ecma_deref_object(ecma_object_t *object_p) /**< object */
ecma_deref_object (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT(object_p != NULL);
JERRY_ASSERT(object_p->gc_info.refs > 0);
@@ -95,31 +95,31 @@ ecma_deref_object(ecma_object_t *object_p) /**< object */
* is less than generation of object specified by obj_p.
*/
void
ecma_gc_update_may_ref_younger_object_flag_by_value( ecma_object_t *obj_p, /**< object */
ecma_gc_update_may_ref_younger_object_flag_by_value (ecma_object_t *obj_p, /**< object */
ecma_value_t value) /**< value */
{
if ( value.value_type != ECMA_TYPE_OBJECT )
if (value.value_type != ECMA_TYPE_OBJECT)
{
return;
}
ecma_object_t *ref_obj_p = ECMA_GET_POINTER( value.value);
JERRY_ASSERT( ref_obj_p != NULL );
ecma_object_t *ref_obj_p = ECMA_GET_POINTER(value.value);
JERRY_ASSERT(ref_obj_p != NULL);
ecma_gc_update_may_ref_younger_object_flag_by_object( obj_p, ref_obj_p);
ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, ref_obj_p);
} /* ecma_gc_update_may_ref_younger_object_flag_by_value */
void
ecma_gc_update_may_ref_younger_object_flag_by_object( ecma_object_t *obj_p, /**< object */
ecma_gc_update_may_ref_younger_object_flag_by_object (ecma_object_t *obj_p, /**< object */
ecma_object_t *ref_obj_p) /**< referenced object
or NULL */
{
if ( ref_obj_p == NULL )
if (ref_obj_p == NULL)
{
return;
}
if ( ref_obj_p->gc_info.generation < obj_p->gc_info.generation )
if (ref_obj_p->gc_info.generation < obj_p->gc_info.generation)
{
obj_p->gc_info.may_ref_younger_objects = true;
}
@@ -129,9 +129,9 @@ ecma_gc_update_may_ref_younger_object_flag_by_object( ecma_object_t *obj_p, /**<
* Initialize garbage collector
*/
void
ecma_gc_init( void)
ecma_gc_init (void)
{
__memset( ecma_gc_objects_lists, 0, sizeof( ecma_gc_objects_lists));
__memset (ecma_gc_objects_lists, 0, sizeof (ecma_gc_objects_lists));
} /* ecma_gc_init */
/**
@@ -139,26 +139,26 @@ ecma_gc_init( void)
* if referenced object's generation is less or equal to maximum_gen_to_traverse.
*/
void
ecma_gc_mark( ecma_object_t *object_p, /**< start object */
ecma_gc_mark (ecma_object_t *object_p, /**< start object */
ecma_gc_gen_t maximum_gen_to_traverse) /**< start recursive traverse
if referenced object generation
is less or equal to maximum_gen_to_traverse */
{
JERRY_ASSERT( object_p != NULL );
JERRY_ASSERT(object_p != NULL);
object_p->gc_info.visited = true;
bool does_reference_object_to_traverse = false;
if ( object_p->is_lexical_environment )
if (object_p->is_lexical_environment)
{
ecma_object_t *lex_env_p = ECMA_GET_POINTER( object_p->u.lexical_environment.outer_reference_p);
if ( lex_env_p != NULL
&& lex_env_p->gc_info.generation <= maximum_gen_to_traverse )
ecma_object_t *lex_env_p = ECMA_GET_POINTER(object_p->u.lexical_environment.outer_reference_p);
if (lex_env_p != NULL
&& lex_env_p->gc_info.generation <= maximum_gen_to_traverse)
{
if ( !lex_env_p->gc_info.visited )
if (!lex_env_p->gc_info.visited)
{
ecma_gc_mark( lex_env_p, ECMA_GC_GEN_COUNT);
ecma_gc_mark (lex_env_p, ECMA_GC_GEN_COUNT);
}
does_reference_object_to_traverse = true;
@@ -166,40 +166,40 @@ ecma_gc_mark( ecma_object_t *object_p, /**< start object */
}
else
{
ecma_object_t *proto_p = ECMA_GET_POINTER( object_p->u.object.prototype_object_p);
if ( proto_p != NULL
&& proto_p->gc_info.generation <= maximum_gen_to_traverse )
ecma_object_t *proto_p = ECMA_GET_POINTER(object_p->u.object.prototype_object_p);
if (proto_p != NULL
&& proto_p->gc_info.generation <= maximum_gen_to_traverse)
{
if ( !proto_p->gc_info.visited )
if (!proto_p->gc_info.visited)
{
ecma_gc_mark( proto_p, ECMA_GC_GEN_COUNT);
ecma_gc_mark (proto_p, ECMA_GC_GEN_COUNT);
}
does_reference_object_to_traverse = true;
}
}
for ( ecma_property_t *property_p = ECMA_GET_POINTER( object_p->properties_p), *next_property_p;
for (ecma_property_t *property_p = ECMA_GET_POINTER(object_p->properties_p), *next_property_p;
property_p != NULL;
property_p = next_property_p )
property_p = next_property_p)
{
next_property_p = ECMA_GET_POINTER( property_p->next_property_p);
next_property_p = ECMA_GET_POINTER(property_p->next_property_p);
switch ( (ecma_property_type_t) property_p->type )
switch ((ecma_property_type_t) property_p->type)
{
case ECMA_PROPERTY_NAMEDDATA:
{
ecma_value_t value = property_p->u.named_data_property.value;
if ( value.value_type == ECMA_TYPE_OBJECT )
if (value.value_type == ECMA_TYPE_OBJECT)
{
ecma_object_t *value_obj_p = ECMA_GET_POINTER( value.value);
ecma_object_t *value_obj_p = ECMA_GET_POINTER(value.value);
if ( value_obj_p->gc_info.generation <= maximum_gen_to_traverse )
if (value_obj_p->gc_info.generation <= maximum_gen_to_traverse)
{
if ( !value_obj_p->gc_info.visited )
if (!value_obj_p->gc_info.visited)
{
ecma_gc_mark( value_obj_p, ECMA_GC_GEN_COUNT);
ecma_gc_mark (value_obj_p, ECMA_GC_GEN_COUNT);
}
does_reference_object_to_traverse = true;
@@ -211,29 +211,29 @@ ecma_gc_mark( ecma_object_t *object_p, /**< start object */
case ECMA_PROPERTY_NAMEDACCESSOR:
{
ecma_object_t *getter_obj_p = ECMA_GET_POINTER( property_p->u.named_accessor_property.get_p);
ecma_object_t *setter_obj_p = ECMA_GET_POINTER( property_p->u.named_accessor_property.set_p);
ecma_object_t *getter_obj_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.get_p);
ecma_object_t *setter_obj_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.set_p);
if ( getter_obj_p != NULL )
if (getter_obj_p != NULL)
{
if ( getter_obj_p->gc_info.generation <= maximum_gen_to_traverse )
if (getter_obj_p->gc_info.generation <= maximum_gen_to_traverse)
{
if ( !getter_obj_p->gc_info.visited )
if (!getter_obj_p->gc_info.visited)
{
ecma_gc_mark( getter_obj_p, ECMA_GC_GEN_COUNT);
ecma_gc_mark (getter_obj_p, ECMA_GC_GEN_COUNT);
}
does_reference_object_to_traverse = true;
}
}
if ( setter_obj_p != NULL )
if (setter_obj_p != NULL)
{
if ( setter_obj_p->gc_info.generation <= maximum_gen_to_traverse )
if (setter_obj_p->gc_info.generation <= maximum_gen_to_traverse)
{
if ( !setter_obj_p->gc_info.visited )
if (!setter_obj_p->gc_info.visited)
{
ecma_gc_mark( setter_obj_p, ECMA_GC_GEN_COUNT);
ecma_gc_mark (setter_obj_p, ECMA_GC_GEN_COUNT);
}
does_reference_object_to_traverse = true;
@@ -248,7 +248,7 @@ ecma_gc_mark( ecma_object_t *object_p, /**< start object */
ecma_internal_property_id_t property_id = property_p->u.internal_property.type;
uint32_t property_value = property_p->u.internal_property.value;
switch ( property_id )
switch (property_id)
{
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* an array */
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* an array */
@@ -265,13 +265,13 @@ ecma_gc_mark( ecma_object_t *object_p, /**< start object */
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
case ECMA_INTERNAL_PROPERTY_BINDING_OBJECT: /* an object */
{
ecma_object_t *obj_p = ECMA_GET_POINTER( property_value);
ecma_object_t *obj_p = ECMA_GET_POINTER(property_value);
if ( obj_p->gc_info.generation <= maximum_gen_to_traverse )
if (obj_p->gc_info.generation <= maximum_gen_to_traverse)
{
if ( !obj_p->gc_info.visited )
if (!obj_p->gc_info.visited)
{
ecma_gc_mark( obj_p, ECMA_GC_GEN_COUNT);
ecma_gc_mark (obj_p, ECMA_GC_GEN_COUNT);
}
does_reference_object_to_traverse = true;
@@ -286,7 +286,7 @@ ecma_gc_mark( ecma_object_t *object_p, /**< start object */
}
}
if ( !does_reference_object_to_traverse )
if (!does_reference_object_to_traverse)
{
object_p->gc_info.may_ref_younger_objects = false;
}
@@ -296,39 +296,39 @@ ecma_gc_mark( ecma_object_t *object_p, /**< start object */
* Free specified object
*/
void
ecma_gc_sweep( ecma_object_t *object_p) /**< object to free */
ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
{
JERRY_ASSERT( object_p != NULL
JERRY_ASSERT(object_p != NULL
&& !object_p->gc_info.visited
&& object_p->gc_info.refs == 0 );
&& object_p->gc_info.refs == 0);
for ( ecma_property_t *property = ECMA_GET_POINTER( object_p->properties_p),
for (ecma_property_t *property = ECMA_GET_POINTER(object_p->properties_p),
*next_property_p;
property != NULL;
property = next_property_p )
property = next_property_p)
{
next_property_p = ECMA_GET_POINTER( property->next_property_p);
next_property_p = ECMA_GET_POINTER(property->next_property_p);
ecma_free_property( property);
ecma_free_property (property);
}
ecma_dealloc_object( object_p);
ecma_dealloc_object (object_p);
} /* ecma_gc_sweep */
/**
* Run garbage collecting
*/
void
ecma_gc_run( ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run collection on */
ecma_gc_run (ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run collection on */
{
JERRY_ASSERT( max_gen_to_collect < ECMA_GC_GEN_COUNT );
JERRY_ASSERT(max_gen_to_collect < ECMA_GC_GEN_COUNT);
/* clearing visited flags for all objects of generations to be processed */
for ( ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++ )
for (ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++)
{
for ( ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
obj_iter_p != NULL;
obj_iter_p = ECMA_GET_POINTER( obj_iter_p->gc_info.next) )
obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next))
{
obj_iter_p->gc_info.visited = false;
}
@@ -336,16 +336,16 @@ ecma_gc_run( ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run co
/* if some object is referenced from stack or globals (i.e. it is root),
* start recursive marking traverse from the object */
for ( ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++ )
for (ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++)
{
for ( ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
obj_iter_p != NULL;
obj_iter_p = ECMA_GET_POINTER( obj_iter_p->gc_info.next) )
obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next))
{
if ( obj_iter_p->gc_info.refs > 0
&& !obj_iter_p->gc_info.visited )
if (obj_iter_p->gc_info.refs > 0
&& !obj_iter_p->gc_info.visited)
{
ecma_gc_mark( obj_iter_p, ECMA_GC_GEN_COUNT);
ecma_gc_mark (obj_iter_p, ECMA_GC_GEN_COUNT);
}
}
}
@@ -353,42 +353,42 @@ ecma_gc_run( ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run co
/* if some object from generations that are not processed during current session may reference
* younger generations, start recursive marking traverse from the object, but one the first level
* consider only references to object of at most max_gen_to_collect generation */
for ( ecma_gc_gen_t gen_id = max_gen_to_collect + 1; gen_id < ECMA_GC_GEN_COUNT; gen_id++ )
for (ecma_gc_gen_t gen_id = max_gen_to_collect + 1; gen_id < ECMA_GC_GEN_COUNT; gen_id++)
{
for ( ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
obj_iter_p != NULL;
obj_iter_p = ECMA_GET_POINTER( obj_iter_p->gc_info.next) )
obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next))
{
if ( obj_iter_p->gc_info.may_ref_younger_objects > 0 )
if (obj_iter_p->gc_info.may_ref_younger_objects > 0)
{
ecma_gc_mark( obj_iter_p, max_gen_to_collect);
ecma_gc_mark (obj_iter_p, max_gen_to_collect);
}
}
}
ecma_object_t *gen_last_obj_p[ max_gen_to_collect + 1 ];
#ifndef JERRY_NDEBUG
__memset( gen_last_obj_p, 0, sizeof(gen_last_obj_p) );
__memset (gen_last_obj_p, 0, sizeof (gen_last_obj_p));
#endif /* !JERRY_NDEBUG */
for ( ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++ )
for (ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++)
{
ecma_object_t *obj_prev_p = NULL;
for ( ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ],
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ],
*obj_next_p;
obj_iter_p != NULL;
obj_iter_p = obj_next_p )
obj_iter_p = obj_next_p)
{
obj_next_p = ECMA_GET_POINTER( obj_iter_p->gc_info.next);
obj_next_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next);
if ( !obj_iter_p->gc_info.visited )
if (!obj_iter_p->gc_info.visited)
{
ecma_gc_sweep( obj_iter_p);
ecma_gc_sweep (obj_iter_p);
if ( likely( obj_prev_p != NULL ) )
if (likely (obj_prev_p != NULL))
{
ECMA_SET_POINTER( obj_prev_p->gc_info.next, obj_next_p);
ECMA_SET_POINTER(obj_prev_p->gc_info.next, obj_next_p);
}
else
{
@@ -399,7 +399,7 @@ ecma_gc_run( ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run co
{
obj_prev_p = obj_iter_p;
if ( obj_iter_p->gc_info.generation != ECMA_GC_GEN_COUNT - 1 )
if (obj_iter_p->gc_info.generation != ECMA_GC_GEN_COUNT - 1)
{
/* the object will be promoted to next generation */
obj_iter_p->gc_info.generation++;
@@ -411,38 +411,38 @@ ecma_gc_run( ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run co
}
ecma_gc_gen_t gen_to_promote = max_gen_to_collect;
if ( unlikely( gen_to_promote == ECMA_GC_GEN_COUNT - 1 ) )
if (unlikely (gen_to_promote == ECMA_GC_GEN_COUNT - 1))
{
/* not promoting last generation */
gen_to_promote--;
}
/* promoting to next generation */
if ( gen_last_obj_p[ gen_to_promote ] != NULL )
if (gen_last_obj_p[ gen_to_promote ] != NULL)
{
ECMA_SET_POINTER( gen_last_obj_p[ gen_to_promote ]->gc_info.next, ecma_gc_objects_lists[ gen_to_promote + 1 ]);
ECMA_SET_POINTER(gen_last_obj_p[ gen_to_promote ]->gc_info.next, ecma_gc_objects_lists[ gen_to_promote + 1 ]);
ecma_gc_objects_lists[ gen_to_promote + 1 ] = ecma_gc_objects_lists[ gen_to_promote ];
ecma_gc_objects_lists[ gen_to_promote ] = NULL;
}
for ( int32_t gen_id = (int32_t)gen_to_promote - 1;
for (int32_t gen_id = (int32_t)gen_to_promote - 1;
gen_id >= 0;
gen_id-- )
gen_id--)
{
ecma_gc_objects_lists[ gen_id + 1 ] = ecma_gc_objects_lists[ gen_id ];
ecma_gc_objects_lists[ gen_id ] = NULL;
}
#ifndef JERRY_NDEBUG
for ( ecma_gc_gen_t gen_id = ECMA_GC_GEN_0;
for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0;
gen_id < ECMA_GC_GEN_COUNT;
gen_id++ )
gen_id++)
{
for ( ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
obj_iter_p != NULL;
obj_iter_p = ECMA_GET_POINTER( obj_iter_p->gc_info.next) )
obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next))
{
JERRY_ASSERT( obj_iter_p->gc_info.generation == gen_id );
JERRY_ASSERT(obj_iter_p->gc_info.generation == gen_id);
}
}
#endif /* !JERRY_NDEBUG */
+7 -7
View File
@@ -36,13 +36,13 @@ typedef enum
ECMA_GC_GEN_COUNT /**< generations' number */
} ecma_gc_gen_t;
extern void ecma_gc_init( void);
extern void ecma_init_gc_info(ecma_object_t *object_p);
extern void ecma_ref_object(ecma_object_t *object_p);
extern void ecma_deref_object(ecma_object_t *object_p);
extern void ecma_gc_update_may_ref_younger_object_flag_by_value( ecma_object_t *obj_p, ecma_value_t value);
extern void ecma_gc_update_may_ref_younger_object_flag_by_object( ecma_object_t *obj_p, ecma_object_t *ref_obj_p);
extern void ecma_gc_run( ecma_gc_gen_t max_gen_to_collect);
extern void ecma_gc_init (void);
extern void ecma_init_gc_info (ecma_object_t *object_p);
extern void ecma_ref_object (ecma_object_t *object_p);
extern void ecma_deref_object (ecma_object_t *object_p);
extern void ecma_gc_update_may_ref_younger_object_flag_by_value (ecma_object_t *obj_p, ecma_value_t value);
extern void ecma_gc_update_may_ref_younger_object_flag_by_object (ecma_object_t *obj_p, ecma_object_t *ref_obj_p);
extern void ecma_gc_run (ecma_gc_gen_t max_gen_to_collect);
#endif /* !ECMA_GC_H */
+6 -6
View File
@@ -21,7 +21,7 @@
*/
#ifndef JERRY_ECMA_GLOBALS_H
#define JERRY_ECMA_GLOBALS_H
#define JERRY_ECMA_GLOBALS_H
#include "globals.h"
#include "mem-allocator.h"
@@ -372,8 +372,8 @@ typedef struct ecma_object_t {
/** GC's information */
ecma_gc_info_t gc_info;
FIXME( Remove aligned attribute after packing the struct )
} __packed __attribute__((aligned(16))) ecma_object_t;
FIXME(Remove aligned attribute after packing the struct)
} __packed __attribute__ ((aligned (16))) ecma_object_t;
/**
* Description of ECMA property descriptor
@@ -467,7 +467,7 @@ typedef struct {
ecma_array_header_t header;
/** Elements */
uint8_t data[ sizeof(uint64_t) - sizeof (ecma_array_header_t) ];
uint8_t data[ sizeof (uint64_t) - sizeof (ecma_array_header_t) ];
} ecma_array_first_chunk_t;
/**
@@ -478,7 +478,7 @@ typedef struct {
uint16_t next_chunk_p;
/** Characters */
uint8_t data[ sizeof(uint64_t) - sizeof (uint16_t) ];
uint8_t data[ sizeof (uint64_t) - sizeof (uint16_t) ];
} ecma_array_non_first_chunk_t;
/**
@@ -505,7 +505,7 @@ typedef struct
* @}
*/
#endif /* JERRY_ECMA_GLOBALS_H */
#endif /* JERRY_ECMA_GLOBALS_H */
/**
* @}
+79 -79
View File
@@ -33,9 +33,9 @@
* false - otherwise.
*/
bool
ecma_is_value_empty( ecma_value_t value) /**< ecma-value */
ecma_is_value_empty (ecma_value_t value) /**< ecma-value */
{
return ( value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_EMPTY );
return (value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_EMPTY);
} /* ecma_is_value_empty */
/**
@@ -45,9 +45,9 @@ ecma_is_value_empty( ecma_value_t value) /**< ecma-value */
* false - otherwise.
*/
bool
ecma_is_value_undefined( ecma_value_t value) /**< ecma-value */
ecma_is_value_undefined (ecma_value_t value) /**< ecma-value */
{
return ( value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_UNDEFINED );
return (value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_UNDEFINED);
} /* ecma_is_value_undefined */
/**
@@ -57,9 +57,9 @@ ecma_is_value_undefined( ecma_value_t value) /**< ecma-value */
* false - otherwise.
*/
bool
ecma_is_value_null( ecma_value_t value) /**< ecma-value */
ecma_is_value_null (ecma_value_t value) /**< ecma-value */
{
return ( value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_NULL );
return (value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_NULL);
} /* ecma_is_value_null */
/**
@@ -69,10 +69,10 @@ ecma_is_value_null( ecma_value_t value) /**< ecma-value */
* false - otherwise.
*/
bool
ecma_is_value_boolean( ecma_value_t value) /**< ecma-value */
ecma_is_value_boolean (ecma_value_t value) /**< ecma-value */
{
return ( ( value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_FALSE )
|| ( value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_TRUE ) );
return ((value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_FALSE)
|| (value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_TRUE));
} /* ecma_is_value_boolean */
/**
@@ -85,18 +85,18 @@ ecma_is_value_boolean( ecma_value_t value) /**< ecma-value */
* false - otherwise.
*/
bool
ecma_is_value_true( ecma_value_t value) /**< ecma-value */
ecma_is_value_true (ecma_value_t value) /**< ecma-value */
{
JERRY_ASSERT( ecma_is_value_boolean( value) );
JERRY_ASSERT(ecma_is_value_boolean (value));
return ( value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_TRUE );
return (value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_TRUE);
} /* ecma_is_value_true */
/**
* Simple value constructor
*/
ecma_value_t
ecma_make_simple_value( ecma_simple_value_t value) /**< simple value */
ecma_make_simple_value (ecma_simple_value_t value) /**< simple value */
{
return (ecma_value_t) { .value_type = ECMA_TYPE_SIMPLE, .value = value };
} /* ecma_make_simple_value */
@@ -105,14 +105,14 @@ ecma_make_simple_value( ecma_simple_value_t value) /**< simple value */
* Number value constructor
*/
ecma_value_t
ecma_make_number_value( ecma_number_t* num_p) /**< number to reference in value */
ecma_make_number_value (ecma_number_t* num_p) /**< number to reference in value */
{
JERRY_ASSERT( num_p != NULL );
JERRY_ASSERT(num_p != NULL);
ecma_value_t number_value;
number_value.value_type = ECMA_TYPE_NUMBER;
ECMA_SET_POINTER( number_value.value, num_p);
ECMA_SET_POINTER(number_value.value, num_p);
return number_value;
} /* ecma_make_number_value */
@@ -121,14 +121,14 @@ ecma_make_number_value( ecma_number_t* num_p) /**< number to reference in value
* String value constructor
*/
ecma_value_t
ecma_make_string_value( ecma_array_first_chunk_t* ecma_string_p) /**< string to reference in value */
ecma_make_string_value (ecma_array_first_chunk_t* ecma_string_p) /**< string to reference in value */
{
JERRY_ASSERT( ecma_string_p != NULL );
JERRY_ASSERT(ecma_string_p != NULL);
ecma_value_t string_value;
string_value.value_type = ECMA_TYPE_STRING;
ECMA_SET_POINTER( string_value.value, ecma_string_p);
ECMA_SET_POINTER(string_value.value, ecma_string_p);
return string_value;
} /* ecma_make_string_value */
@@ -137,14 +137,14 @@ ecma_make_string_value( ecma_array_first_chunk_t* ecma_string_p) /**< string to
* object value constructor
*/
ecma_value_t
ecma_make_object_value( ecma_object_t* object_p) /**< object to reference in value */
ecma_make_object_value (ecma_object_t* object_p) /**< object to reference in value */
{
JERRY_ASSERT( object_p != NULL );
JERRY_ASSERT(object_p != NULL);
ecma_value_t object_value;
object_value.value_type = ECMA_TYPE_OBJECT;
ECMA_SET_POINTER( object_value.value, object_p);
ECMA_SET_POINTER(object_value.value, object_p);
return object_value;
} /* ecma_make_object_value */
@@ -171,13 +171,13 @@ ecma_make_object_value( ecma_object_t* object_p) /**< object to reference in val
* @return See note.
*/
ecma_value_t
ecma_copy_value( const ecma_value_t value, /**< ecma-value */
ecma_copy_value (const ecma_value_t value, /**< ecma-value */
bool do_ref_if_object) /**< if the value is object value,
increment reference counter of object */
{
ecma_value_t value_copy;
switch ( (ecma_type_t)value.value_type )
switch ((ecma_type_t)value.value_type)
{
case ECMA_TYPE_SIMPLE:
{
@@ -187,37 +187,37 @@ ecma_copy_value( const ecma_value_t value, /**< ecma-value */
}
case ECMA_TYPE_NUMBER:
{
ecma_number_t *num_p = ECMA_GET_POINTER( value.value);
JERRY_ASSERT( num_p != NULL );
ecma_number_t *num_p = ECMA_GET_POINTER(value.value);
JERRY_ASSERT(num_p != NULL);
ecma_number_t *number_copy_p = ecma_alloc_number();
ecma_number_t *number_copy_p = ecma_alloc_number ();
*number_copy_p = *num_p;
value_copy = (ecma_value_t) { .value_type = ECMA_TYPE_NUMBER };
ECMA_SET_NON_NULL_POINTER( value_copy.value, number_copy_p);
ECMA_SET_NON_NULL_POINTER(value_copy.value, number_copy_p);
break;
}
case ECMA_TYPE_STRING:
{
ecma_array_first_chunk_t *string_p = ECMA_GET_POINTER( value.value);
JERRY_ASSERT( string_p != NULL );
ecma_array_first_chunk_t *string_p = ECMA_GET_POINTER(value.value);
JERRY_ASSERT(string_p != NULL);
ecma_array_first_chunk_t *string_copy_p = ecma_duplicate_ecma_string( string_p);
ecma_array_first_chunk_t *string_copy_p = ecma_duplicate_ecma_string (string_p);
value_copy = (ecma_value_t) { .value_type = ECMA_TYPE_STRING };
ECMA_SET_POINTER( value_copy.value, string_copy_p);
ECMA_SET_POINTER(value_copy.value, string_copy_p);
break;
}
case ECMA_TYPE_OBJECT:
{
ecma_object_t *obj_p = ECMA_GET_POINTER( value.value);
JERRY_ASSERT( obj_p != NULL );
ecma_object_t *obj_p = ECMA_GET_POINTER(value.value);
JERRY_ASSERT(obj_p != NULL);
if ( do_ref_if_object )
if (do_ref_if_object)
{
ecma_ref_object( obj_p);
ecma_ref_object (obj_p);
}
value_copy = value;
@@ -237,11 +237,11 @@ ecma_copy_value( const ecma_value_t value, /**< ecma-value */
* Free the ecma-value
*/
void
ecma_free_value( ecma_value_t value, /**< value description */
ecma_free_value (ecma_value_t value, /**< value description */
bool do_deref_if_object) /**< if the value is object value,
decrement reference counter of object */
{
switch ( (ecma_type_t) value.value_type )
switch ((ecma_type_t) value.value_type)
{
case ECMA_TYPE_SIMPLE:
{
@@ -251,23 +251,23 @@ ecma_free_value( ecma_value_t value, /**< value description */
case ECMA_TYPE_NUMBER:
{
ecma_number_t *number_p = ECMA_GET_POINTER( value.value);
ecma_dealloc_number( number_p);
ecma_number_t *number_p = ECMA_GET_POINTER(value.value);
ecma_dealloc_number (number_p);
break;
}
case ECMA_TYPE_STRING:
{
ecma_array_first_chunk_t *string_p = ECMA_GET_POINTER( value.value);
ecma_free_array( string_p);
ecma_array_first_chunk_t *string_p = ECMA_GET_POINTER(value.value);
ecma_free_array (string_p);
break;
}
case ECMA_TYPE_OBJECT:
{
if ( do_deref_if_object )
if (do_deref_if_object)
{
ecma_deref_object( ECMA_GET_POINTER( value.value));
ecma_deref_object (ECMA_GET_POINTER(value.value));
}
break;
}
@@ -285,7 +285,7 @@ ecma_free_value( ecma_value_t value, /**< value description */
* @return completion value
*/
ecma_completion_value_t
ecma_make_completion_value(ecma_completion_type_t type, /**< type */
ecma_make_completion_value (ecma_completion_type_t type, /**< type */
ecma_value_t value, /**< value */
uint8_t target) /**< target */
{
@@ -298,15 +298,15 @@ ecma_make_completion_value(ecma_completion_type_t type, /**< type */
* @return completion value
*/
ecma_completion_value_t
ecma_make_simple_completion_value( ecma_simple_value_t simple_value) /**< simple ecma-value */
ecma_make_simple_completion_value (ecma_simple_value_t simple_value) /**< simple ecma-value */
{
JERRY_ASSERT( simple_value == ECMA_SIMPLE_VALUE_UNDEFINED
JERRY_ASSERT(simple_value == ECMA_SIMPLE_VALUE_UNDEFINED
|| simple_value == ECMA_SIMPLE_VALUE_NULL
|| simple_value == ECMA_SIMPLE_VALUE_FALSE
|| simple_value == ECMA_SIMPLE_VALUE_TRUE );
|| simple_value == ECMA_SIMPLE_VALUE_TRUE);
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( simple_value),
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value (simple_value),
ECMA_TARGET_ID_RESERVED);
} /* ecma_make_simple_completion_value */
@@ -316,13 +316,13 @@ ecma_make_simple_completion_value( ecma_simple_value_t simple_value) /**< simple
* @return 'throw' completion value
*/
ecma_completion_value_t
ecma_make_throw_value( ecma_object_t *exception_p) /**< an object */
ecma_make_throw_value (ecma_object_t *exception_p) /**< an object */
{
JERRY_ASSERT( exception_p != NULL && !exception_p->is_lexical_environment );
JERRY_ASSERT(exception_p != NULL && !exception_p->is_lexical_environment);
ecma_value_t exception = ecma_make_object_value( exception_p);
ecma_value_t exception = ecma_make_object_value (exception_p);
return ecma_make_completion_value(ECMA_COMPLETION_TYPE_THROW,
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_THROW,
exception,
ECMA_TARGET_ID_RESERVED);
} /* ecma_make_throw_value */
@@ -333,23 +333,23 @@ ecma_make_throw_value( ecma_object_t *exception_p) /**< an object */
* @return (normal, empty, reserved) completion value.
*/
ecma_completion_value_t
ecma_make_empty_completion_value( void)
ecma_make_empty_completion_value (void)
{
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( ECMA_SIMPLE_VALUE_EMPTY),
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY),
ECMA_TARGET_ID_RESERVED);
} /* ecma_make_empty_completion_value */
/**
* Copy ecma-completion value.
*
* @return (source.type, ecma_copy_value( source.value), source.target).
* @return (source.type, ecma_copy_value (source.value), source.target).
*/
ecma_completion_value_t
ecma_copy_completion_value( ecma_completion_value_t value) /**< completion value */
ecma_copy_completion_value (ecma_completion_value_t value) /**< completion value */
{
return ecma_make_completion_value( value.type,
ecma_copy_value( value.value, true),
return ecma_make_completion_value (value.type,
ecma_copy_value (value.value, true),
value.target);
} /* ecma_copy_completion_value */
@@ -357,19 +357,19 @@ ecma_copy_completion_value( ecma_completion_value_t value) /**< completion value
* Free the completion value.
*/
void
ecma_free_completion_value( ecma_completion_value_t completion_value) /**< completion value */
ecma_free_completion_value (ecma_completion_value_t completion_value) /**< completion value */
{
switch ( completion_value.type )
switch (completion_value.type)
{
case ECMA_COMPLETION_TYPE_NORMAL:
case ECMA_COMPLETION_TYPE_THROW:
case ECMA_COMPLETION_TYPE_RETURN:
ecma_free_value( completion_value.value, true);
ecma_free_value (completion_value.value, true);
break;
case ECMA_COMPLETION_TYPE_CONTINUE:
case ECMA_COMPLETION_TYPE_BREAK:
case ECMA_COMPLETION_TYPE_EXIT:
JERRY_ASSERT( completion_value.value.value_type == ECMA_TYPE_SIMPLE );
JERRY_ASSERT(completion_value.value.value_type == ECMA_TYPE_SIMPLE);
break;
}
} /* ecma_free_completion_value */
@@ -381,9 +381,9 @@ ecma_free_completion_value( ecma_completion_value_t completion_value) /**< compl
* false - otherwise.
*/
bool
ecma_is_completion_value_normal( ecma_completion_value_t value) /**< completion value */
ecma_is_completion_value_normal (ecma_completion_value_t value) /**< completion value */
{
return ( value.type == ECMA_COMPLETION_TYPE_NORMAL );
return (value.type == ECMA_COMPLETION_TYPE_NORMAL);
} /* ecma_is_completion_value_normal */
/**
@@ -393,9 +393,9 @@ ecma_is_completion_value_normal( ecma_completion_value_t value) /**< completion
* false - otherwise.
*/
bool
ecma_is_completion_value_throw( ecma_completion_value_t value) /**< completion value */
ecma_is_completion_value_throw (ecma_completion_value_t value) /**< completion value */
{
return ( value.type == ECMA_COMPLETION_TYPE_THROW );
return (value.type == ECMA_COMPLETION_TYPE_THROW);
} /* ecma_is_completion_value_throw */
/**
@@ -406,12 +406,12 @@ ecma_is_completion_value_throw( ecma_completion_value_t value) /**< completion v
* false - otherwise.
*/
bool
ecma_is_completion_value_normal_simple_value(ecma_completion_value_t value, /**< completion value */
ecma_is_completion_value_normal_simple_value (ecma_completion_value_t value, /**< completion value */
ecma_simple_value_t simple_value) /**< simple value to check for equality with */
{
return ( value.type == ECMA_COMPLETION_TYPE_NORMAL
return (value.type == ECMA_COMPLETION_TYPE_NORMAL
&& value.value.value_type == ECMA_TYPE_SIMPLE
&& value.value.value == simple_value );
&& value.value.value == simple_value);
} /* ecma_is_completion_value_normal_simple_value */
/**
@@ -422,9 +422,9 @@ ecma_is_completion_value_normal_simple_value(ecma_completion_value_t value, /**<
* false - otherwise.
*/
bool
ecma_is_completion_value_normal_true( ecma_completion_value_t value) /**< completion value */
ecma_is_completion_value_normal_true (ecma_completion_value_t value) /**< completion value */
{
return ecma_is_completion_value_normal_simple_value( value, ECMA_SIMPLE_VALUE_TRUE);
return ecma_is_completion_value_normal_simple_value (value, ECMA_SIMPLE_VALUE_TRUE);
} /* ecma_is_completion_value_normal_true */
/**
@@ -435,9 +435,9 @@ ecma_is_completion_value_normal_true( ecma_completion_value_t value) /**< comple
* false - otherwise.
*/
bool
ecma_is_completion_value_normal_false( ecma_completion_value_t value) /**< completion value */
ecma_is_completion_value_normal_false (ecma_completion_value_t value) /**< completion value */
{
return ecma_is_completion_value_normal_simple_value( value, ECMA_SIMPLE_VALUE_FALSE);
return ecma_is_completion_value_normal_simple_value (value, ECMA_SIMPLE_VALUE_FALSE);
} /* ecma_is_completion_value_normal_false */
/**
@@ -448,10 +448,10 @@ ecma_is_completion_value_normal_false( ecma_completion_value_t value) /**< compl
* false - otherwise.
*/
bool
ecma_is_empty_completion_value( ecma_completion_value_t value) /**< completion value */
ecma_is_empty_completion_value (ecma_completion_value_t value) /**< completion value */
{
return ( ecma_is_completion_value_normal( value)
&& ecma_is_value_empty( value.value) );
return (ecma_is_completion_value_normal (value)
&& ecma_is_value_empty (value.value));
} /* ecma_is_empty_completion_value */
/**
+157 -157
View File
@@ -36,18 +36,18 @@
* @return pointer to the object's descriptor
*/
ecma_object_t*
ecma_create_object( ecma_object_t *prototype_object_p, /**< pointer to prototybe of the object (or NULL) */
ecma_create_object (ecma_object_t *prototype_object_p, /**< pointer to prototybe of the object (or NULL) */
bool is_extensible, /**< value of extensible attribute */
ecma_object_type_t type) /**< object type */
{
ecma_object_t *object_p = ecma_alloc_object();
ecma_init_gc_info( object_p);
ecma_object_t *object_p = ecma_alloc_object ();
ecma_init_gc_info (object_p);
object_p->properties_p = ECMA_NULL_POINTER;
object_p->is_lexical_environment = false;
object_p->u.object.extensible = is_extensible;
ECMA_SET_POINTER( object_p->u.object.prototype_object_p, prototype_object_p);
ECMA_SET_POINTER(object_p->u.object.prototype_object_p, prototype_object_p);
object_p->u.object.type = type;
return object_p;
@@ -64,17 +64,17 @@ ecma_create_object( ecma_object_t *prototype_object_p, /**< pointer to prototybe
* @return pointer to the descriptor of lexical environment
*/
ecma_object_t*
ecma_create_decl_lex_env(ecma_object_t *outer_lexical_environment_p) /**< outer lexical environment */
ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p) /**< outer lexical environment */
{
ecma_object_t *new_lexical_environment_p = ecma_alloc_object();
ecma_init_gc_info( new_lexical_environment_p);
ecma_object_t *new_lexical_environment_p = ecma_alloc_object ();
ecma_init_gc_info (new_lexical_environment_p);
new_lexical_environment_p->is_lexical_environment = true;
new_lexical_environment_p->u.lexical_environment.type = ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE;
new_lexical_environment_p->properties_p = ECMA_NULL_POINTER;
ECMA_SET_POINTER( new_lexical_environment_p->u.lexical_environment.outer_reference_p, outer_lexical_environment_p);
ECMA_SET_POINTER(new_lexical_environment_p->u.lexical_environment.outer_reference_p, outer_lexical_environment_p);
return new_lexical_environment_p;
} /* ecma_create_decl_lex_env */
@@ -90,29 +90,29 @@ ecma_create_decl_lex_env(ecma_object_t *outer_lexical_environment_p) /**< outer
* @return pointer to the descriptor of lexical environment
*/
ecma_object_t*
ecma_create_object_lex_env(ecma_object_t *outer_lexical_environment_p, /**< outer lexical environment */
ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, /**< outer lexical environment */
ecma_object_t *binding_obj_p, /**< binding object */
bool provide_this) /**< provideThis flag */
{
JERRY_ASSERT( binding_obj_p != NULL );
JERRY_ASSERT(binding_obj_p != NULL);
ecma_object_t *new_lexical_environment_p = ecma_alloc_object();
ecma_init_gc_info( new_lexical_environment_p);
ecma_object_t *new_lexical_environment_p = ecma_alloc_object ();
ecma_init_gc_info (new_lexical_environment_p);
new_lexical_environment_p->is_lexical_environment = true;
new_lexical_environment_p->u.lexical_environment.type = ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND;
new_lexical_environment_p->properties_p = ECMA_NULL_POINTER;
ECMA_SET_POINTER( new_lexical_environment_p->u.lexical_environment.outer_reference_p, outer_lexical_environment_p);
ECMA_SET_POINTER(new_lexical_environment_p->u.lexical_environment.outer_reference_p, outer_lexical_environment_p);
ecma_property_t *provide_this_prop_p = ecma_create_internal_property( new_lexical_environment_p, ECMA_INTERNAL_PROPERTY_PROVIDE_THIS);
ecma_property_t *provide_this_prop_p = ecma_create_internal_property (new_lexical_environment_p, ECMA_INTERNAL_PROPERTY_PROVIDE_THIS);
provide_this_prop_p->u.internal_property.value = provide_this;
ecma_property_t *binding_object_prop_p = ecma_create_internal_property( new_lexical_environment_p, ECMA_INTERNAL_PROPERTY_BINDING_OBJECT);
ECMA_SET_POINTER( binding_object_prop_p->u.internal_property.value, binding_obj_p);
ecma_property_t *binding_object_prop_p = ecma_create_internal_property (new_lexical_environment_p, ECMA_INTERNAL_PROPERTY_BINDING_OBJECT);
ECMA_SET_POINTER(binding_object_prop_p->u.internal_property.value, binding_obj_p);
ecma_gc_update_may_ref_younger_object_flag_by_object( new_lexical_environment_p, binding_obj_p);
ecma_gc_update_may_ref_younger_object_flag_by_object (new_lexical_environment_p, binding_obj_p);
return new_lexical_environment_p;
} /* ecma_create_object_lex_env */
@@ -124,16 +124,16 @@ ecma_create_object_lex_env(ecma_object_t *outer_lexical_environment_p, /**< oute
* @return pointer to newly created property
*/
ecma_property_t*
ecma_create_internal_property(ecma_object_t *object_p, /**< the object */
ecma_create_internal_property (ecma_object_t *object_p, /**< the object */
ecma_internal_property_id_t property_id) /**< internal property identifier */
{
ecma_property_t *new_property_p = ecma_alloc_property();
ecma_property_t *new_property_p = ecma_alloc_property ();
new_property_p->type = ECMA_PROPERTY_INTERNAL;
ecma_property_t *list_head_p = ECMA_GET_POINTER( object_p->properties_p);
ECMA_SET_POINTER( new_property_p->next_property_p, list_head_p);
ECMA_SET_NON_NULL_POINTER( object_p->properties_p, new_property_p);
ecma_property_t *list_head_p = ECMA_GET_POINTER(object_p->properties_p);
ECMA_SET_POINTER(new_property_p->next_property_p, list_head_p);
ECMA_SET_NON_NULL_POINTER(object_p->properties_p, new_property_p);
new_property_p->u.internal_property.type = property_id;
new_property_p->u.internal_property.value = ECMA_NULL_POINTER;
@@ -148,21 +148,21 @@ ecma_create_internal_property(ecma_object_t *object_p, /**< the object */
* NULL - otherwise.
*/
ecma_property_t*
ecma_find_internal_property(ecma_object_t *object_p, /**< object descriptor */
ecma_find_internal_property (ecma_object_t *object_p, /**< object descriptor */
ecma_internal_property_id_t property_id) /**< internal property identifier */
{
JERRY_ASSERT( object_p != NULL );
JERRY_ASSERT(object_p != NULL);
JERRY_ASSERT( property_id != ECMA_INTERNAL_PROPERTY_PROTOTYPE
&& property_id != ECMA_INTERNAL_PROPERTY_EXTENSIBLE );
JERRY_ASSERT(property_id != ECMA_INTERNAL_PROPERTY_PROTOTYPE
&& property_id != ECMA_INTERNAL_PROPERTY_EXTENSIBLE);
for ( ecma_property_t *property_p = ECMA_GET_POINTER( object_p->properties_p);
for (ecma_property_t *property_p = ECMA_GET_POINTER(object_p->properties_p);
property_p != NULL;
property_p = ECMA_GET_POINTER( property_p->next_property_p) )
property_p = ECMA_GET_POINTER(property_p->next_property_p))
{
if ( property_p->type == ECMA_PROPERTY_INTERNAL )
if (property_p->type == ECMA_PROPERTY_INTERNAL)
{
if ( property_p->u.internal_property.type == property_id )
if (property_p->u.internal_property.type == property_id)
{
return property_p;
}
@@ -181,12 +181,12 @@ ecma_find_internal_property(ecma_object_t *object_p, /**< object descriptor */
* @return pointer to the property
*/
ecma_property_t*
ecma_get_internal_property(ecma_object_t *object_p, /**< object descriptor */
ecma_get_internal_property (ecma_object_t *object_p, /**< object descriptor */
ecma_internal_property_id_t property_id) /**< internal property identifier */
{
ecma_property_t *property_p = ecma_find_internal_property( object_p, property_id);
ecma_property_t *property_p = ecma_find_internal_property (object_p, property_id);
JERRY_ASSERT( property_p != NULL );
JERRY_ASSERT(property_p != NULL);
return property_p;
} /* ecma_get_internal_property */
@@ -198,30 +198,30 @@ ecma_get_internal_property(ecma_object_t *object_p, /**< object descriptor */
* @return pointer to newly created property
*/
ecma_property_t*
ecma_create_named_data_property(ecma_object_t *obj_p, /**< object */
ecma_create_named_data_property (ecma_object_t *obj_p, /**< object */
const ecma_char_t *name_p, /**< property name */
ecma_property_writable_value_t writable, /**< 'writable' attribute */
ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */
ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */
{
JERRY_ASSERT( obj_p != NULL && name_p != NULL );
JERRY_ASSERT(obj_p != NULL && name_p != NULL);
ecma_property_t *prop_p = ecma_alloc_property();
ecma_property_t *prop_p = ecma_alloc_property ();
prop_p->type = ECMA_PROPERTY_NAMEDDATA;
ECMA_SET_NON_NULL_POINTER( prop_p->u.named_data_property.name_p, ecma_new_ecma_string( name_p));
ECMA_SET_NON_NULL_POINTER(prop_p->u.named_data_property.name_p, ecma_new_ecma_string (name_p));
prop_p->u.named_data_property.writable = writable;
prop_p->u.named_data_property.enumerable = enumerable;
prop_p->u.named_data_property.configurable = configurable;
prop_p->u.named_data_property.value = ecma_make_simple_value( ECMA_SIMPLE_VALUE_UNDEFINED);
prop_p->u.named_data_property.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
ecma_property_t *list_head_p = ECMA_GET_POINTER( obj_p->properties_p);
ecma_property_t *list_head_p = ECMA_GET_POINTER(obj_p->properties_p);
ECMA_SET_POINTER( prop_p->next_property_p, list_head_p);
ECMA_SET_NON_NULL_POINTER( obj_p->properties_p, prop_p);
ECMA_SET_POINTER(prop_p->next_property_p, list_head_p);
ECMA_SET_NON_NULL_POINTER(obj_p->properties_p, prop_p);
return prop_p;
} /* ecma_create_named_data_property */
@@ -232,33 +232,33 @@ ecma_create_named_data_property(ecma_object_t *obj_p, /**< object */
* @return pointer to newly created property
*/
ecma_property_t*
ecma_create_named_accessor_property(ecma_object_t *obj_p, /**< object */
ecma_create_named_accessor_property (ecma_object_t *obj_p, /**< object */
const ecma_char_t *name_p, /**< property name */
ecma_object_t *get_p, /**< getter */
ecma_object_t *set_p, /**< setter */
ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */
ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */
{
JERRY_ASSERT( obj_p != NULL && name_p != NULL );
JERRY_ASSERT(obj_p != NULL && name_p != NULL);
ecma_property_t *prop_p = ecma_alloc_property();
ecma_property_t *prop_p = ecma_alloc_property ();
prop_p->type = ECMA_PROPERTY_NAMEDACCESSOR;
ECMA_SET_NON_NULL_POINTER( prop_p->u.named_accessor_property.name_p, ecma_new_ecma_string( name_p));
ECMA_SET_NON_NULL_POINTER(prop_p->u.named_accessor_property.name_p, ecma_new_ecma_string (name_p));
ECMA_SET_POINTER( prop_p->u.named_accessor_property.get_p, get_p);
ecma_gc_update_may_ref_younger_object_flag_by_object( obj_p, get_p);
ECMA_SET_POINTER(prop_p->u.named_accessor_property.get_p, get_p);
ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, get_p);
ECMA_SET_POINTER( prop_p->u.named_accessor_property.set_p, set_p);
ecma_gc_update_may_ref_younger_object_flag_by_object( obj_p, set_p);
ECMA_SET_POINTER(prop_p->u.named_accessor_property.set_p, set_p);
ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, set_p);
prop_p->u.named_accessor_property.enumerable = enumerable;
prop_p->u.named_accessor_property.configurable = configurable;
ecma_property_t *list_head_p = ECMA_GET_POINTER( obj_p->properties_p);
ECMA_SET_POINTER( prop_p->next_property_p, list_head_p);
ECMA_SET_NON_NULL_POINTER( obj_p->properties_p, prop_p);
ecma_property_t *list_head_p = ECMA_GET_POINTER(obj_p->properties_p);
ECMA_SET_POINTER(prop_p->next_property_p, list_head_p);
ECMA_SET_NON_NULL_POINTER(obj_p->properties_p, prop_p);
return prop_p;
} /* ecma_create_named_accessor_property */
@@ -270,32 +270,32 @@ ecma_create_named_accessor_property(ecma_object_t *obj_p, /**< object */
* NULL - otherwise.
*/
ecma_property_t*
ecma_find_named_property(ecma_object_t *obj_p, /**< object to find property in */
ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in */
const ecma_char_t *name_p) /**< property's name */
{
JERRY_ASSERT( obj_p != NULL );
JERRY_ASSERT( name_p != NULL );
JERRY_ASSERT(obj_p != NULL);
JERRY_ASSERT(name_p != NULL);
for ( ecma_property_t *property_p = ECMA_GET_POINTER( obj_p->properties_p);
for (ecma_property_t *property_p = ECMA_GET_POINTER(obj_p->properties_p);
property_p != NULL;
property_p = ECMA_GET_POINTER( property_p->next_property_p) )
property_p = ECMA_GET_POINTER(property_p->next_property_p))
{
ecma_array_first_chunk_t *property_name_p;
if ( property_p->type == ECMA_PROPERTY_NAMEDDATA )
if (property_p->type == ECMA_PROPERTY_NAMEDDATA)
{
property_name_p = ECMA_GET_POINTER( property_p->u.named_data_property.name_p);
} else if ( property_p->type == ECMA_PROPERTY_NAMEDACCESSOR )
property_name_p = ECMA_GET_POINTER(property_p->u.named_data_property.name_p);
} else if (property_p->type == ECMA_PROPERTY_NAMEDACCESSOR)
{
property_name_p = ECMA_GET_POINTER( property_p->u.named_accessor_property.name_p);
property_name_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.name_p);
} else
{
continue;
}
JERRY_ASSERT( property_name_p != NULL );
JERRY_ASSERT(property_name_p != NULL);
if ( ecma_compare_zt_string_to_ecma_string( name_p, property_name_p) )
if (ecma_compare_zt_string_to_ecma_string (name_p, property_name_p))
{
return property_p;
}
@@ -314,15 +314,15 @@ ecma_find_named_property(ecma_object_t *obj_p, /**< object to find property in *
* NULL - otherwise.
*/
ecma_property_t*
ecma_get_named_property(ecma_object_t *obj_p, /**< object to find property in */
ecma_get_named_property (ecma_object_t *obj_p, /**< object to find property in */
const ecma_char_t *name_p) /**< property's name */
{
JERRY_ASSERT( obj_p != NULL );
JERRY_ASSERT( name_p != NULL );
JERRY_ASSERT(obj_p != NULL);
JERRY_ASSERT(name_p != NULL);
ecma_property_t *property_p = ecma_find_named_property( obj_p, name_p);
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
JERRY_ASSERT( property_p != NULL );
JERRY_ASSERT(property_p != NULL);
return property_p;
} /* ecma_get_named_property */
@@ -337,15 +337,15 @@ ecma_get_named_property(ecma_object_t *obj_p, /**< object to find property in */
* NULL - otherwise.
*/
ecma_property_t*
ecma_get_named_data_property(ecma_object_t *obj_p, /**< object to find property in */
ecma_get_named_data_property (ecma_object_t *obj_p, /**< object to find property in */
const ecma_char_t *name_p) /**< property's name */
{
JERRY_ASSERT( obj_p != NULL );
JERRY_ASSERT( name_p != NULL );
JERRY_ASSERT(obj_p != NULL);
JERRY_ASSERT(name_p != NULL);
ecma_property_t *property_p = ecma_find_named_property( obj_p, name_p);
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
JERRY_ASSERT( property_p != NULL && property_p->type == ECMA_PROPERTY_NAMEDDATA );
JERRY_ASSERT(property_p != NULL && property_p->type == ECMA_PROPERTY_NAMEDDATA);
return property_p;
} /* ecma_get_named_data_property */
@@ -354,47 +354,47 @@ ecma_get_named_data_property(ecma_object_t *obj_p, /**< object to find property
* Free the named data property and values it references.
*/
void
ecma_free_named_data_property( ecma_property_t *property_p) /**< the property */
ecma_free_named_data_property (ecma_property_t *property_p) /**< the property */
{
JERRY_ASSERT( property_p->type == ECMA_PROPERTY_NAMEDDATA );
JERRY_ASSERT(property_p->type == ECMA_PROPERTY_NAMEDDATA);
ecma_free_array( ECMA_GET_POINTER( property_p->u.named_data_property.name_p));
ecma_free_value( property_p->u.named_data_property.value, false);
ecma_free_array (ECMA_GET_POINTER(property_p->u.named_data_property.name_p));
ecma_free_value (property_p->u.named_data_property.value, false);
ecma_dealloc_property( property_p);
ecma_dealloc_property (property_p);
} /* ecma_free_named_data_property */
/**
* Free the named accessor property and values it references.
*/
void
ecma_free_named_accessor_property( ecma_property_t *property_p) /**< the property */
ecma_free_named_accessor_property (ecma_property_t *property_p) /**< the property */
{
JERRY_ASSERT( property_p->type == ECMA_PROPERTY_NAMEDACCESSOR );
JERRY_ASSERT(property_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
ecma_free_array( ECMA_GET_POINTER( property_p->u.named_accessor_property.name_p));
ecma_free_array (ECMA_GET_POINTER(property_p->u.named_accessor_property.name_p));
ecma_dealloc_property( property_p);
ecma_dealloc_property (property_p);
} /* ecma_free_named_accessor_property */
/**
* Free the internal property and values it references.
*/
void
ecma_free_internal_property( ecma_property_t *property_p) /**< the property */
ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
{
JERRY_ASSERT( property_p->type == ECMA_PROPERTY_INTERNAL );
JERRY_ASSERT(property_p->type == ECMA_PROPERTY_INTERNAL);
ecma_internal_property_id_t property_id = property_p->u.internal_property.type;
uint32_t property_value = property_p->u.internal_property.value;
switch ( property_id )
switch (property_id)
{
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* an array */
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* an array */
case ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS: /* an array */
{
ecma_free_array( ECMA_GET_POINTER( property_value));
ecma_free_array (ECMA_GET_POINTER(property_value));
break;
}
@@ -410,34 +410,34 @@ ecma_free_internal_property( ecma_property_t *property_p) /**< the property */
}
}
ecma_dealloc_property( property_p);
ecma_dealloc_property (property_p);
} /* ecma_free_internal_property */
/**
* Free the property and values it references.
*/
void
ecma_free_property(ecma_property_t *prop_p) /**< property */
ecma_free_property (ecma_property_t *prop_p) /**< property */
{
switch ( (ecma_property_type_t) prop_p->type )
switch ((ecma_property_type_t) prop_p->type)
{
case ECMA_PROPERTY_NAMEDDATA:
{
ecma_free_named_data_property( prop_p);
ecma_free_named_data_property (prop_p);
break;
}
case ECMA_PROPERTY_NAMEDACCESSOR:
{
ecma_free_named_accessor_property( prop_p);
ecma_free_named_accessor_property (prop_p);
break;
}
case ECMA_PROPERTY_INTERNAL:
{
ecma_free_internal_property( prop_p);
ecma_free_internal_property (prop_p);
break;
}
@@ -450,25 +450,25 @@ ecma_free_property(ecma_property_t *prop_p) /**< property */
* Warning: specified property must be owned by specified object.
*/
void
ecma_delete_property(ecma_object_t *obj_p, /**< object */
ecma_delete_property (ecma_object_t *obj_p, /**< object */
ecma_property_t *prop_p) /**< property */
{
for ( ecma_property_t *cur_prop_p = ECMA_GET_POINTER( obj_p->properties_p), *prev_prop_p = NULL, *next_prop_p;
for (ecma_property_t *cur_prop_p = ECMA_GET_POINTER(obj_p->properties_p), *prev_prop_p = NULL, *next_prop_p;
cur_prop_p != NULL;
prev_prop_p = cur_prop_p, cur_prop_p = next_prop_p )
prev_prop_p = cur_prop_p, cur_prop_p = next_prop_p)
{
next_prop_p = ECMA_GET_POINTER( cur_prop_p->next_property_p);
next_prop_p = ECMA_GET_POINTER(cur_prop_p->next_property_p);
if ( cur_prop_p == prop_p )
if (cur_prop_p == prop_p)
{
ecma_free_property( prop_p);
ecma_free_property (prop_p);
if ( prev_prop_p == NULL )
if (prev_prop_p == NULL)
{
ECMA_SET_POINTER( obj_p->properties_p, next_prop_p);
ECMA_SET_POINTER(obj_p->properties_p, next_prop_p);
} else
{
ECMA_SET_POINTER( prev_prop_p->next_property_p, next_prop_p);
ECMA_SET_POINTER(prev_prop_p->next_property_p, next_prop_p);
}
return;
@@ -484,47 +484,47 @@ ecma_delete_property(ecma_object_t *obj_p, /**< object */
* @return Pointer to first chunk of an array, containing allocated string
*/
ecma_array_first_chunk_t*
ecma_new_ecma_string(const ecma_char_t *string_p) /**< zero-terminated string of ecma-characters */
ecma_new_ecma_string (const ecma_char_t *string_p) /**< zero-terminated string of ecma-characters */
{
ecma_length_t length = 0;
/*
* TODO: Do not precalculate length.
*/
if ( string_p != NULL )
if (string_p != NULL)
{
const ecma_char_t *iter_p = string_p;
while ( *iter_p++ )
while (*iter_p++)
{
length++;
}
}
ecma_array_first_chunk_t *string_first_chunk_p = ecma_alloc_array_first_chunk();
ecma_array_first_chunk_t *string_first_chunk_p = ecma_alloc_array_first_chunk ();
string_first_chunk_p->header.unit_number = length;
uint8_t *copy_pointer = (uint8_t*) string_p;
size_t chars_left = length;
size_t chars_to_copy = JERRY_MIN( length, sizeof (string_first_chunk_p->data) / sizeof (ecma_char_t));
__memcpy(string_first_chunk_p->data, copy_pointer, chars_to_copy * sizeof (ecma_char_t));
size_t chars_to_copy = JERRY_MIN(length, sizeof (string_first_chunk_p->data) / sizeof (ecma_char_t));
__memcpy (string_first_chunk_p->data, copy_pointer, chars_to_copy * sizeof (ecma_char_t));
chars_left -= chars_to_copy;
copy_pointer += chars_to_copy * sizeof (ecma_char_t);
ecma_array_non_first_chunk_t *string_non_first_chunk_p;
JERRY_STATIC_ASSERT( ECMA_POINTER_FIELD_WIDTH <= sizeof(uint16_t) * JERRY_BITSINBYTE );
JERRY_STATIC_ASSERT(ECMA_POINTER_FIELD_WIDTH <= sizeof (uint16_t) * JERRY_BITSINBYTE);
uint16_t *next_chunk_compressed_pointer_p = &string_first_chunk_p->header.next_chunk_p;
while ( chars_left > 0 )
while (chars_left > 0)
{
string_non_first_chunk_p = ecma_alloc_array_non_first_chunk();
string_non_first_chunk_p = ecma_alloc_array_non_first_chunk ();
size_t chars_to_copy = JERRY_MIN( chars_left, sizeof (string_non_first_chunk_p->data) / sizeof (ecma_char_t));
__memcpy(string_non_first_chunk_p->data, copy_pointer, chars_to_copy * sizeof (ecma_char_t));
size_t chars_to_copy = JERRY_MIN(chars_left, sizeof (string_non_first_chunk_p->data) / sizeof (ecma_char_t));
__memcpy (string_non_first_chunk_p->data, copy_pointer, chars_to_copy * sizeof (ecma_char_t));
chars_left -= chars_to_copy;
copy_pointer += chars_to_copy * sizeof (ecma_char_t);
ECMA_SET_NON_NULL_POINTER( *next_chunk_compressed_pointer_p, string_non_first_chunk_p);
ECMA_SET_NON_NULL_POINTER(*next_chunk_compressed_pointer_p, string_non_first_chunk_p);
next_chunk_compressed_pointer_p = &string_non_first_chunk_p->next_chunk_p;
}
@@ -543,16 +543,16 @@ ecma_new_ecma_string(const ecma_char_t *string_p) /**< zero-terminated string of
* to hold the string's content (in case size of buffer is insuficcient).
*/
ssize_t
ecma_copy_ecma_string_chars_to_buffer(ecma_array_first_chunk_t *first_chunk_p, /**< first chunk of ecma-string */
ecma_copy_ecma_string_chars_to_buffer (ecma_array_first_chunk_t *first_chunk_p, /**< first chunk of ecma-string */
uint8_t *buffer_p, /**< destination buffer */
size_t buffer_size) /**< size of buffer */
{
ecma_length_t string_length = first_chunk_p->header.unit_number;
size_t required_buffer_size = sizeof (ecma_length_t) + sizeof (ecma_char_t) * string_length;
if ( required_buffer_size > buffer_size )
if (required_buffer_size > buffer_size)
{
return -(ssize_t) required_buffer_size;
return - (ssize_t) required_buffer_size;
}
*(ecma_length_t*) buffer_p = string_length;
@@ -561,23 +561,23 @@ ecma_copy_ecma_string_chars_to_buffer(ecma_array_first_chunk_t *first_chunk_p, /
uint8_t *dest_pointer = buffer_p + sizeof (ecma_length_t);
size_t copy_chunk_chars = JERRY_MIN(sizeof (first_chunk_p->data) / sizeof (ecma_char_t),
chars_left);
__memcpy( dest_pointer, first_chunk_p->data, copy_chunk_chars * sizeof (ecma_char_t));
__memcpy (dest_pointer, first_chunk_p->data, copy_chunk_chars * sizeof (ecma_char_t));
dest_pointer += copy_chunk_chars * sizeof (ecma_char_t);
chars_left -= copy_chunk_chars;
ecma_array_non_first_chunk_t *non_first_chunk_p = ECMA_GET_POINTER( first_chunk_p->header.next_chunk_p);
ecma_array_non_first_chunk_t *non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p);
while ( chars_left > 0 )
while (chars_left > 0)
{
JERRY_ASSERT( chars_left < string_length );
JERRY_ASSERT(chars_left < string_length);
copy_chunk_chars = JERRY_MIN(sizeof (non_first_chunk_p->data) / sizeof (ecma_char_t),
chars_left);
__memcpy( dest_pointer, non_first_chunk_p->data, copy_chunk_chars * sizeof (ecma_char_t));
__memcpy (dest_pointer, non_first_chunk_p->data, copy_chunk_chars * sizeof (ecma_char_t));
dest_pointer += copy_chunk_chars * sizeof (ecma_char_t);
chars_left -= copy_chunk_chars;
non_first_chunk_p = ECMA_GET_POINTER( non_first_chunk_p->next_chunk_p);
non_first_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p);
}
return (ssize_t) required_buffer_size;
@@ -589,26 +589,26 @@ ecma_copy_ecma_string_chars_to_buffer(ecma_array_first_chunk_t *first_chunk_p, /
* @return pointer to new ecma-string's first chunk
*/
ecma_array_first_chunk_t*
ecma_duplicate_ecma_string( ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of string to duplicate */
ecma_duplicate_ecma_string (ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of string to duplicate */
{
JERRY_ASSERT( first_chunk_p != NULL );
JERRY_ASSERT(first_chunk_p != NULL);
ecma_array_first_chunk_t *first_chunk_copy_p = ecma_alloc_array_first_chunk();
__memcpy( first_chunk_copy_p, first_chunk_p, sizeof (ecma_array_first_chunk_t));
ecma_array_first_chunk_t *first_chunk_copy_p = ecma_alloc_array_first_chunk ();
__memcpy (first_chunk_copy_p, first_chunk_p, sizeof (ecma_array_first_chunk_t));
ecma_array_non_first_chunk_t *non_first_chunk_p, *non_first_chunk_copy_p;
non_first_chunk_p = ECMA_GET_POINTER( first_chunk_p->header.next_chunk_p);
non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p);
uint16_t *next_pointer_p = &first_chunk_copy_p->header.next_chunk_p;
while ( non_first_chunk_p != NULL )
while (non_first_chunk_p != NULL)
{
non_first_chunk_copy_p = ecma_alloc_array_non_first_chunk();
ECMA_SET_POINTER( *next_pointer_p, non_first_chunk_copy_p);
non_first_chunk_copy_p = ecma_alloc_array_non_first_chunk ();
ECMA_SET_POINTER(*next_pointer_p, non_first_chunk_copy_p);
next_pointer_p = &non_first_chunk_copy_p->next_chunk_p;
__memcpy( non_first_chunk_copy_p, non_first_chunk_p, sizeof (ecma_array_non_first_chunk_t));
__memcpy (non_first_chunk_copy_p, non_first_chunk_p, sizeof (ecma_array_non_first_chunk_t));
non_first_chunk_p = ECMA_GET_POINTER( non_first_chunk_p->next_chunk_p);
non_first_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p);
}
*next_pointer_p = ECMA_NULL_POINTER;
@@ -623,10 +623,10 @@ ecma_duplicate_ecma_string( ecma_array_first_chunk_t *first_chunk_p) /**< first
* false - otherwise.
*/
bool
ecma_compare_ecma_string_to_ecma_string(const ecma_array_first_chunk_t *string1_p, /* ecma-string */
ecma_compare_ecma_string_to_ecma_string (const ecma_array_first_chunk_t *string1_p, /* ecma-string */
const ecma_array_first_chunk_t *string2_p) /* ecma-string */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( string1_p, string2_p);
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(string1_p, string2_p);
} /* ecma_compare_ecma_string_to_ecma_string */
/**
@@ -636,41 +636,41 @@ ecma_compare_ecma_string_to_ecma_string(const ecma_array_first_chunk_t *string1_
* false - otherwise.
*/
bool
ecma_compare_zt_string_to_ecma_string(const ecma_char_t *string_p, /**< zero-terminated string */
ecma_compare_zt_string_to_ecma_string (const ecma_char_t *string_p, /**< zero-terminated string */
const ecma_array_first_chunk_t *ecma_string_p) /* ecma-string */
{
JERRY_ASSERT( string_p != NULL );
JERRY_ASSERT( ecma_string_p != NULL );
JERRY_ASSERT(string_p != NULL);
JERRY_ASSERT(ecma_string_p != NULL);
const ecma_char_t *str_iter_p = string_p;
ecma_length_t ecma_str_len = ecma_string_p->header.unit_number;
const ecma_char_t *current_chunk_chars_cur = (const ecma_char_t*) ecma_string_p->data,
*current_chunk_chars_end = (const ecma_char_t*) (ecma_string_p->data
+ sizeof(ecma_string_p->data));
+ sizeof (ecma_string_p->data));
JERRY_STATIC_ASSERT( ECMA_POINTER_FIELD_WIDTH <= sizeof(uint16_t) * JERRY_BITSINBYTE );
JERRY_STATIC_ASSERT(ECMA_POINTER_FIELD_WIDTH <= sizeof (uint16_t) * JERRY_BITSINBYTE);
const uint16_t *next_chunk_compressed_pointer_p = &ecma_string_p->header.next_chunk_p;
for ( ecma_length_t str_index = 0;
for (ecma_length_t str_index = 0;
str_index < ecma_str_len;
str_index++, str_iter_p++, current_chunk_chars_cur++ )
str_index++, str_iter_p++, current_chunk_chars_cur++)
{
JERRY_ASSERT( current_chunk_chars_cur <= current_chunk_chars_end );
JERRY_ASSERT(current_chunk_chars_cur <= current_chunk_chars_end);
if ( current_chunk_chars_cur == current_chunk_chars_end )
if (current_chunk_chars_cur == current_chunk_chars_end)
{
/* switching to next chunk */
ecma_array_non_first_chunk_t *next_chunk_p = ECMA_GET_POINTER( *next_chunk_compressed_pointer_p);
ecma_array_non_first_chunk_t *next_chunk_p = ECMA_GET_POINTER(*next_chunk_compressed_pointer_p);
JERRY_ASSERT( next_chunk_p != NULL );
JERRY_ASSERT(next_chunk_p != NULL);
current_chunk_chars_cur = (const ecma_char_t*) next_chunk_p->data;
current_chunk_chars_end = (const ecma_char_t*) (next_chunk_p->data + sizeof(next_chunk_p->data));
current_chunk_chars_end = (const ecma_char_t*) (next_chunk_p->data + sizeof (next_chunk_p->data));
next_chunk_compressed_pointer_p = &next_chunk_p->next_chunk_p;
}
if ( *str_iter_p != *current_chunk_chars_cur )
if (*str_iter_p != *current_chunk_chars_cur)
{
/*
* Either *str_iter_p is 0 (zero-terminated string is shorter),
@@ -688,26 +688,26 @@ ecma_compare_zt_string_to_ecma_string(const ecma_char_t *string_p, /**< zero-ter
* If we have also reached end of zero-terminated string, than strings are equal.
* Otherwise zero-terminated string is longer.
*/
return ( *str_iter_p == 0 );
return (*str_iter_p == 0);
} /* ecma_compare_zt_string_to_ecma_string */
/**
* Free all chunks of an array
*/
void
ecma_free_array( ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of the array */
ecma_free_array (ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of the array */
{
JERRY_ASSERT( first_chunk_p != NULL );
JERRY_ASSERT(first_chunk_p != NULL);
ecma_array_non_first_chunk_t *non_first_chunk_p = ECMA_GET_POINTER( first_chunk_p->header.next_chunk_p);
ecma_array_non_first_chunk_t *non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p);
ecma_dealloc_array_first_chunk( first_chunk_p);
ecma_dealloc_array_first_chunk (first_chunk_p);
while ( non_first_chunk_p != NULL )
while (non_first_chunk_p != NULL)
{
ecma_array_non_first_chunk_t *next_chunk_p = ECMA_GET_POINTER( non_first_chunk_p->next_chunk_p);
ecma_array_non_first_chunk_t *next_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p);
ecma_dealloc_array_non_first_chunk( non_first_chunk_p);
ecma_dealloc_array_non_first_chunk (non_first_chunk_p);
non_first_chunk_p = next_chunk_p;
}
@@ -720,11 +720,11 @@ ecma_free_array( ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of th
* and rest properties set to default values (ECMA-262 v5, Table 7).
*/
ecma_property_descriptor_t
ecma_make_empty_property_descriptor( void)
ecma_make_empty_property_descriptor (void)
{
ecma_property_descriptor_t prop_desc = (ecma_property_descriptor_t) {
.is_value_defined = false,
.value = ecma_make_simple_value( ECMA_SIMPLE_VALUE_UNDEFINED),
.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
.is_writable_defined = false,
.writable = ECMA_PROPERTY_NOT_WRITABLE,
+55 -55
View File
@@ -29,88 +29,88 @@
/**
* Get value of pointer from specified compressed pointer field.
*/
#define ECMA_GET_POINTER( field) \
( ( unlikely( field == ECMA_NULL_POINTER ) ) ? NULL : mem_decompress_pointer( field) )
#define ECMA_GET_POINTER(field) \
((unlikely (field == ECMA_NULL_POINTER)) ? NULL : mem_decompress_pointer (field))
/**
* Set value of compressed pointer field so that it will correspond
* to specified non_compressed_pointer.
*/
#define ECMA_SET_POINTER( field, non_compressed_pointer) \
#define ECMA_SET_POINTER(field, non_compressed_pointer) \
do { \
void *__temp_pointer = non_compressed_pointer; \
non_compressed_pointer = __temp_pointer; \
} \
while(0); \
(field) = ( unlikely ( ( non_compressed_pointer ) == NULL ) ? ECMA_NULL_POINTER \
: mem_compress_pointer( non_compressed_pointer) \
& ( ( 1u << ECMA_POINTER_FIELD_WIDTH ) - 1) )
while (0); \
(field) = (unlikely ((non_compressed_pointer) == NULL) ? ECMA_NULL_POINTER \
: mem_compress_pointer (non_compressed_pointer) \
& ((1u << ECMA_POINTER_FIELD_WIDTH) - 1))
/**
* Set value of non-null compressed pointer field so that it will correspond
* to specified non_compressed_pointer.
*/
#define ECMA_SET_NON_NULL_POINTER( field, non_compressed_pointer) \
(field) = ( mem_compress_pointer( non_compressed_pointer) & ( ( 1u << ECMA_POINTER_FIELD_WIDTH ) - 1) )
#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) \
(field) = (mem_compress_pointer (non_compressed_pointer) & ((1u << ECMA_POINTER_FIELD_WIDTH) - 1))
/* ecma-helpers-value.c */
extern bool ecma_is_value_empty( ecma_value_t value);
extern bool ecma_is_value_undefined( ecma_value_t value);
extern bool ecma_is_value_null( ecma_value_t value);
extern bool ecma_is_value_boolean( ecma_value_t value);
extern bool ecma_is_value_true( ecma_value_t value);
extern bool ecma_is_value_empty (ecma_value_t value);
extern bool ecma_is_value_undefined (ecma_value_t value);
extern bool ecma_is_value_null (ecma_value_t value);
extern bool ecma_is_value_boolean (ecma_value_t value);
extern bool ecma_is_value_true (ecma_value_t value);
extern ecma_value_t ecma_make_simple_value( ecma_simple_value_t value);
extern ecma_value_t ecma_make_number_value( ecma_number_t* num_p);
extern ecma_value_t ecma_make_string_value( ecma_array_first_chunk_t* ecma_string_p);
extern ecma_value_t ecma_make_object_value( ecma_object_t* object_p);
extern ecma_value_t ecma_copy_value( const ecma_value_t value, bool do_ref_if_object);
extern void ecma_free_value( const ecma_value_t value, bool do_deref_if_object);
extern ecma_value_t ecma_make_simple_value (ecma_simple_value_t value);
extern ecma_value_t ecma_make_number_value (ecma_number_t* num_p);
extern ecma_value_t ecma_make_string_value (ecma_array_first_chunk_t* ecma_string_p);
extern ecma_value_t ecma_make_object_value (ecma_object_t* object_p);
extern ecma_value_t ecma_copy_value (const ecma_value_t value, bool do_ref_if_object);
extern void ecma_free_value (const ecma_value_t value, bool do_deref_if_object);
extern ecma_completion_value_t ecma_make_completion_value( ecma_completion_type_t type, ecma_value_t value, uint8_t target);
extern ecma_completion_value_t ecma_make_simple_completion_value( ecma_simple_value_t simple_value);
extern ecma_completion_value_t ecma_make_throw_value( ecma_object_t *exception_p);
extern ecma_completion_value_t ecma_make_empty_completion_value( void);
extern ecma_completion_value_t ecma_copy_completion_value( ecma_completion_value_t value);
extern void ecma_free_completion_value( ecma_completion_value_t completion_value);
extern ecma_completion_value_t ecma_make_completion_value (ecma_completion_type_t type, ecma_value_t value, uint8_t target);
extern ecma_completion_value_t ecma_make_simple_completion_value (ecma_simple_value_t simple_value);
extern ecma_completion_value_t ecma_make_throw_value (ecma_object_t *exception_p);
extern ecma_completion_value_t ecma_make_empty_completion_value (void);
extern ecma_completion_value_t ecma_copy_completion_value (ecma_completion_value_t value);
extern void ecma_free_completion_value (ecma_completion_value_t completion_value);
extern bool ecma_is_completion_value_normal( ecma_completion_value_t value);
extern bool ecma_is_completion_value_throw( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_simple_value( ecma_completion_value_t value, ecma_simple_value_t simple_value);
extern bool ecma_is_completion_value_normal_true( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_false( ecma_completion_value_t value);
extern bool ecma_is_empty_completion_value( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal (ecma_completion_value_t value);
extern bool ecma_is_completion_value_throw (ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_simple_value (ecma_completion_value_t value, ecma_simple_value_t simple_value);
extern bool ecma_is_completion_value_normal_true (ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_false (ecma_completion_value_t value);
extern bool ecma_is_empty_completion_value (ecma_completion_value_t value);
/* ecma-helpers.c */
extern ecma_object_t* ecma_create_object( ecma_object_t *prototype_object_p, bool is_extensible, ecma_object_type_t type);
extern ecma_object_t* ecma_create_decl_lex_env( ecma_object_t *outer_lexical_environment_p);
extern ecma_object_t* ecma_create_object_lex_env( ecma_object_t *outer_lexical_environment_p, ecma_object_t *binding_obj_p, bool provide_this);
extern ecma_object_t* ecma_create_object (ecma_object_t *prototype_object_p, bool is_extensible, ecma_object_type_t type);
extern ecma_object_t* ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p);
extern ecma_object_t* ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, ecma_object_t *binding_obj_p, bool provide_this);
extern ecma_property_t* ecma_create_internal_property(ecma_object_t *object_p, ecma_internal_property_id_t property_id);
extern ecma_property_t* ecma_find_internal_property(ecma_object_t *object_p, ecma_internal_property_id_t property_id);
extern ecma_property_t* ecma_get_internal_property(ecma_object_t *object_p, ecma_internal_property_id_t property_id);
extern ecma_property_t* ecma_create_internal_property (ecma_object_t *object_p, ecma_internal_property_id_t property_id);
extern ecma_property_t* ecma_find_internal_property (ecma_object_t *object_p, ecma_internal_property_id_t property_id);
extern ecma_property_t* ecma_get_internal_property (ecma_object_t *object_p, ecma_internal_property_id_t property_id);
extern ecma_property_t *ecma_create_named_data_property(ecma_object_t *obj_p, const ecma_char_t *name_p, ecma_property_writable_value_t writable, ecma_property_enumerable_value_t enumerable, ecma_property_configurable_value_t configurable);
extern ecma_property_t *ecma_create_named_accessor_property(ecma_object_t *obj_p, const ecma_char_t *name_p, ecma_object_t *get_p, ecma_object_t *set_p, ecma_property_enumerable_value_t enumerable, ecma_property_configurable_value_t configurable);
extern ecma_property_t *ecma_find_named_property(ecma_object_t *obj_p, const ecma_char_t *name_p);
extern ecma_property_t *ecma_get_named_property(ecma_object_t *obj_p, const ecma_char_t *name_p);
extern ecma_property_t *ecma_get_named_data_property(ecma_object_t *obj_p, const ecma_char_t *name_p);
extern ecma_property_t *ecma_create_named_data_property (ecma_object_t *obj_p, const ecma_char_t *name_p, ecma_property_writable_value_t writable, ecma_property_enumerable_value_t enumerable, ecma_property_configurable_value_t configurable);
extern ecma_property_t *ecma_create_named_accessor_property (ecma_object_t *obj_p, const ecma_char_t *name_p, ecma_object_t *get_p, ecma_object_t *set_p, ecma_property_enumerable_value_t enumerable, ecma_property_configurable_value_t configurable);
extern ecma_property_t *ecma_find_named_property (ecma_object_t *obj_p, const ecma_char_t *name_p);
extern ecma_property_t *ecma_get_named_property (ecma_object_t *obj_p, const ecma_char_t *name_p);
extern ecma_property_t *ecma_get_named_data_property (ecma_object_t *obj_p, const ecma_char_t *name_p);
extern void ecma_free_internal_property(ecma_property_t *prop_p);
extern void ecma_free_named_data_property(ecma_property_t *prop_p);
extern void ecma_free_named_accessor_property(ecma_property_t *prop_p);
extern void ecma_free_property(ecma_property_t *prop_p);
extern void ecma_free_internal_property (ecma_property_t *prop_p);
extern void ecma_free_named_data_property (ecma_property_t *prop_p);
extern void ecma_free_named_accessor_property (ecma_property_t *prop_p);
extern void ecma_free_property (ecma_property_t *prop_p);
extern void ecma_delete_property( ecma_object_t *obj_p, ecma_property_t *prop_p);
extern void ecma_delete_property (ecma_object_t *obj_p, ecma_property_t *prop_p);
extern ecma_array_first_chunk_t* ecma_new_ecma_string( const ecma_char_t *string_p);
extern ssize_t ecma_copy_ecma_string_chars_to_buffer( ecma_array_first_chunk_t *first_chunk_p, uint8_t *buffer_p, size_t buffer_size);
extern ecma_array_first_chunk_t* ecma_duplicate_ecma_string( ecma_array_first_chunk_t *first_chunk_p);
extern bool ecma_compare_zt_string_to_ecma_string( const ecma_char_t *string_p, const ecma_array_first_chunk_t *ecma_string_p);
extern bool ecma_compare_ecma_string_to_ecma_string(const ecma_array_first_chunk_t *string1_p, const ecma_array_first_chunk_t *string2_p);
extern void ecma_free_array( ecma_array_first_chunk_t *first_chunk_p);
extern ecma_array_first_chunk_t* ecma_new_ecma_string (const ecma_char_t *string_p);
extern ssize_t ecma_copy_ecma_string_chars_to_buffer (ecma_array_first_chunk_t *first_chunk_p, uint8_t *buffer_p, size_t buffer_size);
extern ecma_array_first_chunk_t* ecma_duplicate_ecma_string (ecma_array_first_chunk_t *first_chunk_p);
extern bool ecma_compare_zt_string_to_ecma_string (const ecma_char_t *string_p, const ecma_array_first_chunk_t *ecma_string_p);
extern bool ecma_compare_ecma_string_to_ecma_string (const ecma_array_first_chunk_t *string1_p, const ecma_array_first_chunk_t *string2_p);
extern void ecma_free_array (ecma_array_first_chunk_t *first_chunk_p);
extern ecma_property_descriptor_t ecma_make_empty_property_descriptor( void);
extern ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
#endif /* !JERRY_ECMA_HELPERS_H */