Optimize lcache insert (#3155)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2019-09-30 16:46:18 +02:00
committed by GitHub
parent a8fb4eee1e
commit 57abd26c33
2 changed files with 44 additions and 36 deletions
+41 -32
View File
@@ -28,10 +28,19 @@
#if ENABLED (JERRY_LCACHE) #if ENABLED (JERRY_LCACHE)
/**
* Bitshift index for calculating hash.
*/
#if ENABLED (JERRY_CPOINTER_32_BIT)
#define ECMA_LCACHE_HASH_BITSHIFT_INDEX (2 * JMEM_ALIGNMENT_LOG)
#else /* !ENABLED (JERRY_CPOINTER_32_BIT) */
#define ECMA_LCACHE_HASH_BITSHIFT_INDEX 0
#endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
/** /**
* Mask for hash bits * Mask for hash bits
*/ */
#define ECMA_LCACHE_HASH_MASK (ECMA_LCACHE_HASH_ROWS_COUNT - 1) #define ECMA_LCACHE_HASH_MASK ((ECMA_LCACHE_HASH_ROWS_COUNT - 1) << ECMA_LCACHE_HASH_BITSHIFT_INDEX)
/** /**
* Bitshift index for creating property identifier * Bitshift index for creating property identifier
@@ -69,15 +78,15 @@ ecma_lcache_row_index (jmem_cpointer_t object_cp, /**< compressed pointer to obj
{ {
/* Randomize the property name with the object pointer using a xor operation, /* Randomize the property name with the object pointer using a xor operation,
* so properties of different objects with the same name can be cached effectively. */ * so properties of different objects with the same name can be cached effectively. */
return (size_t) ((name_cp ^ object_cp) & ECMA_LCACHE_HASH_MASK); return (size_t) (((name_cp ^ object_cp) & ECMA_LCACHE_HASH_MASK) >> ECMA_LCACHE_HASH_BITSHIFT_INDEX);
} /* ecma_lcache_row_index */ } /* ecma_lcache_row_index */
/** /**
* Insert an entry into LCache * Insert an entry into LCache
*/ */
void void
ecma_lcache_insert (ecma_object_t *object_p, /**< object */ ecma_lcache_insert (const ecma_object_t *object_p, /**< object */
jmem_cpointer_t name_cp, /**< property name */ const jmem_cpointer_t name_cp, /**< property name */
ecma_property_t *prop_p) /**< property */ ecma_property_t *prop_p) /**< property */
{ {
JERRY_ASSERT (object_p != NULL); JERRY_ASSERT (object_p != NULL);
@@ -91,31 +100,32 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
ECMA_SET_NON_NULL_POINTER (object_cp, object_p); ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
size_t row_index = ecma_lcache_row_index (object_cp, name_cp); size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
ecma_lcache_hash_entry_t *entries_p = JERRY_CONTEXT (lcache) [row_index]; ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
uint32_t entry_index; do
for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
{ {
if (entries_p[entry_index].id == 0) if (entry_p->id == 0)
{ {
break; goto insert;
} }
entry_p++;
}
while (entry_p < entry_end_p);
/* Invalidate the last entry. */
ecma_lcache_invalidate_entry (--entry_p);
/* Shift other entries towards the end. */
for (uint32_t i = 0; i < ECMA_LCACHE_HASH_ROW_LENGTH - 1; i++)
{
entry_p->id = entry_p[-1].id;
entry_p->prop_p = entry_p[-1].prop_p;
entry_p--;
} }
if (entry_index == ECMA_LCACHE_HASH_ROW_LENGTH) insert:
{
/* Invalidate the last entry. */
ecma_lcache_invalidate_entry (entries_p + ECMA_LCACHE_HASH_ROW_LENGTH - 1);
/* Shift other entries towards the end. */
for (uint32_t i = ECMA_LCACHE_HASH_ROW_LENGTH - 1; i > 0; i--)
{
entries_p[i] = entries_p[i - 1];
}
entry_index = 0;
}
ecma_lcache_hash_entry_t *entry_p = entries_p + entry_index;
entry_p->prop_p = prop_p; entry_p->prop_p = prop_p;
entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp); entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp);
@@ -129,7 +139,7 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
* NULL otherwise * NULL otherwise
*/ */
inline ecma_property_t * JERRY_ATTR_ALWAYS_INLINE inline ecma_property_t * JERRY_ATTR_ALWAYS_INLINE
ecma_lcache_lookup (ecma_object_t *object_p, /**< object */ ecma_lcache_lookup (const ecma_object_t *object_p, /**< object */
const ecma_string_t *prop_name_p) /**< property's name */ const ecma_string_t *prop_name_p) /**< property's name */
{ {
JERRY_ASSERT (object_p != NULL); JERRY_ASSERT (object_p != NULL);
@@ -138,17 +148,16 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
jmem_cpointer_t object_cp; jmem_cpointer_t object_cp;
ECMA_SET_NON_NULL_POINTER (object_cp, object_p); ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
ecma_property_t prop_name_type; ecma_property_t prop_name_type = ECMA_DIRECT_STRING_PTR;
jmem_cpointer_t prop_name_cp; jmem_cpointer_t prop_name_cp;
if (ECMA_IS_DIRECT_STRING (prop_name_p)) if (JERRY_UNLIKELY (ECMA_IS_DIRECT_STRING (prop_name_p)))
{ {
prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p); prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p);
prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p); prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p);
} }
else else
{ {
prop_name_type = ECMA_DIRECT_STRING_PTR;
ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p); ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p);
} }
@@ -156,18 +165,18 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index]; ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH; ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp); ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp);
while (entry_p < entry_end_p) do
{ {
if (entry_p->id == id && ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type) if (entry_p->id == id && JERRY_LIKELY (ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type))
{ {
JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p)); JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p));
return entry_p->prop_p; return entry_p->prop_p;
} }
entry_p++; entry_p++;
} }
while (entry_p < entry_end_p);
return NULL; return NULL;
} /* ecma_lcache_lookup */ } /* ecma_lcache_lookup */
@@ -176,8 +185,8 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
* Invalidate LCache entries associated with given object and property name / property * Invalidate LCache entries associated with given object and property name / property
*/ */
void void
ecma_lcache_invalidate (ecma_object_t *object_p, /**< object */ ecma_lcache_invalidate (const ecma_object_t *object_p, /**< object */
jmem_cpointer_t name_cp, /**< property name */ const jmem_cpointer_t name_cp, /**< property name */
ecma_property_t *prop_p) /**< property */ ecma_property_t *prop_p) /**< property */
{ {
JERRY_ASSERT (object_p != NULL); JERRY_ASSERT (object_p != NULL);
+3 -4
View File
@@ -24,10 +24,9 @@
*/ */
#if ENABLED (JERRY_LCACHE) #if ENABLED (JERRY_LCACHE)
void ecma_lcache_insert (const ecma_object_t *object_p, const jmem_cpointer_t name_cp, ecma_property_t *prop_p);
void ecma_lcache_insert (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *prop_p); ecma_property_t *ecma_lcache_lookup (const ecma_object_t *object_p, const ecma_string_t *prop_name_p);
ecma_property_t *ecma_lcache_lookup (ecma_object_t *object_p, const ecma_string_t *prop_name_p); void ecma_lcache_invalidate (const ecma_object_t *object_p, const jmem_cpointer_t name_cp, ecma_property_t *prop_p);
void ecma_lcache_invalidate (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *prop_p);
#endif /* ENABLED (JERRY_LCACHE) */ #endif /* ENABLED (JERRY_LCACHE) */