From: Leandro Lucarella Date: Sat, 4 Sep 2010 01:13:06 +0000 (-0300) Subject: Avoid redundant checks for finals bits X-Git-Url: https://git.llucax.com/software/dgc/cdgc.git/commitdiff_plain/cc0ea21e4d2f60ad8cc8c4cc5da47264b8e0dc85 Avoid redundant checks for finals bits In changeset b28fd72842fc9ce935bed74f7b2ba79f9cc59711 (Run the mark phase in a fork()ed process) we inadvertently changed the lazy allocation of finals bit set to eager allocation. This change left a lot of finals bit set initialization checks that are not really needed using eager allocation. We remove this redundant check as we decided to go with the eager allocation to trade some space for a little more speed, as the extra checks takes time and is very rare that a whole pool doesn't have any blocks that need finalization, making the space saving very rare too. Lazy allocation can impact too in locality of reference, as is more likely that all the bit sets are allocated near in space, except for the lazyly allocated one. --- diff --git a/rt/gc/cdgc/gc.d b/rt/gc/cdgc/gc.d index 59d9f55..2d75813 100644 --- a/rt/gc/cdgc/gc.d +++ b/rt/gc/cdgc/gc.d @@ -1000,7 +1000,7 @@ version(none) // BUG: doesn't work because freebits() must also be cleared { 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 @@ -1024,7 +1024,7 @@ version(none) // BUG: doesn't work because freebits() must also be cleared 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 @@ -1047,7 +1047,7 @@ version(none) // BUG: doesn't work because freebits() must also be cleared 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 @@ -1150,14 +1150,11 @@ in 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; } @@ -1175,8 +1172,6 @@ body { if (mask & BlkAttr.FINALIZE) { - if (!pool.finals.nbits) - pool.finals.alloc(pool.mark.nbits); pool.finals.set(bit_i); } if (mask & BlkAttr.NO_SCAN) @@ -1202,7 +1197,7 @@ in } 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);