Péter Gál 01ecc7bb7b Rework usages/naming of configuration macros [part 2] (#2903)
There are quite a few configuration macros in the project.
As discussed in the #2520 issue there are a few awkward constructs.

Main changes:

* The following macros are now 0/1 switches:
** Renamed CONFIG_ECMA_LCACHE_DISABLE to JERRY_LCACHE.
** Renamed CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE to JERRY_PROPERTY_HASHMAP.
** Renamed CONFIG_DISABLE_UNICODE_CASE_CONVERSION to JERRY_UNICODE_CASE_CONVERSION.
** Renamed ENABLE_REGEXP_STRICT_MODE to JERRY_REGEXP_STRICT_MODE.
** Renamed JERRY_DISABLE_JS_PARSER to JERRY_PARSER.
** Renamed JERRY_ENABLE_ERROR_MESSAGES to JERRY_ERROR_MESSAGES.
** Renamed JERRY_ENABLE_EXTERNAL_CONTEXT to JERRY_EXTERNAL_CONTEXT.
** Renamed JERRY_ENABLE_LINE_INFO to JERRY_LINE_INFO.
** Renamed JERRY_ENABLE_LOGGING to JERRY_LOGGING.
** Renamed JERRY_ENABLE_SNAPSHOT_EXEC to JERRY_SNAPSHOT_EXEC.
** Renamed JERRY_ENABLE_SNAPSHOT_SAVE to JERRY_SNAPSHOT_SAVE.
** Renamed JERRY_SYSTEM_ALLOCATOR to JERRY_SYSTEM_ALLOCATOR.
** Renamed JERRY_VM_EXEC_STOP to JERRY_VM_EXEC_STOP.
** Renamed JMEM_GC_BEFORE_EACH_ALLOC to JERRY_MEM_GC_BEFORE_EACH_ALLOC.
** Renamed JMEM_STATS to JERRY_MEM_STATS.
** Renamed PARSER_DUMP_BYTE_CODE to JERRY_PARSER_DUMP_BYTE_CODE.
** Renamed REGEXP_DUMP_BYTE_CODE to JERRY_REGEXP_DUMP_BYTE_CODE.
* Recursion check changes:
** Renamed REGEXP_RECURSION_LIMIT to JERRY_REGEXP_RECURSION_LIMIT.
** Renamed VM_RECURSION_LIMIT to JERRY_VM_RECURSION_LIMIT.
* Attribute macro changes:
** Renamed JERRY_CONST_DATA to JERRY_ATTR_CONST_DATA.
** Renamed JERRY_HEAP_SECTION_ATTR to JERRY_ATTR_GLOBAL_HEAP.
  Now the macro can specify any attribute for the global heap object.
* Other macro changes:
** Renamed CONFIG_MEM_HEAP_AREA_SIZE to JERRY_GLOBAL_HEAP_SIZE.
   Then new macro now specify the global heap size in kilobytes.
* Updated documentations to reflect the new macro names.

For more deatils please see jerry-core/config.h.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-06-19 12:28:21 +02:00

287 lines
11 KiB
C

/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Engine context for JerryScript
*/
#ifndef JCONTEXT_H
#define JCONTEXT_H
#include "debugger.h"
#include "ecma-builtins.h"
#include "ecma-jobqueue.h"
#include "jerryscript-port.h"
#include "jmem.h"
#include "re-bytecode.h"
#include "vm-defines.h"
#include "jerryscript.h"
#include "jerryscript-debugger-transport.h"
#include "js-parser-internal.h"
/** \addtogroup context Context
* @{
*/
/**
* Advanced allocator configurations.
*/
/**
* Maximum global heap size in bytes
*/
#define CONFIG_MEM_HEAP_SIZE (JERRY_GLOBAL_HEAP_SIZE * 1024)
/**
* Max heap usage limit
*/
#define CONFIG_MEM_HEAP_MAX_LIMIT 8192
/**
* Desired limit of heap usage
*/
#define CONFIG_MEM_HEAP_DESIRED_LIMIT (JERRY_MIN (CONFIG_MEM_HEAP_SIZE / 32, CONFIG_MEM_HEAP_MAX_LIMIT))
/**
* Share of newly allocated since last GC objects among all currently allocated objects,
* after achieving which, GC is started upon low severity try-give-memory-back requests.
*
* Share is calculated as the following:
* 1.0 / CONFIG_ECMA_GC_NEW_OBJECTS_SHARE_TO_START_GC
*/
#define CONFIG_ECMA_GC_NEW_OBJECTS_SHARE_TO_START_GC (16)
#if !ENABLED (JERRY_SYSTEM_ALLOCATOR)
/**
* Heap structure
*
* Memory blocks returned by the allocator must not start from the
* beginning of the heap area because offset 0 is reserved for
* JMEM_CP_NULL. This special constant is used in several places,
* e.g. it marks the end of the property chain list, so it cannot
* be eliminated from the project. Although the allocator cannot
* use the first 8 bytes of the heap, nothing prevents to use it
* for other purposes. Currently the free region start is stored
* there.
*/
typedef struct jmem_heap_t jmem_heap_t;
#endif /* !ENABLED (JERRY_SYSTEM_ALLOCATOR) */
/**
* User context item
*/
typedef struct jerry_context_data_header
{
struct jerry_context_data_header *next_p; /**< pointer to next context item */
const jerry_context_data_manager_t *manager_p; /**< manager responsible for deleting this item */
} jerry_context_data_header_t;
#define JERRY_CONTEXT_DATA_HEADER_USER_DATA(item_p) \
((uint8_t *) (item_p + 1))
/**
* First non-external member of the jerry context
*/
#define JERRY_CONTEXT_FIRST_MEMBER ecma_builtin_objects
/**
* JerryScript context
*
* The purpose of this header is storing
* all global variables for Jerry
*/
struct jerry_context_t
{
/* The value of external context members must be preserved across initializations and cleanups. */
#if ENABLED (JERRY_EXTERNAL_CONTEXT)
#if !ENABLED (JERRY_SYSTEM_ALLOCATOR)
jmem_heap_t *heap_p; /**< point to the heap aligned to JMEM_ALIGNMENT. */
uint32_t heap_size; /**< size of the heap */
#endif /* !ENABLED (JERRY_SYSTEM_ALLOCATOR) */
#endif /* ENABLED (JERRY_EXTERNAL_CONTEXT) */
/* Update JERRY_CONTEXT_FIRST_MEMBER if the first non-external member changes */
ecma_object_t *ecma_builtin_objects[ECMA_BUILTIN_ID__COUNT]; /**< pointer to instances of built-in objects */
#if ENABLED (JERRY_BUILTIN_REGEXP)
const re_compiled_code_t *re_cache[RE_CACHE_SIZE]; /**< regex cache */
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
ecma_object_t *ecma_gc_objects_p; /**< List of currently alive objects. */
jmem_heap_free_t *jmem_heap_list_skip_p; /**< This is used to speed up deallocation. */
jmem_pools_chunk_t *jmem_free_8_byte_chunk_p; /**< list of free eight byte pool chunks */
#if ENABLED (JERRY_CPOINTER_32_BIT)
jmem_pools_chunk_t *jmem_free_16_byte_chunk_p; /**< list of free sixteen byte pool chunks */
#endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
jmem_free_unused_memory_callback_t jmem_free_unused_memory_callback; /**< Callback for freeing up memory. */
const lit_utf8_byte_t * const *lit_magic_string_ex_array; /**< array of external magic strings */
const lit_utf8_size_t *lit_magic_string_ex_sizes; /**< external magic string lengths */
ecma_lit_storage_item_t *string_list_first_p; /**< first item of the literal string list */
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
ecma_lit_storage_item_t *symbol_list_first_p; /**< first item of the global symbol list */
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
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 */
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
ecma_module_t *ecma_modules_p; /**< list of referenced modules */
ecma_module_context_t *module_top_context_p; /**< top (current) module parser context */
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
vm_frame_ctx_t *vm_top_context_p; /**< top (current) interpreter context */
jerry_context_data_header_t *context_data_p; /**< linked list of user-provided context-specific pointers */
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 */
size_t jmem_heap_allocated_size; /**< size of allocated regions */
size_t jmem_heap_limit; /**< current limit of heap usage, that is upon being reached,
* causes call of "try give memory back" callbacks */
ecma_value_t error_value; /**< currently thrown error value */
uint32_t lit_magic_string_ex_count; /**< external magic strings count */
uint32_t jerry_init_flags; /**< run-time configuration flags */
uint32_t status_flags; /**< run-time flags (the top 8 bits are used for passing class parsing options) */
#if ENABLED (JERRY_PROPRETY_HASHMAP)
uint8_t ecma_prop_hashmap_alloc_state; /**< property hashmap allocation state: 0-4,
* if !0 property hashmap allocation is disabled */
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
#if ENABLED (JERRY_BUILTIN_REGEXP)
uint8_t re_cache_idx; /**< evicted item index when regex cache is full (round-robin) */
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
ecma_job_queueitem_t *job_queue_head_p; /**< points to the head item of the jobqueue */
ecma_job_queueitem_t *job_queue_tail_p; /**< points to the tail item of the jobqueue*/
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
#if ENABLED (JERRY_VM_EXEC_STOP)
uint32_t vm_exec_stop_frequency; /**< reset value for vm_exec_stop_counter */
uint32_t vm_exec_stop_counter; /**< down counter for reducing the calls of vm_exec_stop_cb */
void *vm_exec_stop_user_p; /**< user pointer for vm_exec_stop_cb */
ecma_vm_exec_stop_callback_t vm_exec_stop_cb; /**< user function which returns whether the
* ECMAScript execution should be stopped */
#endif /* ENABLED (JERRY_VM_EXEC_STOP) */
#if defined (JERRY_VM_RECURSION_LIMIT) && (JERRY_VM_RECURSION_LIMIT != 0)
uint32_t vm_recursion_counter; /**< VM recursion counter */
#endif /* defined (JERRY_VM_RECURSION_LIMIT) && (JERRY_VM_RECURSION_LIMIT != 0) */
#ifdef JERRY_DEBUGGER
uint8_t debugger_send_buffer[JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE]; /**< buffer for sending messages */
uint8_t debugger_receive_buffer[JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE]; /**< buffer for receiving messages */
jerry_debugger_transport_header_t *debugger_transport_header_p; /**< head of transport protocol chain */
uint8_t *debugger_send_buffer_payload_p; /**< start where the outgoing message can be written */
vm_frame_ctx_t *debugger_stop_context; /**< stop only if the current context is equal to this context */
uint8_t *debugger_exception_byte_code_p; /**< Location of the currently executed byte code if an
* error occours while the vm_loop is suspended */
jmem_cpointer_t debugger_byte_code_free_head; /**< head of byte code free linked list */
jmem_cpointer_t debugger_byte_code_free_tail; /**< tail of byte code free linked list */
uint32_t debugger_flags; /**< debugger flags */
uint16_t debugger_received_length; /**< length of currently received bytes */
uint8_t debugger_message_delay; /**< call receive message when reaches zero */
uint8_t debugger_max_send_size; /**< maximum amount of data that can be sent */
uint8_t debugger_max_receive_size; /**< maximum amount of data that can be received */
#endif /* JERRY_DEBUGGER */
#if ENABLED (JERRY_LINE_INFO)
ecma_value_t resource_name; /**< resource name (usually a file name) */
#endif /* ENABLED (JERRY_LINE_INFO) */
#if ENABLED (JERRY_MEM_STATS)
jmem_heap_stats_t jmem_heap_stats; /**< heap's memory usage statistics */
#endif /* ENABLED (JERRY_MEM_STATS) */
/* This must be at the end of the context for performance reasons */
#if ENABLED (JERRY_LCACHE)
/** hash table for caching the last access of properties */
ecma_lcache_hash_entry_t lcache[ECMA_LCACHE_HASH_ROWS_COUNT][ECMA_LCACHE_HASH_ROW_LENGTH];
#endif /* ENABLED (JERRY_LCACHE) */
};
#if ENABLED (JERRY_EXTERNAL_CONTEXT)
/*
* This part is for JerryScript which uses external context.
*/
#define JERRY_CONTEXT(field) (jerry_port_get_current_context ()->field)
#if !ENABLED (JERRY_SYSTEM_ALLOCATOR)
#define JMEM_HEAP_SIZE (JERRY_CONTEXT (heap_size))
#define JMEM_HEAP_AREA_SIZE (JMEM_HEAP_SIZE - JMEM_ALIGNMENT)
struct jmem_heap_t
{
jmem_heap_free_t first; /**< first node in free region list */
uint8_t area[]; /**< heap area */
};
#define JERRY_HEAP_CONTEXT(field) (JERRY_CONTEXT (heap_p)->field)
#endif /* !ENABLED (JERRY_SYSTEM_ALLOCATOR) */
#else /* !ENABLED (JERRY_EXTERNAL_CONTEXT) */
/*
* This part is for JerryScript which uses default context.
*/
/**
* Global context.
*/
extern jerry_context_t jerry_global_context;
/**
* Provides a reference to a field in the current context.
*/
#define JERRY_CONTEXT(field) (jerry_global_context.field)
#if !ENABLED (JERRY_SYSTEM_ALLOCATOR)
/**
* Size of heap
*/
#define JMEM_HEAP_SIZE ((size_t) (CONFIG_MEM_HEAP_SIZE))
/**
* Calculate heap area size, leaving space for a pointer to the free list
*/
#define JMEM_HEAP_AREA_SIZE (JMEM_HEAP_SIZE - JMEM_ALIGNMENT)
struct jmem_heap_t
{
jmem_heap_free_t first; /**< first node in free region list */
uint8_t area[JMEM_HEAP_AREA_SIZE]; /**< heap area */
};
/**
* Global heap.
*/
extern jmem_heap_t jerry_global_heap;
/**
* Provides a reference to a field of the heap.
*/
#define JERRY_HEAP_CONTEXT(field) (jerry_global_heap.field)
#endif /* !ENABLED (JERRY_SYSTEM_ALLOCATOR) */
#endif /* ENABLED (JERRY_EXTERNAL_CONTEXT) */
/**
* @}
*/
#endif /* !JCONTEXT_H */