Implement fast access mode arrays (#3028)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2019-08-30 15:18:15 +02:00
committed by GitHub
parent c6a4a86257
commit 2f1908f894
15 changed files with 982 additions and 262 deletions
+67
View File
@@ -407,6 +407,31 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
break;
}
case ECMA_OBJECT_TYPE_ARRAY:
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
if (ext_object_p->u.array.is_fast_mode)
{
if (object_p->u1.property_list_cp == JMEM_CP_NULL)
{
return;
}
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp);
for (uint32_t i = 0; i < ext_object_p->u.array.length; i++)
{
if (ecma_is_value_object (values_p[i]))
{
ecma_gc_set_object_visited (ecma_get_object_from_value (values_p[i]));
}
}
return;
}
break;
}
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
{
ecma_extended_object_t *ext_function_p = (ecma_extended_object_t *) object_p;
@@ -541,6 +566,37 @@ ecma_gc_free_native_pointer (ecma_property_t *property_p) /**< property */
#endif /* !JERRY_NDEBUG */
} /* ecma_gc_free_native_pointer */
/**
* Free specified fast access mode array object.
*/
static void
ecma_free_fast_access_array (ecma_object_t *object_p) /**< fast access mode array object to free */
{
JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_ARRAY);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
JERRY_ASSERT (ext_object_p->u.array.is_fast_mode);
const uint32_t aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (ext_object_p->u.array.length);
if (object_p->u1.property_list_cp != JMEM_CP_NULL)
{
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp);
for (uint32_t i = 0; i < aligned_length; i++)
{
ecma_free_value_if_not_object (values_p[i]);
}
jmem_heap_free_block (values_p, aligned_length * sizeof (ecma_value_t));
}
JERRY_ASSERT (JERRY_CONTEXT (ecma_gc_objects_number) > 0);
JERRY_CONTEXT (ecma_gc_objects_number)--;
ecma_dealloc_extended_object (object_p, sizeof (ecma_extended_object_t));
} /* ecma_free_fast_access_array */
/**
* Free specified object.
*/
@@ -556,6 +612,17 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
if (obj_is_not_lex_env
|| ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
if (obj_is_not_lex_env && ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_ARRAY)
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
if (ext_object_p->u.array.is_fast_mode)
{
ecma_free_fast_access_array (object_p);
return;
}
}
jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp;
#if ENABLED (JERRY_PROPRETY_HASHMAP)
+18
View File
@@ -331,6 +331,8 @@ typedef enum
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
ECMA_LIST_SYMBOLS = (1 << 3), /**< list symbol properties only */
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
ECMA_LIST_CONVERT_FAST_ARRAYS = (1 << 4), /**< after listing the properties convert
* the fast access mode array back to normal array */
} ecma_list_properties_options_t;
/**
@@ -822,6 +824,9 @@ typedef struct
{
uint32_t length; /**< length property value */
ecma_property_t length_prop; /**< length property */
bool is_fast_mode; /**< true - if the array is a fast access mode array
* false - otherwise */
uint8_t hole_count; /**< Number of array holes in a fast access mode array */
} array;
/**
@@ -869,6 +874,19 @@ typedef struct
ecma_built_in_props_t built_in; /**< built-in object part */
} ecma_extended_built_in_object_t;
/**
* Alignment for the fast access mode array length.
* The real length is aligned up for allocating the underlying buffer.
*/
#define ECMA_FAST_ARRAY_ALIGNMENT (8)
/**
* Align the length of the fast mode array to get the allocated size of the underlying buffer
*/
#define ECMA_FAST_ARRAY_ALIGN_LENGTH(length) \
(uint32_t) ((((length)) + ECMA_FAST_ARRAY_ALIGNMENT - 1) / ECMA_FAST_ARRAY_ALIGNMENT * ECMA_FAST_ARRAY_ALIGNMENT)
/**
* Compiled byte code data.
*/
-153
View File
@@ -849,159 +849,6 @@ ecma_delete_property (ecma_object_t *object_p, /**< object */
}
} /* ecma_delete_property */
/**
* Low level delete of array items from new_length to old_length
*
* Note: new_length must be less than old_length
*
* @return the updated value of new_length
*/
uint32_t
ecma_delete_array_properties (ecma_object_t *object_p, /**< object */
uint32_t new_length, /**< new length */
uint32_t old_length) /**< old length */
{
JERRY_ASSERT (new_length < old_length);
/* First the minimum value of new_length is updated. */
jmem_cpointer_t current_prop_cp = object_p->u1.property_list_cp;
if (current_prop_cp == JMEM_CP_NULL)
{
return new_length;
}
ecma_property_header_t *current_prop_p;
#if ENABLED (JERRY_PROPRETY_HASHMAP)
current_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, current_prop_cp);
if (current_prop_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP)
{
current_prop_cp = current_prop_p->next_property_cp;
}
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
while (current_prop_cp != JMEM_CP_NULL)
{
current_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, current_prop_cp);
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (current_prop_p));
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) current_prop_p;
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
{
if (ECMA_PROPERTY_IS_NAMED_PROPERTY (current_prop_p->types[i])
&& !ecma_is_property_configurable (current_prop_p->types[i]))
{
uint32_t index = ecma_string_get_property_index (current_prop_p->types[i],
prop_pair_p->names_cp[i]);
if (index < old_length && index >= new_length)
{
JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX);
new_length = index + 1;
if (new_length == old_length)
{
/* Early return. */
return new_length;
}
}
}
}
current_prop_cp = current_prop_p->next_property_cp;
}
/* Second all properties between new_length and old_length are deleted. */
current_prop_cp = object_p->u1.property_list_cp;
ecma_property_header_t *prev_prop_p = NULL;
#if ENABLED (JERRY_PROPRETY_HASHMAP)
JERRY_ASSERT (current_prop_cp != JMEM_CP_NULL);
ecma_property_hashmap_delete_status hashmap_status = ECMA_PROPERTY_HASHMAP_DELETE_NO_HASHMAP;
current_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, current_prop_cp);
if (current_prop_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP)
{
prev_prop_p = current_prop_p;
current_prop_cp = current_prop_p->next_property_cp;
hashmap_status = ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP;
}
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
while (current_prop_cp != JMEM_CP_NULL)
{
current_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, current_prop_cp);
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (current_prop_p));
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) current_prop_p;
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
{
if (ECMA_PROPERTY_IS_NAMED_PROPERTY (current_prop_p->types[i])
&& ecma_is_property_configurable (current_prop_p->types[i]))
{
uint32_t index = ecma_string_get_property_index (current_prop_p->types[i],
prop_pair_p->names_cp[i]);
if (index < old_length && index >= new_length)
{
JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX);
#if ENABLED (JERRY_PROPRETY_HASHMAP)
if (hashmap_status == ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP)
{
hashmap_status = ecma_property_hashmap_delete (object_p,
prop_pair_p->names_cp[i],
current_prop_p->types + i);
}
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
ecma_free_property (object_p, prop_pair_p->names_cp[i], current_prop_p->types + i);
current_prop_p->types[i] = ECMA_PROPERTY_TYPE_DELETED;
prop_pair_p->names_cp[i] = LIT_INTERNAL_MAGIC_STRING_DELETED;
}
}
}
if (current_prop_p->types[0] == ECMA_PROPERTY_TYPE_DELETED
&& current_prop_p->types[1] == ECMA_PROPERTY_TYPE_DELETED)
{
if (prev_prop_p == NULL)
{
object_p->u1.property_list_cp = current_prop_p->next_property_cp;
}
else
{
prev_prop_p->next_property_cp = current_prop_p->next_property_cp;
}
jmem_cpointer_t next_prop_cp = current_prop_p->next_property_cp;
ecma_dealloc_property_pair ((ecma_property_pair_t *) current_prop_p);
current_prop_cp = next_prop_cp;
}
else
{
prev_prop_p = current_prop_p;
current_prop_cp = current_prop_p->next_property_cp;
}
}
#if ENABLED (JERRY_PROPRETY_HASHMAP)
if (hashmap_status == ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP)
{
ecma_property_hashmap_free (object_p);
ecma_property_hashmap_create (object_p);
}
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
return new_length;
} /* ecma_delete_array_properties */
/**
* Check whether the object contains a property
*/
-1
View File
@@ -387,7 +387,6 @@ ecma_get_named_data_property (ecma_object_t *obj_p, ecma_string_t *name_p);
void ecma_free_property (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *property_p);
void ecma_delete_property (ecma_object_t *object_p, ecma_property_value_t *prop_value_p);
uint32_t ecma_delete_array_properties (ecma_object_t *object_p, uint32_t new_length, uint32_t old_length);
void ecma_named_data_property_assign_value (ecma_object_t *obj_p, ecma_property_value_t *prop_value_p,
ecma_value_t value);