static void add_page(pool_t *p) { #ifdef USE_MMAP gcpage_t *pg = (gcpage_t*)mmap(NULL, sizeof(gcpage_t), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); #else gcpage_t *pg = (gcpage_t*)malloc_a16(sizeof(gcpage_t)); #endif if (pg == NULL) jl_throw(jl_memory_exception); gcval_t *v = (gcval_t*)&pg->data[0]; char *lim = (char*)v + GC_PAGE_SZ - p->osize; gcval_t *fl; gcval_t **pfl = &fl; while ((char*)v <= lim) { *pfl = v; pfl = &v->next; v = (gcval_t*)((char*)v + p->osize); } // these statements are ordered so that interrupting after any of them // leaves the system in a valid state *pfl = p->freelist; pg->next = p->pages; p->pages = pg; p->freelist = fl; }
void *jl_gc_managed_realloc(void *d, size_t sz, size_t oldsz, int isaligned) { if (allocd_bytes > collect_interval) jl_gc_collect(); sz = (sz+15) & -16; void *b; #ifdef _P64 b = realloc(d, sz); #elif defined(_OS_WINDOWS_) if (isaligned) b = _aligned_realloc(d, sz, 16); else b = realloc(d, sz); #elif defined(__APPLE__) b = realloc(d, sz); #else // TODO better aligned realloc here b = malloc_a16(sz); if (b != NULL) { memcpy(b, d, oldsz); if (isaligned) free_a16(d); else free(d); } #endif if (b == NULL) jl_throw(jl_memory_exception); allocd_bytes += sz; return b; }
void *jl_gc_managed_malloc(size_t sz) { if (allocd_bytes > collect_interval) jl_gc_collect(); sz = (sz+15) & -16; void *b = malloc_a16(sz); if (b == NULL) jl_throw(jl_memory_exception); allocd_bytes += sz; return b; }
jl_mallocptr_t *jl_gc_managed_malloc(size_t sz) { if (allocd_bytes > collect_interval) { jl_gc_collect(); } sz = (sz+15) & -16; void *b = malloc_a16(sz); if (b == NULL) jl_throw(jl_memory_exception); allocd_bytes += sz; return jl_gc_acquire_buffer(b, sz, 1); }
static void *alloc_big(size_t sz) { if (allocd_bytes > collect_interval) { jl_gc_collect(); } size_t offs = BVOFFS*sizeof(void*); if (sz+offs+15 < offs+15) // overflow in adding offs, size was "negative" jl_throw(jl_memory_exception); size_t allocsz = (sz+offs+15) & -16; bigval_t *v = (bigval_t*)malloc_a16(allocsz); allocd_bytes += allocsz; if (v == NULL) jl_throw(jl_memory_exception); v->sz = sz; v->flags = 0; v->next = big_objects; big_objects = v; return &v->_data[0]; }
static void add_page(pool_t *p) { gcpage_t *pg = (gcpage_t*)malloc_a16(sizeof(gcpage_t)); if (pg == NULL) jl_throw(jl_memory_exception); gcval_t *v = (gcval_t*)&pg->data[0]; char *lim = (char*)v + GC_PAGE_SZ - p->osize; gcval_t *fl; gcval_t **pfl = &fl; while ((char*)v <= lim) { *pfl = v; pfl = &v->next; v = (gcval_t*)((char*)v + p->osize); } // these statements are ordered so that interrupting after any of them // leaves the system in a valid state *pfl = p->freelist; pg->next = p->pages; p->pages = pg; p->freelist = fl; }