Skip to content

Commit 6f0391d

Browse files
authored
Unify internal property creation (#4373)
Furthermore free up a bit in the property descriptor. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 4399744 commit 6f0391d

20 files changed

+334
-382
lines changed

docs/04.INTERNALS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ The objects are represented as following structure:
284284
![Object properties](img/ecma_object_property.png)
285285

286286
Objects have a linked list that contains their properties. This list actually contains property pairs, in order to save memory described in the followings:
287-
A property is 7 bit long and its type field is 2 bit long which consumes 9 bit which does not fit into 1 byte but consumes 2 bytes. Hence, placing together two properties (14 bit) with the 2 bit long type field fits into 2 bytes.
287+
A property has a one byte long descriptor, a two byte long name and four byte long value. Hence 14 bytes consumed by a property pair. Another two bytes is
288+
used to show the next property pair, so the total size (16 byte) is divisible by 8.
288289

289290
#### Property Hashmap
290291

jerry-core/debugger/debugger.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,8 +1482,7 @@ jerry_debugger_exception_object_to_string (ecma_value_t exception_obj_value) /**
14821482
property_p = ecma_find_named_property (ecma_get_object_from_value (exception_obj_value),
14831483
ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE));
14841484

1485-
if (property_p == NULL
1486-
|| ECMA_PROPERTY_GET_TYPE (*property_p) != ECMA_PROPERTY_TYPE_NAMEDDATA)
1485+
if (property_p == NULL || !(*property_p & ECMA_PROPERTY_FLAG_DATA))
14871486
{
14881487
return ecma_stringbuilder_finalize (&builder);
14891488
}

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

Lines changed: 87 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "ecma-globals.h"
2626
#include "ecma-gc.h"
2727
#include "ecma-helpers.h"
28+
#include "ecma-lcache.h"
2829
#include "ecma-objects.h"
2930
#include "ecma-property-hashmap.h"
3031
#include "ecma-proxy-object.h"
@@ -223,69 +224,63 @@ ecma_gc_mark_properties (ecma_property_pair_t *property_pair_p) /**< property pa
223224
{
224225
uint8_t property = property_pair_p->header.types[index];
225226

226-
switch (ECMA_PROPERTY_GET_TYPE (property))
227+
if (JERRY_LIKELY (ECMA_PROPERTY_IS_RAW (property)))
227228
{
228-
case ECMA_PROPERTY_TYPE_NAMEDDATA:
229+
if (property & ECMA_PROPERTY_FLAG_DATA)
229230
{
230231
ecma_value_t value = property_pair_p->values[index].value;
231232

232233
if (ecma_is_value_object (value))
233234
{
234235
ecma_gc_set_object_visited (ecma_get_object_from_value (value));
235236
}
236-
break;
237+
continue;
237238
}
238-
case ECMA_PROPERTY_TYPE_NAMEDACCESSOR:
239-
{
240-
ecma_property_value_t *accessor_objs_p = property_pair_p->values + index;
241239

242-
ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (accessor_objs_p);
240+
ecma_property_value_t *accessor_objs_p = property_pair_p->values + index;
243241

244-
if (get_set_pair_p->getter_cp != JMEM_CP_NULL)
245-
{
246-
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->getter_cp));
247-
}
242+
ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (accessor_objs_p);
248243

249-
if (get_set_pair_p->setter_cp != JMEM_CP_NULL)
250-
{
251-
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->setter_cp));
252-
}
253-
break;
244+
if (get_set_pair_p->getter_cp != JMEM_CP_NULL)
245+
{
246+
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->getter_cp));
254247
}
255-
case ECMA_PROPERTY_TYPE_INTERNAL:
248+
249+
if (get_set_pair_p->setter_cp != JMEM_CP_NULL)
256250
{
257-
JERRY_ASSERT (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_MAGIC
258-
&& property_pair_p->names_cp[index] >= LIT_INTERNAL_MAGIC_STRING_FIRST_DATA
259-
&& property_pair_p->names_cp[index] < LIT_MAGIC_STRING__COUNT);
251+
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->setter_cp));
252+
}
260253

261-
#if ENABLED (JERRY_ESNEXT)
262-
if (property_pair_p->names_cp[index] == LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD)
263-
{
264-
ecma_environment_record_t *environment_record_p;
265-
environment_record_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_environment_record_t,
266-
property_pair_p->values[index].value);
254+
continue;
255+
}
267256

268-
if (environment_record_p->this_binding != ECMA_VALUE_UNINITIALIZED)
269-
{
270-
JERRY_ASSERT (ecma_is_value_object (environment_record_p->this_binding));
271-
ecma_gc_set_object_visited (ecma_get_object_from_value (environment_record_p->this_binding));
272-
}
257+
if (!ECMA_PROPERTY_IS_INTERNAL (property))
258+
{
259+
JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_DELETED
260+
|| property == ECMA_PROPERTY_TYPE_HASHMAP);
261+
continue;
262+
}
273263

274-
JERRY_ASSERT (ecma_is_value_object (environment_record_p->function_object));
275-
ecma_gc_set_object_visited (ecma_get_object_from_value (environment_record_p->function_object));
276-
}
277-
#endif /* ENABLED (JERRY_ESNEXT) */
278-
break;
279-
}
280-
default:
281-
{
282-
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (property) == ECMA_PROPERTY_TYPE_SPECIAL);
264+
JERRY_ASSERT (property_pair_p->names_cp[index] >= LIT_INTERNAL_MAGIC_STRING_FIRST_DATA
265+
&& property_pair_p->names_cp[index] < LIT_MAGIC_STRING__COUNT);
283266

