Skip to content

Commit 53801e3

Browse files
committed
Replace array of literals with literal storage.
JerryScript-DCO-1.0-Signed-off-by: Evgeny Gavrin [email protected] JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov [email protected]
1 parent 340a9ef commit 53801e3

36 files changed

+449
-1086
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,20 +758,13 @@ typedef enum
758758
} ecma_string_container_t;
759759

760760
FIXME (Move to library that should define the type (literal.h /* ? */))
761+
761762
/**
762763
* Literal and compressed pointer to literal
763764
*/
764765
typedef rcs_record_t *literal_t;
765766
typedef rcs_cpointer_t lit_cpointer_t;
766767

767-
/**
768-
* Index in literal table
769-
*
770-
* FIXME: Remove after switching to literal storage
771-
*/
772-
typedef uint32_t literal_index_t;
773-
774-
775768
/**
776769
* Identifiers of ECMA and implementation-defined magic string constants
777770
*/
@@ -824,7 +817,7 @@ typedef struct ecma_string_t
824817
union
825818
{
826819
/** Index of string in literal table */
827-
literal_index_t lit_index;
820+
lit_cpointer_t lit_cp;
828821

829822
/** Compressed pointer to an ecma_collection_header_t */
830823
mem_cpointer_t collection_cp : ECMA_POINTER_FIELD_WIDTH;

jerry-core/ecma/base/ecma-helpers-string.cpp

Lines changed: 68 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ static ecma_length_t ecma_magic_string_max_length;
6666
#endif /* !JERRY_NDEBUG */
6767

6868
static void
69-
ecma_init_ecma_string_from_lit_index (ecma_string_t *string_p,
70-
literal_index_t lit_index,
71-
bool is_stack_var);
69+
ecma_init_ecma_string_from_lit_cp (ecma_string_t *string_p,
70+
lit_cpointer_t lit_index,
71+
bool is_stack_var);
7272
static void
7373
ecma_init_ecma_string_from_magic_string_id (ecma_string_t *string_p,
7474
ecma_magic_string_id_t magic_string_id,
@@ -370,42 +370,42 @@ ecma_get_magic_string_ex_count (void)
370370
* Initialize ecma-string descriptor with string described by index in literal table
371371
*/
372372
static void
373-
ecma_init_ecma_string_from_lit_index (ecma_string_t *string_p, /**< descriptor to initialize */
374-
literal_index_t lit_index, /**< index in the literal table */
375-
bool is_stack_var) /**< flag indicating whether the string descriptor
373+
ecma_init_ecma_string_from_lit_cp (ecma_string_t *string_p, /**< descriptor to initialize */
374+
lit_cpointer_t lit_cp, /**< compressed pointer to literal */
375+
bool is_stack_var) /**< flag indicating whether the string descriptor
376376
is placed on stack (true) or in the heap (false) */
377377
{
378378
#ifndef JERRY_NDEBUG
379379
JERRY_ASSERT (is_stack_var == (!mem_is_heap_pointer (string_p)));
380380
#endif /* !JERRY_NDEBUG */
381381

382-
const literal lit = serializer_get_literal_by_id (lit_index);
383-
if (lit.type == LIT_MAGIC_STR)
382+
literal_t lit = lit_get_literal_by_cp (lit_cp);
383+
if (lit->get_type () == LIT_MAGIC_STR_T)
384384
{
385385
ecma_init_ecma_string_from_magic_string_id (string_p,
386-
lit.data.magic_str_id,
386+
lit_magic_record_get_magic_str_id (lit),
387387
is_stack_var);
388388

389389
return;
390390
}
391-
else if (lit.type == LIT_MAGIC_STR_EX)
391+
else if (lit->get_type () == LIT_MAGIC_STR_EX_T)
392392
{
393393
ecma_init_ecma_string_from_magic_string_ex_id (string_p,
394-
lit.data.magic_str_ex_id,
394+
lit_magic_record_ex_get_magic_str_id (lit),
395395
is_stack_var);
396-
397396
return;
398397
}
399-
JERRY_ASSERT (lit.type == LIT_STR);
398+
399+
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
400400

401401
string_p->refs = 1;
402402
string_p->is_stack_var = (is_stack_var != 0);
403403
string_p->container = ECMA_STRING_CONTAINER_LIT_TABLE;
404-
string_p->hash = lit.data.lp.hash;
404+
string_p->hash = lit_charset_literal_get_hash (lit);
405405

406406
string_p->u.common_field = 0;
407-
string_p->u.lit_index = lit_index;
408-
} /* ecma_init_ecma_string_from_lit_index */
407+
string_p->u.lit_cp = lit_cp;
408+
} /* ecma_init_ecma_string_from_lit_cp */
409409

