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
This commit is contained in:
Zoltan Herczeg 2016-08-01 04:25:32 -07:00
parent b14ca4e248
commit d1b0b58729
18 changed files with 200 additions and 290 deletions

View File

@ -160,19 +160,6 @@ ecma_deref_object (ecma_object_t *object_p) /**< object */
object_p->type_flags_refs = (uint16_t) (object_p->type_flags_refs - ECMA_OBJECT_REF_ONE);
} /* ecma_deref_object */
/**
* Initialize garbage collector
*/
void
ecma_gc_init (void)
{
JERRY_CONTEXT (ecma_gc_objects_lists) [ECMA_GC_COLOR_WHITE_GRAY] = NULL;
JERRY_CONTEXT (ecma_gc_objects_lists) [ECMA_GC_COLOR_BLACK] = NULL;
JERRY_CONTEXT (ecma_gc_visited_flip_flag) = false;
JERRY_CONTEXT (ecma_gc_objects_number) = 0;
JERRY_CONTEXT (ecma_gc_new_objects) = 0;
} /* ecma_gc_init */
/**
* Mark referenced object from property
*/

View File

@ -26,7 +26,6 @@
* @{
*/
extern void ecma_gc_init (void);
extern void ecma_init_gc_info (ecma_object_t *);
extern void ecma_ref_object (ecma_object_t *);
extern void ecma_deref_object (ecma_object_t *);

View File

@ -35,10 +35,7 @@
void
ecma_init (void)
{
ecma_gc_init ();
ecma_init_builtins ();
ecma_lcache_init ();
ecma_init_lit_storage ();
ecma_init_global_lex_env ();
jmem_register_free_unused_memory_callback (ecma_free_unused_memory);

View File

@ -28,16 +28,6 @@
JERRY_STATIC_ASSERT (sizeof (ecma_lit_storage_item_t) <= sizeof (uint64_t),
size_of_ecma_lit_storage_item_t_must_be_less_than_or_equal_to_8_bytes);
/**
* Initialize literal storage
*/
void
ecma_init_lit_storage (void)
{
JERRY_CONTEXT (string_list_first_p) = NULL;
JERRY_CONTEXT (number_list_first_p) = NULL;
} /* ecma_init_lit_storage */
/**
* Free string list
*/

View File

@ -37,7 +37,6 @@ typedef struct
jmem_cpointer_t literal_offset; /**< literal offset */
} lit_mem_to_snapshot_id_map_entry_t;
extern void ecma_init_lit_storage (void);
extern void ecma_finalize_lit_storage (void);
extern jmem_cpointer_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *, lit_utf8_size_t);

View File

