import rt.gc.cdgc.bits: GCBits;
import rt.gc.cdgc.stats: GCStats, Stats;
import dynarray = rt.gc.cdgc.dynarray;
-import alloc = rt.gc.cdgc.alloc;
+import os = rt.gc.cdgc.os;
import opts = rt.gc.cdgc.opts;
import cstdlib = tango.stdc.stdlib;
/**
* Compute bin for size.
*/
-static Bins findBin(size_t size)
+Bins findBin(size_t size)
{
Bins bin;
if (size <= 256)
//printf("marking range: %p -> %p\n", pbot, ptop);
for (; p1 + type_size <= p2; p1 += type_size) {
- size_t n = 0;
- if (has_type_info) {
- while (n < type_size && pm_bits[n / BITS_PER_WORD] == 0)
- n += BITS_PER_WORD;
- if (n < type_size && (pm_bits[n / BITS_PER_WORD] &
- ((1 << (BITS_PER_WORD / 2)) - 1)) == 0)
- n += BITS_PER_WORD / 2;
- else if (n < type_size && (pm_bits[n / BITS_PER_WORD] &
- ((1 << (BITS_PER_WORD / 4)) - 1)) == 0)
- n += BITS_PER_WORD / 4;
- }
- for (; n < type_size; n++) {
+ for (size_t n = 0; n < type_size; n++) {
// scan bit set for this word
if (has_type_info &&
!(pm_bits[n / BITS_PER_WORD] & (1 << (n % BITS_PER_WORD))))
for (n = 0; n < gc.pools.length; n++)
{
pool = gc.pools[n];
+ pool.clear_cache();
uint* bbase = pool.mark.base();
size_t pn;
for (pn = 0; pn < pool.npages; pn++, bbase += PAGESIZE / (32 * 16))
size_t npages;
ubyte* pagetable;
+ /// Cache for findSize()
+ size_t cached_size;
+ void* cached_ptr;
+
+ void clear_cache()
+ {
+ this.cached_ptr = null;
+ this.cached_size = 0;
+ }
void initialize(size_t npages)
{
size_t poolsize = npages * PAGESIZE;
assert(poolsize >= POOLSIZE);
- baseAddr = cast(byte *) alloc.os_mem_map(poolsize);
+ baseAddr = cast(byte *) os.alloc(poolsize);
// Some of the code depends on page alignment of memory pools
assert((cast(size_t)baseAddr & (PAGESIZE - 1)) == 0);
if (npages)
{
- result = alloc.os_mem_unmap(baseAddr, npages * PAGESIZE);
+ result = os.dealloc(baseAddr, npages * PAGESIZE);
assert(result);
npages = 0;
}
Bins bin = cast(Bins)this.pagetable[pagenum];
if (bin != B_PAGE)
return binsize[bin];
- for (size_t i = pagenum + 1; i < this.npages; i++)
+ if (this.cached_ptr == p)
+ return this.cached_size;
+ size_t i = pagenum + 1;
+ for (; i < this.npages; i++)
if (this.pagetable[i] != B_PAGEPLUS)
- return (i - pagenum) * PAGESIZE;
- return (this.npages - pagenum) * PAGESIZE;
+ break;
+ this.cached_ptr = p;
+ this.cached_size = (i - pagenum) * PAGESIZE;
+ return this.cached_size;
}