Skip to content

Commit d018106

Browse files
committed
Create extended objects instead of internal properties.
Several internal properties are removed and directly stored as part of the object. Faster built-in and JS function processing. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent c0665da commit d018106

22 files changed

+269
-272
lines changed

jerry-core/ecma/base/ecma-alloc.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ JERRY_STATIC_ASSERT (sizeof (ecma_property_pair_t) == sizeof (uint64_t) * 2,
3030

3131
JERRY_STATIC_ASSERT (sizeof (ecma_object_t) <= sizeof (uint64_t),
3232
size_of_ecma_object_t_must_be_less_than_or_equal_to_8_bytes);
33+
JERRY_STATIC_ASSERT (sizeof (ecma_extended_object_t) <= sizeof (uint64_t) * 2,
34+
size_of_ecma_extended_object_t_must_be_less_than_or_equal_to_16_bytes);
3335

3436
JERRY_STATIC_ASSERT (sizeof (ecma_collection_header_t) == sizeof (uint64_t),
3537
size_of_ecma_collection_header_t_must_be_less_than_or_equal_to_8_bytes);
@@ -96,21 +98,41 @@ DECLARE_ROUTINES_FOR (string)
9698
DECLARE_ROUTINES_FOR (getter_setter_pointers)
9799
DECLARE_ROUTINES_FOR (external_pointer)
98100

101+
/**
102+
* Allocate memory for extended object
103+
*
104+
* @return pointer to allocated memory
105+
*/
106+
inline ecma_extended_object_t * __attr_always_inline___
107+
ecma_alloc_extended_object (void)
108+
{
109+
return jmem_heap_alloc_block (sizeof (ecma_extended_object_t));
110+
} /* ecma_alloc_extended_object */
111+
112+
/**
113+
* Dealloc memory of an extended object
114+
*/
115+
inline void __attr_always_inline___
116+
ecma_dealloc_extended_object (ecma_extended_object_t *ext_object_p) /**< property pair to be freed */
117+
{
118+
jmem_heap_free_block (ext_object_p, sizeof (ecma_extended_object_t));
119+
} /* ecma_dealloc_extended_object */
120+
99121
/**
100122
* Allocate memory for ecma-property pair
101123
*
102124
* @return pointer to allocated memory
103125
*/
104-
ecma_property_pair_t *
126+
inline ecma_property_pair_t * __attr_always_inline___
105127
ecma_alloc_property_pair (void)
106128
{
107129
return jmem_heap_alloc_block (sizeof (ecma_property_pair_t));
108130
} /* ecma_alloc_property_pair */
109131

110132
/**
111-
* Dealloc memory from an ecma-property
133+
* Dealloc memory of an ecma-property
112134
*/
113-
extern void
135+
inline void __attr_always_inline___
114136
ecma_dealloc_property_pair (ecma_property_pair_t *property_pair_p) /**< property pair to be freed */
115137
{
116138
jmem_heap_free_block (property_pair_p, sizeof (ecma_property_pair_t));

jerry-core/ecma/base/ecma-alloc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ extern ecma_external_pointer_t *ecma_alloc_external_pointer (void);
109109
*/
110110
extern void ecma_dealloc_external_pointer (ecma_external_pointer_t *);
111111

112+
/*
113+
* Allocate memory for extended object
114+
*
115+
* @return pointer to allocated memory
116+
*/
117+
extern ecma_extended_object_t *ecma_alloc_extended_object (void);
118+
119+
/**
120+
* Dealloc memory of an extended object
121+
*/
122+
extern void ecma_dealloc_extended_object (ecma_extended_object_t *);
123+
112124
/**
113125
* Allocate memory for ecma-property pair
114126
*

jerry-core/ecma/base/ecma-gc.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,9 @@ ecma_gc_mark_property (ecma_property_t *property_p) /**< property */
245245
case ECMA_INTERNAL_PROPERTY_ECMA_VALUE: /* an ecma_value_t except object */
246246
case ECMA_INTERNAL_PROPERTY_DATE_FLOAT: /* pointer to a ecma_number_t */
247247
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
248-
case ECMA_INTERNAL_PROPERTY_CODE_BYTECODE: /* pointer to a bytecode array */
249248
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE: /* pointer to a regexp bytecode array */
250-
case ECMA_INTERNAL_PROPERTY_NATIVE_CODE: /* an external pointer */
251249
case ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE: /* an external pointer */
252250
case ECMA_INTERNAL_PROPERTY_FREE_CALLBACK: /* an object's native free callback */
253-
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ID: /* an integer */
254-
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_DESC: /* an integer */
255-
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31: /* an integer (bit-mask) */
256251
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63: /* an integer (bit-mask) */
257252
{
258253
break;
@@ -355,6 +350,17 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
355350
{
356351
ecma_gc_set_object_visited (proto_p, true);
357352
}
353+
354+
if (!ecma_get_object_is_builtin (object_p)
355+
&& ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION)
356+
{
357+
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
358+
359+
ecma_object_t *scope_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
360+
ext_func_p->u.function.scope_cp);
361+
362+
ecma_gc_set_object_visited (scope_p, true);
363+
}
358364
}
359365

360366
if (traverse_properties)
@@ -470,6 +476,28 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
470476
JERRY_ASSERT (ecma_gc_objects_number > 0);
471477
ecma_gc_objects_number--;
472478

479+
if (!ecma_is_lexical_environment (object_p))
480+
{
481+
if (ecma_get_object_is_builtin (object_p)
482+
|| ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION)
483+
{
484+
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p);
485+
return;
486+
}
487+
488+
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION)
489+
{
490+
/* Function with byte-code (not a built-in function). */
491+
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
492+
493+
ecma_bytecode_deref (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
494+
ext_func_p->u.function.bytecode_cp));
495+
496+
ecma_dealloc_extended_object (ext_func_p);
497+
return;
498+
}
499+
}
500+
473501
ecma_dealloc_object (object_p);
474502
} /* ecma_gc_sweep */
475503

