/***************************************************/
-import rt.gc.cdgc.bits;
-import rt.gc.cdgc.stats;
-import rt.gc.cdgc.alloc;
-import rt.gc.cdgc.libc;
+import rt.gc.cdgc.bits: GCBits;
+import rt.gc.cdgc.stats: GCStats;
+import alloc = rt.gc.cdgc.alloc;
+import libc = rt.gc.cdgc.libc;
version (GNU)
// subdirectory is elsewhere. Instead, perhaps the functions
// could be declared directly or some other resolution could
// be found.
- import gcc.builtins; // for __builtin_unwind_init
+ static import gcc.builtins; // for __builtin_unwind_int
}
void Dtor()
{
if (data)
- .free(data);
+ libc.free(data);
data = null;
}
assert(dim + nentries <= allocdim);
if (!data)
{
- data = cast(Log*) .malloc(allocdim * Log.sizeof);
+ data = cast(Log*) libc.malloc(allocdim * Log.sizeof);
if (!data && allocdim)
onOutOfMemoryError();
}
else
{ Log *newdata;
- newdata = cast(Log*) .malloc(allocdim * Log.sizeof);
+ newdata = cast(Log*) libc.malloc(allocdim * Log.sizeof);
if (!newdata && allocdim)
onOutOfMemoryError();
- .memcpy(newdata, data, dim * Log.sizeof);
- .free(data);
+ libc.memcpy(newdata, data, dim * Log.sizeof);
+ libc.free(data);
data = newdata;
}
}
void remove(size_t i)
{
- .memmove(data + i, data + i + 1, (dim - i) * Log.sizeof);
+ libc.memmove(data + i, data + i + 1, (dim - i) * Log.sizeof);
dim--;
}
{
reserve(from.dim - dim);
assert(from.dim <= allocdim);
- .memcpy(data, from.data, from.dim * Log.sizeof);
+ libc.memcpy(data, from.data, from.dim * Log.sizeof);
dim = from.dim;
}
}
void initialize()
{
gcLock = GCLock.classinfo;
- gcx = cast(Gcx*) .calloc(1, Gcx.sizeof);
+ gcx = cast(Gcx*) libc.calloc(1, Gcx.sizeof);
if (!gcx)
onOutOfMemoryError();
gcx.initialize();
if (gcx)
{
gcx.Dtor();
- .free(gcx);
+ libc.free(gcx);
gcx = null;
}
}
// Return next item from free list
gcx.bucket[bin] = (cast(List*)p).next;
if( !(bits & BlkAttr.NO_SCAN) )
- .memset(p + size, 0, binsize[bin] - size);
+ libc.memset(p + size, 0, binsize[bin] - size);
//debug(PRINTF) printf("\tmalloc => %x\n", p);
- debug (MEMSTOMP) .memset(p, 0xF0, size);
+ debug (MEMSTOMP) libc.memset(p, 0xF0, size);
}
else
{
//debug(PRINTF) printf("calloc: %x len %d\n", p, len);
void *p = mallocNoSync(size, bits);
- .memset(p, 0, size);
+ libc.memset(p, 0, size);
return p;
}
if (psize < size)
size = psize;
//debug(PRINTF) printf("\tcopying %d bytes\n",size);
- .memcpy(p2, p, size);
+ libc.memcpy(p2, p, size);
p = p2;
}
}
{ // Shrink in place
synchronized (gcLock)
{
- debug (MEMSTOMP) .memset(p + size, 0xF2, psize - size);
+ debug (MEMSTOMP)
+ libc.memset(p + size, 0xF2, psize - size);
pool.freePages(pagenum + newsz, psz - newsz);
}
return p;
{
if (i == pagenum + newsz)
{
- debug (MEMSTOMP) .memset(p + psize, 0xF0, size - psize);
- .memset(&pool.pagetable[pagenum + psz], B_PAGEPLUS, newsz - psz);
+ debug (MEMSTOMP)
+ libc.memset(p + psize, 0xF0,
+ size - psize);
+ libc.memset(&pool.pagetable[pagenum + psz],
+ B_PAGEPLUS, newsz - psz);
return p;
}
if (i == pool.npages)
if (psize < size)
size = psize;
//debug(PRINTF) printf("\tcopying %d bytes\n",size);
- .memcpy(p2, p, size);
+ libc.memcpy(p2, p, size);
p = p2;
}
}
}
if (sz < minsz)
return 0;
- debug (MEMSTOMP) .memset(p + psize, 0xF0, (psz + sz) * PAGESIZE - psize);
- .memset(pool.pagetable + pagenum + psz, B_PAGEPLUS, sz);
+ debug (MEMSTOMP)
+ libc.memset(p + psize, 0xF0, (psz + sz) * PAGESIZE - psize);
+ libc.memset(pool.pagetable + pagenum + psz, B_PAGEPLUS, sz);
gcx.p_cache = null;
gcx.size_cache = 0;
return (psz + sz) * PAGESIZE;
n = pagenum;
while (++n < pool.npages && pool.pagetable[n] == B_PAGEPLUS)
npages++;
- debug (MEMSTOMP) .memset(p, 0xF2, npages * PAGESIZE);
+ debug (MEMSTOMP) libc.memset(p, 0xF2, npages * PAGESIZE);
pool.freePages(pagenum, npages);
}
else
{ // Add to free list
List *list = cast(List*)p;
- debug (MEMSTOMP) .memset(p, 0xF2, binsize[bin]);
+ debug (MEMSTOMP) libc.memset(p, 0xF2, binsize[bin]);
list.next = gcx.bucket[bin];
gcx.bucket[bin] = list;
size_t bsize = 0;
//debug(PRINTF) printf("getStats()\n");
- .memset(&stats, 0, GCStats.sizeof);
+ libc.memset(&stats, 0, GCStats.sizeof);
for (n = 0; n < gcx.npools; n++)
{ Pool *pool = gcx.pooltable[n];
if (wp.reference)
rt_detachDisposeEvent(wp.reference, &wp.ondestroy);
});
- .free(wp);
+ libc.free(wp);
}
}
{ Pool *pool = pooltable[i];
pool.Dtor();
- .free(pool);
+ libc.free(pool);
}
if (pooltable)
- .free(pooltable);
+ libc.free(pooltable);
if (roots)
- .free(roots);
+ libc.free(roots);
if (ranges)
- .free(ranges);
+ libc.free(ranges);
}
size_t newdim = rootdim * 2 + 16;
void** newroots;
- newroots = cast(void**) .malloc(newdim * newroots[0].sizeof);
+ newroots = cast(void**) libc.malloc(newdim * newroots[0].sizeof);
if (!newroots)
onOutOfMemoryError();
if (roots)
- { .memcpy(newroots, roots, nroots * newroots[0].sizeof);
- .free(roots);
+ { libc.memcpy(newroots, roots, nroots * newroots[0].sizeof);
+ libc.free(roots);
}
roots = newroots;
rootdim = newdim;
if (roots[i] == p)
{
nroots--;
- .memmove(roots + i, roots + i + 1, (nroots - i) * roots[0].sizeof);
+ libc.memmove(roots + i, roots + i + 1,
+ (nroots - i) * roots[0].sizeof);
return;
}
}
size_t newdim = rangedim * 2 + 16;
Range *newranges;
- newranges = cast(Range*) .malloc(newdim * newranges[0].sizeof);
+ newranges = cast(Range*) libc.malloc(newdim * newranges[0].sizeof);
if (!newranges)
onOutOfMemoryError();
if (ranges)
- { .memcpy(newranges, ranges, nranges * newranges[0].sizeof);
- .free(ranges);
+ { libc.memcpy(newranges, ranges, nranges * newranges[0].sizeof);
+ libc.free(ranges);
}
ranges = newranges;
rangedim = newdim;
if (ranges[i].pbot == pbot)
{
nranges--;
- .memmove(ranges + i, ranges + i + 1, (nranges - i) * ranges[0].sizeof);
+ libc.memmove(ranges + i, ranges + i + 1,
+ (nranges - i) * ranges[0].sizeof);
return;
}
}
continue;
}
pool.Dtor();
- .free(pool);
- .memmove(pooltable + n,
+ libc.free(pool);
+ libc.memmove(pooltable + n,
pooltable + n + 1,
(--npools - n) * (Pool*).sizeof);
minAddr = pooltable[0].baseAddr;
L1:
pool.pagetable[pn] = B_PAGE;
if (npages > 1)
- .memset(&pool.pagetable[pn + 1], B_PAGEPLUS, npages - 1);
+ libc.memset(&pool.pagetable[pn + 1], B_PAGEPLUS, npages - 1);
p = pool.baseAddr + pn * PAGESIZE;
- .memset(cast(char *)p + size, 0, npages * PAGESIZE - size);
- debug (MEMSTOMP) .memset(p, 0xF1, size);
+ libc.memset(cast(char *)p + size, 0, npages * PAGESIZE - size);
+ debug (MEMSTOMP) libc.memset(p, 0xF1, size);
//debug(PRINTF) printf("\tp = %x\n", p);
return p;
npages = n;
}
- pool = cast(Pool *) .calloc(1, Pool.sizeof);
+ pool = cast(Pool *) libc.calloc(1, Pool.sizeof);
if (pool)
{
pool.initialize(npages);
goto Lerr;
newnpools = npools + 1;
- newpooltable = cast(Pool **) .realloc(pooltable, newnpools * (Pool *).sizeof);
+ newpooltable = cast(Pool **) libc.realloc(pooltable,
+ newnpools * (Pool *).sizeof);
if (!newpooltable)
goto Lerr;
if (pool.opCmp(newpooltable[i]) < 0)
break;
}
- .memmove(newpooltable + i + 1, newpooltable + i, (npools - i) * (Pool *).sizeof);
+ libc.memmove(newpooltable + i + 1, newpooltable + i,
+ (npools - i) * (Pool *).sizeof);
newpooltable[i] = pool;
pooltable = newpooltable;
Lerr:
pool.Dtor();
- .free(pool);
+ libc.free(pool);
return null;
}
size_t result;
version (GNU)
{
- __builtin_unwind_init();
+ gcc.builtins.__builtin_unwind_init();
sp = & sp;
}
else version(LDC)
//debug(PRINTF) printf("\tcollecting %x\n", list);
log_free(sentinel_add(list));
- debug (MEMSTOMP) .memset(p, 0xF3, size);
+ debug (MEMSTOMP) libc.memset(p, 0xF3, size);
}
pool.pagetable[pn] = B_FREE;
freed += PAGESIZE;
debug(PRINTF) printf("\tcollecting %x\n", list);
log_free(sentinel_add(list));
- debug (MEMSTOMP) .memset(p, 0xF3, size);
+ debug (MEMSTOMP) libc.memset(p, 0xF3, size);
freed += size;
}
log_free(sentinel_add(p));
pool.pagetable[pn] = B_FREE;
freedpages++;
- debug (MEMSTOMP) .memset(p, 0xF3, PAGESIZE);
+ debug (MEMSTOMP) libc.memset(p, 0xF3, PAGESIZE);
while (pn + 1 < pool.npages && pool.pagetable[pn + 1] == B_PAGEPLUS)
{
pn++;
debug (MEMSTOMP)
{ p += PAGESIZE;
- .memset(p, 0xF3, PAGESIZE);
+ libc.memset(p, 0xF3, PAGESIZE);
}
}
}
{
byte* baseAddr;
byte* topAddr;
- GCBits mark; // entries already scanned, or should not be scanned
- GCBits scan; // entries that need to be scanned
- GCBits freebits; // entries that are on the free list
- GCBits finals; // entries that need finalizer run on them
- GCBits noscan; // entries that should not be scanned
+ GCBits mark; // entries already scanned, or should not be scanned
+ GCBits scan; // entries that need to be scanned
+ GCBits freebits; // entries that are on the free list
+ GCBits finals; // entries that need finalizer run on them
+ GCBits noscan; // entries that should not be scanned
size_t npages;
ubyte* pagetable;
//debug(PRINTF) printf("Pool::Pool(%u)\n", npages);
poolsize = npages * PAGESIZE;
assert(poolsize >= POOLSIZE);
- baseAddr = cast(byte *)os_mem_map(poolsize);
+ baseAddr = cast(byte *) alloc.os_mem_map(poolsize);
// Some of the code depends on page alignment of memory pools
assert((cast(size_t)baseAddr & (PAGESIZE - 1)) == 0);
freebits.alloc(cast(size_t)poolsize / 16);
noscan.alloc(cast(size_t)poolsize / 16);
- pagetable = cast(ubyte*) .malloc(npages);
+ pagetable = cast(ubyte*) libc.malloc(npages);
if (!pagetable)
onOutOfMemoryError();
- .memset(pagetable, B_FREE, npages);
+ libc.memset(pagetable, B_FREE, npages);
this.npages = npages;
}
if (npages)
{
- result = os_mem_unmap(baseAddr, npages * PAGESIZE);
+ result = alloc.os_mem_unmap(baseAddr, npages * PAGESIZE);
assert(result);
npages = 0;
}
topAddr = null;
}
if (pagetable)
- .free(pagetable);
+ libc.free(pagetable);
mark.Dtor();
scan.Dtor();
*/
void freePages(size_t pagenum, size_t npages)
{
- .memset(&pagetable[pagenum], B_FREE, npages);
+ libc.memset(&pagetable[pagenum], B_FREE, npages);
}