mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
This patch: * Ensures that all calls to `jerry_port_log` in jerry-core happen via macros defined in jrt.h. Also, it unifies the names of those macros: as `JERRY_ERROR_MSG` and `JERRY_WARNING_MSG` gave a good pattern that was well aligned with the naming scheme of the log level enum, `JERRY_DLOG` and `JERRY_DDLOG` were rewritten to `JERRY_DEBUG_MSG` and `JERRY_TRACE_MSG`. * Ensures that all debug logging code parts of jerry-core (i.e., memory statistics, JS byte-code dumps, and RegExp byte-code dumps) are guarded by macros: `JMEM_STATS`, `PARSER_DUMP_BYTE_CODE`, and `REGEXP_DUMP_BYTE_CODE`, which in turn are controled by cmake build system feature flags `FEATURE_MEM_STATS`, `FEATURE_PARSER_DUMP`, and `FEATURE_REGEXP_DUMP`. * Ensures that all debug logging functionalities can be controled during run time (provided that they were enabled during build time): the engine has `JERRY_INIT_MEM_STATS[_SEPARATE]`, `JERRY_INIT_SHOW_OPCODES`, `JERRY_INIT_SHOW_REGEXP_OPCODES` init flags, and the default unix/linux command line app has corresponding command line switches.` * Drops `FEATURE_LOG`, `JERRY_ENABLE_LOG`, and `JERRY_INIT_ENABLE_LOG`, as their name was misleadingly general, even though they mostly controled the regexp engine only. The above-mentioned `*REGEXP*` things mostly act as their replacements. * Updates build, test, and measurement tool scripts, and documentation. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
150 lines
3.8 KiB
C
150 lines
3.8 KiB
C
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
/**
|
|
* Allocator interface
|
|
*/
|
|
#ifndef JMEM_ALLOCATOR_H
|
|
#define JMEM_ALLOCATOR_H
|
|
|
|
#include "jrt.h"
|
|
#include "jmem-config.h"
|
|
#include "jmem-heap.h"
|
|
#include "jmem-poolman.h"
|
|
|
|
/** \addtogroup mem Memory allocation
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* Compressed pointer
|
|
*/
|
|
typedef uint16_t jmem_cpointer_t;
|
|
|
|
/**
|
|
* Representation of NULL value for compressed pointers
|
|
*/
|
|
#define JMEM_CP_NULL ((jmem_cpointer_t) 0)
|
|
|
|
/**
|
|
* Required alignment for allocated units/blocks
|
|
*/
|
|
#define JMEM_ALIGNMENT (1u << JMEM_ALIGNMENT_LOG)
|
|
|
|
/**
|
|
* Width of compressed memory pointer
|
|
*/
|
|
#define JMEM_CP_WIDTH (JMEM_HEAP_OFFSET_LOG - JMEM_ALIGNMENT_LOG)
|
|
|
|
/**
|
|
* Compressed pointer value mask
|
|
*/
|
|
#define JMEM_CP_MASK ((1ull << JMEM_CP_WIDTH) - 1)
|
|
|
|
/**
|
|
* Severity of a 'try give memory back' request
|
|
*
|
|
* The request are posted sequentially beginning from
|
|
* low to high until enough memory is freed.
|
|
*
|
|
* If not enough memory is freed upon a high request
|
|
* then the engine is shut down with ERR_OUT_OF_MEMORY.
|
|
*/
|
|
typedef enum
|
|
{
|
|
JMEM_FREE_UNUSED_MEMORY_SEVERITY_LOW, /* 'low' severity */
|
|
JMEM_FREE_UNUSED_MEMORY_SEVERITY_HIGH, /* 'high' severity */
|
|
} jmem_free_unused_memory_severity_t;
|
|
|
|
/**
|
|
* Free region node
|
|
*/
|
|
typedef struct
|
|
{
|
|
uint32_t next_offset; /* Offset of next region in list */
|
|
uint32_t size; /* Size of region */
|
|
} jmem_heap_free_t;
|
|
|
|
/**
|
|
* Node for free chunk list
|
|
*/
|
|
typedef struct mem_pools_chunk
|
|
{
|
|
struct mem_pools_chunk *next_p; /* pointer to next pool chunk */
|
|
} jmem_pools_chunk_t;
|
|
|
|
/**
|
|
* A free memory callback routine type.
|
|
*/
|
|
typedef void (*jmem_free_unused_memory_callback_t) (jmem_free_unused_memory_severity_t);
|
|
|
|
/**
|
|
* Get value of pointer from specified non-null compressed pointer value
|
|
*/
|
|
#define JMEM_CP_GET_NON_NULL_POINTER(type, cp_value) \
|
|
((type *) (jmem_decompress_pointer (cp_value)))
|
|
|
|
/**
|
|
* Get value of pointer from specified compressed pointer value
|
|
*/
|
|
#define JMEM_CP_GET_POINTER(type, cp_value) \
|
|
(((unlikely ((cp_value) == JMEM_CP_NULL)) ? NULL : JMEM_CP_GET_NON_NULL_POINTER (type, cp_value)))
|
|
|
|
/**
|
|
* Set value of non-null compressed pointer so that it will correspond
|
|
* to specified non_compressed_pointer
|
|
*/
|
|
#define JMEM_CP_SET_NON_NULL_POINTER(cp_value, non_compressed_pointer) \
|
|
(cp_value) = (jmem_compress_pointer (non_compressed_pointer) & JMEM_CP_MASK)
|
|
|
|
/**
|
|
* Set value of compressed pointer so that it will correspond
|
|
* to specified non_compressed_pointer
|
|
*/
|
|
#define JMEM_CP_SET_POINTER(cp_value, non_compressed_pointer) \
|
|
do \
|
|
{ \
|
|
void *ptr_value = (void *) non_compressed_pointer; \
|
|
\
|
|
if (unlikely ((ptr_value) == NULL)) \
|
|
{ \
|
|
(cp_value) = JMEM_CP_NULL; \
|
|
} \
|
|
else \
|
|
{ \
|
|
JMEM_CP_SET_NON_NULL_POINTER (cp_value, ptr_value); \
|
|
} \
|
|
} while (false);
|
|
|
|
extern void jmem_init (void);
|
|
extern void jmem_finalize (void);
|
|
|
|
extern uintptr_t jmem_compress_pointer (const void *);
|
|
extern void *jmem_decompress_pointer (uintptr_t);
|
|
|
|
extern void jmem_register_free_unused_memory_callback (jmem_free_unused_memory_callback_t);
|
|
extern void jmem_unregister_free_unused_memory_callback (jmem_free_unused_memory_callback_t);
|
|
|
|
#ifdef JMEM_STATS
|
|
extern void jmem_stats_reset_peak (void);
|
|
extern void jmem_stats_print (void);
|
|
#endif /* JMEM_STATS */
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#endif /* !JMEM_ALLOCATOR_H */
|