@ -20,6 +20,7 @@
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "jcontext.h"
#include "jrt-bit-fields.h"
#define ECMA_BUILTINS_INTERNAL
@ -32,19 +33,8 @@
* @{
*/
static ecma_value_t
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id,
uint16_t builtin_routine_id,
ecma_value_t this_arg_value,
const ecma_value_t arguments_list[],
ecma_length_t arguments_number);
static void ecma_instantiate_builtin (ecma_builtin_id_t id);
/**
* Pointer to instances of built-in objects
*/
static ecma_object_t *ecma_builtin_objects[ECMA_BUILTIN_ID__COUNT];
/**
* Check if passed object is the instance of specified built-in.
*/
@ -55,7 +45,7 @@ ecma_builtin_is (ecma_object_t *obj_p, /**< pointer to an object */
JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p));
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
if (ecma_builtin_objects[builtin_id] == NULL)
if (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL)
{
/* If a built-in object is not instantiated,
* the specified object cannot be the built-in object */
@ -63,7 +53,7 @@ ecma_builtin_is (ecma_object_t *obj_p, /**< pointer to an object */
}
else
{
return (obj_p == ecma_builtin_objects[builtin_id]);
return (obj_p == JERRY_CONTEXT (ecma_builtin_objects)[builtin_id]);
}
} /* ecma_builtin_is */
@ -77,14 +67,14 @@ ecma_builtin_get (ecma_builtin_id_t builtin_id) /**< id of built-in to check on
{
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
if (unlikely (ecma_builtin_objects[builtin_id] == NULL))
if (unlikely (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL))
{
ecma_instantiate_builtin (builtin_id);
}
ecma_ref_object (ecma_builtin_objects[builtin_id]);
ecma_ref_object (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id]);
return ecma_builtin_objects[builtin_id];
return JERRY_CONTEXT (ecma_builtin_objects)[builtin_id];
} /* ecma_builtin_get */
/**
@ -106,9 +96,6 @@ ecma_builtin_function_is_routine (ecma_object_t *func_obj_p) /**< function objec
/**
* Initialize specified built-in object.
*
* Warning:
* the routine should be called only from ecma_init_builtins
*
* @return pointer to the object
*/
static ecma_object_t *
@ -219,20 +206,6 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
return obj_p;
} /* ecma_builtin_init_object */
/**
* Initialize ECMA built-ins components
*/
void
ecma_init_builtins (void)
{
for (ecma_builtin_id_t id = (ecma_builtin_id_t) 0;
id < ECMA_BUILTIN_ID__COUNT;
id = (ecma_builtin_id_t) (id + 1))
{
ecma_builtin_objects[id] = NULL;
}
} /* ecma_init_builtins */
/**
* Instantiate specified ECMA built-in object
*/
@ -249,7 +222,7 @@ ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
lowercase_name) \
case builtin_id: \
{ \
JERRY_ASSERT (ecma_builtin_objects[builtin_id] == NULL); \
JERRY_ASSERT (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL); \
\
ecma_object_t *prototype_obj_p; \
if (object_prototype_builtin_id == ECMA_BUILTIN_ID__COUNT) \
@ -258,11 +231,11 @@ ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
} \
else \
{ \
if (ecma_builtin_objects[object_prototype_builtin_id] == NULL) \
if (JERRY_CONTEXT (ecma_builtin_objects)[object_prototype_builtin_id] == NULL) \
{ \
ecma_instantiate_builtin (object_prototype_builtin_id); \
} \
prototype_obj_p = ecma_builtin_objects[object_prototype_builtin_id]; \
prototype_obj_p = JERRY_CONTEXT (ecma_builtin_objects)[object_prototype_builtin_id]; \
JERRY_ASSERT (prototype_obj_p != NULL); \
} \
\
@ -270,7 +243,7 @@ ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
prototype_obj_p, \
object_type, \
is_extensible); \
ecma_builtin_objects[builtin_id] = builtin_obj_p; \
JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] = builtin_obj_p; \
\
break; \
}
@ -295,10 +268,10 @@ ecma_finalize_builtins (void)
id < ECMA_BUILTIN_ID__COUNT;
id = (ecma_builtin_id_t) (id + 1))
{
if (ecma_builtin_objects[id] != NULL)
if (JERRY_CONTEXT (ecma_builtin_objects)[id] != NULL)
{
ecma_deref_object (ecma_builtin_objects[id]);
ecma_builtin_objects[id] = NULL;
ecma_deref_object (JERRY_CONTEXT (ecma_builtin_objects)[id]);
JERRY_CONTEXT (ecma_builtin_objects)[id] = NULL;
}
}
} /* ecma_finalize_builtins */
@ -671,6 +644,56 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
}
} /* ecma_builtin_list_lazy_property_names */
/**
* Dispatcher of built-in routines
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-in object' identifier */
uint16_t builtin_routine_id, /**< builtin-wide identifier
* of the built-in object's
* routine property */
ecma_value_t this_arg_value, /**< 'this' argument value */
const ecma_value_t arguments_list[], /**< list of arguments passed to routine */
ecma_length_t arguments_number) /**< length of arguments' list */
{
switch (builtin_object_id)
{
#define BUILTIN(builtin_id, \
object_type, \
object_prototype_builtin_id, \
is_extensible, \
is_static, \
lowercase_name) \
case builtin_id: \
{ \
return ecma_builtin_ ## lowercase_name ## _dispatch_routine (builtin_routine_id, \
this_arg_value, \
arguments_list, \
arguments_number); \
}
#include "ecma-builtins.inc.h"
case ECMA_BUILTIN_ID__COUNT:
{
JERRY_UNREACHABLE ();
}
default:
{
#ifdef CONFIG_ECMA_COMPACT_PROFILE
JERRY_UNREACHABLE ();
#else /* !CONFIG_ECMA_COMPACT_PROFILE */
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
}
}
JERRY_UNREACHABLE ();
} /* ecma_builtin_dispatch_routine */
/**
* Handle calling [[Call]] of built-in object
*
@ -797,56 +820,6 @@ ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
return ret_value;
} /* ecma_builtin_dispatch_construct */
/**
* Dispatcher of built-in routines
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-in object' identifier */
uint16_t builtin_routine_id, /**< builtin-wide identifier
* of the built-in object's
* routine property */
ecma_value_t this_arg_value, /**< 'this' argument value */
const ecma_value_t arguments_list[], /**< list of arguments passed to routine */
ecma_length_t arguments_number) /**< length of arguments' list */
{
switch (builtin_object_id)
{
#define BUILTIN(builtin_id, \
object_type, \
object_prototype_builtin_id, \
is_extensible, \
is_static, \
lowercase_name) \
case builtin_id: \
{ \
return ecma_builtin_ ## lowercase_name ## _dispatch_routine (builtin_routine_id, \
this_arg_value, \
arguments_list, \
arguments_number); \
}
#include "ecma-builtins.inc.h"
case ECMA_BUILTIN_ID__COUNT:
{
JERRY_UNREACHABLE ();
}
default:
{
#ifdef CONFIG_ECMA_COMPACT_PROFILE
JERRY_UNREACHABLE ();
#else /* !CONFIG_ECMA_COMPACT_PROFILE */
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
}
}
JERRY_UNREACHABLE ();
} /* ecma_builtin_dispatch_routine */
/**
* @}
* @}

View File

@ -50,7 +50,6 @@ typedef enum
#define ECMA_GET_ROUTINE_ID(value) ((uint16_t) ((value) >> 4))
/* ecma-builtins.c */
extern void ecma_init_builtins (void);
extern void ecma_finalize_builtins (void);
extern ecma_value_t

View File

