Skip to content

Commit d1b0b58

Browse files
committed
Move all remaining globals to the global context.
Zero out all globals (and remove unnecessary init() functions). Move snapshot globals to a temporary stack variable. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent b14ca4e commit d1b0b58

File tree

18 files changed

+200
-290
lines changed

18 files changed

+200
-290
lines changed

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,6 @@ ecma_deref_object (ecma_object_t *object_p) /**< object */
160160
object_p->type_flags_refs = (uint16_t) (object_p->type_flags_refs - ECMA_OBJECT_REF_ONE);
161161
} /* ecma_deref_object */
162162

163-
/**
164-
* Initialize garbage collector
165-
*/
166-
void
167-
ecma_gc_init (void)
168-
{
169-
JERRY_CONTEXT (ecma_gc_objects_lists) [ECMA_GC_COLOR_WHITE_GRAY] = NULL;
170-
JERRY_CONTEXT (ecma_gc_objects_lists) [ECMA_GC_COLOR_BLACK] = NULL;
171-
JERRY_CONTEXT (ecma_gc_visited_flip_flag) = false;
172-
JERRY_CONTEXT (ecma_gc_objects_number) = 0;
173-
JERRY_CONTEXT (ecma_gc_new_objects) = 0;
174-
} /* ecma_gc_init */
175-
176163
/**
177164
* Mark referenced object from property
178165
*/

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
* @{
2727
*/
2828

29-
extern void ecma_gc_init (void);
3029
extern void ecma_init_gc_info (ecma_object_t *);
3130
extern void ecma_ref_object (ecma_object_t *);
3231
extern void ecma_deref_object (ecma_object_t *);

jerry-core/ecma/base/ecma-init-finalize.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@
3535
void
3636
ecma_init (void)
3737
{
38-
ecma_gc_init ();
39-
ecma_init_builtins ();
4038
ecma_lcache_init ();
41-
ecma_init_lit_storage ();
4239
ecma_init_global_lex_env ();
4340

4441
jmem_register_free_unused_memory_callback (ecma_free_unused_memory);

jerry-core/ecma/base/ecma-literal-storage.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@
2828
JERRY_STATIC_ASSERT (sizeof (ecma_lit_storage_item_t) <= sizeof (uint64_t),
2929
size_of_ecma_lit_storage_item_t_must_be_less_than_or_equal_to_8_bytes);
3030

31-
/**
32-
* Initialize literal storage
33-
*/
34-
void
35-
ecma_init_lit_storage (void)
36-
{
37-
JERRY_CONTEXT (string_list_first_p) = NULL;
38-
JERRY_CONTEXT (number_list_first_p) = NULL;
39-
} /* ecma_init_lit_storage */
40-
4131
/**
4232
* Free string list
4333
*/

jerry-core/ecma/base/ecma-literal-storage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef struct
3737
jmem_cpointer_t literal_offset; /**< literal offset */
3838
} lit_mem_to_snapshot_id_map_entry_t;
3939

40-
extern void ecma_init_lit_storage (void);
4140
extern void ecma_finalize_lit_storage (void);
4241

4342
extern jmem_cpointer_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *, lit_utf8_size_t);

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

Lines changed: 63 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "ecma-globals.h"
2121
#include "ecma-helpers.h"
2222
#include "ecma-objects.h"
23+
#include "jcontext.h"
2324
#include "jrt-bit-fields.h"
2425

2526
#define ECMA_BUILTINS_INTERNAL
@@ -32,19 +33,8 @@
3233
* @{
3334
*/
3435

35-
static ecma_value_t
36-
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id,
37-
uint16_t builtin_routine_id,
38-
ecma_value_t this_arg_value,
39-
const ecma_value_t arguments_list[],
40-
ecma_length_t arguments_number);
4136
static void ecma_instantiate_builtin (ecma_builtin_id_t id);
4237

