Eliminate the allocation of spread object (#3333)

ECMA_VALUE_SPREAD_ELEMENT can be used to represent that the next argument needs to be spreaded, therefore no allocation is needed.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2019-11-19 18:16:43 +01:00
committed by Dániel Bátyai
parent 70566a52fb
commit 830011c033
10 changed files with 49 additions and 207 deletions
+20 -25
View File
@@ -26,7 +26,6 @@
#include "ecma-iterator-object.h"
#include "ecma-lex-env.h"
#include "ecma-objects.h"
#include "ecma-spread-object.h"
#include "ecma-try-catch-macro.h"
#include "jcontext.h"
#include "opcodes.h"
@@ -299,17 +298,18 @@ opfunc_append_to_spread_array (ecma_value_t *stack_top_p, /**< current stack top
ecma_extended_object_t *ext_array_obj_p = (ecma_extended_object_t *) array_obj_p;
uint32_t old_length = ext_array_obj_p->u.array.length;
for (uint32_t i = 0, j = old_length; i < values_length; i++)
for (uint32_t i = 0, idx = old_length; i < values_length; i++, idx++)
{
if (ecma_is_value_array_hole (stack_top_p[i]))
{
continue;
}
if (ecma_op_is_spread_object (stack_top_p[i]))
if (stack_top_p[i] == ECMA_VALUE_SPREAD_ELEMENT)
{
i++;
ecma_value_t ret_value = ECMA_VALUE_ERROR;
ecma_object_t *spread_object_p = ecma_get_object_from_value (stack_top_p[i]);
ecma_value_t spread_value = ecma_op_spread_object_get_spreaded_element (spread_object_p);
ecma_value_t spread_value = stack_top_p[i];
ecma_value_t iterator = ecma_op_get_iterator (spread_value, ECMA_VALUE_EMPTY);
@@ -326,7 +326,7 @@ opfunc_append_to_spread_array (ecma_value_t *stack_top_p, /**< current stack top
if (ecma_is_value_false (next))
{
j--;
idx--;
ret_value = ECMA_VALUE_EMPTY;
break;
}
@@ -342,11 +342,10 @@ opfunc_append_to_spread_array (ecma_value_t *stack_top_p, /**< current stack top
ecma_value_t put_comp;
put_comp = ecma_builtin_helper_def_prop_by_index (array_obj_p,
i + j,
idx++,
value,
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE);
j++;
JERRY_ASSERT (ecma_is_value_true (put_comp));
ecma_free_value (value);
}
@@ -357,22 +356,18 @@ opfunc_append_to_spread_array (ecma_value_t *stack_top_p, /**< current stack top
if (ECMA_IS_VALUE_ERROR (ret_value))
{
for (uint32_t k = i; k < values_length; k++)
for (uint32_t k = i + 1; k < values_length; k++)
{
ecma_free_value (stack_top_p[k]);
}
return ret_value;
}
else
{
ecma_deref_object (spread_object_p);
}
}
else
{
ecma_value_t put_comp = ecma_builtin_helper_def_prop_by_index (array_obj_p,
i + j,
idx,
stack_top_p[i],
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE);
JERRY_ASSERT (ecma_is_value_true (put_comp));
@@ -390,24 +385,24 @@ opfunc_append_to_spread_array (ecma_value_t *stack_top_p, /**< current stack top
* pointer to the ecma-collection with the spreaded arguments, otherwise
*/
ecma_collection_t * JERRY_ATTR_NOINLINE
opfunc_spread_arguments (ecma_value_t *arguments_list_p, /**< arguments list */
opfunc_spread_arguments (ecma_value_t **stack_top_p, /**< [out] pointer to the current stack top */
uint8_t arguments_list_len) /**< number of arguments */
{
ecma_value_t *curr_stack_top_p = *stack_top_p;
ecma_collection_t *buff_p = ecma_new_collection ();
for (uint8_t i = 0; i < arguments_list_len; i++)
for (uint32_t i = 0; i < arguments_list_len; i++)
{
ecma_value_t arg = arguments_list_p[i];
ecma_value_t arg = *(--curr_stack_top_p);
if (!ecma_op_is_spread_object (arg))
if (arg != ECMA_VALUE_SPREAD_ELEMENT)
{
ecma_collection_push_back (buff_p, arg);
continue;
}
ecma_value_t ret_value = ECMA_VALUE_ERROR;
ecma_object_t *spread_object_p = ecma_get_object_from_value (arguments_list_p[i]);
ecma_value_t spread_value = ecma_op_spread_object_get_spreaded_element (spread_object_p);
ecma_value_t spread_value = *(--curr_stack_top_p);
ecma_value_t iterator = ecma_op_get_iterator (spread_value, ECMA_VALUE_EMPTY);
@@ -446,18 +441,18 @@ opfunc_spread_arguments (ecma_value_t *arguments_list_p, /**< arguments list */
if (ECMA_IS_VALUE_ERROR (ret_value))
{
for (uint32_t k = i; k < arguments_list_len; k++)
for (uint32_t k = i + 1; k < arguments_list_len; k++)
{
ecma_free_value (arguments_list_p[k]);
ecma_free_value (*(--curr_stack_top_p));
}
ecma_collection_free (buff_p);
return NULL;
buff_p = NULL;
break;
}
ecma_deref_object (spread_object_p);
}
*stack_top_p = curr_stack_top_p;
return buff_p;
} /* opfunc_spread_arguments */
#endif /* ENABLED (JERRY_ES2015) */
+1 -1
View File
@@ -106,7 +106,7 @@ opfunc_append_array (ecma_value_t *stack_top_p, uint16_t values_length);
#if ENABLED (JERRY_ES2015)
ecma_collection_t *
opfunc_spread_arguments (ecma_value_t *arguments_list_p, uint8_t argument_list_len);
opfunc_spread_arguments (ecma_value_t **stack_top_p, uint8_t argument_list_len);
#endif /* ENABLED (JERRY_ES2015) */
/**
+9 -8
View File
@@ -31,7 +31,6 @@
#include "ecma-objects-general.h"
#include "ecma-regexp-object.h"
#include "ecma-try-catch-macro.h"
#include "ecma-spread-object.h"
#include "jcontext.h"
#include "opcodes.h"
#include "vm.h"
@@ -1581,11 +1580,10 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
case VM_OC_SUPER_CALL:
{
uint8_t arguments_list_len = *byte_code_p++;
stack_top_p -= arguments_list_len;
if (opcode >= CBC_EXT_SPREAD_SUPER_CALL)
{
ecma_collection_t *arguments_p = opfunc_spread_arguments (stack_top_p, arguments_list_len);
ecma_collection_t *arguments_p = opfunc_spread_arguments (&stack_top_p, arguments_list_len);
if (JERRY_UNLIKELY (arguments_p == NULL))
{
@@ -1596,6 +1594,10 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
stack_top_p++;
ECMA_SET_INTERNAL_VALUE_POINTER (stack_top_p[-1], arguments_p);
}
else
{
stack_top_p -= arguments_list_len;
}
frame_ctx_p->call_operation = VM_EXEC_SUPER_CALL;
frame_ctx_p->byte_code_p = byte_code_start_p;
@@ -1919,10 +1921,10 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
goto error;
}
case VM_OC_CREATE_SPREAD_OBJECT:
case VM_OC_PUSH_SPREAD_ELEMENT:
{
*stack_top_p++ = ecma_op_create_spread_object (left_value);
goto free_left_value;
*stack_top_p++ = ECMA_VALUE_SPREAD_ELEMENT;
continue;
}
case VM_OC_GET_ITERATOR:
{
@@ -2029,9 +2031,8 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
case VM_OC_SPREAD_ARGUMENTS:
{
uint8_t arguments_list_len = *byte_code_p++;
stack_top_p -= arguments_list_len;
ecma_collection_t *arguments_p = opfunc_spread_arguments (stack_top_p, arguments_list_len);
ecma_collection_t *arguments_p = opfunc_spread_arguments (&stack_top_p, arguments_list_len);
if (JERRY_UNLIKELY (arguments_p == NULL))
{
+2 -2
View File
@@ -247,7 +247,7 @@ typedef enum
VM_OC_PUSH_CONSTRUCTOR_SUPER, /**< push 'super' inside a class constructor */
VM_OC_PUSH_CONSTRUCTOR_THIS, /**< push 'this' inside a class constructor */
VM_OC_CONSTRUCTOR_RET, /**< explicit return from a class constructor */
VM_OC_CREATE_SPREAD_OBJECT, /**< create spread object */
VM_OC_PUSH_SPREAD_ELEMENT, /**< push spread element */
VM_OC_GET_ITERATOR, /**< GetIterator abstract operation */
VM_OC_ITERATOR_STEP, /**< IteratorStep abstract operation */
VM_OC_DEFAULT_INITIALIZER, /**< default initializer inside a pattern */
@@ -296,7 +296,7 @@ typedef enum
VM_OC_PUSH_CONSTRUCTOR_SUPER = VM_OC_NONE, /**< push 'super' inside a class constructor */
VM_OC_PUSH_CONSTRUCTOR_THIS = VM_OC_NONE, /**< push 'this' inside a class constructor */
VM_OC_CONSTRUCTOR_RET = VM_OC_NONE, /**< explicit return from a class constructor */
VM_OC_CREATE_SPREAD_OBJECT = VM_OC_NONE, /**< create spread object */
VM_OC_PUSH_SPREAD_ELEMENT = VM_OC_NONE, /**< push spread element */
VM_OC_GET_ITERATOR = VM_OC_NONE, /**< GetIterator abstract operation */
VM_OC_ITERATOR_STEP = VM_OC_NONE, /**< IteratorStep abstract operation */
VM_OC_DEFAULT_INITIALIZER = VM_OC_NONE, /**< default initializer inside a pattern */