Skip to content

Commit 5670f25

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 3543d0c commit 5670f25

31 files changed

+375
-420
lines changed

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

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

291-
switch ((ecma_property_type_t) property_p->type)
291+
if (property_p->flags & ECMA_PROPERTY_FLAG_NAMEDDATA)
292292
{
293-
case ECMA_PROPERTY_NAMEDDATA:
294-
{
295-
ecma_value_t value = ecma_get_named_data_property_value (property_p);
293+
ecma_value_t value = ecma_get_named_data_property_value (property_p);
296294

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

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

304-
break;
307+
if (getter_obj_p != NULL)
308+
{
309+
ecma_gc_set_object_visited (getter_obj_p, true);
305310
}
306311

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

312-
if (getter_obj_p != NULL)
324+
switch (property_id)
325+
{
326+
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* a collection of ecma values */
327+
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* a collection of ecma values */
313328
{
314-
ecma_gc_set_object_visited (getter_obj_p, true);
329+
JERRY_UNIMPLEMENTED ("Indexed array storage is not implemented yet.");
315330
}
316331

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

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

330-
switch (property_id)
360+
case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_THIS: /* an ecma value */
331361
{
332-
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* a collection of ecma values */
333-
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* a collection of ecma values */
362+
if (ecma_is_value_object (property_value))
334363
{
335-
JERRY_UNIMPLEMENTED ("Indexed array storage is not implemented yet.");
336-
}
364+
ecma_object_t *obj_p = ecma_get_object_from_value (property_value);
337365

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

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

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

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

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

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

391-
if (ecma_is_value_object (*bound_args_iterator.current_value_p))
392-
{
393-
ecma_object_t *obj_p = ecma_get_object_from_value (*bound_args_iterator.current_value_p);
394-
395-
ecma_gc_set_object_visited (obj_p, true);
396-
}
389+
ecma_gc_set_object_visited (obj_p, true);
397390
}
398-
399-
break;
400391
}
401392

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

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

410-
break;
411-
}
412-
}
402+
ecma_gc_set_object_visited (obj_p, true);
413403

414-
break;
404+
break;
405+
}
415406
}
416407
}
417408
}

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

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

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

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

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

230229
/**
231230
* Description of ecma-property
232231
*/
233-
typedef struct __attr_packed___ ecma_property_t
232+
typedef struct ecma_property_t
234233
{
235-
/** Property's type (ecma_property_type_t) */
236-
unsigned int type : 2;
237-
238234
/** Compressed pointer to next property */
239-
__extension__ mem_cpointer_t next_property_p : ECMA_POINTER_FIELD_WIDTH;
235+
mem_cpointer_t next_property_p;
236+
237+
/** Property's flags (ecma_property_flags_t) */
238+
uint8_t flags;
240239

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

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

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

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

281268
/** Compressed pointer to pair of pointers - to property's getter and setter */
282-
__extension__ mem_cpointer_t getter_setter_pair_cp : ECMA_POINTER_FIELD_WIDTH;
269+
mem_cpointer_t getter_setter_pair_cp;
283270
} named_accessor_property;
284271

285-
/** Description of internal property */
286-
struct __attr_packed___ ecma_internal_property_t
272+
/** Description of internal property (second part) */
273+
struct
287274
{
288-
/** Internal property's type */
289-
unsigned int type : ECMA_PROPERTY_INTERNAL_PROPERTY_TYPE_WIDTH;
290-
291275
/** Value (may be a compressed pointer) */
292276
uint32_t value;
293277
} internal_property;
294-
} u;
278+
} v;
295279
} ecma_property_t;
296280

297281
/**

0 commit comments

Comments
 (0)