Rework literal storage.

The new literal storage keeps ecma strings rather than having a
custom string implementation which duplicates the string management
routines. Conversions between string implementations are eliminated
which improved the performance by 4%.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2016-06-27 00:25:09 -07:00
parent 0940be57f6
commit 0a32c97755
30 changed files with 744 additions and 1641 deletions
+5 -2
View File
@@ -106,9 +106,12 @@ util_print_literal (lexer_literal_t *literal_p) /**< literal */
}
else if (literal_p->type == LEXER_NUMBER_LITERAL)
{
lit_literal_t literal = lit_get_literal_by_cp (literal_p->u.value);
ecma_string_t *value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, literal_p->u.value);
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);
printf ("number(");
util_print_number (lit_number_literal_get_number (literal));
util_print_number (ecma_get_number_from_value (value_p->u.lit_number));
}
else if (literal_p->type == LEXER_REGEXP_LITERAL)
{
+1 -2
View File
@@ -44,7 +44,6 @@
#include "ecma-globals.h"
#include "ecma-regexp-object.h"
#include "lit-literal.h"
#include "jmem-heap.h"
/* Immediate management. */
@@ -90,7 +89,7 @@ typedef struct
{
union
{
lit_cpointer_t value; /**< literal value (not processed by the parser) */
jmem_cpointer_t value; /**< literal value (not processed by the parser) */
const uint8_t *char_p; /**< character value */
ecma_compiled_code_t *bytecode_p; /**< compiled function or regexp pointer */
uint32_t source_data; /**< encoded source literal */
+2 -3
View File
@@ -17,7 +17,7 @@
#include "ecma-alloc.h"
#include "ecma-helpers.h"
#include "ecma-function-object.h"
#include "jerry-snapshot.h"
#include "ecma-literal-storage.h"
#include "js-parser-internal.h"
#include "lit-char-helpers.h"
@@ -1523,7 +1523,6 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */
{
parser_list_iterator_t literal_iterator;
lexer_literal_t *literal_p;
lit_cpointer_t lit_cp;
ecma_number_t num;
uint32_t literal_index = 0;
uint16_t length = context_p->token.lit_location.length;
@@ -1567,7 +1566,7 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */
num = -num;
}
lit_cp = lit_cpointer_compress (lit_find_or_create_literal_from_num (num));
jmem_cpointer_t lit_cp = ecma_find_or_create_literal_number (num);
parser_list_iterator_init (&context_p->literal_pool, &literal_iterator);
while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
+16 -19
View File
@@ -15,10 +15,8 @@
*/
#include "ecma-helpers.h"
#include "jerry-snapshot.h"
#include "ecma-literal-storage.h"
#include "js-parser-internal.h"
#include "lit-literal.h"
#include "lit-cpointer.h"
#ifdef PARSER_DUMP_BYTE_CODE
static int parser_show_instrs = PARSER_FALSE;
@@ -99,9 +97,8 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
if (char_p != NULL)
{
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string (char_p,
literal_p->prop.length);
literal_p->u.value = lit_cpointer_compress (lit);
literal_p->u.value = ecma_find_or_create_literal_string (char_p,
literal_p->prop.length);
if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
{
@@ -424,7 +421,7 @@ parser_encode_literal (uint8_t *dst_p, /**< destination buffer */
static uint8_t *
parser_generate_initializers (parser_context_t *context_p, /**< context */
uint8_t *dst_p, /**< destination buffer */
lit_cpointer_t *literal_pool_p, /**< start of literal pool */
jmem_cpointer_t *literal_pool_p, /**< start of literal pool */
uint16_t uninitialized_var_end, /**< end of the uninitialized var group */
uint16_t initialized_var_end, /**< end of the initialized var group */
uint16_t const_literal_end, /**< end of the const literal group */
@@ -520,9 +517,9 @@ parser_generate_initializers (parser_context_t *context_p, /**< context */
|| literal_p->type == LEXER_STRING_LITERAL)
{
#ifdef PARSER_DUMP_BYTE_CODE
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string (literal_p->u.char_p,
literal_p->prop.length);
literal_pool_p[literal_p->prop.index] = lit_cpointer_compress (lit);
jmem_cpointer_t lit_cp = ecma_find_or_create_literal_string (literal_p->u.char_p,
literal_p->prop.length);
literal_pool_p[literal_p->prop.index] = lit_cp;
if (!context_p->is_show_opcodes
&& !(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
@@ -1095,7 +1092,7 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code
byte_code_start_p += sizeof (cbc_uint8_arguments_t);
}
byte_code_start_p += literal_end * sizeof (lit_cpointer_t);
byte_code_start_p += literal_end * sizeof (jmem_cpointer_t);
byte_code_end_p = byte_code_start_p + length;
byte_code_p = byte_code_start_p;
@@ -1263,7 +1260,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
int needs_uint16_arguments;
cbc_opcode_t last_opcode = CBC_EXT_OPCODE;
ecma_compiled_code_t *compiled_code_p;
lit_cpointer_t *literal_pool_p;
jmem_cpointer_t *literal_pool_p;
uint8_t *dst_p;
if ((size_t) context_p->stack_limit + (size_t) context_p->register_count > PARSER_MAXIMUM_STACK_LIMIT)
@@ -1460,7 +1457,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
total_size = sizeof (cbc_uint16_arguments_t);
}
total_size += length + context_p->literal_count * sizeof (lit_cpointer_t);
total_size += length + context_p->literal_count * sizeof (jmem_cpointer_t);
total_size = JERRY_ALIGNUP (total_size, JMEM_ALIGNMENT);
compiled_code_p = (ecma_compiled_code_t *) parser_malloc (context_p, total_size);
@@ -1520,8 +1517,8 @@ parser_post_processing (parser_context_t *context_p) /**< context */
compiled_code_p->status_flags |= CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED;
}
literal_pool_p = (lit_cpointer_t *) byte_code_p;
byte_code_p += context_p->literal_count * sizeof (lit_cpointer_t);
literal_pool_p = (jmem_cpointer_t *) byte_code_p;
byte_code_p += context_p->literal_count * sizeof (jmem_cpointer_t);
dst_p = parser_generate_initializers (context_p,
byte_code_p,
@@ -1713,9 +1710,9 @@ parser_post_processing (parser_context_t *context_p) /**< context */
{
uint32_t source_data = literal_p->u.source_data;
const uint8_t *char_p = context_p->source_end_p - (source_data & 0xfffff);
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string (char_p,
source_data >> 20);
literal_pool_p[literal_p->prop.index] = lit_cpointer_compress (lit);
jmem_cpointer_t lit_cp = ecma_find_or_create_literal_string (char_p,
source_data >> 20);
literal_pool_p[literal_p->prop.index] = lit_cp;
}
}
}
@@ -1745,7 +1742,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
{
if (literal_p->u.char_p == NULL)
{
literal_pool_p[argument_count] = lit_cpointer_null_cp ();
literal_pool_p[argument_count] = JMEM_CP_NULL;
argument_count++;
continue;
}