Rework ecma collection (#3086)
After this patch the ecma value collection is a resizable buffer of ecma-values where the adjacent elements are allocated next to each other. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
committed by
Zoltan Herczeg
parent
f3d3c34c30
commit
fc30f003ba
+8
-16
@@ -226,17 +226,15 @@ vm_op_delete_var (ecma_value_t name_literal, /**< name literal */
|
||||
*
|
||||
* @return chain list of property names
|
||||
*/
|
||||
ecma_collection_chunk_t *
|
||||
ecma_collection_t *
|
||||
opfunc_for_in (ecma_value_t left_value, /**< left value */
|
||||
ecma_value_t *result_obj_p) /**< expression object */
|
||||
{
|
||||
ecma_collection_chunk_t *prop_names_p = NULL;
|
||||
|
||||
/* 3. */
|
||||
if (ecma_is_value_undefined (left_value)
|
||||
|| ecma_is_value_null (left_value))
|
||||
{
|
||||
return prop_names_p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 4. */
|
||||
@@ -244,24 +242,18 @@ opfunc_for_in (ecma_value_t left_value, /**< left value */
|
||||
/* ecma_op_to_object will only raise error on null/undefined values but those are handled above. */
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (obj_expr_value));
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value);
|
||||
ecma_collection_header_t *prop_names_coll_p;
|
||||
prop_names_coll_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ENUMERABLE_PROTOTYPE);
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ENUMERABLE_PROTOTYPE);
|
||||
|
||||
if (prop_names_coll_p->item_count != 0)
|
||||
if (prop_names_p->item_count != 0)
|
||||
{
|
||||
prop_names_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
|
||||
prop_names_coll_p->first_chunk_cp);
|
||||
|
||||
ecma_ref_object (obj_p);
|
||||
*result_obj_p = ecma_make_object_value (obj_p);
|
||||
return prop_names_p;
|
||||
}
|
||||
|
||||
/* Note: We release the collection header here, and return the chunk list of the collection, which will
|
||||
* be handled and released by the vm loop. */
|
||||
jmem_pools_free (prop_names_coll_p, sizeof (ecma_collection_header_t));
|
||||
ecma_free_value (obj_expr_value);
|
||||
ecma_deref_object (obj_p);
|
||||
ecma_collection_destroy (prop_names_p);
|
||||
|
||||
return prop_names_p;
|
||||
return NULL;
|
||||
} /* opfunc_for_in */
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ vm_op_delete_prop (ecma_value_t object, ecma_value_t property, bool is_strict);
|
||||
ecma_value_t
|
||||
vm_op_delete_var (ecma_value_t name_literal, ecma_object_t *lex_env_p);
|
||||
|
||||
ecma_collection_chunk_t *
|
||||
ecma_collection_t *
|
||||
opfunc_for_in (ecma_value_t left_value, ecma_value_t *result_obj_p);
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,31 +94,19 @@ vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
|
||||
{
|
||||
JERRY_ASSERT (VM_GET_CONTEXT_TYPE (vm_stack_top_p[-1]) == VM_CONTEXT_FOR_IN);
|
||||
|
||||
ecma_collection_chunk_t *chunk_p;
|
||||
chunk_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_collection_chunk_t, vm_stack_top_p[-2]);
|
||||
uint32_t index = vm_stack_top_p[-3];
|
||||
ecma_collection_t *collection_p;
|
||||
collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, vm_stack_top_p[-2]);
|
||||
|
||||
while (chunk_p != NULL)
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t index = vm_stack_top_p[-3]; index < collection_p->item_count; index++)
|
||||
{
|
||||
ecma_value_t value = chunk_p->items[index];
|
||||
|
||||
if (JERRY_UNLIKELY (ecma_is_value_pointer (value)))
|
||||
{
|
||||
ecma_collection_chunk_t *next_chunk_p;
|
||||
next_chunk_p = (ecma_collection_chunk_t *) ecma_get_pointer_from_value (value);
|
||||
jmem_heap_free_block (chunk_p, sizeof (ecma_collection_chunk_t));
|
||||
|
||||
chunk_p = next_chunk_p;
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_free_value (value);
|
||||
index++;
|
||||
}
|
||||
ecma_free_value (buffer_p[index]);
|
||||
}
|
||||
|
||||
ecma_free_value (vm_stack_top_p[-4]);
|
||||
ecma_collection_destroy (collection_p);
|
||||
|
||||
ecma_deref_object (ecma_get_object_from_value (vm_stack_top_p[-4]));
|
||||
|
||||
VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
|
||||
vm_stack_top_p -= PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION;
|
||||
|
||||
+28
-56
@@ -2872,11 +2872,12 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
JERRY_ASSERT (frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth == stack_top_p);
|
||||
|
||||
ecma_value_t expr_obj_value = ECMA_VALUE_UNDEFINED;
|
||||
ecma_collection_chunk_t *prop_names_p = opfunc_for_in (value, &expr_obj_value);
|
||||
ecma_collection_t *prop_names_p = opfunc_for_in (value, &expr_obj_value);
|
||||
ecma_free_value (value);
|
||||
|
||||
if (prop_names_p == NULL)
|
||||
{
|
||||
/* The collection is already released */
|
||||
byte_code_p = byte_code_start_p + branch_offset;
|
||||
continue;
|
||||
}
|
||||
@@ -2896,56 +2897,34 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
{
|
||||
ecma_value_t *context_top_p = frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth;
|
||||
|
||||
ecma_collection_chunk_t *chunk_p;
|
||||
chunk_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_collection_chunk_t, context_top_p[-2]);
|
||||
ecma_collection_t *collection_p;
|
||||
collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, context_top_p[-2]);
|
||||
|
||||
JERRY_ASSERT (VM_GET_CONTEXT_TYPE (context_top_p[-1]) == VM_CONTEXT_FOR_IN);
|
||||
|
||||
uint32_t index = context_top_p[-3];
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
JERRY_ASSERT (!ecma_is_value_pointer (chunk_p->items[index]));
|
||||
|
||||
/* TODO: use collection iterator instead of directly accessing the collection chunks. */
|
||||
*stack_top_p++ = chunk_p->items[index];
|
||||
index++;
|
||||
|
||||
if (JERRY_LIKELY (!ecma_is_value_pointer (chunk_p->items[index])))
|
||||
{
|
||||
context_top_p[-3] = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
context_top_p[-3] = 0;
|
||||
|
||||
ecma_collection_chunk_t *next_chunk_p;
|
||||
next_chunk_p = (ecma_collection_chunk_t *) ecma_get_pointer_from_value (chunk_p->items[index]);
|
||||
ECMA_SET_INTERNAL_VALUE_ANY_POINTER (context_top_p[-2], next_chunk_p);
|
||||
|
||||
jmem_heap_free_block (chunk_p, sizeof (ecma_collection_chunk_t));
|
||||
*stack_top_p++ = buffer_p[index];
|
||||
context_top_p[-3]++;
|
||||
continue;
|
||||
}
|
||||
case VM_OC_FOR_IN_HAS_NEXT:
|
||||
{
|
||||
JERRY_ASSERT (frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth == stack_top_p);
|
||||
|
||||
ecma_collection_chunk_t *chunk_p;
|
||||
chunk_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_collection_chunk_t, stack_top_p[-2]);
|
||||
ecma_collection_t *collection_p;
|
||||
collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, stack_top_p[-2]);
|
||||
|
||||
uint32_t index = stack_top_p[-3];
|
||||
JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FOR_IN);
|
||||
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (stack_top_p[-4]);
|
||||
uint32_t index = stack_top_p[-3];
|
||||
|
||||
while (true)
|
||||
while (index < collection_p->item_count)
|
||||
{
|
||||
if (chunk_p == NULL)
|
||||
{
|
||||
ecma_deref_object (object_p);
|
||||
|
||||
VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
|
||||
stack_top_p -= PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION;
|
||||
break;
|
||||
}
|
||||
|
||||
ecma_string_t *prop_name_p = ecma_get_string_from_value (chunk_p->items[index]);
|
||||
ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (buffer_p[index]);
|
||||
|
||||
if (JERRY_LIKELY (ecma_op_object_has_property (object_p, prop_name_p)))
|
||||
{
|
||||
@@ -2953,27 +2932,20 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
ecma_value_t value = chunk_p->items[index];
|
||||
|
||||
if (JERRY_LIKELY (!ecma_is_value_pointer (value)))
|
||||
{
|
||||
stack_top_p[-3] = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 0;
|
||||
stack_top_p[-3] = 0;
|
||||
|
||||
ecma_collection_chunk_t *next_chunk_p;
|
||||
next_chunk_p = (ecma_collection_chunk_t *) ecma_get_pointer_from_value (value);
|
||||
ECMA_SET_INTERNAL_VALUE_ANY_POINTER (stack_top_p[-2], next_chunk_p);
|
||||
|
||||
jmem_heap_free_block (chunk_p, sizeof (ecma_collection_chunk_t));
|
||||
chunk_p = next_chunk_p;
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (prop_name_p);
|
||||
index++;
|
||||
}
|
||||
|
||||
if (index == collection_p->item_count)
|
||||
{
|
||||
ecma_deref_object (object_p);
|
||||
ecma_collection_destroy (collection_p);
|
||||
VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
|
||||
stack_top_p -= PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION;
|
||||
}
|
||||
else
|
||||
{
|
||||
stack_top_p[-3] = index;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user