34#define NUM_POOLS (sizeof(pool_sizes) / sizeof(pool_size_spec))
58#define ADDR_IN_STATE_ALLOC(st,p) \
59 ((char *) (p) >= (st)->alloc_start && (char *) (p) < (st)->alloc_end)
60#define ADDR_IN_HEADER_ALLOC(hdr,p) \
61 ((char *) (p) >= (hdr)->alloc_start && (char *) (p) < (hdr)->alloc_end)
63#ifdef DUK_ALLOC_HYBRID_DEBUG
69 printf(
"=== Pool state: st=%p\n", (
void *) st);
77 printf(
"[%d]: size %ld, count %ld, used %ld, free list len %ld\n",
79 (
long) (hdr->
count - free_len),
91 size_t total_size, max_size;
103 for (i = 0, total_size = 0, max_size = 0; i < (int)
NUM_POOLS; i++) {
104#ifdef DUK_ALLOC_HYBRID_DEBUG
112#ifdef DUK_ALLOC_HYBRID_DEBUG
113 printf(
"Total size %ld, max pool size %ld\n", (
long) total_size, (
long) max_size);
164#ifdef DUK_ALLOC_HYBRID_DEBUG
165 printf(
"alloc fallback: %ld\n", (
long) size);
172 if (hdr->
size < size) {
178 printf(
"alloc from pool: %ld -> pool size %ld\n", (
long) size, (
long) hdr->
size);
180 new_ptr = (
void *) hdr->
free;
184#ifdef DUK_ALLOC_HYBRID_DEBUG
185 printf(
"alloc out of pool entries: %ld -> pool size %ld\n", (
long) size, (
long) hdr->
size);
191#ifdef DUK_ALLOC_HYBRID_DEBUG
192 printf(
"alloc fallback (out of pool): %ld\n", (
long) size);
211 if (size <= hdr->size) {
214 printf(
"realloc original from pool: still fits, size %ld, pool size %ld\n",
215 (
long) size, (
long) hdr->
size);
222#ifdef DUK_ALLOC_HYBRID_DEBUG
223 printf(
"realloc original from pool: needed larger size, failed to alloc\n");
227 memcpy(new_ptr, ptr, hdr->
size);
232 printf(
"realloc original from pool: size %ld, pool size %ld\n", (
long) size, (
long) hdr->
size);
237#ifdef DUK_ALLOC_HYBRID_DEBUG
241 }
else if (ptr !=
NULL) {
246#ifdef DUK_ALLOC_HYBRID_DEBUG
247 printf(
"realloc fallback: size %ld\n", (
long) size);
253 printf(
"realloc NULL ptr, call alloc: %ld\n", (
long) size);
272 printf(
"free out of pool: %p\n", (
void *) ptr);
284 printf(
"free from pool: %p\n", ptr);
290#ifdef DUK_ALLOC_HYBRID_DEBUG
void * duk_realloc_hybrid(void *udata, void *ptr, duk_size_t size)
static void dump_pool_state(pool_state *st)
void * duk_alloc_hybrid_init(void)
void * duk_alloc_hybrid(void *udata, duk_size_t size)
void duk_free_hybrid(void *udata, void *ptr)
#define ADDR_IN_STATE_ALLOC(st, p)
#define ADDR_IN_HEADER_ALLOC(hdr, p)
static pool_size_spec pool_sizes[]
pool_header headers[NUM_POOLS]