Optimize parser memory consumption. Remove 'prev' and 'block_size' fields form the linked list structure. Remove 'magic' field from structures used in parser.
This commit is contained in:
@@ -17,11 +17,8 @@
|
|||||||
#include "mem-heap.h"
|
#include "mem-heap.h"
|
||||||
#include "jrt-libc-includes.h"
|
#include "jrt-libc-includes.h"
|
||||||
|
|
||||||
#define ARRAY_LIST_MAGIC 0x39
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t magic;
|
|
||||||
uint8_t element_size;
|
uint8_t element_size;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -33,7 +30,6 @@ extract_header (array_list al)
|
|||||||
{
|
{
|
||||||
JERRY_ASSERT (al != null_list);
|
JERRY_ASSERT (al != null_list);
|
||||||
array_list_header *header = (array_list_header *) al;
|
array_list_header *header = (array_list_header *) al;
|
||||||
JERRY_ASSERT (header->magic == ARRAY_LIST_MAGIC);
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +115,6 @@ array_list_init (uint8_t element_size)
|
|||||||
size_t size = mem_heap_recommend_allocation_size (sizeof (array_list_header));
|
size_t size = mem_heap_recommend_allocation_size (sizeof (array_list_header));
|
||||||
array_list_header *header = (array_list_header *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM);
|
array_list_header *header = (array_list_header *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||||
memset (header, 0, size);
|
memset (header, 0, size);
|
||||||
header->magic = ARRAY_LIST_MAGIC;
|
|
||||||
header->element_size = element_size;
|
header->element_size = element_size;
|
||||||
header->len = 0;
|
header->len = 0;
|
||||||
header->size = size;
|
header->size = size;
|
||||||
|
|||||||
@@ -18,14 +18,11 @@
|
|||||||
#include "mem-heap.h"
|
#include "mem-heap.h"
|
||||||
#include "jrt-libc-includes.h"
|
#include "jrt-libc-includes.h"
|
||||||
|
|
||||||
#define HASH_MAP_MAGIC 0x67
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t (*hash) (void *);
|
uint16_t (*hash) (void *);
|
||||||
array_list *data;
|
array_list *data;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t magic;
|
|
||||||
uint8_t key_size;
|
uint8_t key_size;
|
||||||
uint8_t value_size;
|
uint8_t value_size;
|
||||||
mem_heap_alloc_term_t alloc_term;
|
mem_heap_alloc_term_t alloc_term;
|
||||||
@@ -37,7 +34,6 @@ extract_header (hash_table ht)
|
|||||||
{
|
{
|
||||||
JERRY_ASSERT (ht != null_hash);
|
JERRY_ASSERT (ht != null_hash);
|
||||||
hash_table_int *hti = (hash_table_int *) ht;
|
hash_table_int *hti = (hash_table_int *) ht;
|
||||||
JERRY_ASSERT (hti->magic == HASH_MAP_MAGIC);
|
|
||||||
return hti;
|
return hti;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +103,6 @@ hash_table_init (uint8_t key_size, uint8_t value_size, uint16_t size,
|
|||||||
{
|
{
|
||||||
hash_table_int *res = (hash_table_int *) mem_heap_alloc_block (sizeof (hash_table_int), alloc_term);
|
hash_table_int *res = (hash_table_int *) mem_heap_alloc_block (sizeof (hash_table_int), alloc_term);
|
||||||
memset (res, 0, sizeof (hash_table_int));
|
memset (res, 0, sizeof (hash_table_int));
|
||||||
res->magic = HASH_MAP_MAGIC;
|
|
||||||
res->key_size = key_size;
|
res->key_size = key_size;
|
||||||
res->value_size = value_size;
|
res->value_size = value_size;
|
||||||
res->size = size;
|
res->size = size;
|
||||||
|
|||||||
@@ -19,15 +19,10 @@
|
|||||||
#include "mem-heap.h"
|
#include "mem-heap.h"
|
||||||
#include "lp-string.h"
|
#include "lp-string.h"
|
||||||
|
|
||||||
#define LINKED_LIST_MAGIC 0x42
|
|
||||||
|
|
||||||
typedef struct linked_list_header
|
typedef struct linked_list_header
|
||||||
{
|
{
|
||||||
struct linked_list_header *next;
|
struct linked_list_header *next;
|
||||||
struct linked_list_header *prev;
|
|
||||||
uint16_t block_size;
|
|
||||||
uint16_t element_size;
|
uint16_t element_size;
|
||||||
uint8_t magic;
|
|
||||||
}
|
}
|
||||||
linked_list_header;
|
linked_list_header;
|
||||||
|
|
||||||
@@ -35,13 +30,17 @@ linked_list_header;
|
|||||||
do { \
|
do { \
|
||||||
linked_list_header *header = (linked_list_header *) list; \
|
linked_list_header *header = (linked_list_header *) list; \
|
||||||
JERRY_ASSERT (header); \
|
JERRY_ASSERT (header); \
|
||||||
JERRY_ASSERT (header->magic == LINKED_LIST_MAGIC); \
|
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
static size_t linked_list_block_size (uint16_t element_size)
|
||||||
|
{
|
||||||
|
return mem_heap_recommend_allocation_size (sizeof (linked_list_header) + element_size) - sizeof (linked_list_header);
|
||||||
|
}
|
||||||
|
|
||||||
linked_list
|
linked_list
|
||||||
linked_list_init (uint16_t element_size)
|
linked_list_init (uint16_t element_size)
|
||||||
{
|
{
|
||||||
size_t size = mem_heap_recommend_allocation_size (element_size);
|
size_t size = sizeof (linked_list_header) + linked_list_block_size (element_size);
|
||||||
linked_list list = (linked_list) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM);
|
linked_list list = (linked_list) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||||
if (list == null_list)
|
if (list == null_list)
|
||||||
{
|
{
|
||||||
@@ -50,10 +49,8 @@ linked_list_init (uint16_t element_size)
|
|||||||
}
|
}
|
||||||
memset (list, 0, size);
|
memset (list, 0, size);
|
||||||
linked_list_header* header = (linked_list_header *) list;
|
linked_list_header* header = (linked_list_header *) list;
|
||||||
header->magic = LINKED_LIST_MAGIC;
|
header->next = null_list;
|
||||||
header->prev = header->next = null_list;
|
|
||||||
header->element_size = element_size;
|
header->element_size = element_size;
|
||||||
header->block_size = (uint8_t) (size - sizeof (linked_list_header));
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,17 +67,18 @@ linked_list_free (linked_list list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
linked_list_element (linked_list list, uint16_t element_num)
|
linked_list_element (linked_list list, size_t element_num)
|
||||||
{
|
{
|
||||||
ASSERT_LIST (list);
|
ASSERT_LIST (list);
|
||||||
linked_list_header *header = (linked_list_header *) list;
|
linked_list_header *header = (linked_list_header *) list;
|
||||||
|
size_t block_size = linked_list_block_size (header->element_size);
|
||||||
linked_list raw = list + sizeof (linked_list_header);
|
linked_list raw = list + sizeof (linked_list_header);
|
||||||
if (header->block_size < header->element_size * (element_num + 1))
|
if (block_size < header->element_size * (element_num + 1))
|
||||||
{
|
{
|
||||||
if (header->next)
|
if (header->next)
|
||||||
{
|
{
|
||||||
return linked_list_element ((linked_list) header->next,
|
return linked_list_element ((linked_list) header->next,
|
||||||
(uint16_t) (element_num - (header->block_size / header->element_size)));
|
element_num - (block_size / header->element_size));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -92,20 +90,20 @@ linked_list_element (linked_list list, uint16_t element_num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
linked_list_set_element (linked_list list, uint16_t element_num, void *element)
|
linked_list_set_element (linked_list list, size_t element_num, void *element)
|
||||||
{
|
{
|
||||||
ASSERT_LIST (list);
|
ASSERT_LIST (list);
|
||||||
linked_list_header *header = (linked_list_header *) list;
|
linked_list_header *header = (linked_list_header *) list;
|
||||||
|
size_t block_size = linked_list_block_size (header->element_size);
|
||||||
uint8_t *raw = (uint8_t *) (header + 1);
|
uint8_t *raw = (uint8_t *) (header + 1);
|
||||||
if (header->block_size < header->element_size * (element_num + 1))
|
if (block_size < header->element_size * (element_num + 1))
|
||||||
{
|
{
|
||||||
if (header->next == null_list)
|
if (header->next == null_list)
|
||||||
{
|
{
|
||||||
header->next = (linked_list_header *) linked_list_init (header->element_size);
|
header->next = (linked_list_header *) linked_list_init (header->element_size);
|
||||||
header->next->prev = header;
|
|
||||||
}
|
}
|
||||||
linked_list_set_element ((linked_list) header->next,
|
linked_list_set_element ((linked_list) header->next,
|
||||||
(uint16_t) (element_num - (header->block_size / header->element_size)),
|
element_num - (block_size / header->element_size),
|
||||||
element);
|
element);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ typedef uint8_t* linked_list;
|
|||||||
|
|
||||||
linked_list linked_list_init (uint16_t);
|
linked_list linked_list_init (uint16_t);
|
||||||
void linked_list_free (linked_list);
|
void linked_list_free (linked_list);
|
||||||
void *linked_list_element (linked_list, uint16_t);
|
void *linked_list_element (linked_list, size_t);
|
||||||
void linked_list_set_element (linked_list, uint16_t, void *);
|
void linked_list_set_element (linked_list, size_t, void *);
|
||||||
|
|
||||||
#endif /* LINKED_LIST_H */
|
#endif /* LINKED_LIST_H */
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "lp-string.h"
|
#include "lp-string.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum __attr_packed___
|
||||||
{
|
{
|
||||||
LIT_UNKNOWN,
|
LIT_UNKNOWN,
|
||||||
LIT_STR,
|
LIT_STR,
|
||||||
|
|||||||
@@ -18,13 +18,10 @@
|
|||||||
|
|
||||||
#include "linked-list.h"
|
#include "linked-list.h"
|
||||||
|
|
||||||
#define TREE_MAGIC 0x43
|
|
||||||
|
|
||||||
typedef struct tree_header
|
typedef struct tree_header
|
||||||
{
|
{
|
||||||
struct tree_header *parent;
|
struct tree_header *parent;
|
||||||
linked_list children;
|
linked_list children;
|
||||||
uint8_t magic;
|
|
||||||
uint8_t children_num;
|
uint8_t children_num;
|
||||||
}
|
}
|
||||||
tree_header;
|
tree_header;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define INVALID_LITERAL UINT32_MAX
|
#define INVALID_LITERAL UINT32_MAX
|
||||||
|
|
||||||
/* Keywords. */
|
/* Keywords. */
|
||||||
typedef enum
|
typedef enum __attr_packed___
|
||||||
{
|
{
|
||||||
/* Not a keyword. */
|
/* Not a keyword. */
|
||||||
KW_NONE = 0,
|
KW_NONE = 0,
|
||||||
@@ -81,7 +81,7 @@ keyword;
|
|||||||
|
|
||||||
|
|
||||||
/* Type of tokens. */
|
/* Type of tokens. */
|
||||||
typedef enum
|
typedef enum __attr_packed___
|
||||||
{
|
{
|
||||||
TOK_EOF = 0, // End of file
|
TOK_EOF = 0, // End of file
|
||||||
TOK_NAME, // Identifier
|
TOK_NAME, // Identifier
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "lp-string.h"
|
#include "lp-string.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum __attr_packed___
|
||||||
{
|
{
|
||||||
LIT_UNKNOWN,
|
LIT_UNKNOWN,
|
||||||
LIT_STR,
|
LIT_STR,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum __attr_packed___
|
||||||
{
|
{
|
||||||
OPERAND_LITERAL,
|
OPERAND_LITERAL,
|
||||||
OPERAND_TMP
|
OPERAND_TMP
|
||||||
@@ -39,7 +39,7 @@ typedef struct
|
|||||||
}
|
}
|
||||||
operand;
|
operand;
|
||||||
|
|
||||||
typedef enum
|
typedef enum __attr_packed___
|
||||||
{
|
{
|
||||||
VARG_FUNC_DECL,
|
VARG_FUNC_DECL,
|
||||||
VARG_FUNC_EXPR,
|
VARG_FUNC_EXPR,
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ static void
|
|||||||
assert_tree (scopes_tree t)
|
assert_tree (scopes_tree t)
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (t != NULL);
|
JERRY_ASSERT (t != NULL);
|
||||||
JERRY_ASSERT (t->t.magic == TREE_MAGIC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static idx_t
|
static idx_t
|
||||||
@@ -648,7 +647,6 @@ scopes_tree_init (scopes_tree parent)
|
|||||||
{
|
{
|
||||||
scopes_tree tree = (scopes_tree) mem_heap_alloc_block (sizeof (scopes_tree_int), MEM_HEAP_ALLOC_SHORT_TERM);
|
scopes_tree tree = (scopes_tree) mem_heap_alloc_block (sizeof (scopes_tree_int), MEM_HEAP_ALLOC_SHORT_TERM);
|
||||||
memset (tree, 0, sizeof (scopes_tree_int));
|
memset (tree, 0, sizeof (scopes_tree_int));
|
||||||
tree->t.magic = TREE_MAGIC;
|
|
||||||
tree->t.parent = (tree_header *) parent;
|
tree->t.parent = (tree_header *) parent;
|
||||||
tree->t.children = null_list;
|
tree->t.children = null_list;
|
||||||
tree->t.children_num = 0;
|
tree->t.children_num = 0;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
#endif /* JERRY_NDEBUG */
|
#endif /* JERRY_NDEBUG */
|
||||||
|
|
||||||
typedef enum
|
typedef enum __attr_packed___
|
||||||
{
|
{
|
||||||
PROP_DATA,
|
PROP_DATA,
|
||||||
PROP_SET,
|
PROP_SET,
|
||||||
|
|||||||
Reference in New Issue
Block a user