Skip to content

Commit 257b767

Browse files
committed
Opt LCache
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
1 parent a1fdcf0 commit 257b767

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,14 @@ typedef struct
14891489
} ecma_lit_storage_item_t;
14901490

14911491
#ifndef CONFIG_ECMA_LCACHE_DISABLE
1492+
/**
1493+
* Container of an LCache entry identifier
1494+
*/
1495+
#ifdef JERRY_CPOINTER_32_BIT
1496+
typedef uint64_t ecma_lcache_hash_entry_id_t;
1497+
#else /* !JERRY_CPOINTER_32_BIT */
1498+
typedef uint32_t ecma_lcache_hash_entry_id_t;
1499+
#endif /* JERRY_CPOINTER_32_BIT */
14921500

14931501
/**
14941502
* Entry of LCache hash table
@@ -1498,11 +1506,8 @@ typedef struct
14981506
/** Pointer to a property of the object */
14991507
ecma_property_t *prop_p;
15001508

1501-
/** Compressed pointer to object (ECMA_NULL_POINTER marks record empty) */
1502-
jmem_cpointer_t object_cp;
1503-
1504-
/** Compressed pointer to property's name */
1505-
jmem_cpointer_t prop_name_cp;
1509+
/** Entry identifier in LCache */
1510+
ecma_lcache_hash_entry_id_t id;
15061511
} ecma_lcache_hash_entry_t;
15071512

15081513
/**

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,28 @@
3333
*/
3434
#define ECMA_LCACHE_HASH_MASK (ECMA_LCACHE_HASH_ROWS_COUNT - 1)
3535

36+
/**
37+
* Bitshift index for creating property identifier
38+
*/
39+
#define ECMA_LCACHE_HASH_ENTRY_ID_SHIFT (8 * sizeof (jmem_cpointer_t))
40+
41+
/**
42+
* Create property identifier
43+
*/
44+
#define ECMA_LCACHE_CREATE_ID(object_cp, name_cp) \
45+
(((ecma_lcache_hash_entry_id_t) (object_cp) << ECMA_LCACHE_HASH_ENTRY_ID_SHIFT) | (name_cp))
46+
3647
/**
3748
* Invalidate specified LCache entry
3849
*/
3950
static inline void JERRY_ATTR_ALWAYS_INLINE
4051
ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t *entry_p) /**< entry to invalidate */
4152
{
4253
JERRY_ASSERT (entry_p != NULL);
43-
JERRY_ASSERT (entry_p->object_cp != ECMA_NULL_POINTER);
54+
JERRY_ASSERT (entry_p->id != 0);
4455
JERRY_ASSERT (entry_p->prop_p != NULL);
4556

46-
entry_p->object_cp = ECMA_NULL_POINTER;
57+
entry_p->id = 0;
4758
ecma_set_property_lcached (entry_p->prop_p, false);
4859
} /* ecma_lcache_invalidate_entry */
4960

@@ -86,7 +97,7 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
8697
uint32_t entry_index;
8798
for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
8899
{
89-
if (entries_p[entry_index].object_cp == ECMA_NULL_POINTER)
100+
if (entries_p[entry_index].id == 0)
90101
{
91102
break;
92103
}
@@ -107,9 +118,8 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
107118
}
108119

109120
ecma_lcache_hash_entry_t *entry_p = entries_p + entry_index;
110-
ECMA_SET_NON_NULL_POINTER (entry_p->object_cp, object_p);
111-
entry_p->prop_name_cp = name_cp;
112121
entry_p->prop_p = prop_p;
122+
entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp);
113123

114124
ecma_set_property_lcached (entry_p->prop_p, true);
115125
} /* ecma_lcache_insert */
@@ -130,7 +140,7 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
130140
jmem_cpointer_t object_cp;
131141
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
132142

133-
ecma_property_t prop_name_type;
143+
ecma_property_t prop_name_type = ECMA_DIRECT_STRING_PTR;
134144
jmem_cpointer_t prop_name_cp;
135145
lit_string_hash_t name_hash;
136146

@@ -149,8 +159,6 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
149159
}
150160
else
151161
{
152-
prop_name_type = ECMA_DIRECT_STRING_PTR;
153-
154162
ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p);
155163
name_hash = prop_name_p->hash;
156164
}
@@ -160,25 +168,15 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
160168
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
161169
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
162170

171+
ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp);
172+
163173
while (entry_p < entry_end_p)
164174
{
165-
if (entry_p->object_cp == object_cp
166-
&& entry_p->prop_name_cp == prop_name_cp)
167-
{
168-
ecma_property_t *prop_p = entry_p->prop_p;
169-
170-
JERRY_ASSERT (prop_p != NULL && ecma_is_property_lcached (prop_p));
171-
172-
if (ECMA_PROPERTY_GET_NAME_TYPE (*prop_p) == prop_name_type)
173-
{
174-
return prop_p;
175-
}
176-
}
177-
else
175+
if (entry_p->id == id && ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type)
178176
{
179-
/* They can be equal, but generic string comparison is too costly. */
177+
JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p));
178+
return entry_p->prop_p;
180179
}
181-
182180
entry_p++;
183181
}
184182

@@ -211,9 +209,9 @@ ecma_lcache_invalidate (ecma_object_t *object_p, /**< object */
211209
/* The property must be present. */
212210
JERRY_ASSERT (entry_p - JERRY_CONTEXT (lcache) [row_index] < ECMA_LCACHE_HASH_ROW_LENGTH);
213211

214-
if (entry_p->object_cp != ECMA_NULL_POINTER && entry_p->prop_p == prop_p)
212+
if (entry_p->id != 0 && entry_p->prop_p == prop_p)
215213
{
216-
JERRY_ASSERT (entry_p->object_cp == object_cp);
214+
JERRY_ASSERT (entry_p->id == ECMA_LCACHE_CREATE_ID (object_cp, name_cp));
217215

218216
ecma_lcache_invalidate_entry (entry_p);
219217
return;

0 commit comments

Comments
 (0)