43-
/**
44-
* Pointer to instances of built-in objects
45-
*/
46-
static ecma_object_t *ecma_builtin_objects[ECMA_BUILTIN_ID__COUNT];
47-
4838
/**
4939
* Check if passed object is the instance of specified built-in.
5040
*/
@@ -55,15 +45,15 @@ ecma_builtin_is (ecma_object_t *obj_p, /**< pointer to an object */
5545
JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p));
5646
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
5747

58-
if (ecma_builtin_objects[builtin_id] == NULL)
48+
if (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL)
5949
{
6050
/* If a built-in object is not instantiated,
6151
* the specified object cannot be the built-in object */
6252
return false;
6353
}
6454
else
6555
{
66-
return (obj_p == ecma_builtin_objects[builtin_id]);
56+
return (obj_p == JERRY_CONTEXT (ecma_builtin_objects)[builtin_id]);
6757
}
6858
} /* ecma_builtin_is */
6959

@@ -77,14 +67,14 @@ ecma_builtin_get (ecma_builtin_id_t builtin_id) /**< id of built-in to check on
7767
{
7868
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
7969

80-
if (unlikely (ecma_builtin_objects[builtin_id] == NULL))
70+
if (unlikely (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL))
8171
{
8272
ecma_instantiate_builtin (builtin_id);
8373
}
8474

85-
ecma_ref_object (ecma_builtin_objects[builtin_id]);
75+
ecma_ref_object (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id]);
8676

87-
return ecma_builtin_objects[builtin_id];
77+
return JERRY_CONTEXT (ecma_builtin_objects)[builtin_id];
8878
} /* ecma_builtin_get */
8979

9080
/**
@@ -106,9 +96,6 @@ ecma_builtin_function_is_routine (ecma_object_t *func_obj_p) /**< function objec
10696
/**
10797
* Initialize specified built-in object.
10898
*
109-
* Warning:
110-
* the routine should be called only from ecma_init_builtins
111-
*
11299
* @return pointer to the object
113100
*/
114101
static ecma_object_t *
@@ -219,20 +206,6 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
219206
return obj_p;
220207
} /* ecma_builtin_init_object */
221208

222-
/**
223-
* Initialize ECMA built-ins components
224-
*/
225-
void
226-
ecma_init_builtins (void)
227-
{
228-
for (ecma_builtin_id_t id = (ecma_builtin_id_t) 0;
229-
id < ECMA_BUILTIN_ID__COUNT;
230-
id = (ecma_builtin_id_t) (id + 1))
231-
{
232-
ecma_builtin_objects[id] = NULL;
233-
}
234-
} /* ecma_init_builtins */
235-
236209
/**
237210
* Instantiate specified ECMA built-in object
238211
*/
@@ -249,7 +222,7 @@ ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
249222
lowercase_name) \
250223
case builtin_id: \
251224
{ \
252-
JERRY_ASSERT (ecma_builtin_objects[builtin_id] == NULL); \
225+
JERRY_ASSERT (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL); \
253226
\
254227
ecma_object_t *prototype_obj_p; \
255228
if (object_prototype_builtin_id == ECMA_BUILTIN_ID__COUNT) \
@@ -258,19 +231,19 @@ ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
258231
} \
259232
else \
260233
{ \
261-
if (ecma_builtin_objects[object_prototype_builtin_id] == NULL) \
234+
if (JERRY_CONTEXT (ecma_builtin_objects)[object_prototype_builtin_id] == NULL) \
262235
{ \
263236
ecma_instantiate_builtin (object_prototype_builtin_id); \
264237
} \
265-
prototype_obj_p = ecma_builtin_objects[object_prototype_builtin_id]; \
238+
prototype_obj_p = JERRY_CONTEXT (ecma_builtin_objects)[object_prototype_builtin_id]; \
266239
JERRY_ASSERT (prototype_obj_p != NULL); \
267240
} \
268241
\
269242
ecma_object_t *builtin_obj_p = ecma_builtin_init_object (builtin_id, \
270243
prototype_obj_p, \
271244
object_type, \
272245
is_extensible); \
273-
ecma_builtin_objects[builtin_id] = builtin_obj_p; \
246+
JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] = builtin_obj_p; \
274247
\
275248
break; \
276249
}
@@ -295,10 +268,10 @@ ecma_finalize_builtins (void)
295268
id < ECMA_BUILTIN_ID__COUNT;
296269
id = (ecma_builtin_id_t) (id + 1))
297270
{
298-
if (ecma_builtin_objects[id] != NULL)
271+
if (JERRY_CONTEXT (ecma_builtin_objects)[id] != NULL)
299272
{
300-
ecma_deref_object (ecma_builtin_objects[id]);
301-
ecma_builtin_objects[id] = NULL;
273+
ecma_deref_object (JERRY_CONTEXT (ecma_builtin_objects)[id]);
274+
JERRY_CONTEXT (ecma_builtin_objects)[id] = NULL;
302275
}
303276
}
304277
} /* ecma_finalize_builtins */
@@ -671,6 +644,56 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
671644
}
672645
} /* ecma_builtin_list_lazy_property_names */
673646