@ -20,10 +20,12 @@
#ifndef JCONTEXT_H
#define JCONTEXT_H
#include "jrt.h"
#include "ecma-globals.h"
#include "ecma-builtins.h"
#include "jmem-allocator.h"
#include "jmem-config.h"
#include "jrt.h"
#include "re-bytecode.h"
#include "vm-defines.h"
/** \addtogroup context Jerry context
* @{
@ -32,6 +34,11 @@
* @{
*/
/**
* First member of the jerry context
*/
#define JERRY_CONTEXT_FIRST_MEMBER jmem_heap_allocated_size
/**
* JerryScript context
*
@ -60,17 +67,38 @@ typedef struct
* allocator request is in progress */
#endif /* JERRY_VALGRIND_FREYA */
/**
* Literal part.
*/
const lit_utf8_byte_t **lit_magic_string_ex_array; /**< array of external magic strings */
uint32_t lit_magic_string_ex_count; /**< external magic strings count */
const lit_utf8_size_t *lit_magic_string_ex_sizes; /**< external magic string lengths */
/**
* Ecma part.
*/
ecma_object_t *ecma_builtin_objects[ECMA_BUILTIN_ID__COUNT]; /**< pointer to instances of built-in objects */
ecma_object_t *ecma_gc_objects_lists[ECMA_GC_COLOR__COUNT]; /**< List of marked (visited during
* current GC session) and umarked objects */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
const re_compiled_code_t *re_cache[RE_CACHE_SIZE]; /**< regex cache */
uint8_t re_cache_idx; /**< evicted item index when regex cache is full (round-robin) */
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
bool ecma_gc_visited_flip_flag; /**< current state of an object's visited flag */
bool is_direct_eval_form_call; /**< direct call from eval */
size_t ecma_gc_objects_number; /**< number of currently allocated objects */
size_t ecma_gc_new_objects; /**< number of newly allocated objects since last GC session */
ecma_lit_storage_item_t *string_list_first_p; /**< first item of the literal string list */
ecma_lit_storage_item_t *number_list_first_p; /**< first item of the literal number list */
ecma_object_t *ecma_global_lex_env_p; /**< global lexical environment */
vm_frame_ctx_t *vm_top_context_p; /**< top (current) interpreter context */
/**
* API part.
*/
jerry_init_flag_t jerry_init_flags; /**< run-time configuration flags */
bool jerry_api_available; /**< API availability flag */
} jerry_context_t;
/**

View File

@ -16,6 +16,7 @@
#include <stdio.h>
#include "lit-magic-strings.h"
#include "ecma-alloc.h"
#include "ecma-array-object.h"
#include "ecma-builtin-helpers.h"
@ -30,11 +31,12 @@
#include "ecma-literal-storage.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "jcontext.h"
#include "jerry-api.h"
#include "jerry-snapshot.h"
#include "lit-magic-strings.h"
#include "js-parser.h"
#include "re-compiler.h"
#include "vm.h"
#define JERRY_INTERNAL
#include "jerry-internal.h"
@ -51,27 +53,17 @@ JERRY_STATIC_ASSERT ((int) ECMA_ERROR_COMMON == (int) JERRY_ERROR_COMMON
&& (int) ECMA_ERROR_URI == (int) JERRY_ERROR_URI,
ecma_standard_error_t_must_be_equal_to_jerry_error_t);
/**
* Jerry run-time configuration flags
*/
static jerry_init_flag_t jerry_init_flags;
/**
* Jerry API availability flag
*/
static bool jerry_api_available;
#ifdef JERRY_ENABLE_ERROR_MESSAGES
/**
* Error message, if an argument is has an error flag
*/
static const char *error_value_msg_p = "argument cannot have an error flag";
static const char * const error_value_msg_p = "argument cannot have an error flag";
/**
* Error message, if types of arguments are incorrect
*/
static const char *wrong_args_msg_p = "wrong type of argument";
static const char * const wrong_args_msg_p = "wrong type of argument";
#endif /* JERRY_ENABLE_ERROR_MESSAGES */
@ -99,7 +91,7 @@ static const char *wrong_args_msg_p = "wrong type of argument";
static inline void __attr_always_inline___
jerry_assert_api_available (void)
{
if (unlikely (!jerry_api_available))
if (unlikely (!JERRY_CONTEXT (jerry_api_available)))
{
/* Terminates the execution. */
JERRY_UNREACHABLE ();
@ -112,7 +104,7 @@ jerry_assert_api_available (void)
static inline void __attr_always_inline___
jerry_make_api_available (void)
{
jerry_api_available = true;
JERRY_CONTEXT (jerry_api_available) = true;
} /* jerry_make_api_available */
/**
@ -121,7 +113,7 @@ jerry_make_api_available (void)
static inline void __attr_always_inline___
jerry_make_api_unavailable (void)
{
jerry_api_available = false;
JERRY_CONTEXT (jerry_api_available) = false;
} /* jerry_make_api_unavailable */
/**
@ -142,12 +134,15 @@ jerry_create_type_error (void)
void
jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */
{
if (unlikely (jerry_api_available))
if (unlikely (JERRY_CONTEXT (jerry_api_available)))
{
/* This function cannot be called twice unless jerry_cleanup is called. */
JERRY_UNREACHABLE ();
}
/* Zero out all members. */
memset (&JERRY_CONTEXT (JERRY_CONTEXT_FIRST_MEMBER), 0, sizeof (jerry_context_t));
if (flags & (JERRY_INIT_ENABLE_LOG))
{
#ifndef JERRY_ENABLE_LOG
@ -169,7 +164,7 @@ jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */
#endif /* !JMEM_STATS */
}
jerry_init_flags = flags;
JERRY_CONTEXT (jerry_init_flags) = flags;
jerry_make_api_available ();
@ -187,7 +182,7 @@ jerry_cleanup (void)
jerry_make_api_unavailable ();
ecma_finalize ();
jmem_finalize ((jerry_init_flags & JERRY_INIT_MEM_STATS) != 0);
jmem_finalize ((JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_MEM_STATS) != 0);
} /* jerry_cleanup */
/**
@ -276,7 +271,7 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */
{
jerry_assert_api_available ();
parser_set_show_instrs ((jerry_init_flags & JERRY_INIT_SHOW_OPCODES));
parser_set_show_instrs ((JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_SHOW_OPCODES));
ecma_compiled_code_t *bytecode_data_p;
ecma_value_t parse_status;
@ -294,7 +289,7 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */
ecma_free_value (parse_status);
#ifdef JMEM_STATS
if (jerry_init_flags & JERRY_INIT_MEM_STATS_SEPARATE)
if (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_MEM_STATS_SEPARATE)
{
jmem_stats_print ();
jmem_stats_reset_peak ();
@ -1746,10 +1741,11 @@ jerry_foreach_object_property (const jerry_value_t obj_val, /**< object value */
/**
* Variables required to take a snapshot.
*/
static bool snapshot_error_occured;
static size_t snapshot_buffer_write_offset;
static uint8_t *snapshot_buffer_p;
static size_t snapshot_buffer_size;
typedef struct
{
bool snapshot_error_occured;
size_t snapshot_buffer_write_offset;
} snapshot_globals_t;
/**
* Snapshot callback for byte codes.
@ -1757,37 +1753,40 @@ static size_t snapshot_buffer_size;
* @return start offset
*/
static uint16_t
snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p) /**< compiled code */
snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled code */
uint8_t *snapshot_buffer_p, /**< snapshot buffer */
size_t snapshot_buffer_size, /**< snapshot buffer size */
snapshot_globals_t *globals_p) /**< snapshot globals */
{
if (snapshot_error_occured)
if (globals_p->snapshot_error_occured)
{
return 0;
}
JERRY_ASSERT ((snapshot_buffer_write_offset & (JMEM_ALIGNMENT - 1)) == 0);
JERRY_ASSERT ((globals_p->snapshot_buffer_write_offset & (JMEM_ALIGNMENT - 1)) == 0);
if ((snapshot_buffer_write_offset >> JMEM_ALIGNMENT_LOG) > 0xffffu)
if ((globals_p->snapshot_buffer_write_offset >> JMEM_ALIGNMENT_LOG) > 0xffffu)
{
snapshot_error_occured = true;
globals_p->snapshot_error_occured = true;
return 0;
}
uint16_t start_offset = (uint16_t) (snapshot_buffer_write_offset >> JMEM_ALIGNMENT_LOG);
ecma_compiled_code_t *copied_compiled_code_p;
uint16_t start_offset = (uint16_t) (globals_p->snapshot_buffer_write_offset >> JMEM_ALIGNMENT_LOG);
copied_compiled_code_p = (ecma_compiled_code_t *) (snapshot_buffer_p + snapshot_buffer_write_offset);
uint8_t *copied_code_start_p = snapshot_buffer_p + globals_p->snapshot_buffer_write_offset;
ecma_compiled_code_t *copied_code_p = (ecma_compiled_code_t *) copied_code_start_p;
if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FUNCTION))
{
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
/* Regular expression. */
if (snapshot_buffer_write_offset + sizeof (ecma_compiled_code_t) > snapshot_buffer_size)
if (globals_p->snapshot_buffer_write_offset + sizeof (ecma_compiled_code_t) > snapshot_buffer_size)
{
snapshot_error_occured = true;
globals_p->snapshot_error_occured = true;
return 0;
}
snapshot_buffer_write_offset += sizeof (ecma_compiled_code_t);
globals_p->snapshot_buffer_write_offset += sizeof (ecma_compiled_code_t);
jmem_cpointer_t pattern_cp = ((re_compiled_code_t *) compiled_code_p)->pattern_cp;
ecma_string_t *pattern_string_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
@ -1801,24 +1800,25 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p) /**< compiled
if (!jrt_write_to_buffer_by_offset (snapshot_buffer_p,
snapshot_buffer_size,
&snapshot_buffer_write_offset,
&globals_p->snapshot_buffer_write_offset,
buffer_p,
buffer_size))
{
snapshot_error_occured = true;
globals_p->snapshot_error_occured = true;
}
ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size);
snapshot_buffer_write_offset = JERRY_ALIGNUP (snapshot_buffer_write_offset, JMEM_ALIGNMENT);
globals_p->snapshot_buffer_write_offset = JERRY_ALIGNUP (globals_p->snapshot_buffer_write_offset,
JMEM_ALIGNMENT);
/* Regexp character size is stored in refs. */
copied_compiled_code_p->refs = (uint16_t) pattern_size;
copied_code_p->refs = (uint16_t) pattern_size;
pattern_size += (ecma_length_t) sizeof (ecma_compiled_code_t);
copied_compiled_code_p->size = (uint16_t) ((pattern_size + JMEM_ALIGNMENT - 1) >> JMEM_ALIGNMENT_LOG);
copied_code_p->size = (uint16_t) ((pattern_size + JMEM_ALIGNMENT - 1) >> JMEM_ALIGNMENT_LOG);
copied_compiled_code_p->status_flags = compiled_code_p->status_flags;
copied_code_p->status_flags = compiled_code_p->status_flags;
#else /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
JERRY_UNIMPLEMENTED ("RegExp is not supported in compact profile.");
@ -1828,17 +1828,17 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p) /**< compiled
if (!jrt_write_to_buffer_by_offset (snapshot_buffer_p,
snapshot_buffer_size,
&snapshot_buffer_write_offset,
&globals_p->snapshot_buffer_write_offset,
compiled_code_p,
((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG))
{
snapshot_error_occured = true;
globals_p->snapshot_error_occured = true;
return 0;
}
/* Sub-functions and regular expressions are stored recursively. */
uint8_t *src_buffer_p = (uint8_t *) compiled_code_p;
uint8_t *dst_buffer_p = (uint8_t *) copied_compiled_code_p;
uint8_t *dst_buffer_p = (uint8_t *) copied_code_p;
jmem_cpointer_t *src_literal_start_p;
jmem_cpointer_t *dst_literal_start_p;
uint32_t const_literal_end;
@ -1874,7 +1874,10 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p) /**< compiled
}
else
{
dst_literal_start_p[i] = snapshot_add_compiled_code (bytecode_p);
dst_literal_start_p[i] = snapshot_add_compiled_code (bytecode_p,
snapshot_buffer_p,
snapshot_buffer_size,
globals_p);
}
}
@ -1995,14 +1998,13 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
size_t buffer_size) /**< the buffer's size */
{
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
snapshot_globals_t globals;
ecma_value_t parse_status;
ecma_compiled_code_t *bytecode_data_p;
snapshot_buffer_write_offset = JERRY_ALIGNUP (sizeof (jerry_snapshot_header_t),
JMEM_ALIGNMENT);
snapshot_error_occured = false;
snapshot_buffer_p = buffer_p;
snapshot_buffer_size = buffer_size;
globals.snapshot_buffer_write_offset = JERRY_ALIGNUP (sizeof (jerry_snapshot_header_t),
JMEM_ALIGNMENT);
globals.snapshot_error_occured = false;
parse_status = parser_parse_script (source_p,
source_size,
@ -2015,16 +2017,16 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
return 0;
}
snapshot_add_compiled_code (bytecode_data_p);
snapshot_add_compiled_code (bytecode_data_p, buffer_p, buffer_size, &globals);
if (snapshot_error_occured)
if (globals.snapshot_error_occured)
{
return 0;
}
jerry_snapshot_header_t header;
header.version = JERRY_SNAPSHOT_VERSION;
header.lit_table_offset = (uint32_t) snapshot_buffer_write_offset;
header.lit_table_offset = (uint32_t) globals.snapshot_buffer_write_offset;
header.is_run_global = is_for_global;
lit_mem_to_snapshot_id_map_entry_t *lit_map_p = NULL;
@ -2032,7 +2034,7 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
if (!ecma_save_literals_for_snapshot (buffer_p,
buffer_size,
&snapshot_buffer_write_offset,
&globals.snapshot_buffer_write_offset,
&lit_map_p,
&literals_num,
&header.lit_table_size))
@ -2060,7 +2062,7 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
ecma_bytecode_deref (bytecode_data_p);
return snapshot_buffer_write_offset;
return globals.snapshot_buffer_write_offset;
#else /* !JERRY_ENABLE_SNAPSHOT_SAVE */
JERRY_UNUSED (source_p);
JERRY_UNUSED (source_size);
@ -2236,9 +2238,8 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
#ifdef JERRY_ENABLE_SNAPSHOT_EXEC
JERRY_ASSERT (snapshot_p != NULL);
static const char *invalid_version_error_p = "Invalid snapshot version";
static const char *invalid_format_error_p = "Invalid snapshot format";
static const char * const invalid_version_error_p = "Invalid snapshot version";
static const char * const invalid_format_error_p = "Invalid snapshot format";
const uint8_t *snapshot_data_p = (uint8_t *) snapshot_p;
if (snapshot_size <= sizeof (jerry_snapshot_header_t))

View File

@ -34,7 +34,6 @@ void
jmem_init (void)
{
jmem_heap_init ();
jmem_pools_init ();
} /* jmem_init */
/**

View File

@ -150,9 +150,7 @@ jmem_heap_init (void)
JERRY_ASSERT ((uintptr_t) JERRY_HEAP_CONTEXT (area) % JMEM_ALIGNMENT == 0);
JERRY_CONTEXT (jmem_heap_allocated_size) = 0;
JERRY_CONTEXT (jmem_heap_limit) = CONFIG_MEM_HEAP_DESIRED_LIMIT;
JERRY_CONTEXT (jmem_free_unused_memory_callback) = NULL;
jmem_heap_free_t *const region_p = (jmem_heap_free_t *) JERRY_HEAP_CONTEXT (area);
@ -164,10 +162,6 @@ jmem_heap_init (void)
JERRY_CONTEXT (jmem_heap_list_skip_p) = &JERRY_HEAP_CONTEXT (first);
#ifdef JERRY_VALGRIND_FREYA
JERRY_CONTEXT (valgrind_freya_mempool_request) = false;
#endif /* JERRY_VALGRIND_FREYA */
VALGRIND_NOACCESS_SPACE (JERRY_HEAP_CONTEXT (area), JMEM_HEAP_AREA_SIZE);
JMEM_HEAP_STAT_INIT ();
@ -681,8 +675,6 @@ jmem_heap_stats_print (void)
static void
jmem_heap_stat_init ()
{
memset (&JERRY_CONTEXT (jmem_heap_stats), 0, sizeof (jmem_heap_stats_t));
JERRY_CONTEXT (jmem_heap_stats).size = JMEM_HEAP_AREA_SIZE;
} /* jmem_heap_stat_init */

View File

@ -36,19 +36,16 @@
#ifdef JMEM_STATS
static void jmem_pools_stat_init (void);
static void jmem_pools_stat_free_pool (void);
static void jmem_pools_stat_new_alloc (void);
static void jmem_pools_stat_reuse (void);
static void jmem_pools_stat_dealloc (void);
# define JMEM_POOLS_STAT_INIT() jmem_pools_stat_init ()
# define JMEM_POOLS_STAT_FREE_POOL() jmem_pools_stat_free_pool ()
# define JMEM_POOLS_STAT_NEW_ALLOC() jmem_pools_stat_new_alloc ()
# define JMEM_POOLS_STAT_REUSE() jmem_pools_stat_reuse ()
# define JMEM_POOLS_STAT_DEALLOC() jmem_pools_stat_dealloc ()
#else /* !JMEM_STATS */
# define JMEM_POOLS_STAT_INIT()
# define JMEM_POOLS_STAT_FREE_POOL()
# define JMEM_POOLS_STAT_NEW_ALLOC()
# define JMEM_POOLS_STAT_REUSE()
@ -80,19 +77,8 @@ static void jmem_pools_stat_dealloc (void);
# define VALGRIND_FREYA_FREELIKE_SPACE(p)
#endif /* JERRY_VALGRIND_FREYA */
/**
* Initialize pool manager
*/
void
jmem_pools_init (void)
{
JERRY_STATIC_ASSERT (sizeof (jmem_pools_chunk_t) <= JMEM_POOL_CHUNK_SIZE,
size_of_mem_pools_chunk_t_must_be_less_than_or_equal_to_MEM_POOL_CHUNK_SIZE);
JERRY_CONTEXT (jmem_free_chunk_p) = NULL;
JMEM_POOLS_STAT_INIT ();
} /* jmem_pools_init */
JERRY_STATIC_ASSERT (sizeof (jmem_pools_chunk_t) <= JMEM_POOL_CHUNK_SIZE,
size_of_mem_pools_chunk_t_must_be_less_than_or_equal_to_MEM_POOL_CHUNK_SIZE);
/**
* Finalize pool manager
@ -219,15 +205,6 @@ jmem_pools_stats_print (void)
pools_stats->reused_count % pools_stats->new_alloc_count * 10000 / pools_stats->new_alloc_count);
} /* jmem_pools_stats_print */
/**
* Initalize pools' memory usage statistics account structure
*/
static void
jmem_pools_stat_init (void)
{
memset (&JERRY_CONTEXT (jmem_pools_stats), 0, sizeof (jmem_pools_stats_t));
} /* jmem_pools_stat_init */
/**
* Account for allocation of new pool chunk
*/

View File

@ -29,7 +29,6 @@
* @{
*/
extern void jmem_pools_init (void);
extern void jmem_pools_finalize (void);
extern void *jmem_pools_alloc (void);
extern void jmem_pools_free (void *);

View File

@ -13,28 +13,10 @@
* limitations under the License.
*/
#include "jcontext.h"
#include "lit-magic-strings.h"
#include "lit-strings.h"
/**
* External magic strings data array, count and lengths
*/
static const lit_utf8_byte_t **lit_magic_string_ex_array = NULL;
static uint32_t lit_magic_string_ex_count = 0;
static const lit_utf8_size_t *lit_magic_string_ex_sizes = NULL;
/**
* Initialize external magic strings
*/
void
lit_magic_strings_ex_init (void)
{
lit_magic_string_ex_array = NULL;
lit_magic_string_ex_count = 0;
lit_magic_string_ex_sizes = NULL;
} /* lit_magic_strings_ex_init */
/**
* Get number of external magic strings
*
@ -44,7 +26,7 @@ lit_magic_strings_ex_init (void)
uint32_t
lit_get_magic_string_ex_count (void)
{
return lit_magic_string_ex_count;
return JERRY_CONTEXT (lit_magic_string_ex_count);
} /* lit_get_magic_string_ex_count */
/**
@ -97,9 +79,9 @@ lit_get_magic_string_size (lit_magic_string_id_t id) /**< magic string id */
const lit_utf8_byte_t *
lit_get_magic_string_ex_utf8 (lit_magic_string_ex_id_t id) /**< extern magic string id */
{
if (lit_magic_string_ex_array && id < lit_magic_string_ex_count)
if (JERRY_CONTEXT (lit_magic_string_ex_array) && id < JERRY_CONTEXT (lit_magic_string_ex_count))
{
return lit_magic_string_ex_array[id];
return JERRY_CONTEXT (lit_magic_string_ex_array)[id];
}
JERRY_UNREACHABLE ();
@ -113,7 +95,7 @@ lit_get_magic_string_ex_utf8 (lit_magic_string_ex_id_t id) /**< extern magic str
lit_utf8_size_t
lit_get_magic_string_ex_size (lit_magic_string_ex_id_t id) /**< external magic string id */
{
return lit_magic_string_ex_sizes[id];
return JERRY_CONTEXT (lit_magic_string_ex_sizes)[id];
} /* lit_get_magic_string_ex_size */
/**
@ -129,22 +111,23 @@ lit_magic_strings_ex_set (const lit_utf8_byte_t **ex_str_items, /**< character a
JERRY_ASSERT (count > 0);
JERRY_ASSERT (ex_str_sizes != NULL);
JERRY_ASSERT (lit_magic_string_ex_array == NULL);
JERRY_ASSERT (lit_magic_string_ex_count == 0);
JERRY_ASSERT (lit_magic_string_ex_sizes == NULL);
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_array) == NULL);
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_count) == 0);
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_sizes) == NULL);
/* Set external magic strings information */
lit_magic_string_ex_array = ex_str_items;
lit_magic_string_ex_count = count;
lit_magic_string_ex_sizes = ex_str_sizes;
JERRY_CONTEXT (lit_magic_string_ex_array) = ex_str_items;
JERRY_CONTEXT (lit_magic_string_ex_count) = count;
JERRY_CONTEXT (lit_magic_string_ex_sizes) = ex_str_sizes;
#ifndef JERRY_NDEBUG
for (lit_magic_string_ex_id_t id = (lit_magic_string_ex_id_t) 0;
id < lit_magic_string_ex_count;
id < JERRY_CONTEXT (lit_magic_string_ex_count);
id = (lit_magic_string_ex_id_t) (id + 1))
{
JERRY_ASSERT (lit_magic_string_ex_sizes[id] == lit_zt_utf8_string_size (lit_get_magic_string_ex_utf8 (id)));
JERRY_ASSERT (lit_magic_string_ex_sizes[id] <= LIT_MAGIC_STRING_LENGTH_LIMIT);
lit_utf8_size_t string_size = lit_zt_utf8_string_size (lit_get_magic_string_ex_utf8 (id));
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_sizes)[id] == string_size);
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_sizes)[id] <= LIT_MAGIC_STRING_LENGTH_LIMIT);
}
#endif /* !JERRY_NDEBUG */
} /* lit_magic_strings_ex_set */
@ -195,7 +178,7 @@ bool lit_is_ex_utf8_string_magic (const lit_utf8_byte_t *string_p, /**< utf-8 st
/* TODO: Improve performance of search */
for (lit_magic_string_ex_id_t id = (lit_magic_string_ex_id_t) 0;
id < lit_magic_string_ex_count;
id < JERRY_CONTEXT (lit_magic_string_ex_count);
id = (lit_magic_string_ex_id_t) (id + 1))
{
if (lit_compare_utf8_string_and_magic_string_ex (string_p, string_size, id))
@ -206,7 +189,7 @@ bool lit_is_ex_utf8_string_magic (const lit_utf8_byte_t *string_p, /**< utf-8 st
}
}
*out_id_p = lit_magic_string_ex_count;
*out_id_p = JERRY_CONTEXT (lit_magic_string_ex_count);
return false;
} /* lit_is_ex_utf8_string_magic */

View File

@ -41,8 +41,6 @@ typedef enum
*/
typedef uint32_t lit_magic_string_ex_id_t;
extern void lit_magic_strings_ex_init (void);
extern uint32_t lit_get_magic_string_ex_count (void);
extern const lit_utf8_byte_t *lit_get_magic_string_utf8 (lit_magic_string_id_t);

View File

@ -18,6 +18,7 @@
#include "ecma-helpers.h"
#include "ecma-regexp-object.h"
#include "ecma-try-catch-macro.h"
#include "jcontext.h"
#include "jrt-libc-includes.h"
#include "jmem-heap.h"
#include "re-bytecode.h"
@ -444,9 +445,6 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
return ret_value;
} /* re_parse_alternative */
static const re_compiled_code_t *re_cache[RE_CACHE_SIZE];
static uint8_t re_cache_idx = RE_CACHE_SIZE;
/**
* Search for the given pattern in the RegExp cache
*
@ -461,7 +459,7 @@ re_find_bytecode_in_cache (ecma_string_t *pattern_str_p, /**< pattern string */
for (uint8_t idx = 0u; idx < RE_CACHE_SIZE; idx++)
{
const re_compiled_code_t *cached_bytecode_p = re_cache[idx];
const re_compiled_code_t *cached_bytecode_p = JERRY_CONTEXT (re_cache)[idx];
if (cached_bytecode_p != NULL)
{
@ -494,14 +492,14 @@ re_cache_gc_run ()
{
for (uint32_t i = 0u; i < RE_CACHE_SIZE; i++)
{
const re_compiled_code_t *cached_bytecode_p = re_cache[i];
const re_compiled_code_t *cached_bytecode_p = JERRY_CONTEXT (re_cache)[i];
if (cached_bytecode_p != NULL
&& cached_bytecode_p->header.refs == 1)
{
/* Only the cache has reference for the bytecode */
ecma_bytecode_deref ((ecma_compiled_code_t *) cached_bytecode_p);
re_cache[i] = NULL;
JERRY_CONTEXT (re_cache)[i] = NULL;
}
}
} /* re_cache_gc_run */
@ -524,7 +522,7 @@ re_compile_bytecode (const re_compiled_code_t **out_bytecode_p, /**< [out] point
if (cache_idx < RE_CACHE_SIZE)
{
*out_bytecode_p = re_cache[cache_idx];
*out_bytecode_p = JERRY_CONTEXT (re_cache)[cache_idx];
if (*out_bytecode_p != NULL)
{
@ -614,25 +612,26 @@ re_compile_bytecode (const re_compiled_code_t **out_bytecode_p, /**< [out] point
if (cache_idx == RE_CACHE_SIZE)
{
if (re_cache_idx == 0u)
if (JERRY_CONTEXT (re_cache_idx) == RE_CACHE_SIZE)
{
re_cache_idx = RE_CACHE_SIZE;
JERRY_CONTEXT (re_cache_idx) = 0;
}
const re_compiled_code_t *cached_bytecode_p = re_cache[--re_cache_idx];
JERRY_DDLOG ("RegExp cache is full! Remove the element on idx: %d\n", re_cache_idx);
JERRY_DDLOG ("RegExp cache is full! Remove the element on idx: %d\n", JERRY_CONTEXT (re_cache_idx));
if (cached_bytecode_p != NULL)
cache_idx = JERRY_CONTEXT (re_cache_idx)++;
/* The garbage collector might run during the byte code
* allocations above and it may free this entry. */
if (JERRY_CONTEXT (re_cache)[cache_idx] != NULL)
{
ecma_bytecode_deref ((ecma_compiled_code_t *) cached_bytecode_p);
ecma_bytecode_deref ((ecma_compiled_code_t *) JERRY_CONTEXT (re_cache)[cache_idx]);
}
cache_idx = re_cache_idx;
}
JERRY_DDLOG ("Insert bytecode into RegExp cache (idx: %d).\n", cache_idx);
ecma_bytecode_ref ((ecma_compiled_code_t *) *out_bytecode_p);
re_cache[cache_idx] = *out_bytecode_p;
JERRY_CONTEXT (re_cache)[cache_idx] = *out_bytecode_p;
}
return ret_value;

View File

@ -31,6 +31,7 @@
#include "ecma-objects-general.h"
#include "ecma-regexp-object.h"
#include "ecma-try-catch-macro.h"
#include "jcontext.h"
#include "opcodes.h"
#include "vm.h"
#include "vm-stack.h"
@ -44,16 +45,6 @@
* @{
*/
/**
* Top (current) interpreter context
*/
static vm_frame_ctx_t *vm_top_context_p = NULL;
/**
* Direct call from eval;
*/
static bool is_direct_eval_form_call = false;
/**
* Get the value of object[property].
*
@ -240,8 +231,8 @@ vm_run_eval (ecma_compiled_code_t *bytecode_data_p, /**< byte-code data */
/* ECMA-262 v5, 10.4.2 */
if (is_direct)
{
this_binding = ecma_copy_value (vm_top_context_p->this_binding);
lex_env_p = vm_top_context_p->lex_env_p;
this_binding = ecma_copy_value (JERRY_CONTEXT (vm_top_context_p)->this_binding);
lex_env_p = JERRY_CONTEXT (vm_top_context_p)->lex_env_p;
}
else
{
@ -394,7 +385,7 @@ opfunc_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
arguments_list_len);
}
is_direct_eval_form_call = false;
JERRY_CONTEXT (is_direct_eval_form_call) = false;
/* Free registers. */
for (uint32_t i = 0; i < arguments_list_len; i++)
@ -1346,7 +1337,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
}
case VM_OC_EVAL:
{
is_direct_eval_form_call = true;
JERRY_CONTEXT (is_direct_eval_form_call) = true;
JERRY_ASSERT (*byte_code_p >= CBC_CALL && *byte_code_p <= CBC_CALL2_PROP_BLOCK);
continue;
}
@ -2574,10 +2565,10 @@ vm_execute (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
}
}
is_direct_eval_form_call = false;
JERRY_CONTEXT (is_direct_eval_form_call) = false;
prev_context_p = vm_top_context_p;
vm_top_context_p = frame_ctx_p;
prev_context_p = JERRY_CONTEXT (vm_top_context_p);
JERRY_CONTEXT (vm_top_context_p) = frame_ctx_p;
completion_value = vm_init_loop (frame_ctx_p);
@ -2610,7 +2601,7 @@ vm_execute (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
ecma_fast_free_value (frame_ctx_p->registers_p[i]);
}
vm_top_context_p = prev_context_p;
JERRY_CONTEXT (vm_top_context_p) = prev_context_p;
return completion_value;
} /* vm_execute */
@ -2724,9 +2715,9 @@ vm_run (const ecma_compiled_code_t *bytecode_header_p, /**< byte-code data heade
bool
vm_is_strict_mode (void)
{
JERRY_ASSERT (vm_top_context_p != NULL);
JERRY_ASSERT (JERRY_CONTEXT (vm_top_context_p) != NULL);
return vm_top_context_p->bytecode_header_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE;
return JERRY_CONTEXT (vm_top_context_p)->bytecode_header_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE;
} /* vm_is_strict_mode */
/**
@ -2741,10 +2732,10 @@ vm_is_strict_mode (void)
* without 'this' argument,
* false - otherwise.
*/
bool
inline bool __attr_always_inline___
vm_is_direct_eval_form_call (void)
{
return is_direct_eval_form_call;
return JERRY_CONTEXT (is_direct_eval_form_call);
} /* vm_is_direct_eval_form_call */
/**

View File

@ -65,7 +65,6 @@ main ()
lit_utf8_size_t lengths[test_sub_iters];
jmem_init ();
ecma_init_lit_storage ();
for (uint32_t i = 0; i < test_iters; i++)
{