Skip to content

Commit 4d02437

Browse files
committed
Minor fixes
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent 3e08bf5 commit 4d02437

File tree

7 files changed

+53
-14
lines changed

7 files changed

+53
-14
lines changed

jerry-core/ecma/base/ecma-gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "jrt.h"
3333
#include "jrt-libc-includes.h"
3434
#include "jrt-bit-fields.h"
35+
#include "re-compiler.h"
3536
#include "vm-defines.h"
3637
#include "vm-stack.h"
3738

@@ -549,6 +550,11 @@ ecma_gc_run (void)
549550
ecma_gc_objects_lists[ECMA_GC_COLOR_BLACK] = NULL;
550551

551552
ecma_gc_visited_flip_flag = !ecma_gc_visited_flip_flag;
553+
554+
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
555+
/* Free RegExp bytecodes stored in cache */
556+
re_cache_gc_run ();
557+
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
552558
} /* ecma_gc_run */
553559

554560
/**

jerry-core/ecma/operations/ecma-regexp-object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ re_initialize_props (ecma_object_t *re_obj_p, /**< RegExp obejct */
234234
* Returned value must be freed with ecma_free_value
235235
*/
236236
ecma_value_t
237-
ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t *bytecode_p) /**< input pattern */
237+
ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t *bytecode_p) /**< RegExp bytecode */
238238
{
239239
JERRY_ASSERT (bytecode_p != NULL);
240240

jerry-core/jerry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,9 +1653,9 @@ jerry_cleanup (void)
16531653

16541654
bool is_show_mem_stats = ((jerry_flags & JERRY_FLAG_MEM_STATS) != 0);
16551655

1656+
vm_finalize ();
16561657
ecma_finalize ();
16571658
lit_finalize ();
1658-
vm_finalize ();
16591659
mem_finalize (is_show_mem_stats);
16601660
} /* jerry_cleanup */
16611661

jerry-core/parser/js/js-lexer.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,6 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */
18121812
ecma_value_t completion_value;
18131813

18141814
ecma_string_t *pattern_str_p = ecma_new_ecma_string_from_utf8 (regex_start_p, length);
1815-
// FIXME: check return value of 're_compile_bytecode' and throw an error
18161815
completion_value = re_compile_bytecode (&re_bytecode_p,
18171816
pattern_str_p,
18181817
current_flags);

jerry-core/parser/regexp/re-bytecode.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
/**
3535
* Size of the RegExp bytecode cache
3636
*/
37-
#define RE_CHACHE_SIZE 10u
37+
#define RE_CACHE_SIZE 8u
38+
39+
/**
40+
* RegExp flags mask (first 10 bits are for reference count and the rest for the actual RegExp flags)
41+
*/
42+
#define RE_FLAGS_MASK 0x3F
3843

3944
/**
4045
* RegExp opcodes

jerry-core/parser/regexp/re-compiler.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,31 +444,34 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
444444
return ret_value;
445445
} /* re_parse_alternative */
446446

447-
static const re_compiled_code_t *re_cache[RE_CHACHE_SIZE];
447+
static const re_compiled_code_t *re_cache[RE_CACHE_SIZE];
448448