647+
/**
648+
* Dispatcher of built-in routines
649+
*
650+
* @return ecma value
651+
* Returned value must be freed with ecma_free_value.
652+
*/
653+
static ecma_value_t
654+
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-in object' identifier */
655+
uint16_t builtin_routine_id, /**< builtin-wide identifier
656+
* of the built-in object's
657+
* routine property */
658+
ecma_value_t this_arg_value, /**< 'this' argument value */
659+
const ecma_value_t arguments_list[], /**< list of arguments passed to routine */
660+
ecma_length_t arguments_number) /**< length of arguments' list */
661+
{
662+
switch (builtin_object_id)
663+
{
664+
#define BUILTIN(builtin_id, \
665+
object_type, \
666+
object_prototype_builtin_id, \
667+
is_extensible, \
668+
is_static, \
669+
lowercase_name) \
670+
case builtin_id: \
671+
{ \
672+
return ecma_builtin_ ## lowercase_name ## _dispatch_routine (builtin_routine_id, \
673+
this_arg_value, \
674+
arguments_list, \
675+
arguments_number); \
676+
}
677+
#include "ecma-builtins.inc.h"
678+
679+
case ECMA_BUILTIN_ID__COUNT:
680+
{
681+
JERRY_UNREACHABLE ();
682+
}
683+
684+
default:
685+
{
686+
#ifdef CONFIG_ECMA_COMPACT_PROFILE
687+
JERRY_UNREACHABLE ();
688+
#else /* !CONFIG_ECMA_COMPACT_PROFILE */
689+
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
690+
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
691+
}
692+
}
693+
694+
JERRY_UNREACHABLE ();
695+
} /* ecma_builtin_dispatch_routine */
696+
674697
/**
675698
* Handle calling [[Call]] of built-in object
676699
*
@@ -797,56 +820,6 @@ ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
797820
return ret_value;
798821
} /* ecma_builtin_dispatch_construct */
799822

800-
/**
801-
* Dispatcher of built-in routines
802-
*
803-
* @return ecma value
804-
* Returned value must be freed with ecma_free_value.
805-
*/
806-
static ecma_value_t
807-
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-in object' identifier */
808-
uint16_t builtin_routine_id, /**< builtin-wide identifier
809-
* of the built-in object's
810-
* routine property */
811-
ecma_value_t this_arg_value, /**< 'this' argument value */
812-
const ecma_value_t arguments_list[], /**< list of arguments passed to routine */
813-
ecma_length_t arguments_number) /**< length of arguments' list */
814-
{
815-
switch (builtin_object_id)
816-
{
817-
#define BUILTIN(builtin_id, \
818-
object_type, \
819-
object_prototype_builtin_id, \
820-
is_extensible, \
821-
is_static, \
822-
lowercase_name) \
823-
case builtin_id: \
824-
{ \
825-
return ecma_builtin_ ## lowercase_name ## _dispatch_routine (builtin_routine_id, \
826-
this_arg_value, \
827-
arguments_list, \
828-
arguments_number); \
829-
}
830-
#include "ecma-builtins.inc.h"
831-
832-
case ECMA_BUILTIN_ID__COUNT:
833-
{
834-
JERRY_UNREACHABLE ();
835-
}
836-
837-
default:
838-
{
839-
#ifdef CONFIG_ECMA_COMPACT_PROFILE
840-
JERRY_UNREACHABLE ();
841-
#else /* !CONFIG_ECMA_COMPACT_PROFILE */
842-
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
843-
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
844-
}
845-
}
846-
847-
JERRY_UNREACHABLE ();
848-
} /* ecma_builtin_dispatch_routine */
849-
850823
/**
851824
* @}
852825
* @}

jerry-core/ecma/builtin-objects/ecma-builtins.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ typedef enum
5050
#define ECMA_GET_ROUTINE_ID(value) ((uint16_t) ((value) >> 4))
5151

5252
/* ecma-builtins.c */
53-
extern void ecma_init_builtins (void);
5453
extern void ecma_finalize_builtins (void);
5554

