Introducing MEM_CP_{GET_[NON_NULL_]POINTER, SET_[NON_NULL_]POINTER} getters / setters for compressed pointers.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -36,7 +36,7 @@ typedef uint16_t mem_cpointer_t;
|
||||
/**
|
||||
* Representation of NULL value for compressed pointers
|
||||
*/
|
||||
#define MEM_COMPRESSED_POINTER_NULL 0
|
||||
#define MEM_CP_NULL 0
|
||||
|
||||
/**
|
||||
* Required alignment for allocated units/blocks
|
||||
@@ -46,12 +46,12 @@ typedef uint16_t mem_cpointer_t;
|
||||
/**
|
||||
* Width of compressed memory pointer
|
||||
*/
|
||||
#define MEM_COMPRESSED_POINTER_WIDTH (MEM_HEAP_OFFSET_LOG - MEM_ALIGNMENT_LOG)
|
||||
#define MEM_CP_WIDTH (MEM_HEAP_OFFSET_LOG - MEM_ALIGNMENT_LOG)
|
||||
|
||||
/**
|
||||
* Compressed pointer value mask
|
||||
*/
|
||||
#define MEM_COMPRESSED_POINTER_MASK ((1ull << MEM_COMPRESSED_POINTER_WIDTH) - 1)
|
||||
#define MEM_CP_MASK ((1ull << MEM_CP_WIDTH) - 1)
|
||||
|
||||
/**
|
||||
* Heap offset value mask
|
||||
@@ -80,6 +80,45 @@ typedef enum
|
||||
*/
|
||||
typedef void (*mem_try_give_memory_back_callback_t) (mem_try_give_memory_back_severity_t);
|
||||
|
||||
/**
|
||||
* Get value of pointer from specified non-null compressed pointer value
|
||||
*/
|
||||
#define MEM_CP_GET_NON_NULL_POINTER(type, cp_value) \
|
||||
((type *) mem_decompress_pointer (cp_value))
|
||||
|
||||
/**
|
||||
* Get value of pointer from specified compressed pointer value
|
||||
*/
|
||||
#define MEM_CP_GET_POINTER(type, cp_value) \
|
||||
(((unlikely ((cp_value) == MEM_CP_NULL)) ? NULL : MEM_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 MEM_CP_SET_NON_NULL_POINTER(cp_value, non_compressed_pointer) \
|
||||
(cp_value) = (mem_compress_pointer (non_compressed_pointer) & MEM_CP_MASK)
|
||||
|
||||
/**
|
||||
* Set value of compressed pointer so that it will correspond
|
||||
* to specified non_compressed_pointer
|
||||
*/
|
||||
#define MEM_CP_SET_POINTER(cp_value, non_compressed_pointer) \
|
||||
do \
|
||||
{ \
|
||||
auto __temp_pointer = non_compressed_pointer; \
|
||||
non_compressed_pointer = __temp_pointer; \
|
||||
} while (0); \
|
||||
\
|
||||
if (unlikely ((non_compressed_pointer) == NULL)) \
|
||||
{ \
|
||||
(cp_value) = MEM_CP_NULL; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
MEM_CP_SET_NON_NULL_POINTER (cp_value, non_compressed_pointer); \
|
||||
}
|
||||
|
||||
extern void mem_init (void);
|
||||
extern void mem_finalize (bool is_show_mem_stats);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user