Commit c69402d8 authored by Carl Shapiro's avatar Carl Shapiro

runtime: remove outdated comment and related indentation

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/39810043
parent ddbad5ef
...@@ -409,131 +409,125 @@ flushptrbuf(Scanbuf *sbuf) ...@@ -409,131 +409,125 @@ flushptrbuf(Scanbuf *sbuf)
runtime·throw("ptrbuf has to be smaller than WorkBuf"); runtime·throw("ptrbuf has to be smaller than WorkBuf");
} }
// TODO(atom): This block is a branch of an if-then-else statement. while(ptrbuf < ptrbuf_end) {
// The single-threaded branch may be added in a next CL. obj = ptrbuf->p;
{ ti = ptrbuf->ti;
// Multi-threaded version. ptrbuf++;
while(ptrbuf < ptrbuf_end) {
obj = ptrbuf->p;
ti = ptrbuf->ti;
ptrbuf++;
// obj belongs to interval [mheap.arena_start, mheap.arena_used).
if(Debug > 1) {
if(obj < runtime·mheap.arena_start || obj >= runtime·mheap.arena_used)
runtime·throw("object is outside of mheap");
}
// obj may be a pointer to a live object. // obj belongs to interval [mheap.arena_start, mheap.arena_used).
// Try to find the beginning of the object. if(Debug > 1) {
if(obj < runtime·mheap.arena_start || obj >= runtime·mheap.arena_used)
runtime·throw("object is outside of mheap");
}
// Round down to word boundary. // obj may be a pointer to a live object.
if(((uintptr)obj & ((uintptr)PtrSize-1)) != 0) { // Try to find the beginning of the object.
obj = (void*)((uintptr)obj & ~((uintptr)PtrSize-1));
ti = 0;
}
// Find bits for this word. // Round down to word boundary.
off = (uintptr*)obj - (uintptr*)arena_start; if(((uintptr)obj & ((uintptr)PtrSize-1)) != 0) {
bitp = (uintptr*)arena_start - off/wordsPerBitmapWord - 1; obj = (void*)((uintptr)obj & ~((uintptr)PtrSize-1));
shift = off % wordsPerBitmapWord; ti = 0;
xbits = *bitp; }
bits = xbits >> shift;
// Pointing at the beginning of a block? // Find bits for this word.
if((bits & (bitAllocated|bitBlockBoundary)) != 0) { off = (uintptr*)obj - (uintptr*)arena_start;
if(CollectStats) bitp = (uintptr*)arena_start - off/wordsPerBitmapWord - 1;
runtime·xadd64(&gcstats.flushptrbuf.foundbit, 1); shift = off % wordsPerBitmapWord;
goto found; xbits = *bitp;
} bits = xbits >> shift;
ti = 0; // Pointing at the beginning of a block?
if((bits & (bitAllocated|bitBlockBoundary)) != 0) {
if(CollectStats)
runtime·xadd64(&gcstats.flushptrbuf.foundbit, 1);
goto found;
}
// Pointing just past the beginning? ti = 0;
// Scan backward a little to find a block boundary.
for(j=shift; j-->0; ) {
if(((xbits>>j) & (bitAllocated|bitBlockBoundary)) != 0) {
obj = (byte*)obj - (shift-j)*PtrSize;
shift = j;
bits = xbits>>shift;
if(CollectStats)
runtime·xadd64(&gcstats.flushptrbuf.foundword, 1);
goto found;
}
}
// Otherwise consult span table to find beginning. // Pointing just past the beginning?
// (Manually inlined copy of MHeap_LookupMaybe.) // Scan backward a little to find a block boundary.
k = (uintptr)obj>>PageShift; for(j=shift; j-->0; ) {
x = k; if(((xbits>>j) & (bitAllocated|bitBlockBoundary)) != 0) {
if(sizeof(void*) == 8) obj = (byte*)obj - (shift-j)*PtrSize;
x -= (uintptr)arena_start>>PageShift; shift = j;
s = runtime·mheap.spans[x]; bits = xbits>>shift;
if(s == nil || k < s->start || obj >= s->limit || s->state != MSpanInUse) if(CollectStats)
continue; runtime·xadd64(&gcstats.flushptrbuf.foundword, 1);
p = (byte*)((uintptr)s->start<<PageShift); goto found;
if(s->sizeclass == 0) {
obj = p;
} else {
size = s->elemsize;
int32 i = ((byte*)obj - p)/size;
obj = p+i*size;
} }
}
// Now that we know the object header, reload bits. // Otherwise consult span table to find beginning.
off = (uintptr*)obj - (uintptr*)arena_start; // (Manually inlined copy of MHeap_LookupMaybe.)
bitp = (uintptr*)arena_start - off/wordsPerBitmapWord - 1; k = (uintptr)obj>>PageShift;
shift = off % wordsPerBitmapWord; x = k;
xbits = *bitp; if(sizeof(void*) == 8)
bits = xbits >> shift; x -= (uintptr)arena_start>>PageShift;
if(CollectStats) s = runtime·mheap.spans[x];
runtime·xadd64(&gcstats.flushptrbuf.foundspan, 1); if(s == nil || k < s->start || obj >= s->limit || s->state != MSpanInUse)
continue;
p = (byte*)((uintptr)s->start<<PageShift);
if(s->sizeclass == 0) {
obj = p;
} else {
size = s->elemsize;
int32 i = ((byte*)obj - p)/size;
obj = p+i*size;
}
found: // Now that we know the object header, reload bits.
// Now we have bits, bitp, and shift correct for off = (uintptr*)obj - (uintptr*)arena_start;
// obj pointing at the base of the object. bitp = (uintptr*)arena_start - off/wordsPerBitmapWord - 1;
// Only care about allocated and not marked. shift = off % wordsPerBitmapWord;
if((bits & (bitAllocated|bitMarked)) != bitAllocated) xbits = *bitp;
continue; bits = xbits >> shift;
if(work.nproc == 1) if(CollectStats)
*bitp |= bitMarked<<shift; runtime·xadd64(&gcstats.flushptrbuf.foundspan, 1);
else {
for(;;) { found:
x = *bitp; // Now we have bits, bitp, and shift correct for
if(x & (bitMarked<<shift)) // obj pointing at the base of the object.
goto continue_obj; // Only care about allocated and not marked.
if(runtime·casp((void**)bitp, (void*)x, (void*)(x|(bitMarked<<shift)))) if((bits & (bitAllocated|bitMarked)) != bitAllocated)
break; continue;
} if(work.nproc == 1)
*bitp |= bitMarked<<shift;
else {
for(;;) {
x = *bitp;
if(x & (bitMarked<<shift))
goto continue_obj;
if(runtime·casp((void**)bitp, (void*)x, (void*)(x|(bitMarked<<shift))))
break;
} }
}
// If object has no pointers, don't need to scan further. // If object has no pointers, don't need to scan further.
if((bits & bitNoScan) != 0) if((bits & bitNoScan) != 0)
continue; continue;
// Ask span about size class. // Ask span about size class.
// (Manually inlined copy of MHeap_Lookup.) // (Manually inlined copy of MHeap_Lookup.)
x = (uintptr)obj >> PageShift; x = (uintptr)obj >> PageShift;
if(sizeof(void*) == 8) if(sizeof(void*) == 8)
x -= (uintptr)arena_start>>PageShift; x -= (uintptr)arena_start>>PageShift;
s = runtime·mheap.spans[x]; s = runtime·mheap.spans[x];
PREFETCH(obj); PREFETCH(obj);
*wp = (Obj){obj, s->elemsize, ti}; *wp = (Obj){obj, s->elemsize, ti};
wp++; wp++;
nobj++; nobj++;
continue_obj:; continue_obj:;
} }
// If another proc wants a pointer, give it some. // If another proc wants a pointer, give it some.
if(work.nwait > 0 && nobj > handoffThreshold && work.full == 0) { if(work.nwait > 0 && nobj > handoffThreshold && work.full == 0) {
wbuf->nobj = nobj; wbuf->nobj = nobj;
wbuf = handoff(wbuf); wbuf = handoff(wbuf);
nobj = wbuf->nobj; nobj = wbuf->nobj;
wp = wbuf->obj + nobj; wp = wbuf->obj + nobj;
}
} }
sbuf->wp = wp; sbuf->wp = wp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment