Skip to content

Commit cb2ad29

Browse files
committed
Rearrange fields of ecma_property_t to be naturally aligned. Packed attribute
and __extension__ keywords are removed. The standard approach reduced the binary size by 2K. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 86cdc4b commit cb2ad29

31 files changed

+375
-423
lines changed

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

Lines changed: 82 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -289,130 +289,121 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
289289
next_property_p = ECMA_GET_POINTER (ecma_property_t,
290290
property_p->next_property_p);
291291

292-
switch ((ecma_property_type_t) property_p->type)
292+
if (property_p->flags & ECMA_PROPERTY_FLAG_NAMEDDATA)
293293
{
294-
case ECMA_PROPERTY_NAMEDDATA:
295-
{
296-
ecma_value_t value = ecma_get_named_data_property_value (property_p);
294+
ecma_value_t value = ecma_get_named_data_property_value (property_p);
297295

298-
if (ecma_is_value_object (value))
299-
{
300-
ecma_object_t *value_obj_p = ecma_get_object_from_value (value);
296+
if (ecma_is_value_object (value))
297+
{
298+
ecma_object_t *value_obj_p = ecma_get_object_from_value (value);
301299

302-
ecma_gc_set_object_visited (value_obj_p, true);
303-
}
300+
ecma_gc_set_object_visited (value_obj_p, true);
301+
}
302+
}
303+
else if (property_p->flags & ECMA_PROPERTY_FLAG_NAMEDACCESSOR)
304+
{
305+
ecma_object_t *getter_obj_p = ecma_get_named_accessor_property_getter (property_p);
306+
ecma_object_t *setter_obj_p = ecma_get_named_accessor_property_setter (property_p);
304307

305-
break;
308+
if (getter_obj_p != NULL)
309+
{
310+
ecma_gc_set_object_visited (getter_obj_p, true);
306311
}
307312

308-
case ECMA_PROPERTY_NAMEDACCESSOR:
313+
if (setter_obj_p != NULL)
309314
{
310-
ecma_object_t *getter_obj_p = ecma_get_named_accessor_property_getter (property_p);
311-
ecma_object_t *setter_obj_p = ecma_get_named_accessor_property_setter (property_p);
315+
ecma_gc_set_object_visited (setter_obj_p, true);
316+
}
317+
}
318+
else
319+
{
320+
JERRY_ASSERT (property_p->flags & ECMA_PROPERTY_FLAG_INTERNAL);
321+
322+
ecma_internal_property_id_t property_id = (ecma_internal_property_id_t) property_p->h.internal_property_type;
323+
uint32_t property_value = property_p->v.internal_property.value;
312324

313-
if (getter_obj_p != NULL)
325+
switch (property_id)
326+
{
327+
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* a collection of ecma values */
328+
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* a collection of ecma values */
314329
{
315-
ecma_gc_set_object_visited (getter_obj_p, true);
330+
JERRY_UNIMPLEMENTED ("Indexed array storage is not implemented yet.");
316331
}
317332

318-
if (setter_obj_p != NULL)
333+
case ECMA_INTERNAL_PROPERTY_PROTOTYPE: /* the property's value is located in ecma_object_t
334+
(see above in the routine) */
335+
case ECMA_INTERNAL_PROPERTY_EXTENSIBLE: /* the property's value is located in ecma_object_t
336+
(see above in the routine) */
337+
case ECMA_INTERNAL_PROPERTY__COUNT: /* not a real internal property type,
338+
* but number of the real internal property types */
319339
{
320-
ecma_gc_set_object_visited (setter_obj_p, true);
340+
JERRY_UNREACHABLE ();
321341
}
322342

323-
break;
324-
}
325-
326-
case ECMA_PROPERTY_INTERNAL:
327-
{
328-
ecma_internal_property_id_t property_id = (ecma_internal_property_id_t) property_p->u.internal_property.type;
329-
uint32_t property_value = property_p->u.internal_property.value;
343+
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE: /* compressed pointer to a ecma_string_t */
344+
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE: /* compressed pointer to a ecma_number_t */
345+
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE: /* a simple boolean value */
346+
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
347+
case ECMA_INTERNAL_PROPERTY_CODE_BYTECODE: /* compressed pointer to a bytecode array */
348+
case ECMA_INTERNAL_PROPERTY_NATIVE_CODE: /* an external pointer */
349+
case ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE: /* an external pointer */
350+
case ECMA_INTERNAL_PROPERTY_FREE_CALLBACK: /* an object's native free callback */
351+
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ID: /* an integer */
352+
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_DESC: /* an integer */
353+
case ECMA_INTERNAL_PROPERTY_EXTENSION_ID: /* an integer */
354+
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31: /* an integer (bit-mask) */
355+
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63: /* an integer (bit-mask) */
356+
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE:
357+
{
358+
break;
359+
}
330360

331-
switch (property_id)
361+
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_THIS: /* an ecma value */
332362
{
333-
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* a collection of ecma values */
334-
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* a collection of ecma values */
363+
if (ecma_is_value_object (property_value))
335364
{
336-
JERRY_UNIMPLEMENTED ("Indexed array storage is not implemented yet.");
337-
}
365+
ecma_object_t *obj_p = ecma_get_object_from_value (property_value);
338366

339-
case ECMA_INTERNAL_PROPERTY_PROTOTYPE: /* the property's value is located in ecma_object_t
340-
(see above in the routine) */
341-
case ECMA_INTERNAL_PROPERTY_EXTENSIBLE: /* the property's value is located in ecma_object_t
342-
(see above in the routine) */
343-
case ECMA_INTERNAL_PROPERTY__COUNT: /* not a real internal property type,
344-
* but number of the real internal property types */
345-
{
346-
JERRY_UNREACHABLE ();
347-
}
348-
349-
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE: /* compressed pointer to a ecma_string_t */
350-
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE: /* compressed pointer to a ecma_number_t */
351-
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE: /* a simple boolean value */
352-
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
353-
case ECMA_INTERNAL_PROPERTY_CODE_BYTECODE: /* compressed pointer to a bytecode array */
354-
case ECMA_INTERNAL_PROPERTY_NATIVE_CODE: /* an external pointer */
355-
case ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE: /* an external pointer */
356-
case ECMA_INTERNAL_PROPERTY_FREE_CALLBACK: /* an object's native free callback */
357-
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ID: /* an integer */
358-
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_DESC: /* an integer */
359-
case ECMA_INTERNAL_PROPERTY_EXTENSION_ID: /* an integer */
360-
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31: /* an integer (bit-mask) */
361-
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63: /* an integer (bit-mask) */
362-
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE:
363-
{
364-
break;
367+
ecma_gc_set_object_visited (obj_p, true);
365368
}
366369

367-
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_THIS: /* an ecma value */
368-
{
369-
if (ecma_is_value_object (property_value))
370-
{
371-
ecma_object_t *obj_p = ecma_get_object_from_value (property_value);
370+
break;
371+
}
372372

373-
ecma_gc_set_object_visited (obj_p, true);
374-
}
373+
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_ARGS: /* a collection of ecma values */
374+
{
375+
ecma_collection_header_t *bound_arg_list_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_header_t,
376+
property_value);
375377

376-
break;
377-
}
378+
ecma_collection_iterator_t bound_args_iterator;
379+
ecma_collection_iterator_init (&bound_args_iterator, bound_arg_list_p);
378380

379-
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_ARGS: /* a collection of ecma values */
381+
for (ecma_length_t i = 0; i < bound_arg_list_p->unit_number; i++)
380382
{
381-
ecma_collection_header_t *bound_arg_list_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_header_t,
382-
property_value);
383-
384-
ecma_collection_iterator_t bound_args_iterator;
385-
ecma_collection_iterator_init (&bound_args_iterator, bound_arg_list_p);
383+
bool is_moved = ecma_collection_iterator_next (&bound_args_iterator);
384+
JERRY_ASSERT (is_moved);
386385

387-
for (ecma_length_t i = 0; i < bound_arg_list_p->unit_number; i++)
386+
if (ecma_is_value_object (*bound_args_iterator.current_value_p))
388387
{
389-
bool is_moved = ecma_collection_iterator_next (&bound_args_iterator);
390-
JERRY_ASSERT (is_moved);
388+
ecma_object_t *obj_p = ecma_get_object_from_value (*bound_args_iterator.current_value_p);
391389

392-
if (ecma_is_value_object (*bound_args_iterator.current_value_p))
393-
{
394-
ecma_object_t *obj_p = ecma_get_object_from_value (*bound_args_iterator.current_value_p);
395-
396-
ecma_gc_set_object_visited (obj_p, true);
397-
}
390+
ecma_gc_set_object_visited (obj_p, true);
398391
}
399-
400-
break;
401392
}
402393

403-
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_TARGET_FUNCTION: /* an object */
404-
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
405-
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
406-
{
407-
ecma_object_t *obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, property_value);
394+
break;
395+
}
408396

409-
ecma_gc_set_object_visited (obj_p, true);
397+
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_TARGET_FUNCTION: /* an object */
398+
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
399+
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
400+
{
401+
ecma_object_t *obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, property_value);
410402

411-
break;
412-
}
413-
}
403+
ecma_gc_set_object_visited (obj_p, true);
414404

