Skip to content

Commit 90f37a5

Browse files
rerobikadbatyai
authored andcommitted
Optimize LCache entrys keys (#2767)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent ea195cd commit 90f37a5

File tree

2 files changed

+39
-48
lines changed

2 files changed

+39
-48
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: 29 additions & 43 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

@@ -54,11 +65,11 @@ ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t *entry_p) /**< entry to i
5465
*/
5566
static inline size_t JERRY_ATTR_ALWAYS_INLINE
5667
ecma_lcache_row_index (jmem_cpointer_t object_cp, /**< compressed pointer to object */
57-
lit_string_hash_t name_hash) /**< property name hash */
68+
jmem_cpointer_t name_cp) /**< compressed pointer to property name */
5869
{
59-
/* Randomize the hash of the property name with the object pointer using a xor operation,
70+
/* Randomize the property name with the object pointer using a xor operation,
6071
* so properties of different objects with the same name can be cached effectively. */
61-
return (size_t) ((name_hash ^ object_cp) & ECMA_LCACHE_HASH_MASK);
72+
return (size_t) ((name_cp ^ object_cp) & ECMA_LCACHE_HASH_MASK);
6273
} /* ecma_lcache_row_index */
6374

6475
/**
@@ -79,14 +90,13 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
7990

8091
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
8192

82-
lit_string_hash_t name_hash = ecma_string_get_property_name_hash (*prop_p, name_cp);
83-
size_t row_index = ecma_lcache_row_index (object_cp, name_hash);
93+
size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
8494
ecma_lcache_hash_entry_t *entries_p = JERRY_CONTEXT (lcache) [row_index];
8595

8696
uint32_t entry_index;
8797
for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
8898
{
89-
if (entries_p[entry_index].object_cp == ECMA_NULL_POINTER)
99+
if (entries_p[entry_index].id == 0)
90100
{
91101
break;
92102
}
@@ -102,14 +112,12 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
102112
{
103113
entries_p[i] = entries_p[i - 1];
104114
}
105-
106115
entry_index = 0;
107116
}
108117

109118
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;
112119
entry_p->prop_p = prop_p;
120+
entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp);
113121

114122
ecma_set_property_lcached (entry_p->prop_p, true);
115123
} /* ecma_lcache_insert */
@@ -132,53 +140,32 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
132140

133141
ecma_property_t prop_name_type;
134142
jmem_cpointer_t prop_name_cp;
135-
lit_string_hash_t name_hash;
136143

137144
if (ECMA_IS_DIRECT_STRING (prop_name_p))
138145
{
139146
prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p);
140-
141-
uintptr_t value = ECMA_GET_DIRECT_STRING_VALUE (prop_name_p);
142-
prop_name_cp = (jmem_cpointer_t) value;
143-
name_hash = (lit_string_hash_t) value;
144-
145-
if (prop_name_type == ECMA_DIRECT_STRING_MAGIC_EX)
146-
{
147-
name_hash = (lit_string_hash_t) (name_hash + LIT_MAGIC_STRING__COUNT);
148-
}
147+
prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p);
149148
}
150149
else
151150
{
152151
prop_name_type = ECMA_DIRECT_STRING_PTR;
153-
154152
ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p);
155-
name_hash = prop_name_p->hash;
156153
}
157154

158-
size_t row_index = ecma_lcache_row_index (object_cp, name_hash);
155+
size_t row_index = ecma_lcache_row_index (object_cp, prop_name_cp);
159156

160157
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
161158
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
162159

160+
ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp);
161+
163162
while (entry_p < entry_end_p)
164163
{
165-
if (entry_p->object_cp == object_cp
166-
&& entry_p->prop_name_cp == prop_name_cp)
164+
if (entry_p->id == id && ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type)
167165
{
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
178-
{
179-
/* They can be equal, but generic string comparison is too costly. */
166+
JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p));
167+
return entry_p->prop_p;
180168
}
181-
182169
entry_p++;
183170
}
184171

@@ -202,18 +189,17 @@ ecma_lcache_invalidate (ecma_object_t *object_p, /**< object */
202189
jmem_cpointer_t object_cp;
203190
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
204191

205-
lit_string_hash_t name_hash = ecma_string_get_property_name_hash (*prop_p, name_cp);
206-
size_t row_index = ecma_lcache_row_index (object_cp, name_hash);
192+
size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
207193
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
208194

209195
while (true)
210196
{
211197
/* The property must be present. */
212198
JERRY_ASSERT (entry_p - JERRY_CONTEXT (lcache) [row_index] < ECMA_LCACHE_HASH_ROW_LENGTH);
213199

214-
if (entry_p->object_cp != ECMA_NULL_POINTER && entry_p->prop_p == prop_p)
200+
if (entry_p->id != 0 && entry_p->prop_p == prop_p)
215201
{
216-
JERRY_ASSERT (entry_p->object_cp == object_cp);
202+
JERRY_ASSERT (entry_p->id == ECMA_LCACHE_CREATE_ID (object_cp, name_cp));
217203

218204
ecma_lcache_invalidate_entry (entry_p);
219205
return;

0 commit comments

Comments
 (0)