410410
/**
411411
* Initialize ecma-string descriptor with specified magic string
@@ -591,27 +591,27 @@ ecma_new_ecma_string_from_number (ecma_number_t num) /**< ecma-number */
591591
* with string described by index in literal table
592592
*/
593593
void
594-
ecma_new_ecma_string_on_stack_from_lit_index (ecma_string_t *string_p, /**< pointer to the ecma-string
594+
ecma_new_ecma_string_on_stack_from_lit_cp (ecma_string_t *string_p, /**< pointer to the ecma-string
595595
descriptor to initialize */
596-
literal_index_t lit_index) /**< index in the literal table */
596+
lit_cpointer_t lit_cp) /**< compressed pointer to literal */
597597
{
598-
ecma_init_ecma_string_from_lit_index (string_p, lit_index, true);
599-
} /* ecma_new_ecma_string_on_stack_from_lit_index */
598+
ecma_init_ecma_string_from_lit_cp (string_p, lit_cp, true);
599+
} /* ecma_new_ecma_string_on_stack_from_lit_cp */
600600

601601
/**
602602
* Allocate new ecma-string and fill it with reference to string literal
603603
*
604604
* @return pointer to ecma-string descriptor
605605
*/
606606
ecma_string_t*
607-
ecma_new_ecma_string_from_lit_index (literal_index_t lit_index) /**< index in the literal table */
607+
ecma_new_ecma_string_from_lit_cp (lit_cpointer_t lit_cp) /**< index in the literal table */
608608
{
609609
ecma_string_t* string_desc_p = ecma_alloc_string ();
610610

611-
ecma_init_ecma_string_from_lit_index (string_desc_p, lit_index, false);
611+
ecma_init_ecma_string_from_lit_cp (string_desc_p, lit_cp, false);
612612

613613
return string_desc_p;
614-
} /* ecma_new_ecma_string_from_lit_index */
614+
} /* ecma_new_ecma_string_from_lit_cp */
615615

