uintptr i;
for(i = 0; i < bv->n; i += BitsPerPointer) {
- switch(bv->data[i/32] >> i%32 & 3) {
+ switch(bv->bytedata[i/8] >> i%8 & 3) {
case BitsDead:
case BitsScalar:
break;
dumpint(offset + i / BitsPerPointer * PtrSize);
break;
case BitsMultiWord:
- switch(bv->data[(i+BitsPerPointer)/32] >> (i+BitsPerPointer)%32 & 3) {
+ switch(bv->bytedata[(i+BitsPerPointer)/8] >> (i+BitsPerPointer)%8 & 3) {
case BitsString:
dumpint(FieldKindString);
dumpint(offset + i / BitsPerPointer * PtrSize);
dumpint(TagData);
dumpint((uintptr)data);
dumpmemrange(data, edata - data);
- dumpfields((BitVector){(edata - data)*8, (uint32*)gcdata});
+ dumpfields((BitVector){(edata - data)*8, (byte*)gcdata}); /* WRONG! gcbss is not a bitmap */
// bss segment
dumpint(TagBss);
dumpint((uintptr)bss);
dumpmemrange(bss, ebss - bss);
- dumpfields((BitVector){(ebss - bss)*8, (uint32*)gcbss});
+ dumpfields((BitVector){(ebss - bss)*8, (byte*)gcbss}); /* WRONG! gcbss is not a bitmap */
// MSpan.types
allspans = runtime·mheap.allspans;
uintptr i;
for(i = 0; i < bv->n; i += BitsPerPointer) {
- if((bv->data[i/32] >> i%32 & 3) != BitsMultiWord)
+ if((bv->bytedata[i/8] >> i%8 & 3) != BitsMultiWord)
continue;
- switch(bv->data[(i+BitsPerPointer)/32] >> (i+BitsPerPointer)%32 & 3) {
+ switch(bv->bytedata[(i+BitsPerPointer)/8] >> (i+BitsPerPointer)%8 & 3) {
case BitsString:
case BitsIface:
i += BitsPerPointer;
tmpbuf[i*BitsPerPointer/8] &= ~(3<<((i*BitsPerPointer)%8));
tmpbuf[i*BitsPerPointer/8] |= bits<<((i*BitsPerPointer)%8);
}
- return (BitVector){i*BitsPerPointer, (uint32*)tmpbuf};
+ return (BitVector){i*BitsPerPointer, (byte*)tmpbuf};
}
enum {
Debug = 0,
- ConcurrentSweep = 1,
+ ConcurrentSweep = 0,
PreciseScan = 1,
WorkbufSize = 4*1024,
RootSpans = 3,
RootFlushCaches = 4,
RootCount = 5,
+
+#ifdef _64BIT
+ byteEndian = BigEndian*7,
+#else
+ byteEndian = BigEndian*3,
+#endif
};
#define ScanConservatively ((byte*)1)
{
if(n < 0 || n >= stackmap->n)
runtime·throw("stackmapdata: index out of range");
- return (BitVector){stackmap->nbit, stackmap->data + n*((stackmap->nbit+31)/32)};
+ return (BitVector){stackmap->nbit, stackmap->bytedata + 4*n*((stackmap->nbit+31)/32)};
}
// Scan a stack frame: local variables and function arguments/results.
}
bv = runtime·stackmapdata(stackmap, pcdata);
size = (bv.n * PtrSize) / BitsPerPointer;
- scanblock(frame->varp - size, bv.n/BitsPerPointer*PtrSize, (byte*)bv.data);
+ scanblock(frame->varp - size, bv.n/BitsPerPointer*PtrSize, (byte*)bv.bytedata);
}
// Scan arguments.
stackmap = runtime·funcdata(f, FUNCDATA_ArgsPointerMaps);
if(stackmap != nil) {
bv = runtime·stackmapdata(stackmap, pcdata);
- scanblock(frame->argp, bv.n/BitsPerPointer*PtrSize, (byte*)bv.data);
+ scanblock(frame->argp, bv.n/BitsPerPointer*PtrSize, (byte*)bv.bytedata);
} else {
if(Debug > 2)
runtime·printf("frame %s conservative args %p+%p\n", runtime·funcname(f), frame->argp, (uintptr)frame->arglen);
struct gc_args a;
int32 i;
+//if(thechar == '9') return;
+
if(sizeof(Workbuf) != WorkbufSize)
runtime·throw("runtime: size of Workbuf is suboptimal");
// The gc is turned off (via enablegc) until
if(!mstats.enablegc || g == g->m->g0 || g->m->locks > 0 || runtime·panicking)
return;
- if(thechar == '9') {
- runtime·gcpercent = -1;
- return;
- }
if(runtime·gcpercent == GcpercentUnknown) { // first time through
runtime·lock(&runtime·mheap);
if(runtime·gcpercent == GcpercentUnknown)
b = (uintptr*)arena_start - off/wordsPerBitmapWord - 1;
shift = (off % wordsPerBitmapWord) * gcBits;
if((shift%8)==0)
- ((byte*)b)[shift/8] = 0;
- ((byte*)b)[shift/8] |= v<<((shift%8)+2);
+ ((byte*)b)[(shift/8)^byteEndian] = 0;
+ ((byte*)b)[(shift/8)^byteEndian] |= v<<((shift%8)+2);
pos += PtrSize;
} else if(sparse) {
// 4-bits per word
static Lock lock;
byte *mask, *prog;
uintptr pos;
- uint32 x;
+ uintptr x;
runtime·lock(&lock);
mask = (byte*)typ->gc[0];
prog = (byte*)typ->gc[1];
unrollgcprog1(mask, prog, &pos, false, true);
}
+
// atomic way to say mask[0] = 1
- x = ((uint32*)mask)[0];
- runtime·atomicstore((uint32*)mask, x|1);
+ x = typ->gc[0];
+ ((byte*)&x)[0] = 1;
+ runtime·atomicstorep((void**)mask, (void*)x);
}
runtime·unlock(&lock);
}
void
runtime·markallocated(void *v, uintptr size, uintptr size0, Type *typ, bool scan)
{
- uintptr *b, off, shift, i, ti, te, nptr, masksize;
+ uintptr *b, off, shift, i, ti, te, nptr, masksize, maskword;
byte *arena_start, x;
bool *ptrmask;
b = (uintptr*)arena_start - off/wordsPerBitmapWord - 1;
shift = (off % wordsPerBitmapWord) * gcBits;
if(Debug && (((*b)>>shift)&bitMask) != bitBoundary) {
- runtime·printf("runtime: bad bits in markallocated (%p) b=%p[%p]\n", v, b, *b);
+ runtime·printf("runtime: bad bits in markallocated (%p) b=%p[%p] off=%p shift=%d\n", v, b, *b, off, (int32)shift);
runtime·throw("bad bits in markallocated");
}
if(size == PtrSize)
*b = (*b & ~((bitBoundary|bitPtrMask)<<shift)) | ((bitAllocated+(BitsDead<<2))<<shift);
else
- ((byte*)b)[shift/8] = bitAllocated+(BitsDead<<2);
+ ((byte*)b)[(shift/8)^byteEndian] = bitAllocated+(BitsDead<<2);
return;
}
if(size == PtrSize) {
}
ptrmask = (byte*)typ->gc[0];
// check whether the program is already unrolled
- if((runtime·atomicload((uint32*)ptrmask)&0xff) == 0)
+ maskword = (uintptr)runtime·atomicloadp((void*)&typ->gc[0]);
+ if(((byte*)&maskword)[0] == 0)
unrollgcprog(typ);
ptrmask++; // skip the unroll flag byte
} else
ptrmask = (byte*)&typ->gc[0]; // embed mask
if(size == 2*PtrSize) {
- ((byte*)b)[shift/8] = ptrmask[0] | bitAllocated;
+ ((byte*)b)[(shift/8)^byteEndian] = ptrmask[0] | bitAllocated;
return;
}
te = typ->size/PtrSize;
te /= 2;
}
if(size == 2*PtrSize) {
- ((byte*)b)[shift/8] = (BitsPointer<<2) | (BitsPointer<<6) | bitAllocated;
+ ((byte*)b)[(shift/8)^byteEndian] = (BitsPointer<<2) | (BitsPointer<<6) | bitAllocated;
return;
}
// Copy pointer bitmask into the bitmap.
x |= bitAllocated;
if(i+PtrSize == size0)
x &= ~(bitPtrMask<<4);
- ((byte*)b)[shift/8] = x;
+ ((byte*)b)[(shift/8)^byteEndian] = x;
}
if(size0 == i && size0 < size) {
// mark the word after last object's word as BitsDead
off = (uintptr*)((byte*)v + size0) - (uintptr*)arena_start;
b = (uintptr*)arena_start - off/wordsPerBitmapWord - 1;
shift = (off % wordsPerBitmapWord) * gcBits;
- ((byte*)b)[shift/8] = 0;
+ ((byte*)b)[(shift/8)^byteEndian] = 0;
}
}
*mask = runtime·mallocgc(*len, nil, 0);
for(i = 0; i < n; i += PtrSize) {
off = (p+i-frame.varp+size)/PtrSize;
- bits = (bv.data[off/PointersPerByte] >> ((off%PointersPerByte)*BitsPerPointer))&BitsMask;
+ bits = (bv.bytedata[off/PointersPerByte] >> ((off%PointersPerByte)*BitsPerPointer))&BitsMask;
(*mask)[i/PtrSize] = bits;
}
}