Rework arguments object. (#1401)

Instead of allocating a helper object, argument names are appended right
after the arguments objects. This reduces memory consumption and improve
performance as well. In the future this could be further improved by a
bitfield, but that would require a reference to the byte code which
might increase memory consumption in a few corner cases.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2016-10-21 11:58:42 +02:00
committed by yichoi
parent 3e0d3e588f
commit c8f2747209
6 changed files with 237 additions and 268 deletions
+37 -7
View File
@@ -247,8 +247,6 @@ ecma_gc_mark_property (ecma_property_t *property_p) /**< property */
}
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_TARGET_FUNCTION: /* an object */
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
{
ecma_object_t *obj_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, property_value);
@@ -308,8 +306,17 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
ecma_gc_set_object_visited (proto_p, true);
}
if (!ecma_get_object_is_builtin (object_p)
&& ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION)
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_ARGUMENTS)
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
ext_object_p->u.arguments.lex_env_cp);
ecma_gc_set_object_visited (lex_env_p, true);
}
else if (!ecma_get_object_is_builtin (object_p)
&& ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION)
{
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
@@ -436,7 +443,9 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
if (!ecma_is_lexical_environment (object_p))
{
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_CLASS)
ecma_object_type_t object_type = ecma_get_object_type (object_p);
if (object_type == ECMA_OBJECT_TYPE_CLASS)
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
@@ -491,13 +500,13 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
}
if (ecma_get_object_is_builtin (object_p)
|| ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION)
|| object_type == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION)
{
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p, sizeof (ecma_extended_object_t));
return;
}
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION)
if (object_type == ECMA_OBJECT_TYPE_FUNCTION)
{
/* Function with byte-code (not a built-in function). */
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
@@ -508,6 +517,27 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
ecma_dealloc_extended_object (ext_func_p, sizeof (ecma_extended_object_t));
return;
}
if (object_type == ECMA_OBJECT_TYPE_ARGUMENTS)
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_length_t formal_params_number = ext_object_p->u.arguments.length;
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
for (ecma_length_t i = 0; i < formal_params_number; i++)
{
if (arg_Literal_p[i] != JMEM_CP_NULL)
{
ecma_string_t *name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, arg_Literal_p[i]);
ecma_deref_ecma_string (name_p);
}
}
size_t formal_params_size = formal_params_number * sizeof (jmem_cpointer_t);
ecma_dealloc_extended_object (ext_object_p, sizeof (ecma_extended_object_t) + formal_params_size);
return;
}
}
ecma_dealloc_object (object_p);
+9 -3
View File
@@ -197,9 +197,6 @@ typedef uintptr_t ecma_external_pointer_t;
*/
typedef enum
{
ECMA_INTERNAL_PROPERTY_SCOPE, /**< [[Scope]] */
ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP, /**< [[ParametersMap]] */
ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE, /**< native handle associated with an object */
ECMA_INTERNAL_PROPERTY_FREE_CALLBACK, /**< object's native free callback */
@@ -606,6 +603,15 @@ typedef struct
ecma_value_t bytecode_cp; /**< function byte code */
} function;
/*
* Description of arguments objects.
*/
struct
{
ecma_value_t lex_env_cp; /**< lexical environment */
uint32_t length; /**< length of names */
} arguments;
ecma_external_pointer_t external_function; /**< external function */
} u;
} ecma_extended_object_t;
-2
View File
@@ -783,8 +783,6 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
break;
}
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
case ECMA_INTERNAL_PROPERTY_INSTANTIATED_MASK_32_63: /* an integer (bit-mask) */
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_TARGET_FUNCTION:
{