5655
extern ecma_value_t

jerry-core/jcontext/jcontext.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
#ifndef JCONTEXT_H
2121
#define JCONTEXT_H
2222

23-
#include "jrt.h"
24-
#include "ecma-globals.h"
23+
#include "ecma-builtins.h"
2524
#include "jmem-allocator.h"
2625
#include "jmem-config.h"
26+
#include "jrt.h"
27+
#include "re-bytecode.h"
28+
#include "vm-defines.h"
2729

2830
/** \addtogroup context Jerry context
2931
* @{
@@ -32,6 +34,11 @@
3234
* @{
3335
*/
3436

37+
/**
38+
* First member of the jerry context
39+
*/
40+
#define JERRY_CONTEXT_FIRST_MEMBER jmem_heap_allocated_size
41+
3542
/**
3643
* JerryScript context
3744
*
@@ -60,17 +67,38 @@ typedef struct
6067
* allocator request is in progress */
6168
#endif /* JERRY_VALGRIND_FREYA */
6269

70+
/**
71+
* Literal part.
72+
*/
73+
const lit_utf8_byte_t **lit_magic_string_ex_array; /**< array of external magic strings */
74+
uint32_t lit_magic_string_ex_count; /**< external magic strings count */
75+
const lit_utf8_size_t *lit_magic_string_ex_sizes; /**< external magic string lengths */
76+
6377
/**
6478
* Ecma part.
6579
*/
80+
ecma_object_t *ecma_builtin_objects[ECMA_BUILTIN_ID__COUNT]; /**< pointer to instances of built-in objects */
6681
ecma_object_t *ecma_gc_objects_lists[ECMA_GC_COLOR__COUNT]; /**< List of marked (visited during
6782
* current GC session) and umarked objects */
83+
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
84+
const re_compiled_code_t *re_cache[RE_CACHE_SIZE]; /**< regex cache */
85+
uint8_t re_cache_idx; /**< evicted item index when regex cache is full (round-robin) */
86+
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
87+
6888
bool ecma_gc_visited_flip_flag; /**< current state of an object's visited flag */
89+
bool is_direct_eval_form_call; /**< direct call from eval */
6990
size_t ecma_gc_objects_number; /**< number of currently allocated objects */
7091
size_t ecma_gc_new_objects; /**< number of newly allocated objects since last GC session */
7192
ecma_lit_storage_item_t *string_list_first_p; /**< first item of the literal string list */
7293
ecma_lit_storage_item_t *number_list_first_p; /**< first item of the literal number list */
7394
ecma_object_t *ecma_global_lex_env_p; /**< global lexical environment */
95+
vm_frame_ctx_t *vm_top_context_p; /**< top (current) interpreter context */
96+
97+
/**
98+
* API part.
99+
*/
100+
jerry_init_flag_t jerry_init_flags; /**< run-time configuration flags */
101+
bool jerry_api_available; /**< API availability flag */
74102
} jerry_context_t;
75103

76104
/**

0 commit comments

Comments
 (0)