Skip to content

Commit

Permalink
Refactoring ecma_extended_object_t::cls:: to ease the builtin Class c…
Browse files Browse the repository at this point in the history
…oding

Currently all builtin class are sharing same union u1 u2 u3 in ecma_extended_object_t::cls::, that's complicated the things, so
let's

move Arguments,ArrayBuffer,TypedArray,DataView class members clz.arguments,clz.arraybuffer,clz.typedarray,clz.dataview

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
  • Loading branch information
lygstate committed Nov 25, 2024
1 parent 00d12c0 commit 6a8a7fc
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 85 deletions.
6 changes: 3 additions & 3 deletions jerry-core/api/jerryscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -5993,7 +5993,7 @@ jerry_arraybuffer_external (uint8_t *buffer_p, /**< the backing store used by th

if (buffer_p != NULL)
{
arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
arraybuffer_pointer_p->extended_object.u.clz.arraybuffer.flags |= ECMA_ARRAYBUFFER_ALLOCATED;
arraybuffer_pointer_p->buffer_p = buffer_p;
}
}
Expand Down Expand Up @@ -6081,7 +6081,7 @@ jerry_shared_arraybuffer_external (uint8_t *buffer_p, /**< the backing store use

if (buffer_p != NULL)
{
shared_arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
shared_arraybuffer_pointer_p->extended_object.u.clz.arraybuffer.flags |= ECMA_ARRAYBUFFER_ALLOCATED;
shared_arraybuffer_pointer_p->buffer_p = buffer_p;
}
}
Expand Down Expand Up @@ -6529,7 +6529,7 @@ jerry_dataview_buffer (const jerry_value_t value, /**< DataView to get the array

if (byte_length != NULL)
{
*byte_length = dataview_p->header.u.cls.u3.length;
*byte_length = dataview_p->header.u.clz.dataview.length;
}

ecma_object_t *arraybuffer_p = dataview_p->buffer_p;
Expand Down
17 changes: 9 additions & 8 deletions jerry-core/ecma/base/ecma-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ ecma_gc_mark_arguments_object (ecma_extended_object_t *ext_object_p) /**< argume

ecma_value_t *argv_p = (ecma_value_t *) (arguments_p + 1);

if (ext_object_p->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED)
if (ext_object_p->u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_MAPPED)
{
ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) ext_object_p;
argv_p = (ecma_value_t *) (mapped_arguments_p + 1);

ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, mapped_arguments_p->lex_env));
}

uint32_t arguments_number = arguments_p->header.u.cls.u3.arguments_number;
uint32_t arguments_number = arguments_p->header.u.clz.arguments.number;

for (uint32_t i = 0; i < arguments_number; i++)
{
Expand Down Expand Up @@ -1336,13 +1336,13 @@ ecma_free_arguments_object (ecma_extended_object_t *ext_object_p) /**< arguments

size_t object_size = sizeof (ecma_unmapped_arguments_t);

if (ext_object_p->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED)
if (ext_object_p->u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_MAPPED)
{
ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) ext_object_p;
object_size = sizeof (ecma_mapped_arguments_t);

#if JERRY_SNAPSHOT_EXEC
if (!(mapped_arguments_p->unmapped.header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE))
if (!(mapped_arguments_p->unmapped.header.u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE))
#endif /* JERRY_SNAPSHOT_EXEC */
{
ecma_compiled_code_t *byte_code_p =
Expand All @@ -1354,14 +1354,15 @@ ecma_free_arguments_object (ecma_extended_object_t *ext_object_p) /**< arguments

ecma_value_t *argv_p = (ecma_value_t *) (((uint8_t *) ext_object_p) + object_size);
ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) ext_object_p;
uint32_t arguments_number = arguments_p->header.u.cls.u3.arguments_number;
uint32_t arguments_number = arguments_p->header.u.clz.arguments.number;

for (uint32_t i = 0; i < arguments_number; i++)
{
ecma_free_value_if_not_object (argv_p[i]);
}

uint32_t saved_argument_count = JERRY_MAX (arguments_number, arguments_p->header.u.cls.u2.formal_params_number);
uint32_t saved_argument_count =
JERRY_MAX (arguments_number, arguments_p->header.u.clz.arguments.formal_params_number);

return object_size + (saved_argument_count * sizeof (ecma_value_t));
} /* ecma_free_arguments_object */
Expand Down Expand Up @@ -1781,7 +1782,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
#if JERRY_BUILTIN_TYPEDARRAY
case ECMA_OBJECT_CLASS_TYPEDARRAY:
{
if (ext_object_p->u.cls.u2.typedarray_flags & ECMA_TYPEDARRAY_IS_EXTENDED)
if (ext_object_p->u.clz.typedarray.flags & ECMA_TYPEDARRAY_IS_EXTENDED)
{
ext_object_size = sizeof (ecma_extended_typedarray_object_t);
}
Expand Down Expand Up @@ -1858,7 +1859,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
{
if (!(ECMA_ARRAYBUFFER_GET_FLAGS (ext_object_p) & ECMA_ARRAYBUFFER_HAS_POINTER))
{
ext_object_size += ext_object_p->u.cls.u3.length;
ext_object_size += ext_object_p->u.clz.arraybuffer.length;
break;
}

Expand Down
59 changes: 45 additions & 14 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,6 @@ typedef struct
*/
union
{
uint8_t arguments_flags; /**< arguments object flags */
uint8_t error_type; /**< jerry_error_t type of native error objects */
#if JERRY_BUILTIN_DATE
uint8_t date_flags; /**< flags for date objects */
Expand All @@ -1039,17 +1038,12 @@ typedef struct
#if JERRY_BUILTIN_CONTAINER
uint8_t container_flags; /**< container object flags */
#endif /* JERRY_BUILTIN_CONTAINER */
#if JERRY_BUILTIN_TYPEDARRAY
uint8_t array_buffer_flags; /**< ArrayBuffer flags */
uint8_t typedarray_type; /**< type of typed array */
#endif /* JERRY_BUILTIN_TYPEDARRAY */
} u1;
/**
* Description of 16 bit extra fields. These extra fields depend on the type.
*/
union
{
uint16_t formal_params_number; /**< for arguments: formal parameters number */
#if JERRY_MODULE_SYSTEM
uint16_t module_flags; /**< Module flags */
#endif /* JERRY_MODULE_SYSTEM */
Expand All @@ -1058,9 +1052,6 @@ typedef struct
#if JERRY_BUILTIN_CONTAINER
uint16_t container_id; /**< magic string id of a container */
#endif /* JERRY_BUILTIN_CONTAINER */
#if JERRY_BUILTIN_TYPEDARRAY
uint16_t typedarray_flags; /**< typed array object flags */
#endif /* JERRY_BUILTIN_TYPEDARRAY */
} u2;
/**
* Description of 32 bit / value. These extra fields depend on the type.
Expand All @@ -1069,23 +1060,63 @@ typedef struct
{
ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */
ecma_value_t target; /**< [[ProxyTarget]] or [[WeakRefTarget]] internal property */
#if JERRY_BUILTIN_TYPEDARRAY
ecma_value_t arraybuffer; /**< for typedarray: ArrayBuffer reference */
#endif /* JERRY_BUILTIN_TYPEDARRAY */
ecma_value_t head; /**< points to the async generator task queue head item */
ecma_value_t iterated_value; /**< for %Iterator%: [[IteratedObject]] property */
ecma_value_t promise; /**< PromiseCapability[[Promise]] internal slot */
ecma_value_t sync_iterator; /**< IteratorRecord [[Iterator]] internal slot for AsyncFromSyncIterator */
ecma_value_t spread_value; /**< for spread object: spreaded element */
int32_t tza; /**< TimeZone adjustment for date objects */
uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
uint32_t arguments_number; /**< for arguments: arguments number */
#if JERRY_MODULE_SYSTEM
uint32_t dfs_ancestor_index; /**< module dfs ancestor index (ES2020 15.2.1.16) */
#endif /* JERRY_MODULE_SYSTEM */
} u3;
} cls;

union
{
/**
* Fields can only used by Arguments Exotic Object
*/
struct
{
uint8_t cls_type; /**< class type of the object */
uint8_t flags; /**< arguments object flags */
uint16_t formal_params_number; /**< for arguments: formal parameters number */
uint32_t number; /**< for arguments: arguments number */
} arguments;
#if JERRY_BUILTIN_TYPEDARRAY
/**
* Fields can only used by ArrayBuffer Object
*/
struct
{
uint8_t cls_type; /**< class type of the object */
uint8_t flags; /**< ArrayBuffer flags */
uint32_t length; /**< length of ArrayBuffer */
} arraybuffer;
/**
* Fields can only used by TypedArray Object
*/
struct
{
uint8_t cls_type; /**< class type of the object */
uint8_t type; /**< type of typed array */
uint16_t flags; /**< typed array object flags */
ecma_value_t arraybuffer; /**< for typedarray: ArrayBuffer reference */
} typedarray;
#endif /* JERRY_BUILTIN_TYPEDARRAY */
#if JERRY_BUILTIN_DATAVIEW
/**
* Fields can only used by DataView Object
*/
struct
{
uint8_t cls_type; /**< class type of the object */
uint32_t length; /**< length of DataView */
} dataview;
#endif /* JERRY_BUILTIN_DATAVIEW */
} clz;

/**
* Description of function objects.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ ecma_builtin_dataview_prototype_object_getters (ecma_value_t this_arg, /**< this
{
return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED);
}
return ecma_make_uint32_value (obj_p->header.u.cls.u3.length);
return ecma_make_uint32_value (obj_p->header.u.clz.arraybuffer.length);
}
default:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ ecma_builtin_typedarray_prototype_dispatch_routine (uint8_t builtin_routine_id,
case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_TO_STRING_TAG_GETTER:
{
ecma_extended_object_t *object_p = (ecma_extended_object_t *) typedarray_p;
return ecma_make_magic_string_value (ecma_get_typedarray_magic_string_id (object_p->u.cls.u1.typedarray_type));
return ecma_make_magic_string_value (ecma_get_typedarray_magic_string_id (object_p->u.clz.typedarray.type));
}
default:
{
Expand Down
46 changes: 23 additions & 23 deletions jerry-core/ecma/operations/ecma-arguments-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ ecma_op_create_arguments_object (vm_frame_ctx_shared_args_t *shared_p, /**< shar
ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) obj_p;

arguments_p->header.u.cls.type = ECMA_OBJECT_CLASS_ARGUMENTS;
arguments_p->header.u.cls.u1.arguments_flags = ECMA_ARGUMENTS_OBJECT_NO_FLAGS;
arguments_p->header.u.cls.u2.formal_params_number = formal_params_number;
arguments_p->header.u.cls.u3.arguments_number = 0;
arguments_p->header.u.clz.arguments.flags = ECMA_ARGUMENTS_OBJECT_NO_FLAGS;
arguments_p->header.u.clz.arguments.formal_params_number = formal_params_number;
arguments_p->header.u.clz.arguments.number = 0;
arguments_p->callee = ecma_make_object_value (func_obj_p);

ecma_value_t *argv_p = (ecma_value_t *) (((uint8_t *) obj_p) + object_size);
Expand All @@ -93,19 +93,19 @@ ecma_op_create_arguments_object (vm_frame_ctx_shared_args_t *shared_p, /**< shar
argv_p[i] = ECMA_VALUE_UNDEFINED;
}

arguments_p->header.u.cls.u3.arguments_number = shared_p->arg_list_len;
arguments_p->header.u.clz.arguments.number = shared_p->arg_list_len;

if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
{
ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) obj_p;

ECMA_SET_INTERNAL_VALUE_POINTER (mapped_arguments_p->lex_env, lex_env_p);
arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_MAPPED;
arguments_p->header.u.clz.arguments.flags |= ECMA_ARGUMENTS_OBJECT_MAPPED;

#if JERRY_SNAPSHOT_EXEC
if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)
{
arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE;
arguments_p->header.u.clz.arguments.flags |= ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE;
mapped_arguments_p->u.byte_code_p = (ecma_compiled_code_t *) bytecode_data_p;
}
else
Expand Down Expand Up @@ -166,15 +166,15 @@ ecma_op_arguments_object_define_own_property (ecma_object_t *object_p, /**< the
ecma_value_t ret_value = ecma_op_general_object_define_own_property (object_p, property_name_p, property_desc_p);

if (ECMA_IS_VALUE_ERROR (ret_value)
|| !(((ecma_extended_object_t *) object_p)->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED))
|| !(((ecma_extended_object_t *) object_p)->u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_MAPPED))
{
return ret_value;
}

ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) object_p;
uint32_t index = ecma_string_get_array_index (property_name_p);

if (index >= mapped_arguments_p->unmapped.header.u.cls.u2.formal_params_number)
if (index >= mapped_arguments_p->unmapped.header.u.clz.arguments.formal_params_number)
{
return ret_value;
}
Expand Down Expand Up @@ -228,8 +228,8 @@ ecma_op_arguments_object_try_to_lazy_instantiate_property (ecma_object_t *object
ecma_value_t *argv_p = (ecma_value_t *) (arguments_p + 1);
ecma_property_value_t *prop_value_p;
ecma_property_t *prop_p;
uint32_t arguments_number = arguments_p->header.u.cls.u3.arguments_number;
uint8_t flags = arguments_p->header.u.cls.u1.arguments_flags;
uint32_t arguments_number = arguments_p->header.u.clz.arguments.number;
uint8_t flags = arguments_p->header.u.clz.arguments.flags;

if (flags & ECMA_ARGUMENTS_OBJECT_MAPPED)
{
Expand Down Expand Up @@ -327,35 +327,35 @@ ecma_op_arguments_delete_built_in_property (ecma_object_t *object_p, /**< the ob

if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH))
{
JERRY_ASSERT (!(arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED));
JERRY_ASSERT (!(arguments_p->header.u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED));

arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED;
arguments_p->header.u.clz.arguments.flags |= ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED;
return;
}

if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_CALLEE))
{
JERRY_ASSERT (!(arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED));
JERRY_ASSERT (arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED);
JERRY_ASSERT (!(arguments_p->header.u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED));
JERRY_ASSERT (arguments_p->header.u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_MAPPED);

arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED;
arguments_p->header.u.clz.arguments.flags |= ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED;
return;
}

if (ecma_prop_name_is_symbol (property_name_p))
{
JERRY_ASSERT (!(arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED));
JERRY_ASSERT (!(arguments_p->header.u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED));
JERRY_ASSERT (ecma_op_compare_string_to_global_symbol (property_name_p, LIT_GLOBAL_SYMBOL_ITERATOR));

arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED;
arguments_p->header.u.clz.arguments.flags |= ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED;
return;
}

uint32_t index = ecma_string_get_array_index (property_name_p);

ecma_value_t *argv_p = (ecma_value_t *) (arguments_p + 1);

if (arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED)
if (arguments_p->header.u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_MAPPED)
{
argv_p = (ecma_value_t *) (((ecma_mapped_arguments_t *) object_p) + 1);
}
Expand All @@ -378,8 +378,8 @@ ecma_op_arguments_object_list_lazy_property_names (ecma_object_t *obj_p, /**< ar

ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) obj_p;

uint32_t arguments_number = arguments_p->header.u.cls.u3.arguments_number;
uint8_t flags = arguments_p->header.u.cls.u1.arguments_flags;
uint32_t arguments_number = arguments_p->header.u.clz.arguments.number;
uint8_t flags = arguments_p->header.u.clz.arguments.flags;

if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES))
{
Expand Down Expand Up @@ -434,13 +434,13 @@ ecma_op_arguments_object_get_formal_parameter (ecma_mapped_arguments_t *mapped_a
* object */
uint32_t index) /**< formal parameter index */
{
JERRY_ASSERT (mapped_arguments_p->unmapped.header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED);
JERRY_ASSERT (index < mapped_arguments_p->unmapped.header.u.cls.u2.formal_params_number);
JERRY_ASSERT (mapped_arguments_p->unmapped.header.u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_MAPPED);
JERRY_ASSERT (index < mapped_arguments_p->unmapped.header.u.clz.arguments.formal_params_number);

ecma_compiled_code_t *byte_code_p;

#if JERRY_SNAPSHOT_EXEC
if (mapped_arguments_p->unmapped.header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE)
if (mapped_arguments_p->unmapped.header.u.clz.arguments.flags & ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE)
{
byte_code_p = mapped_arguments_p->u.byte_code_p;
}
Expand Down
Loading

0 comments on commit 6a8a7fc

Please sign in to comment.