jerry-core/ecma/base/ecma-globals.h

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ typedef int32_t ecma_integer_value_t;
178178
#define ECMA_IS_VALUE_ERROR(value) \
179179
(unlikely ((value & ECMA_VALUE_ERROR_FLAG) != 0))
180180

181+
/**
182+
* Representation for native external pointer
183+
*/
184+
typedef uintptr_t ecma_external_pointer_t;
185+
181186
/**
182187
* Internal properties' identifiers.
183188
*/
@@ -186,10 +191,8 @@ typedef enum
186191
ECMA_INTERNAL_PROPERTY_CLASS, /**< [[Class]] */
187192
ECMA_INTERNAL_PROPERTY_SCOPE, /**< [[Scope]] */
188193
ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP, /**< [[ParametersMap]] */
189-
ECMA_INTERNAL_PROPERTY_CODE_BYTECODE, /**< pointer to compact bytecode array */
190194
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE, /**< pointer to RegExp bytecode array */
191195

192-
ECMA_INTERNAL_PROPERTY_NATIVE_CODE, /**< native handler location descriptor */
193196
ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE, /**< native handle associated with an object */
194197
ECMA_INTERNAL_PROPERTY_FREE_CALLBACK, /**< object's native free callback */
195198
ECMA_INTERNAL_PROPERTY_ECMA_VALUE, /**< [[Primitive value]] for String, Number, and Boolean */
@@ -200,17 +203,6 @@ typedef enum
200203
ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_THIS,
201204
ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_ARGS,
202205

203-
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID, /**< Implementation-defined identifier of built-in object */
204-
205-
ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_DESC, /**< Implementation-defined identifier of built-in routine
206-
* that corresponds to a built-in function object
207-
* ([[Built-in routine's description]])
208-
*/
209-
210-
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31, /**< Bit-mask of non-instantiated
211-
* built-in's properties (bits 0-31)
212-
*/
213-
214206
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63, /**< Bit-mask of non-instantiated
215207
* built-in's properties (bits 32-63)
216208
*/
@@ -526,6 +518,44 @@ typedef struct ecma_object_t
526518
jmem_cpointer_t prototype_or_outer_reference_cp;
527519
} ecma_object_t;
528520

