Skip to content

Commit 2662694

Browse files
authored
Inline ecma_gc_set_object_visited for performance critical code paths (#3154)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 57abd26 commit 2662694

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* @return true - if visited
6060
* false - otherwise
6161
*/
62-
static inline bool
62+
static inline bool JERRY_ATTR_ALWAYS_INLINE
6363
ecma_gc_is_object_visited (ecma_object_t *object_p) /**< object */
6464
{
6565
JERRY_ASSERT (object_p != NULL);
@@ -69,15 +69,25 @@ ecma_gc_is_object_visited (ecma_object_t *object_p) /**< object */
6969

7070
/**
7171
* Set visited flag of the object.
72+
* Note: This macro can be inlined for performance critical code paths
7273
*/
73-
static inline void
74+
#define ECMA_GC_SET_OBJECT_VISITED(object_p) \
75+
do \
76+
{ \
77+
if ((object_p)->type_flags_refs < ECMA_OBJECT_REF_ONE) \
78+
{ \
79+
(object_p)->type_flags_refs |= ECMA_OBJECT_REF_ONE; \
80+
} \
81+
} while (0)
82+
83+
/**
84+
* Set visited flag of the object.
85+
*/
86+
static void JERRY_ATTR_NOINLINE
7487
ecma_gc_set_object_visited (ecma_object_t *object_p) /**< object */
7588
{
7689
/* Set reference counter to one if it is zero. */
77-
if (object_p->type_flags_refs < ECMA_OBJECT_REF_ONE)
78-
{
79-
object_p->type_flags_refs |= ECMA_OBJECT_REF_ONE;
80-
}
90+
ECMA_GC_SET_OBJECT_VISITED (object_p);
8191
} /* ecma_gc_set_object_visited */
8292

8393
/**
@@ -144,7 +154,7 @@ ecma_gc_mark_properties (ecma_property_pair_t *property_pair_p) /**< property pa
144154
{
145155
ecma_object_t *value_obj_p = ecma_get_object_from_value (value);
146156

147-
ecma_gc_set_object_visited (value_obj_p);
157+
ECMA_GC_SET_OBJECT_VISITED (value_obj_p);
148158
}
149159
break;
150160
}
@@ -305,7 +315,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
305315

306316
if (outer_lex_env_cp != JMEM_CP_NULL)
307317
{
308-
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, outer_lex_env_cp));
318+
ECMA_GC_SET_OBJECT_VISITED (ECMA_GET_NON_NULL_POINTER (ecma_object_t, outer_lex_env_cp));
309319
}
310320

311321
if (ecma_get_lex_env_type (object_p) != ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
@@ -322,7 +332,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
322332

323333
if (proto_cp != JMEM_CP_NULL)
324334
{
325-
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp));
335+
ECMA_GC_SET_OBJECT_VISITED (ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp));
326336
}
327337

328338
switch (ecma_get_object_type (object_p))
@@ -432,7 +442,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
432442
{
433443
if (ecma_is_value_object (values_p[i]))
434444
{
435-
ecma_gc_set_object_visited (ecma_get_object_from_value (values_p[i]));
445+
ECMA_GC_SET_OBJECT_VISITED (ecma_get_object_from_value (values_p[i]));
436446
}
437447
}
438448

@@ -481,7 +491,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
481491
{
482492
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
483493

484-
ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
494+
ECMA_GC_SET_OBJECT_VISITED (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
485495
ext_func_p->u.function.scope_cp));
486496
}
487497
break;
@@ -663,8 +673,8 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
663673
jmem_cpointer_t name_cp = prop_pair_p->names_cp[i];
664674

665675
/* Call the native's free callback. */
666-
if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC
667-
&& (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER))
676+
if (JERRY_UNLIKELY (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC
677+
&& (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER)))
668678
{
669679
ecma_gc_free_native_pointer (property_p);
670680
}

0 commit comments

Comments
 (0)