415-
break;
405+
break;
406+
}
416407
}
417408
}
418409
}

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

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ typedef enum
8282
ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma values */
8383
} ecma_simple_value_t;
8484

85-
/**
86-
* Type of ecma-property
87-
*/
88-
typedef enum
89-
{
90-
ECMA_PROPERTY_NAMEDDATA, /**< named data property */
91-
ECMA_PROPERTY_NAMEDACCESSOR, /**< named accessor property */
92-
ECMA_PROPERTY_INTERNAL /**< internal property */
93-
} ecma_property_type_t;
94-
9585
/**
9686
* Description of an ecma value
9787
*
@@ -213,84 +203,78 @@ typedef enum
213203
} ecma_property_configurable_value_t;
214204

215205
/**
216-
* Width of internal property type field's width
206+
* Property's flag list.
217207
*/
218-
#define ECMA_PROPERTY_INTERNAL_PROPERTY_TYPE_WIDTH (5)
208+
typedef enum
209+
{
210+
ECMA_PROPERTY_FLAG_NAMEDDATA = 1u << 0, /**< property is named data */
211+
ECMA_PROPERTY_FLAG_NAMEDACCESSOR = 1u << 1, /**< property is named accessor */
212+
ECMA_PROPERTY_FLAG_INTERNAL = 1u << 2, /**< property is internal property */
213+
ECMA_PROPERTY_FLAG_CONFIGURABLE = 1u << 3, /**< property is configurable */
214+
ECMA_PROPERTY_FLAG_ENUMERABLE = 1u << 4, /**< property is enumerable */
215+
ECMA_PROPERTY_FLAG_WRITABLE = 1u << 5, /**< property is writable */
216+
ECMA_PROPERTY_FLAG_LCACHED = 1u << 6, /**< property is lcached */
217+
} ecma_property_flags_t;
219218