284-
JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_HASHMAP
285-
|| property == ECMA_PROPERTY_TYPE_DELETED);
286-
break;
267+
#if ENABLED (JERRY_ESNEXT)
268+
if (property_pair_p->names_cp[index] == LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD)
269+
{
270+
ecma_environment_record_t *environment_record_p;
271+
environment_record_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_environment_record_t,
272+
property_pair_p->values[index].value);
273+
274+
if (environment_record_p->this_binding != ECMA_VALUE_UNINITIALIZED)
275+
{
276+
JERRY_ASSERT (ecma_is_value_object (environment_record_p->this_binding));
277+
ecma_gc_set_object_visited (ecma_get_object_from_value (environment_record_p->this_binding));
287278
}
279+
280+
JERRY_ASSERT (ecma_is_value_object (environment_record_p->function_object));
281+
ecma_gc_set_object_visited (ecma_get_object_from_value (environment_record_p->function_object));
288282
}
283+
#endif /* ENABLED (JERRY_ESNEXT) */
289284
}
290285
} /* ecma_gc_mark_properties */
291286

@@ -1311,65 +1306,73 @@ ecma_gc_free_properties (ecma_object_t *object_p) /**< object */
13111306
ecma_property_t *property_p = (ecma_property_t *) (prop_iter_p->types + i);
13121307
jmem_cpointer_t name_cp = prop_pair_p->names_cp[i];
13131308

1314-
if (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_INTERNAL)
1309+
if (*property_p == ECMA_PROPERTY_TYPE_DELETED)
13151310
{
1316-
JERRY_ASSERT (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC);
1311+
continue;
1312+
}
13171313

1318-
/* Call the native's free callback. */
1319-
switch (name_cp)
1320-
{
1314+
if (!ECMA_PROPERTY_IS_INTERNAL (*property_p))
1315+
{
1316+
ecma_free_property (object_p, name_cp, property_p);
1317+
continue;
1318+
}
1319+
1320+
/* Call the native's free callback. */
1321+
switch (name_cp)
1322+
{
13211323
#if ENABLED (JERRY_ESNEXT)
1322-
case LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD:
1323-
{
1324-
ecma_environment_record_t *environment_record_p;
1325-
environment_record_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_environment_record_t,
1324+
case LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD:
1325+
{
1326+
ecma_environment_record_t *environment_record_p;
1327+
environment_record_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_environment_record_t,
13261328
prop_pair_p->values[i].value);
1327-
jmem_heap_free_block (environment_record_p, sizeof (ecma_environment_record_t));
1328-
break;
1329-
}
1330-
case LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED:
1331-
{
1332-
ecma_value_t *compact_collection_p;
1333-
compact_collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t,
1329+
jmem_heap_free_block (environment_record_p, sizeof (ecma_environment_record_t));
1330+
break;
1331+
}
1332+
case LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED:
1333+
{
1334+
ecma_value_t *compact_collection_p;
1335+
compact_collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t,
13341336
prop_pair_p->values[i].value);
1335-
ecma_compact_collection_free (compact_collection_p);
1336-
break;
1337-
}
1337+
ecma_compact_collection_free (compact_collection_p);
1338+
break;
1339+
}
13381340
#endif /* ENABLED (JERRY_ESNEXT) */
13391341
#if ENABLED (JERRY_BUILTIN_WEAKMAP) || ENABLED (JERRY_BUILTIN_WEAKSET)
1340-
case LIT_INTERNAL_MAGIC_STRING_WEAK_REFS:
1341-
{
1342-
ecma_collection_t *refs_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
1342+
case LIT_INTERNAL_MAGIC_STRING_WEAK_REFS:
1343+
{
1344+
ecma_collection_t *refs_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
13431345
prop_pair_p->values[i].value);
1344-
for (uint32_t j = 0; j < refs_p->item_count; j++)
1346+
for (uint32_t j = 0; j < refs_p->item_count; j++)
1347+
{
1348+
const ecma_value_t value = refs_p->buffer_p[j];
1349+
if (!ecma_is_value_empty (value))
13451350
{
1346-
const ecma_value_t value = refs_p->buffer_p[j];
1347-
if (!ecma_is_value_empty (value))
1348-
{
1349-
ecma_object_t *container_p = ecma_get_object_from_value (value);
1351+
ecma_object_t *container_p = ecma_get_object_from_value (value);
13501352

1351-
ecma_op_container_remove_weak_entry (container_p,
1352-
ecma_make_object_value (object_p));
1353-
}
1353+
ecma_op_container_remove_weak_entry (container_p,
1354+
ecma_make_object_value (object_p));
13541355
}
1355-
1356-
ecma_collection_destroy (refs_p);
1357-
break;
13581356
}
1357+
1358+
ecma_collection_destroy (refs_p);
1359+
break;
1360+
}
13591361
#endif /* ENABLED (JERRY_BUILTIN_WEAKMAP) || ENABLED (JERRY_BUILTIN_WEAKSET) */
1360-
default:
1361-
{
1362-
JERRY_ASSERT (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
1363-
ecma_gc_free_native_pointer (property_p);
1364-
break;
1365-
}
1362+
default:
1363+
{
1364+
JERRY_ASSERT (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
1365+
ecma_gc_free_native_pointer (property_p);
1366+
break;
13661367
}
13671368
}
13681369

1369-
if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
1370+
#if ENABLED (JERRY_LCACHE)
1371+
if (ecma_is_property_lcached (property_p))
13701372
{
1371-
ecma_free_property (object_p, name_cp, property_p);
1373+
ecma_lcache_invalidate (object_p, name_cp, property_p);
13721374
}
1375+
#endif /* ENABLED (JERRY_LCACHE) */
13731376
}
13741377

13751378
prop_iter_cp = prop_iter_p->next_property_cp;

0 commit comments

Comments
 (0)