616616
/**
617617
* Initialize ecma-string descriptor placed on stack with specified magic string
@@ -1037,13 +1037,9 @@ ecma_string_to_zt_string (const ecma_string_t *string_desc_p, /**< ecma-string d
10371037
}
10381038
case ECMA_STRING_CONTAINER_LIT_TABLE:
10391039
{
1040-
const literal lit = serializer_get_literal_by_id (string_desc_p->u.lit_index);
1041-
JERRY_ASSERT (lit.type == LIT_STR);
1042-
const ecma_char_t *str_p = literal_to_zt (lit);
1043-
JERRY_ASSERT (str_p != NULL);
1044-
1045-
ecma_copy_zt_string_to_buffer (str_p, buffer_p, required_buffer_size);
1046-
1040+
literal_t lit = lit_get_literal_by_cp (string_desc_p->u.lit_cp);
1041+
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
1042+
lit_literal_to_charset (lit, buffer_p, (size_t) required_buffer_size);
10471043
break;
10481044
}
10491045
case ECMA_STRING_CONTAINER_UINT32_IN_DESC:
@@ -1141,7 +1137,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
11411137
{
11421138
if (string1_p->container == ECMA_STRING_CONTAINER_LIT_TABLE)
11431139
{
1144-
JERRY_ASSERT (string1_p->u.lit_index != string2_p->u.lit_index);
1140+
JERRY_ASSERT (string1_p->u.lit_cp.packed_value != string2_p->u.lit_cp.packed_value);
11451141

11461142
return false;
11471143
}
@@ -1214,7 +1210,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
12141210
}
12151211
case ECMA_STRING_CONTAINER_LIT_TABLE:
12161212
{
1217-
JERRY_ASSERT (string1_p->u.lit_index != string2_p->u.lit_index);
1213+
JERRY_ASSERT (string1_p->u.lit_cp.packed_value != string2_p->u.lit_cp.packed_value);
12181214

12191215
return false;
12201216
}
@@ -1346,74 +1342,56 @@ ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, /**< ecma-
13461342
ecma_char_t zt_string1_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1];
13471343
ecma_char_t zt_string2_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1];
13481344

1349-
if (string1_p->container == ECMA_STRING_CONTAINER_LIT_TABLE)
1350-
{
1351-
const literal lit = serializer_get_literal_by_id (string1_p->u.lit_index);
1352-
JERRY_ASSERT (lit.type == LIT_STR);
1353-
zt_string1_p = literal_to_zt (lit);
1354-
}
1355-
else
1356-
{
1357-
ssize_t req_size = ecma_string_to_zt_string (string1_p,
1358-
zt_string1_buffer,
1359-
sizeof (zt_string1_buffer));
1345+
ssize_t req_size = ecma_string_to_zt_string (string1_p,
1346+
zt_string1_buffer,
1347+
sizeof (zt_string1_buffer));
13601348

1361-
if (req_size < 0)
1349+
if (req_size < 0)
1350+
{
1351+
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
1352+
if (heap_buffer_p == NULL)
13621353
{
1363-
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
1364-
if (heap_buffer_p == NULL)
1365-
{
1366-
jerry_fatal (ERR_OUT_OF_MEMORY);
1367-
}
1354+
jerry_fatal (ERR_OUT_OF_MEMORY);
1355+
}
13681356

1369-
ssize_t bytes_copied = ecma_string_to_zt_string (string1_p,
1370-
heap_buffer_p,
1371-
-req_size);
1357+
ssize_t bytes_copied = ecma_string_to_zt_string (string1_p,
1358+
heap_buffer_p,
1359+
-req_size);
13721360

1373-
JERRY_ASSERT (bytes_copied > 0);
1361+
JERRY_ASSERT (bytes_copied > 0);
13741362

1375-
zt_string1_p = heap_buffer_p;
1376-
is_zt_string1_on_heap = true;
1377-
}
1378-
else
1379-
{
1380-
zt_string1_p = zt_string1_buffer;
1381-
}
1382-
}
1383-
1384-
if (string2_p->container == ECMA_STRING_CONTAINER_LIT_TABLE)
1385-
{
1386-
const literal lit = serializer_get_literal_by_id (string2_p->u.lit_index);
1387-
JERRY_ASSERT (lit.type == LIT_STR);
1388-
zt_string2_p = literal_to_zt (lit);
1363+
zt_string1_p = heap_buffer_p;
1364+
is_zt_string1_on_heap = true;
13891365
}
13901366
else
13911367
{
1392-
ssize_t req_size = ecma_string_to_zt_string (string2_p,
1393-
zt_string2_buffer,
1394-
sizeof (zt_string2_buffer));
1368+
zt_string1_p = zt_string1_buffer;
1369+
}
13951370

1396-
if (req_size < 0)
1371+
req_size = ecma_string_to_zt_string (string2_p,
1372+
zt_string2_buffer,
1373+
sizeof (zt_string2_buffer));
1374+
1375+
if (req_size < 0)
1376+
{
1377+
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
1378+
if (heap_buffer_p == NULL)
13971379
{
1398-
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
1399-
if (heap_buffer_p == NULL)
1400-
{
1401-
jerry_fatal (ERR_OUT_OF_MEMORY);
1402-
}
1380+
jerry_fatal (ERR_OUT_OF_MEMORY);
1381+
}
14031382

1404-
ssize_t bytes_copied = ecma_string_to_zt_string (string2_p,
1405-
heap_buffer_p,
1406-
-req_size);
1383+
ssize_t bytes_copied = ecma_string_to_zt_string (string2_p,
1384+
heap_buffer_p,
1385+
-req_size);
14071386

1408-
JERRY_ASSERT (bytes_copied > 0);
1387+
JERRY_ASSERT (bytes_copied > 0);
14091388

1410-
zt_string2_p = heap_buffer_p;
1411-
is_zt_string2_on_heap = true;
1412-
}
1413-
else
1414-
{
1415-
zt_string2_p = zt_string2_buffer;
1416-
}
1389+
zt_string2_p = heap_buffer_p;
1390+
is_zt_string2_on_heap = true;
1391+
}
1392+
else
1393+
{
1394+
zt_string2_p = zt_string2_buffer;
14171395
}
14181396

14191397
bool is_first_less_than_second = ecma_compare_zt_strings_relational (zt_string1_p,
@@ -1445,9 +1423,9 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
14451423

14461424
if (container == ECMA_STRING_CONTAINER_LIT_TABLE)
14471425
{
1448-
const literal lit = serializer_get_literal_by_id (string_p->u.lit_index);
1449-
1450-
return lit.data.lp.length;
1426+
literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
1427+
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
1428+
return lit_charset_record_get_length (lit);
14511429
}
14521430
else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING)
14531431
{

jerry-core/ecma/base/ecma-helpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ extern bool ecma_is_completion_value_empty (ecma_completion_value_t value);
112112
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p);
113113
extern ecma_string_t* ecma_new_ecma_string_from_uint32 (uint32_t uint_number);
114114
extern ecma_string_t* ecma_new_ecma_string_from_number (ecma_number_t number);
115-
extern void ecma_new_ecma_string_on_stack_from_lit_index (ecma_string_t *string_p,
116-
literal_index_t lit_index);
117-
extern ecma_string_t* ecma_new_ecma_string_from_lit_index (literal_index_t lit_index);
115+
extern void ecma_new_ecma_string_on_stack_from_lit_cp (ecma_string_t *string_p,
116+
lit_cpointer_t lit_index);
117+
extern ecma_string_t *ecma_new_ecma_string_from_lit_cp (lit_cpointer_t lit_cp);
118118
extern void ecma_new_ecma_string_on_stack_from_magic_string_id (ecma_string_t *string_p,
119119
ecma_magic_string_id_t id);
120120
extern ecma_string_t* ecma_new_ecma_string_from_magic_string_id (ecma_magic_string_id_t id);

jerry-core/ecma/operations/ecma-function-object.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
#include "ecma-exceptions.h"
1919
#include "ecma-function-object.h"
2020
#include "ecma-gc.h"
21-
#include "ecma-globals.h"
2221
#include "ecma-helpers.h"
2322
#include "ecma-lex-env.h"
2423
#include "ecma-objects.h"
2524
#include "ecma-objects-general.h"
2625
#include "ecma-objects-arguments.h"
2726
#include "ecma-try-catch-macro.h"
28-
#include "jrt.h"
2927

3028
#define JERRY_INTERNAL
3129
#include "jerry-internal.h"

jerry-core/jerry.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@
2626
#include "ecma-init-finalize.h"
2727
#include "ecma-objects.h"
2828
#include "ecma-objects-general.h"
29-
#include "jerry.h"
30-
#include "jrt.h"
31-
#include "mem-heap.h"
32-
#include "mem-poolman.h"
3329
#include "parser.h"
3430
#include "serializer.h"
35-
#include "vm.h"
3631

3732
#define JERRY_INTERNAL
3833
#include "jerry-internal.h"

0 commit comments

Comments
 (0)