449449
/**
450450
* Search for the given pattern in the RegExp cache
451451
*
452452
* @return compiled bytecode - if found
453-
* NULL - otherwise
453+
* NULL - otherwise
454454
*/
455-
static re_compiled_code_t *
455+
re_compiled_code_t *
456456
re_find_bytecode_in_cache (ecma_string_t *pattern_str_p, /**< pattern string */
457+
uint16_t flags, /**< flags */
457458
uint32_t *idx) /**< [out] index */
458459
{
459-
uint32_t free_idx = RE_CHACHE_SIZE;
460+
uint32_t free_idx = RE_CACHE_SIZE;
460461

461-
for (*idx = 0u; *idx < RE_CHACHE_SIZE && re_cache[*idx] != NULL; (*idx)++)
462+
for (*idx = 0u; *idx < RE_CACHE_SIZE; (*idx)++)
462463
{
463464
re_compiled_code_t *cached_bytecode_p = re_cache[*idx];
464465

465-
if ((cached_bytecode_p->flags >> ECMA_BYTECODE_REF_SHIFT) > 0)
466+
if (cached_bytecode_p != NULL)
466467
{
467468
ecma_string_t *cached_pattern_str_p;
468469
cached_pattern_str_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, cached_bytecode_p->pattern_cp);
469470

470-
if (ecma_compare_ecma_strings (cached_pattern_str_p, pattern_str_p))
471+
if ((cached_bytecode_p->flags & RE_FLAGS_MASK) == flags
472+
&& ecma_compare_ecma_strings (cached_pattern_str_p, pattern_str_p))
471473
{
474+
JERRY_DDLOG ("RegExp is found in cache\n");
472475
return re_cache[*idx];
473476
}
474477
}
@@ -479,11 +482,31 @@ re_find_bytecode_in_cache (ecma_string_t *pattern_str_p, /**< pattern string */
479482
}
480483
}
481484

485+
JERRY_DDLOG ("RegExp is NOT found in cache\n");
482486
*idx = free_idx;
483-
484487
return NULL;
485488
} /* re_find_bytecode_in_cache */
486489

490+
/**
491+
* Run gerbage collection in RegExp cache
492+
*/
493+
void
494+
re_cache_gc_run ()
495+
{
496+
for (uint32_t i = 0u; i < RE_CACHE_SIZE; i++)
497+
{
498+
re_compiled_code_t *cached_bytecode_p = re_cache[i];
499+
500+
if (cached_bytecode_p != NULL
501+
&& (cached_bytecode_p->flags >> ECMA_BYTECODE_REF_SHIFT) == 1)
502+
{ /* Only the cache has reference for the bytecode */
503+
504+
ecma_bytecode_deref (cached_bytecode_p);
505+
re_cache[i] = NULL;
506+
}
507+
}
508+
} /* re_cache_gc_run */
509+
487510
/**
488511
* Compilation of RegExp bytecode
489512
*
@@ -511,7 +534,7 @@ re_compile_bytecode (re_compiled_code_t **out_bytecode_p, /**< [out] pointer to
511534
re_ctx.bytecode_ctx_p = &bc_ctx;
512535

513536
uint32_t cache_idx;
514-
*out_bytecode_p = re_find_bytecode_in_cache (pattern_str_p, &cache_idx);
537+
*out_bytecode_p = re_find_bytecode_in_cache (pattern_str_p, flags, &cache_idx);
515538

516539
if (*out_bytecode_p != NULL)
517540
{
@@ -578,8 +601,9 @@ re_compile_bytecode (re_compiled_code_t **out_bytecode_p, /**< [out] pointer to
578601
JERRY_ASSERT (bc_ctx.block_start_p != NULL);
579602
*out_bytecode_p = (re_compiled_code_t *) bc_ctx.block_start_p;
580603

581-
if (cache_idx < RE_CHACHE_SIZE)
604+
if (cache_idx < RE_CACHE_SIZE)
582605
{
606+
ecma_bytecode_ref (*out_bytecode_p);
583607
re_cache[cache_idx] = *out_bytecode_p;
584608
}
585609
else

jerry-core/parser/regexp/re-compiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ typedef struct
5050
ecma_value_t
5151
re_compile_bytecode (re_compiled_code_t **, ecma_string_t *, uint16_t);
5252

53+
re_compiled_code_t *
54+
re_find_bytecode_in_cache (ecma_string_t *pattern_str_p, uint16_t flags, uint32_t *idx);
55+
56+
void re_cache_gc_run ();
57+
5358
/**
5459
* @}
5560
* @}

0 commit comments

Comments
 (0)