Skip to content

Commit 2e6343f

Browse files
committed
Optimize LCache operation.
The cache stores only real properties now, because storing NULLs has little benefit according to tests. Since only real properties are stored now, there is no need to create real references to objects and property names, which reduces the keeping of dead objects after garbage collection. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent d7f9543 commit 2e6343f

File tree

12 files changed

+178
-246
lines changed

12 files changed

+178
-246
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,6 @@ ecma_try_to_give_back_some_memory (jmem_try_give_memory_back_severity_t severity
583583
JERRY_ASSERT (severity == JMEM_TRY_GIVE_MEMORY_BACK_SEVERITY_HIGH);
584584

585585
/* Freeing as much memory as we currently can */
586-
ecma_lcache_invalidate_all ();
587-
588586
ecma_gc_run ();
589587
}
590588
} /* ecma_try_to_give_back_some_memory */

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ ecma_copy_or_ref_ecma_string (ecma_string_t *string_p) /**< string descriptor */
527527
if (unlikely (string_p->refs_and_container >= ECMA_STRING_MAX_REF))
528528
{
529529
/* First trying to free unreachable objects that maybe refer to the string */
530-
ecma_lcache_invalidate_all ();
531530
ecma_gc_run ();
532531

533532
if (string_p->refs_and_container >= ECMA_STRING_MAX_REF)

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,6 @@ ecma_create_named_data_property (ecma_object_t *object_p, /**< object */
586586

587587
name_p = ecma_copy_or_ref_ecma_string (name_p);
588588

589-
ecma_lcache_invalidate (object_p, name_p, NULL);
590-
591589
ecma_property_value_t value;
592590
value.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
593591

@@ -614,8 +612,6 @@ ecma_create_named_accessor_property (ecma_object_t *object_p, /**< object */
614612

615613
name_p = ecma_copy_or_ref_ecma_string (name_p);
616614

617-
ecma_lcache_invalidate (object_p, name_p, NULL);
618-
619615
ecma_property_value_t value;
620616
ECMA_SET_POINTER (value.getter_setter_pair.getter_p, get_p);
621617
ECMA_SET_POINTER (value.getter_setter_pair.setter_p, set_p);
@@ -636,9 +632,9 @@ ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in
636632
JERRY_ASSERT (obj_p != NULL);
637633
JERRY_ASSERT (name_p != NULL);
638634

639-
ecma_property_t *property_p;
635+
ecma_property_t *property_p = ecma_lcache_lookup (obj_p, name_p);
640636

641-
if (ecma_lcache_lookup (obj_p, name_p, &property_p))
637+
if (property_p != NULL)
642638
{
643639
return property_p;
644640
}
@@ -649,14 +645,23 @@ ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in
649645
if (prop_iter_p != NULL
650646
&& ECMA_PROPERTY_GET_TYPE (prop_iter_p->types + 0) == ECMA_PROPERTY_TYPE_HASHMAP)
651647
{
652-
property_p = ecma_property_hashmap_find ((ecma_property_hashmap_t *) prop_iter_p, name_p);
653-
ecma_lcache_insert (obj_p, name_p, property_p);
648+
ecma_string_t *property_real_name_p;
649+
property_p = ecma_property_hashmap_find ((ecma_property_hashmap_t *) prop_iter_p,
650+
name_p,
651+
&property_real_name_p);
652+
653+
if (property_p != NULL
654+
&& !ecma_is_property_lcached (property_p))
655+
{
656+
ecma_lcache_insert (obj_p, property_real_name_p, property_p);
657+
}
654658

655659
return property_p;
656660
}
657661
#endif /* !CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
658662

659663
property_p = NULL;
664+
ecma_string_t *property_name_p = NULL;
660665

661666
uint32_t steps = 0;
662667

@@ -670,8 +675,8 @@ ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in
670675

671676
if (prop_pair_p->names_cp[0] != ECMA_NULL_POINTER)
672677
{
673-
ecma_string_t *property_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
674-
prop_pair_p->names_cp[0]);
678+
property_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
679+
prop_pair_p->names_cp[0]);
675680

676681
if (ecma_compare_ecma_strings (name_p, property_name_p))
677682
{
@@ -682,8 +687,8 @@ ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in
682687

683688
if (prop_pair_p->names_cp[1] != ECMA_NULL_POINTER)
684689
{
685-
ecma_string_t *property_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
686-
prop_pair_p->names_cp[1]);
690+
property_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
691+
prop_pair_p->names_cp[1]);
687692

688693
if (ecma_compare_ecma_strings (name_p, property_name_p))
689694
{
@@ -703,7 +708,11 @@ ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in
703708
ecma_property_hashmap_create (obj_p);
704709
}
705710

706-
ecma_lcache_insert (obj_p, name_p, property_p);
711+
if (property_p != NULL
712+
&& !ecma_is_property_lcached (property_p))
713+
{
714+
ecma_lcache_insert (obj_p, property_name_p, property_p);
715+
}
707716

708717
return property_p;
709718
} /* ecma_find_named_property */
@@ -875,12 +884,18 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
875884
case ECMA_PROPERTY_TYPE_NAMEDDATA:
876885
{
877886
ecma_free_named_data_property (object_p, property_p);
878-
ecma_lcache_invalidate (object_p, name_p, property_p);
887+
if (ecma_is_property_lcached (property_p))
888+
{
889+
ecma_lcache_invalidate (object_p, name_p, property_p);
890+
}
879891
break;
880892
}
881893
case ECMA_PROPERTY_TYPE_NAMEDACCESSOR:
882894
{
883-
ecma_lcache_invalidate (object_p, name_p, property_p);
895+
if (ecma_is_property_lcached (property_p))
896+
{
897+
ecma_lcache_invalidate (object_p, name_p, property_p);
898+
}
884899
break;
885900
}
886901
case ECMA_PROPERTY_TYPE_INTERNAL:
@@ -1270,7 +1285,7 @@ ecma_is_property_lcached (ecma_property_t *prop_p) /**< property */
12701285
/**
12711286
* Set value of flag indicating whether the property is registered in LCache
12721287
*/
1273-
void
1288+
inline void __attr_always_inline___
12741289
ecma_set_property_lcached (ecma_property_t *prop_p, /**< property */
12751290
bool is_lcached) /**< contained (true) or not (false) */
12761291
{

jerry-core/ecma/base/ecma-init-finalize.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ ecma_finalize (void)
5151
jmem_unregister_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
5252

5353
ecma_finalize_environment ();
54-
ecma_lcache_invalidate_all ();
5554
ecma_finalize_builtins ();
5655
ecma_gc_run ();
5756
} /* ecma_finalize */

0 commit comments

Comments
 (0)