521+
/**
522+
* Description of extended ECMA-object.
523+
*
524+
* The extended object is an object with extra fields.
525+
*/
526+
typedef struct
527+
{
528+
ecma_object_t object; /**< object header */
529+
530+
/*
531+
* Description of extra fields. These extra fields depends on the object type.
532+
*/
533+
union
534+
{
535+
/*
536+
* Description of built-in objects.
537+
*/
538+
struct
539+
{
540+
uint8_t id; /**< built-in id */
541+
uint8_t length; /**< length for built-in functions */
542+
uint16_t routine_id; /**< routine id for built-in functions */
543+
uint32_t instantiated_bitset; /**< bit set for instantiated properties */
544+
} built_in;
545+
546+
/*
547+
* Description of function objects.
548+
*/
549+
struct
550+
{
551+
ecma_value_t scope_cp; /**< function scope */
552+
ecma_value_t bytecode_cp; /**< function byte code */
553+
} function;
554+
555+
ecma_external_pointer_t external_function; /**< external function */
556+
} u;
557+
} ecma_extended_object_t;
558+
529559
/**
530560
* Description of ECMA property descriptor
531561
*
@@ -870,14 +900,9 @@ typedef struct ecma_string_t
870900
} u;
871901
} ecma_string_t;
872902

873-
/**
874-
* Representation for native external pointer
875-
*/
876-
typedef uintptr_t ecma_external_pointer_t;
877-
878903
/**
879904
* Compiled byte code data.
880-
*/
905+
*/
881906
typedef struct
882907
{
883908
uint16_t size; /**< real size >> JMEM_ALIGNMENT_LOG */

jerry-core/ecma/base/ecma-helpers-external-pointers.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
*
3131
* Note:
3232
* property identifier should be one of the following:
33-
* - ECMA_INTERNAL_PROPERTY_NATIVE_CODE;
3433
* - ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE;
3534
* - ECMA_INTERNAL_PROPERTY_FREE_CALLBACK.
3635
*
@@ -43,8 +42,7 @@ ecma_create_external_pointer_property (ecma_object_t *obj_p, /**< object to crea
4342
* property to create */
4443
ecma_external_pointer_t ptr_value) /**< value to store in the property */
4544
{
46-
JERRY_ASSERT (id == ECMA_INTERNAL_PROPERTY_NATIVE_CODE
47-
|| id == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
45+
JERRY_ASSERT (id == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
4846
|| id == ECMA_INTERNAL_PROPERTY_FREE_CALLBACK);
4947

5048
bool is_new;
@@ -96,7 +94,6 @@ ecma_create_external_pointer_property (ecma_object_t *obj_p, /**< object to crea
9694
*
9795
* Note:
9896
* property identifier should be one of the following:
99-
* - ECMA_INTERNAL_PROPERTY_NATIVE_CODE;
10097
* - ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE;
10198
* - ECMA_INTERNAL_PROPERTY_FREE_CALLBACK.
10299
*
@@ -109,8 +106,7 @@ ecma_get_external_pointer_value (ecma_object_t *obj_p, /**< object to get proper
109106
* to get value from */
110107
ecma_external_pointer_t *out_pointer_p) /**< [out] value of the external pointer */
111108
{
112-
JERRY_ASSERT (id == ECMA_INTERNAL_PROPERTY_NATIVE_CODE
113-
|| id == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
109+
JERRY_ASSERT (id == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
114110
|| id == ECMA_INTERNAL_PROPERTY_FREE_CALLBACK);
115111

116112
ecma_property_t *prop_p = ecma_find_internal_property (obj_p, id);
@@ -142,15 +138,13 @@ ecma_get_external_pointer_value (ecma_object_t *obj_p, /**< object to get proper
142138
*
143139
* Note:
144140
* property identifier should be one of the following:
145-
* - ECMA_INTERNAL_PROPERTY_NATIVE_CODE;
146141
* - ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE;
147142
* - ECMA_INTERNAL_PROPERTY_FREE_CALLBACK.
148143
*/
149144
void
150145
ecma_free_external_pointer_in_property (ecma_property_t *prop_p) /**< internal property */
151146
{
152-
JERRY_ASSERT (ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (prop_p) == ECMA_INTERNAL_PROPERTY_NATIVE_CODE
153-
|| ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (prop_p) == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
147+
JERRY_ASSERT (ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (prop_p) == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
154148
|| ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (prop_p) == ECMA_INTERNAL_PROPERTY_FREE_CALLBACK);
155149

156150
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY

jerry-core/ecma/base/ecma-helpers.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ JERRY_STATIC_ASSERT ((ECMA_OBJECT_MAX_REF | (ECMA_OBJECT_REF_ONE - 1)) == UINT16
9090
*/
9191
ecma_object_t *
9292
ecma_create_object (ecma_object_t *prototype_object_p, /**< pointer to prototybe of the object (or NULL) */
93+
bool is_extended, /**< extended object */
9394
bool is_extensible, /**< value of extensible attribute */
9495
ecma_object_type_t type) /**< object type */
9596
{
96-
ecma_object_t *new_object_p = ecma_alloc_object ();
97+
ecma_object_t *new_object_p = (is_extended ? ((ecma_object_t *) ecma_alloc_extended_object ())
98+
: ecma_alloc_object ());
9799

98100
uint16_t type_flags = (uint16_t) type;
99101

@@ -805,7 +807,6 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
805807
break;
806808
}
807809

808-
case ECMA_INTERNAL_PROPERTY_NATIVE_CODE: /* an external pointer */
809810
case ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE: /* an external pointer */
810811
case ECMA_INTERNAL_PROPERTY_FREE_CALLBACK: /* an external pointer */
811812
{
@@ -817,9 +818,6 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
817818
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
818819
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
819820
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
820-
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ID: /* an integer */
821-
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_DESC: /* an integer */
822-
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31: /* an integer (bit-mask) */
823821
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63: /* an integer (bit-mask) */
824822
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_TARGET_FUNCTION:
825823
{
@@ -850,12 +848,6 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
850848
break;
851849
}
852850

853-
case ECMA_INTERNAL_PROPERTY_CODE_BYTECODE: /* compressed pointer to a bytecode array */
854-
{
855-
ecma_bytecode_deref (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, property_value));
856-
break;
857-
}
858-
859851
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE: /* compressed pointer to a regexp bytecode array */
860852
{
861853
ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, property_value);

jerry-core/ecma/base/ecma-helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ extern bool
245245
ecma_collection_iterator_next (ecma_collection_iterator_t *);
246246

247247
/* ecma-helpers.c */
248-
extern ecma_object_t *ecma_create_object (ecma_object_t *, bool, ecma_object_type_t);
248+
extern ecma_object_t *ecma_create_object (ecma_object_t *, bool, bool, ecma_object_type_t);
249249
extern ecma_object_t *ecma_create_decl_lex_env (ecma_object_t *);
250250
extern ecma_object_t *ecma_create_object_lex_env (ecma_object_t *, ecma_object_t *, bool);
251251
extern bool ecma_is_lexical_environment (const ecma_object_t *) __attr_pure___;

jerry-core/ecma/builtin-objects/ecma-builtin-date.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
481481

482482
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_DATE_PROTOTYPE);
483483
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
484+
false,
484485
true,
485486
ECMA_OBJECT_TYPE_GENERAL);
486487
ecma_deref_object (prototype_obj_p);

jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ ecma_builtin_function_prototype_object_bind (ecma_value_t this_arg, /**< this ar
237237
{
238238
/* 4. 11. 18. */
239239
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
240-
ecma_object_t *function_p = ecma_create_object (prototype_obj_p, true, ECMA_OBJECT_TYPE_BOUND_FUNCTION);
240+
ecma_object_t *function_p = ecma_create_object (prototype_obj_p,
241+
false,
242+
true,
243+
ECMA_OBJECT_TYPE_BOUND_FUNCTION);
241244

242245
ecma_deref_object (prototype_obj_p);
243246

0 commit comments

Comments
 (0)