import cstdlib = tango.stdc.stdlib;
import cstring = tango.stdc.string;
+import cstdio = tango.stdc.stdio;
/*
* This is a small optimization that proved it's usefulness. For small chunks
return BlkInfo.init;
BlkInfo info;
info.base = pool.findBase(p);
+ if (info.base is null)
+ return BlkInfo.init;
info.size = pool.findSize(info.base);
info.attr = getAttr(pool, cast(size_t)(info.base - pool.baseAddr) / 16u);
if (has_pointermap(info.attr)) {
gc.stats.world_stopped();
if (opts.options.fork) {
+ cstdio.fflush(null); // avoid duplicated FILE* output
os.pid_t child_pid = os.fork();
assert (child_pid != -1); // don't accept errors in non-release mode
switch (child_pid) {
{
debug(COLLECT_PRINTF) printf("\tmark()\n");
- gc.p_cache = null;
- gc.size_cache = 0;
-
gc.any_changes = false;
for (size_t n = 0; n < gc.pools.length; n++)
{
{
// Free up everything not marked
debug(COLLECT_PRINTF) printf("\tsweep\n");
+ gc.p_cache = null;
+ gc.size_cache = 0;
size_t freedpages = 0;
size_t freed = 0;
for (size_t n = 0; n < gc.pools.length; n++)
{
for (; p < ptop; p += size, bit_i += bit_stride)
{
- if (pool.finals.nbits && pool.finals.testClear(bit_i)) {
+ if (pool.finals.testClear(bit_i)) {
if (opts.options.sentinel)
rt_finalize(sentinel_add(p), false/*gc.no_stack > 0*/);
else
sentinel_Invariant(sentinel_add(p));
pool.freebits.set(bit_i);
- if (pool.finals.nbits && pool.finals.testClear(bit_i)) {
+ if (pool.finals.testClear(bit_i)) {
if (opts.options.sentinel)
rt_finalize(sentinel_add(p), false/*gc.no_stack > 0*/);
else
byte *p = pool.baseAddr + pn * PAGESIZE;
if (opts.options.sentinel)
sentinel_Invariant(sentinel_add(p));
- if (pool.finals.nbits && pool.finals.testClear(bit_i)) {
+ if (pool.finals.testClear(bit_i)) {
if (opts.options.sentinel)
rt_finalize(sentinel_add(p), false/*gc.no_stack > 0*/);
else
body
{
uint attrs;
-
- if (pool.finals.nbits &&
- pool.finals.test(bit_i))
+ if (pool.finals.test(bit_i))
attrs |= BlkAttr.FINALIZE;
if (pool.noscan.test(bit_i))
attrs |= BlkAttr.NO_SCAN;
-// if (pool.nomove.nbits &&
-// pool.nomove.test(bit_i))
+// if (pool.nomove.test(bit_i))
// attrs |= BlkAttr.NO_MOVE;
return attrs;
}
{
if (mask & BlkAttr.FINALIZE)
{
- if (!pool.finals.nbits)
- pool.finals.alloc(pool.mark.nbits);
pool.finals.set(bit_i);
}
if (mask & BlkAttr.NO_SCAN)
}
body
{
- if (mask & BlkAttr.FINALIZE && pool.finals.nbits)
+ if (mask & BlkAttr.FINALIZE)
pool.finals.clear(bit_i);
if (mask & BlkAttr.NO_SCAN)
pool.noscan.clear(bit_i);
memset(p + size - pm_bitmask_size, 0xF2,
blk_size - size - pm_bitmask_size);
pool.freePages(pagenum + newsz, psz - newsz);
+ auto new_blk_size = (PAGESIZE * newsz);
+ // update the size cache, assuming that is very likely the
+ // size of this block will be queried in the near future
+ pool.update_cache(p, new_blk_size);
if (has_pm) {
- auto end_of_blk = cast(size_t**)(
- blk_base_addr + (PAGESIZE * newsz) -
- pm_bitmask_size);
+ auto end_of_blk = cast(size_t**)(blk_base_addr +
+ new_blk_size - pm_bitmask_size);
*end_of_blk = pm_bitmask;
}
return p;
- pm_bitmask_size);
memset(pool.pagetable + pagenum +
psz, B_PAGEPLUS, newsz - psz);
+ auto new_blk_size = (PAGESIZE * newsz);
+ // update the size cache, assuming that is very
+ // likely the size of this block will be queried in
+ // the near future
+ pool.update_cache(p, new_blk_size);
if (has_pm) {
auto end_of_blk = cast(size_t**)(
- blk_base_addr +
- (PAGESIZE * newsz) -
+ blk_base_addr + new_blk_size -
pm_bitmask_size);
*end_of_blk = pm_bitmask;
}
memset(pool.pagetable + pagenum + psz, B_PAGEPLUS, sz);
gc.p_cache = null;
gc.size_cache = 0;
+ // update the size cache, assuming that is very likely the size of this
+ // block will be queried in the near future
+ pool.update_cache(p, new_size);
if (has_pm) {
new_size -= size_t.sizeof;
if (opts.options.mem_stomp)
memset(p, 0xF2, npages * PAGESIZE);
pool.freePages(pagenum, npages);
+ // just in case we were caching this pointer
+ pool.clear_cache(p);
}
else
{
size_t cached_size;
void* cached_ptr;
- void clear_cache()
+ void clear_cache(void* ptr = null)
+ {
+ if (ptr is null || ptr is this.cached_ptr) {
+ this.cached_ptr = null;
+ this.cached_size = 0;
+ }
+ }
+
+ void update_cache(void* ptr, size_t size)
{
- this.cached_ptr = null;
- this.cached_size = 0;
+ this.cached_ptr = ptr;
+ this.cached_size = size;
}
void initialize(size_t npages)