mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/gc, runtime: treat slices and strings like pointers in garbage collection
Before, a slice with cap=0 or a string with len=0 might have its base pointer pointing beyond the actual slice/string data into the next block. The collector had to ignore slices and strings with cap=0 in order to avoid misinterpreting the base pointer. Now, a slice with cap=0 or a string with len=0 still has a base pointer pointing into the actual slice/string data, no matter what. The collector can now always scan the pointer, which means strings and slices are no longer special. Fixes #8404. LGTM=khr, josharian R=josharian, khr, dvyukov CC=golang-codereviews https://golang.org/cl/112570044
This commit is contained in:
parent
c6f7c176a3
commit
613383c765
25 changed files with 248 additions and 162 deletions
|
|
@ -592,19 +592,8 @@ adjustpointers(byte **scanp, BitVector *bv, AdjustInfo *adjinfo, Func *f)
|
|||
break;
|
||||
case BitsMultiWord:
|
||||
switch(bv->data[(i+1) / (32 / BitsPerPointer)] >> ((i+1) * BitsPerPointer & 31) & 3) {
|
||||
case BitsString:
|
||||
// string referents are never on the stack, never need to be adjusted
|
||||
i++; // skip len
|
||||
break;
|
||||
case BitsSlice:
|
||||
p = scanp[i];
|
||||
if(minp <= p && p < maxp) {
|
||||
if(StackDebug >= 3)
|
||||
runtime·printf("adjust slice %p\n", p);
|
||||
scanp[i] = p + delta;
|
||||
}
|
||||
i += 2; // skip len, cap
|
||||
break;
|
||||
default:
|
||||
runtime·throw("unexpected garbage collection bits");
|
||||
case BitsEface:
|
||||
t = (Type*)scanp[i];
|
||||
if(t != nil && ((t->kind & KindDirectIface) == 0 || (t->kind & KindNoPointers) == 0)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue