Skip to content

Commit 5efa522

Browse files
Introducing MEM_CP_{GET_[NON_NULL_]POINTER, SET_[NON_NULL_]POINTER} getters / setters for compressed pointers.
1 parent da86a52 commit 5efa522

File tree

6 files changed

+62
-58
lines changed

6 files changed

+62
-58
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
* The offset is shifted right by MEM_ALIGNMENT_LOG.
3939
* Least significant MEM_ALIGNMENT_LOG bits of non-shifted offset are zeroes.
4040
*/
41-
#define ECMA_POINTER_FIELD_WIDTH MEM_COMPRESSED_POINTER_WIDTH
41+
#define ECMA_POINTER_FIELD_WIDTH MEM_CP_WIDTH
4242

4343
/**
4444
* The NULL value for compressed pointers
4545
*/
46-
#define ECMA_NULL_POINTER MEM_COMPRESSED_POINTER_NULL
46+
#define ECMA_NULL_POINTER MEM_CP_NULL
4747

4848
/**
4949
* @}

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

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,27 @@
2727
#include "mem-allocator.h"
2828

2929
/**
30-
* Get value of pointer from specified non-null compressed pointer field.
30+
* Get value of pointer from specified non-null compressed pointer.
3131
*/
32-
#define ECMA_GET_NON_NULL_POINTER(type, field) \
33-
((type *) mem_decompress_pointer (field))
32+
#define ECMA_GET_NON_NULL_POINTER(type, field) MEM_CP_GET_NON_NULL_POINTER (type, field)
3433

3534
/**
36-
* Get value of pointer from specified compressed pointer field.
35+
* Get value of pointer from specified compressed pointer.
3736
*/
38-
#define ECMA_GET_POINTER(type, field) \
39-
(((unlikely (field == ECMA_NULL_POINTER)) ? NULL : ECMA_GET_NON_NULL_POINTER (type, field)))
37+
#define ECMA_GET_POINTER(type, field) MEM_CP_GET_POINTER (type, field)
4038

4139
/**
42-
* Set value of non-null compressed pointer field so that it will correspond
40+
* Set value of non-null compressed pointer so that it will correspond
4341
* to specified non_compressed_pointer.
4442
*/
45-
#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) \
46-
(field) = (mem_compress_pointer (non_compressed_pointer) & \
47-
((((mem_cpointer_t) 1u) << ECMA_POINTER_FIELD_WIDTH) - 1))
43+
#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) MEM_CP_SET_NON_NULL_POINTER (field, \
44+
non_compressed_pointer)
4845

4946
/**
50-
* Set value of compressed pointer field so that it will correspond
47+
* Set value of compressed pointer so that it will correspond
5148
* to specified non_compressed_pointer.
5249
*/
53-
#define ECMA_SET_POINTER(field, non_compressed_pointer) \
54-
do \
55-
{ \
56-
auto __temp_pointer = non_compressed_pointer; \
57-
non_compressed_pointer = __temp_pointer; \
58-
} while (0); \
59-
\
60-
if (unlikely ((non_compressed_pointer) == NULL)) \
61-
{ \
62-
(field) = ECMA_NULL_POINTER; \
63-
} \
64-
else \
65-
{ \
66-
ECMA_SET_NON_NULL_POINTER (field, non_compressed_pointer); \
67-
}
50+
#define ECMA_SET_POINTER(field, non_compressed_pointer) MEM_CP_SET_POINTER (field, non_compressed_pointer)
6851

6952
/* ecma-helpers-value.c */
7053
extern bool ecma_is_value_empty (ecma_value_t value);

jerry-core/mem/mem-allocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ mem_compress_pointer (const void *pointer) /**< pointer to compress */
109109

110110
JERRY_ASSERT((int_ptr & ~((1u << MEM_HEAP_OFFSET_LOG) - 1)) == 0);
111111

112-
JERRY_ASSERT(int_ptr != MEM_COMPRESSED_POINTER_NULL);
112+
JERRY_ASSERT (int_ptr != MEM_CP_NULL);
113113

114114
return int_ptr;
115115
} /* mem_compress_pointer */
@@ -120,7 +120,7 @@ mem_compress_pointer (const void *pointer) /**< pointer to compress */
120120
void*
121121
mem_decompress_pointer (uintptr_t compressed_pointer) /**< pointer to decompress */
122122
{
123-
JERRY_ASSERT(compressed_pointer != MEM_COMPRESSED_POINTER_NULL);
123+
JERRY_ASSERT (compressed_pointer != MEM_CP_NULL);
124124

125125
uintptr_t int_ptr = compressed_pointer;
126126

jerry-core/mem/mem-allocator.h

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef uint16_t mem_cpointer_t;
3636
/**
3737
* Representation of NULL value for compressed pointers
3838
*/
39-
#define MEM_COMPRESSED_POINTER_NULL 0
39+
#define MEM_CP_NULL 0
4040

4141
/**
4242
* Required alignment for allocated units/blocks
@@ -46,12 +46,12 @@ typedef uint16_t mem_cpointer_t;
4646
/**
4747
* Width of compressed memory pointer
4848
*/
49-
#define MEM_COMPRESSED_POINTER_WIDTH (MEM_HEAP_OFFSET_LOG - MEM_ALIGNMENT_LOG)
49+
#define MEM_CP_WIDTH (MEM_HEAP_OFFSET_LOG - MEM_ALIGNMENT_LOG)
5050

5151
/**
5252
* Compressed pointer value mask
5353
*/
54-
#define MEM_COMPRESSED_POINTER_MASK ((1ull << MEM_COMPRESSED_POINTER_WIDTH) - 1)
54+
#define MEM_CP_MASK ((1ull << MEM_CP_WIDTH) - 1)
5555

5656
/**
5757
* Heap offset value mask
@@ -80,6 +80,45 @@ typedef enum
8080
*/
8181
typedef void (*mem_try_give_memory_back_callback_t) (mem_try_give_memory_back_severity_t);
8282

83+
/**
84+
* Get value of pointer from specified non-null compressed pointer value
85+
*/
86+
#define MEM_CP_GET_NON_NULL_POINTER(type, cp_value) \
87+
((type *) mem_decompress_pointer (cp_value))
88+
89+
/**
90+
* Get value of pointer from specified compressed pointer value
91+
*/
92+
#define MEM_CP_GET_POINTER(type, cp_value) \
93+
(((unlikely ((cp_value) == MEM_CP_NULL)) ? NULL : MEM_CP_GET_NON_NULL_POINTER (type, cp_value)))
94+
95+
/**
96+
* Set value of non-null compressed pointer so that it will correspond
97+
* to specified non_compressed_pointer
98+
*/
99+
#define MEM_CP_SET_NON_NULL_POINTER(cp_value, non_compressed_pointer) \
100+
(cp_value) = (mem_compress_pointer (non_compressed_pointer) & MEM_CP_MASK)
101+
102+
/**
103+
* Set value of compressed pointer so that it will correspond
104+
* to specified non_compressed_pointer
105+
*/
106+
#define MEM_CP_SET_POINTER(cp_value, non_compressed_pointer) \
107+
do \
108+
{ \
109+
auto __temp_pointer = non_compressed_pointer; \
110+
non_compressed_pointer = __temp_pointer; \
111+
} while (0); \
112+
\
113+
if (unlikely ((non_compressed_pointer) == NULL)) \
114+
{ \
115+
(cp_value) = MEM_CP_NULL; \
116+
} \
117+
else \
118+
{ \
119+
MEM_CP_SET_NON_NULL_POINTER (cp_value, non_compressed_pointer); \
120+
}
121+
83122
extern void mem_init (void);
84123
extern void mem_finalize (bool is_show_mem_stats);
85124

jerry-core/mem/mem-pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef struct __attribute__ ((aligned (MEM_ALIGNMENT))) mem_pool_state_t
6565
mem_pool_chunk_index_t free_chunks_number : MEM_POOL_MAX_CHUNKS_NUMBER_LOG;
6666

6767
/** Pointer to the next pool with same chunk size */
68-
mem_cpointer_t next_pool_cp : MEM_COMPRESSED_POINTER_WIDTH;
68+
mem_cpointer_t next_pool_cp : MEM_CP_WIDTH;
6969
} mem_pool_state_t;
7070

7171
extern void mem_pool_init (mem_pool_state_t *pool_p, size_t pool_size);

jerry-core/mem/mem-poolman.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,7 @@ mem_pools_alloc_longpath (void)
110110

111111
mem_pool_init (pool_state, MEM_POOL_SIZE);
112112

113-
if (mem_pools == NULL)
114-
{
115-
pool_state->next_pool_cp = MEM_COMPRESSED_POINTER_NULL;
116-
}
117-
else
118-
{
119-
pool_state->next_pool_cp = mem_compress_pointer (mem_pools) & MEM_COMPRESSED_POINTER_MASK;
120-
}
113+
MEM_CP_SET_POINTER (pool_state->next_pool_cp, mem_pools);
121114

122115
mem_pools = pool_state;
123116

@@ -137,15 +130,13 @@ mem_pools_alloc_longpath (void)
137130
while (pool_state->first_free_chunk == MEM_POOL_CHUNKS_NUMBER)
138131
{
139132
prev_pool_state_p = pool_state;
140-
pool_state = (mem_pool_state_t*) mem_decompress_pointer (pool_state->next_pool_cp);
141-
142-
JERRY_ASSERT(pool_state != NULL);
133+
pool_state = MEM_CP_GET_NON_NULL_POINTER (mem_pool_state_t, pool_state->next_pool_cp);
143134
}
144135

145136
JERRY_ASSERT (prev_pool_state_p != NULL && pool_state != mem_pools);
146137

147138
prev_pool_state_p->next_pool_cp = pool_state->next_pool_cp;
148-
pool_state->next_pool_cp = mem_compress_pointer (mem_pools) & MEM_COMPRESSED_POINTER_MASK;
139+
MEM_CP_SET_NON_NULL_POINTER (pool_state->next_pool_cp, mem_pools);
149140
mem_pools = pool_state;
150141
}
151142

@@ -195,9 +186,7 @@ mem_pools_free (uint8_t *chunk_p) /**< pointer to the chunk */
195186
while (!mem_pool_is_chunk_inside (pool_state, chunk_p))
196187
{
197188
prev_pool_state_p = pool_state;
198-
pool_state = (mem_pool_state_t*) mem_decompress_pointer (pool_state->next_pool_cp);
199-
200-
JERRY_ASSERT(pool_state != NULL);
189+
pool_state = MEM_CP_GET_NON_NULL_POINTER (mem_pool_state_t, pool_state->next_pool_cp);
201190
}
202191

203192
/**
@@ -219,14 +208,7 @@ mem_pools_free (uint8_t *chunk_p) /**< pointer to the chunk */
219208
}
220209
else
221210
{
222-
if (pool_state->next_pool_cp == MEM_COMPRESSED_POINTER_NULL)
223-
{
224-
mem_pools = NULL;
225-
}
226-
else
227-
{
228-
mem_pools = (mem_pool_state_t*) mem_decompress_pointer (pool_state->next_pool_cp);
229-
}
211+
mem_pools = MEM_CP_GET_POINTER (mem_pool_state_t, pool_state->next_pool_cp);
230212
}
231213

232214
mem_free_chunks_number -= MEM_POOL_CHUNKS_NUMBER;
@@ -240,7 +222,7 @@ mem_pools_free (uint8_t *chunk_p) /**< pointer to the chunk */
240222
JERRY_ASSERT (prev_pool_state_p != NULL);
241223

242224
prev_pool_state_p->next_pool_cp = pool_state->next_pool_cp;
243-
pool_state->next_pool_cp = mem_compress_pointer (mem_pools) & MEM_COMPRESSED_POINTER_MASK;
225+
MEM_CP_SET_NON_NULL_POINTER (pool_state->next_pool_cp, mem_pools);
244226
mem_pools = pool_state;
245227
}
246228
} /* mem_pools_free */

0 commit comments

Comments
 (0)