220219
/**
221220
* Pair of pointers - to property's getter and setter
222221
*/
223222
typedef struct
224223
{
225-
__extension__ mem_cpointer_t getter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to getter object */
226-
__extension__ mem_cpointer_t setter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to setter object */
224+
mem_cpointer_t getter_p; /**< pointer to getter object */
225+
mem_cpointer_t setter_p; /**< pointer to setter object */
227226
} ecma_getter_setter_pointers_t;
228227

229228
/**
230229
* Description of ecma-property
231230
*/
232-
typedef struct __attr_packed___ ecma_property_t
231+
typedef struct ecma_property_t
233232
{
234-
/** Property's type (ecma_property_type_t) */
235-
unsigned int type : 2;
236-
237233
/** Compressed pointer to next property */
238-
__extension__ mem_cpointer_t next_property_p : ECMA_POINTER_FIELD_WIDTH;
234+
mem_cpointer_t next_property_p;
235+
236+
/** Property's flags (ecma_property_flags_t) */
237+
uint8_t flags;
239238

240-
/** Property's details (depending on Type) */
239+
/** Property's header part (depending on Type) */
241240
union
242241
{
243-
/** Description of named data property */
244-
struct __attr_packed___ ecma_named_data_property_t
245-
{
246-
/** Value */
247-
__extension__ ecma_value_t value : ECMA_VALUE_SIZE;
242+
/** Named data property value upper bits */
243+
uint8_t named_data_property_value_high;
244+
/** Internal property type */
245+
uint8_t internal_property_type;
246+
} h;
248247

248+
/** Property's value part (depending on Type) */
249+
union
250+
{
251+
/** Description of named data property (second part) */
252+
struct
253+
{
249254
/** Compressed pointer to property's name (pointer to String) */
250-
__extension__ mem_cpointer_t name_p : ECMA_POINTER_FIELD_WIDTH;
251-
252-
/** Flag indicating whether the property is registered in LCache */
253-
unsigned int is_lcached : 1;
254-
255-
/** Attribute 'Writable' (ecma_property_writable_value_t) */
256-
unsigned int writable : 1;
257-
258-
/** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */
259-
unsigned int enumerable : 1;
255+
mem_cpointer_t name_p;
260256

261-
/** Attribute 'Configurable' (ecma_property_configurable_value_t) */
262-
unsigned int configurable : 1;
257+
/** Lower 16 bits of value */
258+
uint16_t value_low;
263259
} named_data_property;
264260

265-
/** Description of named accessor property */
266-
struct __attr_packed___ ecma_named_accessor_property_t
261+
/** Description of named accessor property (second part) */
262+
struct
267263
{
268264
/** Compressed pointer to property's name (pointer to String) */
269-
__extension__ mem_cpointer_t name_p : ECMA_POINTER_FIELD_WIDTH;
270-
271-
/** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */
272-
unsigned int enumerable : 1;
273-
274-
/** Attribute 'Configurable' (ecma_property_configurable_value_t) */
275-
unsigned int configurable : 1;
276-
277-
/** Flag indicating whether the property is registered in LCache */
278-
unsigned int is_lcached : 1;
265+
mem_cpointer_t name_p;
279266

280267
/** Compressed pointer to pair of pointers - to property's getter and setter */
281-
__extension__ mem_cpointer_t getter_setter_pair_cp : ECMA_POINTER_FIELD_WIDTH;
268+
mem_cpointer_t getter_setter_pair_cp;
282269
} named_accessor_property;
283270

284-
/** Description of internal property */
285-
struct __attr_packed___ ecma_internal_property_t
271+
/** Description of internal property (second part) */
272+
struct
286273
{
287-
/** Internal property's type */
288-
unsigned int type : ECMA_PROPERTY_INTERNAL_PROPERTY_TYPE_WIDTH;
289-
290274
/** Value (may be a compressed pointer) */
291275
uint32_t value;
292276
} internal_property;
293-
} u;
277+
} v;
294278
} ecma_property_t;
295279

296280
/**

0 commit comments

Comments
 (0)