1
0
mirror of https://github.com/golang/go synced 2024-11-11 18:51:37 -07:00

all: merge dev.garbage (d1238958d4ae) into default branch

When we start work on Gerrit, ppc64 and garbage collection
work will continue in the master branch, not the dev branches.

(We may still use dev branches for other things later, but
these are ready to be merged, and doing it now, before moving
to Git means we don't have to have dev branches working
in the Gerrit workflow on day one.)

TBR=rlh
CC=golang-codereviews
https://golang.org/cl/183140043
This commit is contained in:
Russ Cox 2014-12-05 20:34:45 -05:00
commit 31457cef6d
43 changed files with 1926 additions and 590 deletions

View File

@ -2024,13 +2024,13 @@ def submit(ui, repo, *pats, **opts):
# push to remote; if it fails for any reason, roll back
try:
new_heads = len(hg_heads(ui, repo).split())
if old_heads != new_heads and not (old_heads == 0 and new_heads == 1):
if cl.desc.find("create new branch") < 0 and old_heads != new_heads and not (old_heads == 0 and new_heads == 1):
# Created new head, so we weren't up to date.
need_sync()
# Push changes to remote. If it works, we're committed. If not, roll back.
try:
if hg_push(ui, repo):
if hg_push(ui, repo, new_branch=cl.desc.find("create new branch")>=0):
raise hg_util.Abort("push error")
except hg_error.Abort, e:
if e.message.find("push creates new heads") >= 0:

View File

@ -24,6 +24,8 @@ char *runtimeimport =
"func @\"\".printslice (? any)\n"
"func @\"\".printnl ()\n"
"func @\"\".printsp ()\n"
"func @\"\".printlock ()\n"
"func @\"\".printunlock ()\n"
"func @\"\".concatstring2 (? string, ? string) (? string)\n"
"func @\"\".concatstring3 (? string, ? string, ? string) (? string)\n"
"func @\"\".concatstring4 (? string, ? string, ? string, ? string) (? string)\n"
@ -86,10 +88,33 @@ char *runtimeimport =
"func @\"\".writebarrierstring (@\"\".dst·1 *any, @\"\".src·2 any)\n"
"func @\"\".writebarrierslice (@\"\".dst·1 *any, @\"\".src·2 any)\n"
"func @\"\".writebarrieriface (@\"\".dst·1 *any, @\"\".src·2 any)\n"
"func @\"\".writebarrierfat2 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat3 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat4 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat01 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat10 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat11 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat001 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat010 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat011 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat100 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat101 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat110 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat111 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat0001 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat0010 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat0011 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat0100 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat0101 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat0110 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat0111 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat1000 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat1001 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat1010 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat1011 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat1100 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat1101 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat1110 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat1111 (@\"\".dst·1 *any, _ *byte, @\"\".src·3 any)\n"
"func @\"\".writebarrierfat (@\"\".typ·1 *byte, @\"\".dst·2 *any, @\"\".src·3 *any)\n"
"func @\"\".writebarriercopy (@\"\".typ·2 *byte, @\"\".dst·3 any, @\"\".src·4 any) (? int)\n"
"func @\"\".selectnbsend (@\"\".chanType·2 *byte, @\"\".hchan·3 chan<- any, @\"\".elem·4 *any) (? bool)\n"
"func @\"\".selectnbrecv (@\"\".chanType·2 *byte, @\"\".elem·3 *any, @\"\".hchan·4 <-chan any) (? bool)\n"
"func @\"\".selectnbrecv2 (@\"\".chanType·2 *byte, @\"\".elem·3 *any, @\"\".received·4 *bool, @\"\".hchan·5 <-chan any) (? bool)\n"

View File

@ -1473,6 +1473,7 @@ void walk(Node *fn);
void walkexpr(Node **np, NodeList **init);
void walkexprlist(NodeList *l, NodeList **init);
void walkexprlistsafe(NodeList *l, NodeList **init);
void walkexprlistcheap(NodeList *l, NodeList **init);
void walkstmt(Node **np);
void walkstmtlist(NodeList *l);
Node* conv(Node*, Type*);

View File

@ -36,6 +36,8 @@ func printeface(any)
func printslice(any)
func printnl()
func printsp()
func printlock()
func printunlock()
func concatstring2(string, string) string
func concatstring3(string, string, string) string
@ -115,10 +117,35 @@ func writebarrieriface(dst *any, src any)
// The unused *byte argument makes sure that src is 2-pointer-aligned,
// which is the maximum alignment on NaCl amd64p32
// (and possibly on 32-bit systems if we start 64-bit aligning uint64s).
func writebarrierfat2(dst *any, _ *byte, src any)
func writebarrierfat3(dst *any, _ *byte, src any)
func writebarrierfat4(dst *any, _ *byte, src any)
// The bitmap in the name tells which words being copied are pointers.
func writebarrierfat01(dst *any, _ *byte, src any)
func writebarrierfat10(dst *any, _ *byte, src any)
func writebarrierfat11(dst *any, _ *byte, src any)
func writebarrierfat001(dst *any, _ *byte, src any)
func writebarrierfat010(dst *any, _ *byte, src any)
func writebarrierfat011(dst *any, _ *byte, src any)
func writebarrierfat100(dst *any, _ *byte, src any)
func writebarrierfat101(dst *any, _ *byte, src any)
func writebarrierfat110(dst *any, _ *byte, src any)
func writebarrierfat111(dst *any, _ *byte, src any)
func writebarrierfat0001(dst *any, _ *byte, src any)
func writebarrierfat0010(dst *any, _ *byte, src any)
func writebarrierfat0011(dst *any, _ *byte, src any)
func writebarrierfat0100(dst *any, _ *byte, src any)
func writebarrierfat0101(dst *any, _ *byte, src any)
func writebarrierfat0110(dst *any, _ *byte, src any)
func writebarrierfat0111(dst *any, _ *byte, src any)
func writebarrierfat1000(dst *any, _ *byte, src any)
func writebarrierfat1001(dst *any, _ *byte, src any)
func writebarrierfat1010(dst *any, _ *byte, src any)
func writebarrierfat1011(dst *any, _ *byte, src any)
func writebarrierfat1100(dst *any, _ *byte, src any)
func writebarrierfat1101(dst *any, _ *byte, src any)
func writebarrierfat1110(dst *any, _ *byte, src any)
func writebarrierfat1111(dst *any, _ *byte, src any)
func writebarrierfat(typ *byte, dst *any, src *any)
func writebarriercopy(typ *byte, dst any, src any) int
func selectnbsend(chanType *byte, hchan chan<- any, elem *any) bool
func selectnbrecv(chanType *byte, elem *any, hchan <-chan any) bool

View File

@ -2891,7 +2891,8 @@ typecheckas(Node *n)
case OSLICE3:
case OSLICESTR:
// For x = x[0:y], x can be updated in place, without touching pointer.
if(samesafeexpr(n->left, n->right->left) && (n->right->right->left == N || iszero(n->right->right->left)))
// TODO(rsc): Reenable once it is actually updated in place without touching the pointer.
if(0 && samesafeexpr(n->left, n->right->left) && (n->right->right->left == N || iszero(n->right->right->left)))
n->right->reslice = 1;
break;
@ -2899,7 +2900,8 @@ typecheckas(Node *n)
// For x = append(x, ...), x can be updated in place when there is capacity,
// without touching the pointer; otherwise the emitted code to growslice
// can take care of updating the pointer, and only in that case.
if(n->right->list != nil && samesafeexpr(n->left, n->right->list->n))
// TODO(rsc): Reenable once the emitted code does update the pointer.
if(0 && n->right->list != nil && samesafeexpr(n->left, n->right->list->n))
n->right->reslice = 1;
break;
}

View File

@ -6,6 +6,7 @@
#include <libc.h>
#include "go.h"
#include "../ld/textflag.h"
#include "../../runtime/mgc0.h"
static Node* walkprint(Node*, NodeList**);
static Node* writebarrierfn(char*, Type*, Type*);
@ -362,6 +363,15 @@ walkexprlistsafe(NodeList *l, NodeList **init)
}
}
void
walkexprlistcheap(NodeList *l, NodeList **init)
{
for(; l; l=l->next) {
l->n = cheapexpr(l->n, init);
walkexpr(&l->n, init);
}
}
void
walkexpr(Node **np, NodeList **init)
{
@ -1771,6 +1781,11 @@ walkprint(Node *nn, NodeList **init)
calls = nil;
notfirst = 0;
// Hoist all the argument evaluation up before the lock.
walkexprlistcheap(all, init);
calls = list(calls, mkcall("printlock", T, init));
for(l=all; l; l=l->next) {
if(notfirst) {
calls = list(calls, mkcall("printsp", T, init));
@ -1851,6 +1866,9 @@ walkprint(Node *nn, NodeList **init)
if(op == OPRINTN)
calls = list(calls, mkcall("printnl", T, nil));
calls = list(calls, mkcall("printunlock", T, init));
typechecklist(calls, Etop);
walkexprlist(calls, init);
@ -1987,6 +2005,9 @@ applywritebarrier(Node *n, NodeList **init)
{
Node *l, *r;
Type *t;
vlong x;
static Bvec *bv;
char name[32];
if(n->left && n->right && needwritebarrier(n->left, n->right)) {
t = n->left->type;
@ -2004,14 +2025,35 @@ applywritebarrier(Node *n, NodeList **init)
} else if(isinter(t)) {
n = mkcall1(writebarrierfn("writebarrieriface", t, n->right->type), T, init,
l, n->right);
} else if(t->width == 2*widthptr) {
n = mkcall1(writebarrierfn("writebarrierfat2", t, n->right->type), T, init,
l, nodnil(), n->right);
} else if(t->width == 3*widthptr) {
n = mkcall1(writebarrierfn("writebarrierfat3", t, n->right->type), T, init,
l, nodnil(), n->right);
} else if(t->width == 4*widthptr) {
n = mkcall1(writebarrierfn("writebarrierfat4", t, n->right->type), T, init,
} else if(t->width <= 4*widthptr) {
x = 0;
if(bv == nil)
bv = bvalloc(BitsPerPointer*4);
bvresetall(bv);
twobitwalktype1(t, &x, bv);
// The bvgets are looking for BitsPointer in successive slots.
enum {
PtrBit = 1,
};
if(BitsPointer != (1<<PtrBit))
fatal("wrong PtrBit");
switch(t->width/widthptr) {
default:
fatal("found writebarrierfat for %d-byte object of type %T", (int)t->width, t);
case 2:
snprint(name, sizeof name, "writebarrierfat%d%d",
bvget(bv, PtrBit), bvget(bv, BitsPerPointer+PtrBit));
break;
case 3:
snprint(name, sizeof name, "writebarrierfat%d%d%d",
bvget(bv, PtrBit), bvget(bv, BitsPerPointer+PtrBit), bvget(bv, 2*BitsPerPointer+PtrBit));
break;
case 4:
snprint(name, sizeof name, "writebarrierfat%d%d%d%d",
bvget(bv, PtrBit), bvget(bv, BitsPerPointer+PtrBit), bvget(bv, 2*BitsPerPointer+PtrBit), bvget(bv, 3*BitsPerPointer+PtrBit));
break;
}
n = mkcall1(writebarrierfn(name, t, n->right->type), T, init,
l, nodnil(), n->right);
} else {
r = n->right;
@ -2873,6 +2915,11 @@ copyany(Node *n, NodeList **init, int runtimecall)
{
Node *nl, *nr, *nfrm, *nto, *nif, *nlen, *nwid, *fn;
NodeList *l;
if(haspointers(n->left->type->type)) {
fn = writebarrierfn("writebarriercopy", n->left->type, n->right->type);
return mkcall1(fn, n->type, init, typename(n->left->type->type), n->left, n->right);
}
if(runtimecall) {
if(n->right->type->etype == TSTRING)

View File

@ -2285,3 +2285,23 @@ TEXT runtime·getg(SB),NOSPLIT,$0-4
MOVL AX, ret+0(FP)
RET
TEXT runtime·prefetcht0(SB),NOSPLIT,$0-4
MOVL addr+0(FP), AX
PREFETCHT0 (AX)
RET
TEXT runtime·prefetcht1(SB),NOSPLIT,$0-4
MOVL addr+0(FP), AX
PREFETCHT1 (AX)
RET
TEXT runtime·prefetcht2(SB),NOSPLIT,$0-4
MOVL addr+0(FP), AX
PREFETCHT2 (AX)
RET
TEXT runtime·prefetchnta(SB),NOSPLIT,$0-4
MOVL addr+0(FP), AX
PREFETCHNTA (AX)
RET

View File

@ -2228,3 +2228,23 @@ TEXT runtime·getg(SB),NOSPLIT,$0-8
MOVQ g(CX), AX
MOVQ AX, ret+0(FP)
RET
TEXT runtime·prefetcht0(SB),NOSPLIT,$0-8
MOVQ addr+0(FP), AX
PREFETCHT0 (AX)
RET
TEXT runtime·prefetcht1(SB),NOSPLIT,$0-8
MOVQ addr+0(FP), AX
PREFETCHT1 (AX)
RET
TEXT runtime·prefetcht2(SB),NOSPLIT,$0-8
MOVQ addr+0(FP), AX
PREFETCHT2 (AX)
RET
TEXT runtime·prefetchnta(SB),NOSPLIT,$0-8
MOVQ addr+0(FP), AX
PREFETCHNTA (AX)
RET

View File

@ -1079,3 +1079,24 @@ TEXT runtime·getg(SB),NOSPLIT,$0-4
MOVL g(CX), AX
MOVL AX, ret+0(FP)
RET
TEXT runtime·prefetcht0(SB),NOSPLIT,$0-4
MOVL addr+0(FP), AX
PREFETCHT0 (AX)
RET
TEXT runtime·prefetcht1(SB),NOSPLIT,$0-4
MOVL addr+0(FP), AX
PREFETCHT1 (AX)
RET
TEXT runtime·prefetcht2(SB),NOSPLIT,$0-4
MOVL addr+0(FP), AX
PREFETCHT2 (AX)
RET
TEXT runtime·prefetchnta(SB),NOSPLIT,$0-4
MOVL addr+0(FP), AX
PREFETCHNTA (AX)
RET

View File

@ -1320,3 +1320,15 @@ TEXT runtime·goexit(SB),NOSPLIT,$-4-0
TEXT runtime·getg(SB),NOSPLIT,$-4-4
MOVW g, ret+0(FP)
RET
TEXT runtime·prefetcht0(SB),NOSPLIT,$0-4
RET
TEXT runtime·prefetcht1(SB),NOSPLIT,$0-4
RET
TEXT runtime·prefetcht2(SB),NOSPLIT,$0-4
RET
TEXT runtime·prefetchnta(SB),NOSPLIT,$0-4
RET

View File

@ -977,3 +977,15 @@ TEXT runtime·goexit(SB),NOSPLIT,$-8-0
TEXT runtime·getg(SB),NOSPLIT,$-8-8
MOVD g, ret+0(FP)
RETURN
TEXT runtime·prefetcht0(SB),NOSPLIT,$0-8
RETURN
TEXT runtime·prefetcht1(SB),NOSPLIT,$0-8
RETURN
TEXT runtime·prefetcht2(SB),NOSPLIT,$0-8
RETURN
TEXT runtime·prefetchnta(SB),NOSPLIT,$0-8
RETURN

View File

@ -26,7 +26,7 @@ var Exitsyscall = exitsyscall
var LockedOSThread = lockedOSThread
type LFNode struct {
Next *LFNode
Next uint64
Pushcnt uintptr
}

View File

@ -464,8 +464,8 @@ func dumpobjs() {
if n > uintptr(len(freemark)) {
gothrow("freemark array doesn't have enough entries")
}
for l := s.freelist; l != nil; l = l.next {
freemark[(uintptr(unsafe.Pointer(l))-p)/size] = true
for l := s.freelist; l.ptr() != nil; l = l.ptr().next {
freemark[(uintptr(l)-p)/size] = true
}
for j := uintptr(0); j < n; j, p = j+1, p+size {
if freemark[j] {

View File

@ -18,7 +18,7 @@ func lfstackpush(head *uint64, node *lfnode) {
}
for {
old := atomicload64(head)
node.next, _ = lfstackUnpack(old)
node.next = old
if cas64(head, old, new) {
break
}
@ -32,12 +32,8 @@ func lfstackpop(head *uint64) unsafe.Pointer {
return nil
}
node, _ := lfstackUnpack(old)
node2 := (*lfnode)(atomicloadp(unsafe.Pointer(&node.next)))
new := uint64(0)
if node2 != nil {
new = lfstackPack(node2, node2.pushcnt)
}
if cas64(head, old, new) {
next := atomicload64(&node.next)
if cas64(head, old, next) {
return unsafe.Pointer(node)
}
}

View File

@ -121,7 +121,7 @@ func TestLFStackStress(t *testing.T) {
}
cnt++
sum2 += node.data
node.Next = nil
node.Next = 0
}
}
if cnt != K {

View File

@ -140,14 +140,14 @@ func mallocgc(size uintptr, typ *_type, flags uint32) unsafe.Pointer {
// Allocate a new maxTinySize block.
s = c.alloc[tinySizeClass]
v := s.freelist
if v == nil {
if v.ptr() == nil {
systemstack(func() {
mCache_Refill(c, tinySizeClass)
})
s = c.alloc[tinySizeClass]
v = s.freelist
}
s.freelist = v.next
s.freelist = v.ptr().next
s.ref++
//TODO: prefetch v.next
x = unsafe.Pointer(v)
@ -170,19 +170,19 @@ func mallocgc(size uintptr, typ *_type, flags uint32) unsafe.Pointer {
size = uintptr(class_to_size[sizeclass])
s = c.alloc[sizeclass]
v := s.freelist
if v == nil {
if v.ptr() == nil {
systemstack(func() {
mCache_Refill(c, int32(sizeclass))
})
s = c.alloc[sizeclass]
v = s.freelist
}
s.freelist = v.next
s.freelist = v.ptr().next
s.ref++
//TODO: prefetch
x = unsafe.Pointer(v)
if flags&flagNoZero == 0 {
v.next = nil
v.ptr().next = 0
if size > 2*ptrSize && ((*[2]uintptr)(x))[1] != 0 {
memclr(unsafe.Pointer(v), size)
}
@ -241,6 +241,8 @@ func mallocgc(size uintptr, typ *_type, flags uint32) unsafe.Pointer {
masksize = masksize * pointersPerByte / 8 // 4 bits per word
masksize++ // unroll flag in the beginning
if masksize > maxGCMask && typ.gc[1] != 0 {
// write barriers have not been updated to deal with this case yet.
gothrow("maxGCMask too small for now")
// If the mask is too large, unroll the program directly
// into the GC bitmap. It's 7 times slower than copying
// from the pre-unrolled mask, but saves 1/16 of type size
@ -295,6 +297,17 @@ func mallocgc(size uintptr, typ *_type, flags uint32) unsafe.Pointer {
}
}
marked:
// GCmarkterminate allocates black
// All slots hold nil so no scanning is needed.
// This may be racing with GC so do it atomically if there can be
// a race marking the bit.
if gcphase == _GCmarktermination {
systemstack(func() {
gcmarknewobject_m(uintptr(x))
})
}
if raceenabled {
racemalloc(x, size)
}
@ -328,13 +341,43 @@ marked:
}
}
if memstats.heap_alloc >= memstats.next_gc {
if memstats.heap_alloc >= memstats.next_gc/2 {
gogc(0)
}
return x
}
func loadPtrMask(typ *_type) []uint8 {
var ptrmask *uint8
nptr := (uintptr(typ.size) + ptrSize - 1) / ptrSize
if typ.kind&kindGCProg != 0 {
masksize := nptr
if masksize%2 != 0 {
masksize *= 2 // repeated
}
masksize = masksize * pointersPerByte / 8 // 4 bits per word
masksize++ // unroll flag in the beginning
if masksize > maxGCMask && typ.gc[1] != 0 {
// write barriers have not been updated to deal with this case yet.
gothrow("maxGCMask too small for now")
}
ptrmask = (*uint8)(unsafe.Pointer(uintptr(typ.gc[0])))
// Check whether the program is already unrolled
// by checking if the unroll flag byte is set
maskword := uintptr(atomicloadp(unsafe.Pointer(ptrmask)))
if *(*uint8)(unsafe.Pointer(&maskword)) == 0 {
systemstack(func() {
unrollgcprog_m(typ)
})
}
ptrmask = (*uint8)(add(unsafe.Pointer(ptrmask), 1)) // skip the unroll flag byte
} else {
ptrmask = (*uint8)(unsafe.Pointer(typ.gc[0])) // pointer to unrolled mask
}
return (*[1 << 30]byte)(unsafe.Pointer(ptrmask))[:(nptr+1)/2]
}
// implementation of new builtin
func newobject(typ *_type) unsafe.Pointer {
flags := uint32(0)
@ -429,7 +472,21 @@ func gogc(force int32) {
mp = acquirem()
mp.gcing = 1
releasem(mp)
systemstack(stoptheworld)
systemstack(finishsweep_m) // finish sweep before we start concurrent scan.
if true { // To turn on concurrent scan and mark set to true...
systemstack(starttheworld)
// Do a concurrent heap scan before we stop the world.
systemstack(gcscan_m)
systemstack(stoptheworld)
systemstack(gcinstallmarkwb_m)
systemstack(starttheworld)
systemstack(gcmark_m)
systemstack(stoptheworld)
systemstack(gcinstalloffwb_m)
}
if mp != acquirem() {
gothrow("gogc: rescheduled")
}
@ -445,17 +502,21 @@ func gogc(force int32) {
if debug.gctrace > 1 {
n = 2
}
eagersweep := force >= 2
for i := 0; i < n; i++ {
if i > 0 {
startTime = nanotime()
}
// switch to g0, call gc, then switch back
eagersweep := force >= 2
systemstack(func() {
gc_m(startTime, eagersweep)
})
}
systemstack(func() {
gccheckmark_m(startTime, eagersweep)
})
// all done
mp.gcing = 0
semrelease(&worldsema)
@ -470,6 +531,14 @@ func gogc(force int32) {
}
}
func GCcheckmarkenable() {
systemstack(gccheckmarkenable_m)
}
func GCcheckmarkdisable() {
systemstack(gccheckmarkdisable_m)
}
// GC runs a garbage collection.
func GC() {
gogc(2)

View File

@ -139,10 +139,35 @@ const (
)
// A generic linked list of blocks. (Typically the block is bigger than sizeof(MLink).)
// Since assignments to mlink.next will result in a write barrier being preformed
// this can not be used by some of the internal GC structures. For example when
// the sweeper is placing an unmarked object on the free list it does not want the
// write barrier to be called since that could result in the object being reachable.
type mlink struct {
next *mlink
}
// A gclink is a node in a linked list of blocks, like mlink,
// but it is opaque to the garbage collector.
// The GC does not trace the pointers during collection,
// and the compiler does not emit write barriers for assignments
// of gclinkptr values. Code should store references to gclinks
// as gclinkptr, not as *gclink.
type gclink struct {
next gclinkptr
}
// A gclinkptr is a pointer to a gclink, but it is opaque
// to the garbage collector.
type gclinkptr uintptr
// ptr returns the *gclink form of p.
// The result should be used for accessing fields, not stored
// in other data structures.
func (p gclinkptr) ptr() *gclink {
return (*gclink)(unsafe.Pointer(p))
}
// sysAlloc obtains a large chunk of zeroed memory from the
// operating system, typically on the order of a hundred kilobytes
// or a megabyte.
@ -275,8 +300,8 @@ type mcachelist struct {
}
type stackfreelist struct {
list *mlink // linked list of free stacks
size uintptr // total size of stacks in list
list gclinkptr // linked list of free stacks
size uintptr // total size of stacks in list
}
// Per-thread (in Go, per-P) cache for small objects.
@ -299,8 +324,6 @@ type mcache struct {
sudogcache *sudog
gcworkbuf unsafe.Pointer
// Local allocator stats, flushed during GC.
local_nlookup uintptr // number of pointer lookups
local_largefree uintptr // bytes freed for large objects (>maxsmallsize)
@ -348,11 +371,11 @@ const (
)
type mspan struct {
next *mspan // in a span linked list
prev *mspan // in a span linked list
start pageID // starting page number
npages uintptr // number of pages in span
freelist *mlink // list of free objects
next *mspan // in a span linked list
prev *mspan // in a span linked list
start pageID // starting page number
npages uintptr // number of pages in span
freelist gclinkptr // list of free objects
// sweep generation:
// if sweepgen == h->sweepgen - 2, the span needs sweeping
// if sweepgen == h->sweepgen - 1, the span is currently being swept

View File

@ -38,7 +38,12 @@ func freemcache(c *mcache) {
systemstack(func() {
mCache_ReleaseAll(c)
stackcache_clear(c)
gcworkbuffree(c.gcworkbuf)
// NOTE(rsc,rlh): If gcworkbuffree comes back, we need to coordinate
// with the stealing of gcworkbufs during garbage collection to avoid
// a race where the workbuf is double-freed.
// gcworkbuffree(c.gcworkbuf)
lock(&mheap_.lock)
purgecachedstats(c)
fixAlloc_Free(&mheap_.cachealloc, unsafe.Pointer(c))
@ -54,7 +59,7 @@ func mCache_Refill(c *mcache, sizeclass int32) *mspan {
_g_.m.locks++
// Return the current cached span to the central lists.
s := c.alloc[sizeclass]
if s.freelist != nil {
if s.freelist.ptr() != nil {
gothrow("refill on a nonempty span")
}
if s != &emptymspan {
@ -66,7 +71,7 @@ func mCache_Refill(c *mcache, sizeclass int32) *mspan {
if s == nil {
gothrow("out of memory")
}
if s.freelist == nil {
if s.freelist.ptr() == nil {
println(s.ref, (s.npages<<_PageShift)/s.elemsize)
gothrow("empty span")
}

View File

@ -55,7 +55,7 @@ retry:
mSpanList_InsertBack(&c.empty, s)
unlock(&c.lock)
mSpan_Sweep(s, true)
if s.freelist != nil {
if s.freelist.ptr() != nil {
goto havespan
}
lock(&c.lock)
@ -90,7 +90,7 @@ havespan:
if n == 0 {
gothrow("empty span")
}
if s.freelist == nil {
if s.freelist.ptr() == nil {
gothrow("freelist empty")
}
s.incache = true
@ -122,14 +122,14 @@ func mCentral_UncacheSpan(c *mcentral, s *mspan) {
// the latest generation.
// If preserve=true, don't return the span to heap nor relink in MCentral lists;
// caller takes care of it.
func mCentral_FreeSpan(c *mcentral, s *mspan, n int32, start *mlink, end *mlink, preserve bool) bool {
func mCentral_FreeSpan(c *mcentral, s *mspan, n int32, start gclinkptr, end gclinkptr, preserve bool) bool {
if s.incache {
gothrow("freespan into cached span")
}
// Add the objects back to s's free list.
wasempty := s.freelist == nil
end.next = s.freelist
wasempty := s.freelist.ptr() == nil
end.ptr().next = s.freelist
s.freelist = start
s.ref -= uint16(n)
@ -165,7 +165,7 @@ func mCentral_FreeSpan(c *mcentral, s *mspan, n int32, start *mlink, end *mlink,
// s is completely freed, return it to the heap.
mSpanList_Remove(s)
s.needzero = 1
s.freelist = nil
s.freelist = 0
unlock(&c.lock)
unmarkspan(uintptr(s.start)<<_PageShift, s.npages<<_PageShift)
mHeap_Free(&mheap_, s, 0)
@ -183,17 +183,21 @@ func mCentral_Grow(c *mcentral) *mspan {
return nil
}
// Carve span into sequence of blocks.
tailp := &s.freelist
p := uintptr(s.start << _PageShift)
s.limit = p + size*n
for i := uintptr(0); i < n; i++ {
v := (*mlink)(unsafe.Pointer(p))
*tailp = v
tailp = &v.next
head := gclinkptr(p)
tail := gclinkptr(p)
// i==0 iteration already done
for i := uintptr(1); i < n; i++ {
p += size
tail.ptr().next = gclinkptr(p)
tail = gclinkptr(p)
}
*tailp = nil
if s.freelist.ptr() != nil {
gothrow("freelist not empty")
}
tail.ptr().next = 0
s.freelist = head
markspan(unsafe.Pointer(uintptr(s.start)<<_PageShift), size, n, size*n < s.npages<<_PageShift)
return s
}

File diff suppressed because it is too large Load Diff

View File

@ -97,54 +97,155 @@ func bgsweep() {
}
}
const (
_PoisonGC = 0xf969696969696969 & (1<<(8*ptrSize) - 1)
_PoisonStack = 0x6868686868686868 & (1<<(8*ptrSize) - 1)
)
func needwb() bool {
return gcphase == _GCmark || gcphase == _GCmarktermination
}
// NOTE: Really dst *unsafe.Pointer, src unsafe.Pointer,
// but if we do that, Go inserts a write barrier on *dst = src.
//go:nosplit
func writebarrierptr(dst *uintptr, src uintptr) {
*dst = src
if needwb() {
writebarrierptr_nostore(dst, src)
}
}
// Like writebarrierptr, but the store has already been applied.
// Do not reapply.
//go:nosplit
func writebarrierptr_nostore(dst *uintptr, src uintptr) {
if getg() == nil || !needwb() { // very low-level startup
return
}
if src != 0 && (src < _PageSize || src == _PoisonGC || src == _PoisonStack) {
systemstack(func() { gothrow("bad pointer in write barrier") })
}
mp := acquirem()
if mp.inwb || mp.dying > 0 {
releasem(mp)
return
}
mp.inwb = true
systemstack(func() {
gcmarkwb_m(dst, src)
})
mp.inwb = false
releasem(mp)
}
//go:nosplit
func writebarrierstring(dst *[2]uintptr, src [2]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
}
//go:nosplit
func writebarrierslice(dst *[3]uintptr, src [3]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
dst[2] = src[2]
}
//go:nosplit
func writebarrieriface(dst *[2]uintptr, src [2]uintptr) {
dst[0] = src[0]
dst[1] = src[1]
writebarrierptr(&dst[0], src[0])
writebarrierptr(&dst[1], src[1])
}
//go:nosplit
func writebarrierfat2(dst *[2]uintptr, _ *byte, src [2]uintptr) {
dst[0] = src[0]
dst[1] = src[1]
}
//go:nosplit
func writebarrierfat3(dst *[3]uintptr, _ *byte, src [3]uintptr) {
dst[0] = src[0]
dst[1] = src[1]
dst[2] = src[2]
}
//go:nosplit
func writebarrierfat4(dst *[4]uintptr, _ *byte, src [4]uintptr) {
dst[0] = src[0]
dst[1] = src[1]
dst[2] = src[2]
dst[3] = src[3]
}
//go:generate go run wbfat_gen.go -- wbfat.go
//
// The above line generates multiword write barriers for
// all the combinations of ptr+scalar up to four words.
// The implementations are written to wbfat.go.
//go:nosplit
func writebarrierfat(typ *_type, dst, src unsafe.Pointer) {
memmove(dst, src, typ.size)
if !needwb() {
memmove(dst, src, typ.size)
return
}
systemstack(func() {
mask := loadPtrMask(typ)
nptr := typ.size / ptrSize
for i := uintptr(0); i < nptr; i += 2 {
bits := mask[i/2]
if (bits>>2)&_BitsMask == _BitsPointer {
writebarrierptr((*uintptr)(dst), *(*uintptr)(src))
} else {
*(*uintptr)(dst) = *(*uintptr)(src)
}
dst = add(dst, ptrSize)
src = add(src, ptrSize)
if i+1 == nptr {
break
}
bits >>= 4
if (bits>>2)&_BitsMask == _BitsPointer {
writebarrierptr((*uintptr)(dst), *(*uintptr)(src))
} else {
*(*uintptr)(dst) = *(*uintptr)(src)
}
dst = add(dst, ptrSize)
src = add(src, ptrSize)
}
})
}
//go:nosplit
func writebarriercopy(typ *_type, dst, src slice) int {
n := dst.len
if n > src.len {
n = src.len
}
if n == 0 {
return 0
}
dstp := unsafe.Pointer(dst.array)
srcp := unsafe.Pointer(src.array)
if !needwb() {
memmove(dstp, srcp, uintptr(n)*typ.size)
return int(n)
}
systemstack(func() {
if uintptr(srcp) < uintptr(dstp) && uintptr(srcp)+uintptr(n)*typ.size > uintptr(dstp) {
// Overlap with src before dst.
// Copy backward, being careful not to move dstp/srcp
// out of the array they point into.
dstp = add(dstp, uintptr(n-1)*typ.size)
srcp = add(srcp, uintptr(n-1)*typ.size)
i := uint(0)
for {
writebarrierfat(typ, dstp, srcp)
if i++; i >= n {
break
}
dstp = add(dstp, -typ.size)
srcp = add(srcp, -typ.size)
}
} else {
// Copy forward, being careful not to move dstp/srcp
// out of the array they point into.
i := uint(0)
for {
writebarrierfat(typ, dstp, srcp)
if i++; i >= n {
break
}
dstp = add(dstp, typ.size)
srcp = add(srcp, typ.size)
}
}
})
return int(n)
}

View File

@ -12,9 +12,11 @@ enum {
BitsPointer = 2,
BitsMask = 3,
PointersPerByte = 8/BitsPerPointer,
MaxGCMask = 64,
insData = 1,
insArray,
insArrayEnd,
insEnd,
// 64 bytes cover objects of size 1024/512 on 64/32 bits, respectively.
MaxGCMask = 65536, // TODO(rsc): change back to 64
};

View File

@ -50,12 +50,15 @@ const (
// If you change these, also change scanblock.
// scanblock does "if(bits == BitsScalar || bits == BitsDead)" as "if(bits <= BitsScalar)".
_BitsDead = 0
_BitsScalar = 1
_BitsPointer = 2
_BitsDead = 0
_BitsScalar = 1 // 01
_BitsPointer = 2 // 10
_BitsCheckMarkXor = 1 // 10
_BitsScalarMarked = _BitsScalar ^ _BitsCheckMarkXor // 00
_BitsPointerMarked = _BitsPointer ^ _BitsCheckMarkXor // 11
// 64 bytes cover objects of size 1024/512 on 64/32 bits, respectively.
_MaxGCMask = 64
_MaxGCMask = 65536 // TODO(rsc): change back to 64
)
// Bits in per-word bitmap.

View File

@ -196,7 +196,7 @@ func mHeap_Alloc_m(h *mheap, npage uintptr, sizeclass int32, large bool) *mspan
// able to map interior pointer to containing span.
atomicstore(&s.sweepgen, h.sweepgen)
s.state = _MSpanInUse
s.freelist = nil
s.freelist = 0
s.ref = 0
s.sizeclass = uint8(sizeclass)
if sizeclass == 0 {
@ -248,7 +248,7 @@ func mHeap_AllocStack(h *mheap, npage uintptr) *mspan {
s := mHeap_AllocSpanLocked(h, npage)
if s != nil {
s.state = _MSpanStack
s.freelist = nil
s.freelist = 0
s.ref = 0
memstats.stacks_inuse += uint64(s.npages << _PageShift)
}
@ -571,7 +571,7 @@ func mSpan_Init(span *mspan, start pageID, npages uintptr) {
span.prev = nil
span.start = start
span.npages = npages
span.freelist = nil
span.freelist = 0
span.ref = 0
span.sizeclass = 0
span.incache = false

View File

@ -14,8 +14,7 @@ const (
var _vdso uint32
//go:nosplit
func linux_setup_vdso(argc int32, argv **byte) {
func sysargs(argc int32, argv **byte) {
// skip over argv, envv to get to auxv
n := argc + 1
for argv_index(argv, n) != nil {

View File

@ -41,7 +41,31 @@ func snprintf(dst *byte, n int32, s *byte) {
gp.writebuf = nil
}
//var debuglock mutex
var debuglock mutex
// The compiler emits calls to printlock and printunlock around
// the multiple calls that implement a single Go print or println
// statement. Some of the print helpers (printsp, for example)
// call print recursively. There is also the problem of a crash
// happening during the print routines and needing to acquire
// the print lock to print information about the crash.
// For both these reasons, let a thread acquire the printlock 'recursively'.
func printlock() {
mp := getg().m
mp.printlock++
if mp.printlock == 1 {
lock(&debuglock)
}
}
func printunlock() {
mp := getg().m
mp.printlock--
if mp.printlock == 0 {
unlock(&debuglock)
}
}
// write to goroutine-local buffer if diverting output,
// or else standard error.
@ -80,7 +104,7 @@ func printnl() {
// Very simple printf. Only for debugging prints.
// Do not add to this without checking with Rob.
func vprintf(str string, arg unsafe.Pointer) {
//lock(&debuglock);
printlock()
s := bytes(str)
start := 0
@ -160,7 +184,7 @@ func vprintf(str string, arg unsafe.Pointer) {
gwrite(s[start:i])
}
//unlock(&debuglock);
printunlock()
}
func printpc(p unsafe.Pointer) {

View File

@ -181,6 +181,9 @@ func acquireSudog() *sudog {
// which keeps the garbage collector from being invoked.
mp := acquirem()
p := new(sudog)
if p.elem != nil {
gothrow("acquireSudog: found p.elem != nil after new")
}
releasem(mp)
return p
}

View File

@ -316,6 +316,10 @@ func casfrom_Gscanstatus(gp *g, oldval, newval uint32) {
// Check that transition is valid.
switch oldval {
default:
print("runtime: casfrom_Gscanstatus bad oldval gp=", gp, ", oldval=", hex(oldval), ", newval=", hex(newval), "\n")
dumpgstatus(gp)
gothrow("casfrom_Gscanstatus:top gp->status is not in scan state")
case _Gscanrunnable,
_Gscanwaiting,
_Gscanrunning,
@ -377,12 +381,12 @@ func casgstatus(gp *g, oldval, newval uint32) {
})
}
// Help GC if needed.
if gp.preemptscan && !gp.gcworkdone && (oldval == _Grunning || oldval == _Gsyscall) {
gp.preemptscan = false
systemstack(func() {
gcphasework(gp)
})
}
// if gp.preemptscan && !gp.gcworkdone && (oldval == _Grunning || oldval == _Gsyscall) {
// gp.preemptscan = false
// systemstack(func() {
// gcphasework(gp)
// })
// }
}
}
@ -512,9 +516,10 @@ func stopscanstart(gp *g) {
// Runs on g0 and does the actual work after putting the g back on the run queue.
func mquiesce(gpmaster *g) {
activeglen := len(allgs)
// enqueue the calling goroutine.
restartg(gpmaster)
activeglen := len(allgs)
for i := 0; i < activeglen; i++ {
gp := allgs[i]
if readgstatus(gp) == _Gdead {
@ -1579,7 +1584,8 @@ func save(pc, sp uintptr) {
_g_.sched.lr = 0
_g_.sched.ret = 0
_g_.sched.ctxt = nil
_g_.sched.g = _g_
// write as uintptr to avoid write barrier, which will smash _g_.sched.
*(*uintptr)(unsafe.Pointer(&_g_.sched.g)) = uintptr(unsafe.Pointer(_g_))
}
// The goroutine g is about to enter a system call.
@ -1625,7 +1631,10 @@ func reentersyscall(pc, sp uintptr) {
_g_.syscallpc = pc
casgstatus(_g_, _Grunning, _Gsyscall)
if _g_.syscallsp < _g_.stack.lo || _g_.stack.hi < _g_.syscallsp {
systemstack(entersyscall_bad)
systemstack(func() {
print("entersyscall inconsistent ", hex(_g_.syscallsp), " [", hex(_g_.stack.lo), ",", hex(_g_.stack.hi), "]\n")
gothrow("entersyscall")
})
}
if atomicload(&sched.sysmonwait) != 0 { // TODO: fast atomic
@ -1654,13 +1663,6 @@ func entersyscall(dummy int32) {
reentersyscall(getcallerpc(unsafe.Pointer(&dummy)), getcallersp(unsafe.Pointer(&dummy)))
}
func entersyscall_bad() {
var gp *g
gp = getg().m.curg
print("entersyscall inconsistent ", hex(gp.syscallsp), " [", hex(gp.stack.lo), ",", hex(gp.stack.hi), "]\n")
gothrow("entersyscall")
}
func entersyscall_sysmon() {
lock(&sched.lock)
if atomicload(&sched.sysmonwait) != 0 {
@ -1692,12 +1694,26 @@ func entersyscallblock(dummy int32) {
_g_.stackguard0 = stackPreempt // see comment in entersyscall
// Leave SP around for GC and traceback.
save(getcallerpc(unsafe.Pointer(&dummy)), getcallersp(unsafe.Pointer(&dummy)))
pc := getcallerpc(unsafe.Pointer(&dummy))
sp := getcallersp(unsafe.Pointer(&dummy))
save(pc, sp)
_g_.syscallsp = _g_.sched.sp
_g_.syscallpc = _g_.sched.pc
if _g_.syscallsp < _g_.stack.lo || _g_.stack.hi < _g_.syscallsp {
sp1 := sp
sp2 := _g_.sched.sp
sp3 := _g_.syscallsp
systemstack(func() {
print("entersyscallblock inconsistent ", hex(sp1), " ", hex(sp2), " ", hex(sp3), " [", hex(_g_.stack.lo), ",", hex(_g_.stack.hi), "]\n")
gothrow("entersyscallblock")
})
}
casgstatus(_g_, _Grunning, _Gsyscall)
if _g_.syscallsp < _g_.stack.lo || _g_.stack.hi < _g_.syscallsp {
systemstack(entersyscall_bad)
systemstack(func() {
print("entersyscallblock inconsistent ", hex(sp), " ", hex(_g_.sched.sp), " ", hex(_g_.syscallsp), " [", hex(_g_.stack.lo), ",", hex(_g_.stack.hi), "]\n")
gothrow("entersyscallblock")
})
}
systemstack(entersyscallblock_handoff)
@ -1776,6 +1792,7 @@ func exitsyscallfast() bool {
// Freezetheworld sets stopwait but does not retake P's.
if sched.stopwait != 0 {
_g_.m.mcache = nil
_g_.m.p = nil
return false
}
@ -1789,6 +1806,7 @@ func exitsyscallfast() bool {
}
// Try to get any other idle P.
_g_.m.mcache = nil
_g_.m.p = nil
if sched.pidle != nil {
var ok bool
@ -2363,6 +2381,8 @@ func setcpuprofilerate_m(hz int32) {
}
// Change number of processors. The world is stopped, sched is locked.
// gcworkbufs are not being modified by either the GC or
// the write barrier code.
func procresize(new int32) {
old := gomaxprocs
if old < 0 || old > _MaxGomaxprocs || new <= 0 || new > _MaxGomaxprocs {

View File

@ -9,7 +9,6 @@ TEXT _rt0_386_linux(SB),NOSPLIT,$8
LEAL 12(SP), BX
MOVL AX, 0(SP)
MOVL BX, 4(SP)
CALL runtime·linux_setup_vdso(SB)
CALL main(SB)
INT $3

View File

@ -97,7 +97,10 @@ func testAtomic64() {
z64 = 42
x64 = 0
// TODO: PREFETCH((unsafe.Pointer)(&z64))
prefetcht0(uintptr(unsafe.Pointer(&z64)))
prefetcht1(uintptr(unsafe.Pointer(&z64)))
prefetcht2(uintptr(unsafe.Pointer(&z64)))
prefetchnta(uintptr(unsafe.Pointer(&z64)))
if cas64(&z64, x64, 1) {
gothrow("cas64 failed")
}

View File

@ -227,6 +227,8 @@ type m struct {
helpgc int32
spinning bool // m is out of work and is actively looking for work
blocked bool // m is blocked on a note
inwb bool // m is executing a write barrier
printlock int8
fastrand uint32
ncgocall uint64 // number of cgo calls in total
ncgo int32 // number of cgo calls currently in progress
@ -402,8 +404,9 @@ type itab struct {
}
// Lock-free stack node.
// // Also known to export_test.go.
type lfnode struct {
next *lfnode
next uint64
pushcnt uintptr
}
@ -448,11 +451,13 @@ type debugvars struct {
// Indicates to write barrier and sychronization task to preform.
const (
_GCoff = iota // stop and start nop
_GCquiesce // stop and start nop
_GCstw // stop the ps nop
_GCmark // scan the stacks and start no white to black
_GCsweep // stop and start nop
_GCoff = iota // GC not running, write barrier disabled
_GCquiesce // unused state
_GCstw // unused state
_GCscan // GC collecting roots into workbufs, write barrier disabled
_GCmark // GC marking from workbufs, write barrier ENABLED
_GCmarktermination // GC mark termination: allocate black, P's help GC, write barrier ENABLED
_GCsweep // GC mark completed; sweeping in background, write barrier disabled
)
type forcegcstate struct {

View File

@ -377,12 +377,7 @@ loop:
// iterating through the linked list they are in reverse order.
cas = nil
sglist = gp.waiting
// Clear all selectdone and elem before unlinking from gp.waiting.
// They must be cleared before being put back into the sudog cache.
// Clear before unlinking, because if a stack copy happens after the unlink,
// they will not be updated, they will be left pointing to the old stack,
// which creates dangling pointers, which may be detected by the
// garbage collector.
// Clear all elem before unlinking from gp.waiting.
for sg1 := gp.waiting; sg1 != nil; sg1 = sg1.waitlink {
sg1.selectdone = nil
sg1.elem = nil

View File

@ -17,7 +17,7 @@ enum {
#endif // Windows
StackBig = 4096,
StackGuard = 512 + StackSystem,
StackGuard = 640 + StackSystem,
StackSmall = 128,
StackLimit = StackGuard - StackSystem - StackSmall,
};

View File

@ -58,7 +58,7 @@ func stackinit() {
// Allocates a stack from the free pool. Must be called with
// stackpoolmu held.
func stackpoolalloc(order uint8) *mlink {
func stackpoolalloc(order uint8) gclinkptr {
list := &stackpool[order]
s := list.next
if s == list {
@ -70,23 +70,23 @@ func stackpoolalloc(order uint8) *mlink {
if s.ref != 0 {
gothrow("bad ref")
}
if s.freelist != nil {
if s.freelist.ptr() != nil {
gothrow("bad freelist")
}
for i := uintptr(0); i < _StackCacheSize; i += _FixedStack << order {
x := (*mlink)(unsafe.Pointer(uintptr(s.start)<<_PageShift + i))
x.next = s.freelist
x := gclinkptr(uintptr(s.start)<<_PageShift + i)
x.ptr().next = s.freelist
s.freelist = x
}
mSpanList_Insert(list, s)
}
x := s.freelist
if x == nil {
if x.ptr() == nil {
gothrow("span has no free stacks")
}
s.freelist = x.next
s.freelist = x.ptr().next
s.ref++
if s.freelist == nil {
if s.freelist.ptr() == nil {
// all stacks in s are allocated.
mSpanList_Remove(s)
}
@ -94,22 +94,22 @@ func stackpoolalloc(order uint8) *mlink {
}
// Adds stack x to the free pool. Must be called with stackpoolmu held.
func stackpoolfree(x *mlink, order uint8) {
func stackpoolfree(x gclinkptr, order uint8) {
s := mHeap_Lookup(&mheap_, (unsafe.Pointer)(x))
if s.state != _MSpanStack {
gothrow("freeing stack not in a stack span")
}
if s.freelist == nil {
if s.freelist.ptr() == nil {
// s will now have a free stack
mSpanList_Insert(&stackpool[order], s)
}
x.next = s.freelist
x.ptr().next = s.freelist
s.freelist = x
s.ref--
if s.ref == 0 {
// span is completely free - return to heap
mSpanList_Remove(s)
s.freelist = nil
s.freelist = 0
mHeap_FreeStack(&mheap_, s)
}
}
@ -123,12 +123,12 @@ func stackcacherefill(c *mcache, order uint8) {
// Grab some stacks from the global cache.
// Grab half of the allowed capacity (to prevent thrashing).
var list *mlink
var list gclinkptr
var size uintptr
lock(&stackpoolmu)
for size < _StackCacheSize/2 {
x := stackpoolalloc(order)
x.next = list
x.ptr().next = list
list = x
size += _FixedStack << order
}
@ -145,7 +145,7 @@ func stackcacherelease(c *mcache, order uint8) {
size := c.stackcache[order].size
lock(&stackpoolmu)
for size > _StackCacheSize/2 {
y := x.next
y := x.ptr().next
stackpoolfree(x, order)
x = y
size -= _FixedStack << order
@ -162,12 +162,12 @@ func stackcache_clear(c *mcache) {
lock(&stackpoolmu)
for order := uint8(0); order < _NumStackOrders; order++ {
x := c.stackcache[order].list
for x != nil {
y := x.next
for x.ptr() != nil {
y := x.ptr().next
stackpoolfree(x, order)
x = y
}
c.stackcache[order].list = nil
c.stackcache[order].list = 0
c.stackcache[order].size = 0
}
unlock(&stackpoolmu)
@ -207,7 +207,7 @@ func stackalloc(n uint32) stack {
order++
n2 >>= 1
}
var x *mlink
var x gclinkptr
c := thisg.m.mcache
if c == nil || thisg.m.gcing != 0 || thisg.m.helpgc != 0 {
// c == nil can happen in the guts of exitsyscall or
@ -219,11 +219,11 @@ func stackalloc(n uint32) stack {
unlock(&stackpoolmu)
} else {
x = c.stackcache[order].list
if x == nil {
if x.ptr() == nil {
stackcacherefill(c, order)
x = c.stackcache[order].list
}
c.stackcache[order].list = x.next
c.stackcache[order].list = x.ptr().next
c.stackcache[order].size -= uintptr(n)
}
v = (unsafe.Pointer)(x)
@ -270,7 +270,7 @@ func stackfree(stk stack) {
order++
n2 >>= 1
}
x := (*mlink)(v)
x := gclinkptr(v)
c := gp.m.mcache
if c == nil || gp.m.gcing != 0 || gp.m.helpgc != 0 {
lock(&stackpoolmu)
@ -280,7 +280,7 @@ func stackfree(stk stack) {
if c.stackcache[order].size >= _StackCacheSize {
stackcacherelease(c, order)
}
x.next = c.stackcache[order].list
x.ptr().next = c.stackcache[order].list
c.stackcache[order].list = x
c.stackcache[order].size += n
}
@ -526,6 +526,7 @@ func fillstack(stk stack, b byte) {
}
// Copies gp's stack to a new stack of a different size.
// Caller must have changed gp status to Gcopystack.
func copystack(gp *g, newsize uintptr) {
if gp.syscallsp != 0 {
gothrow("stack growth not allowed in system call")
@ -563,15 +564,11 @@ func copystack(gp *g, newsize uintptr) {
}
memmove(unsafe.Pointer(new.hi-used), unsafe.Pointer(old.hi-used), used)
oldstatus := casgcopystack(gp) // cas from Gwaiting or Grunnable to Gcopystack, return old status
// Swap out old stack for new one
gp.stack = new
gp.stackguard0 = new.lo + _StackGuard // NOTE: might clobber a preempt request
gp.sched.sp = new.hi - used
casgstatus(gp, _Gcopystack, oldstatus) // oldstatus is Gwaiting or Grunnable
// free old stack
if stackPoisonCopy != 0 {
fillstack(old, 0xfc)
@ -669,6 +666,14 @@ func newstack() {
gothrow("runtime: split stack overflow")
}
if gp.sched.ctxt != nil {
// morestack wrote sched.ctxt on its way in here,
// without a write barrier. Run the write barrier now.
// It is not possible to be preempted between then
// and now, so it's okay.
writebarrierptr_nostore((*uintptr)(unsafe.Pointer(&gp.sched.ctxt)), uintptr(gp.sched.ctxt))
}
if gp.stackguard0 == stackPreempt {
if gp == thisg.m.g0 {
gothrow("runtime: preempt g0")
@ -677,7 +682,12 @@ func newstack() {
gothrow("runtime: g is running but p is not")
}
if gp.preemptscan {
for !castogscanstatus(gp, _Gwaiting, _Gscanwaiting) {
// Likely to be racing with the GC as it sees a _Gwaiting and does the stack scan.
// If so this stack will be scanned twice which does not change correctness.
}
gcphasework(gp)
casfrom_Gscanstatus(gp, _Gscanwaiting, _Gwaiting)
casgstatus(gp, _Gwaiting, _Grunning)
gp.stackguard0 = gp.stack.lo + _StackGuard
gp.preempt = false
@ -708,13 +718,15 @@ func newstack() {
gothrow("stack overflow")
}
// Note that the concurrent GC might be scanning the stack as we try to replace it.
// copystack takes care of the appropriate coordination with the stack scanner.
casgstatus(gp, _Gwaiting, _Gcopystack)
// The concurrent GC will not scan the stack while we are doing the copy since
// the gp is in a Gcopystack status.
copystack(gp, uintptr(newsize))
if stackDebug >= 1 {
print("stack grow done\n")
}
casgstatus(gp, _Gwaiting, _Grunning)
casgstatus(gp, _Gcopystack, _Grunning)
gogo(&gp.sched)
}
@ -767,17 +779,17 @@ func shrinkstack(gp *g) {
if gp.syscallsp != 0 {
return
}
/* TODO
if goos_windows && gp.m != nil && gp.m.libcallsp != 0 {
if goos_windows != 0 && gp.m != nil && gp.m.libcallsp != 0 {
return
}
*/
if stackDebug > 0 {
print("shrinking stack ", oldsize, "->", newsize, "\n")
}
oldstatus := casgcopystack(gp)
copystack(gp, newsize)
casgstatus(gp, _Gcopystack, oldstatus)
}
// Do any delayed stack freeing that was queued up during GC.

View File

@ -84,7 +84,7 @@ const (
// The stack guard is a pointer this many bytes above the
// bottom of the stack.
_StackGuard = 512 + _StackSystem
_StackGuard = 640 + _StackSystem
// After a stack split check the SP is allowed to be this
// many bytes below the stack guard. This saves an instruction

View File

@ -231,3 +231,8 @@ func call536870912(fn, arg unsafe.Pointer, n, retoffset uint32)
func call1073741824(fn, arg unsafe.Pointer, n, retoffset uint32)
func systemstack_switch()
func prefetcht0(addr uintptr)
func prefetcht1(addr uintptr)
func prefetcht2(addr uintptr)
func prefetchnta(addr uintptr)

View File

@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.
// +build !linux !amd64
// +build !linux !386
package runtime

190
src/runtime/wbfat.go Normal file
View File

@ -0,0 +1,190 @@
// generated by wbfat_gen.go; use go generate
package runtime
//go:nosplit
func writebarrierfat01(dst *[2]uintptr, _ *byte, src [2]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[1], src[1])
}
//go:nosplit
func writebarrierfat10(dst *[2]uintptr, _ *byte, src [2]uintptr) {
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
}
//go:nosplit
func writebarrierfat11(dst *[2]uintptr, _ *byte, src [2]uintptr) {
writebarrierptr(&dst[0], src[0])
writebarrierptr(&dst[1], src[1])
}
//go:nosplit
func writebarrierfat001(dst *[3]uintptr, _ *byte, src [3]uintptr) {
dst[0] = src[0]
dst[1] = src[1]
writebarrierptr(&dst[2], src[2])
}
//go:nosplit
func writebarrierfat010(dst *[3]uintptr, _ *byte, src [3]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[1], src[1])
dst[2] = src[2]
}
//go:nosplit
func writebarrierfat011(dst *[3]uintptr, _ *byte, src [3]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[1], src[1])
writebarrierptr(&dst[2], src[2])
}
//go:nosplit
func writebarrierfat100(dst *[3]uintptr, _ *byte, src [3]uintptr) {
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
dst[2] = src[2]
}
//go:nosplit
func writebarrierfat101(dst *[3]uintptr, _ *byte, src [3]uintptr) {
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
writebarrierptr(&dst[2], src[2])
}
//go:nosplit
func writebarrierfat110(dst *[3]uintptr, _ *byte, src [3]uintptr) {
writebarrierptr(&dst[0], src[0])
writebarrierptr(&dst[1], src[1])
dst[2] = src[2]
}
//go:nosplit
func writebarrierfat111(dst *[3]uintptr, _ *byte, src [3]uintptr) {
writebarrierptr(&dst[0], src[0])
writebarrierptr(&dst[1], src[1])
writebarrierptr(&dst[2], src[2])
}
//go:nosplit
func writebarrierfat0001(dst *[4]uintptr, _ *byte, src [4]uintptr) {
dst[0] = src[0]
dst[1] = src[1]
dst[2] = src[2]
writebarrierptr(&dst[3], src[3])
}
//go:nosplit
func writebarrierfat0010(dst *[4]uintptr, _ *byte, src [4]uintptr) {
dst[0] = src[0]
dst[1] = src[1]
writebarrierptr(&dst[2], src[2])
dst[3] = src[3]
}
//go:nosplit
func writebarrierfat0011(dst *[4]uintptr, _ *byte, src [4]uintptr) {
dst[0] = src[0]
dst[1] = src[1]
writebarrierptr(&dst[2], src[2])
writebarrierptr(&dst[3], src[3])
}
//go:nosplit
func writebarrierfat0100(dst *[4]uintptr, _ *byte, src [4]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[1], src[1])
dst[2] = src[2]
dst[3] = src[3]
}
//go:nosplit
func writebarrierfat0101(dst *[4]uintptr, _ *byte, src [4]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[1], src[1])
dst[2] = src[2]
writebarrierptr(&dst[3], src[3])
}
//go:nosplit
func writebarrierfat0110(dst *[4]uintptr, _ *byte, src [4]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[1], src[1])
writebarrierptr(&dst[2], src[2])
dst[3] = src[3]
}
//go:nosplit
func writebarrierfat0111(dst *[4]uintptr, _ *byte, src [4]uintptr) {
dst[0] = src[0]
writebarrierptr(&dst[1], src[1])
writebarrierptr(&dst[2], src[2])
writebarrierptr(&dst[3], src[3])
}
//go:nosplit
func writebarrierfat1000(dst *[4]uintptr, _ *byte, src [4]uintptr) {
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
dst[2] = src[2]
dst[3] = src[3]
}
//go:nosplit
func writebarrierfat1001(dst *[4]uintptr, _ *byte, src [4]uintptr) {
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
dst[2] = src[2]
writebarrierptr(&dst[3], src[3])
}
//go:nosplit
func writebarrierfat1010(dst *[4]uintptr, _ *byte, src [4]uintptr) {
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
writebarrierptr(&dst[2], src[2])
dst[3] = src[3]
}
//go:nosplit
func writebarrierfat1011(dst *[4]uintptr, _ *byte, src [4]uintptr) {
writebarrierptr(&dst[0], src[0])
dst[1] = src[1]
writebarrierptr(&dst[2], src[2])
writebarrierptr(&dst[3], src[3])
}
//go:nosplit
func writebarrierfat1100(dst *[4]uintptr, _ *byte, src [4]uintptr) {
writebarrierptr(&dst[0], src[0])
writebarrierptr(&dst[1], src[1])
dst[2] = src[2]
dst[3] = src[3]
}
//go:nosplit
func writebarrierfat1101(dst *[4]uintptr, _ *byte, src [4]uintptr) {
writebarrierptr(&dst[0], src[0])
writebarrierptr(&dst[1], src[1])
dst[2] = src[2]
writebarrierptr(&dst[3], src[3])
}
//go:nosplit
func writebarrierfat1110(dst *[4]uintptr, _ *byte, src [4]uintptr) {
writebarrierptr(&dst[0], src[0])
writebarrierptr(&dst[1], src[1])
writebarrierptr(&dst[2], src[2])
dst[3] = src[3]
}
//go:nosplit
func writebarrierfat1111(dst *[4]uintptr, _ *byte, src [4]uintptr) {
writebarrierptr(&dst[0], src[0])
writebarrierptr(&dst[1], src[1])
writebarrierptr(&dst[2], src[2])
writebarrierptr(&dst[3], src[3])
}

41
src/runtime/wbfat_gen.go Normal file
View File

@ -0,0 +1,41 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"flag"
"fmt"
"log"
"os"
)
func main() {
flag.Parse()
if flag.NArg() > 0 {
f, err := os.Create(flag.Arg(0))
if err != nil {
log.Fatal(err)
}
os.Stdout = f
}
fmt.Printf("// generated by wbfat_gen.go; use go generate\n\n")
fmt.Printf("package runtime\n")
for i := uint(2); i <= 4; i++ {
for j := 1; j < 1<<i; j++ {
fmt.Printf("\n//go:nosplit\n")
fmt.Printf("func writebarrierfat%0*b(dst *[%d]uintptr, _ *byte, src [%d]uintptr) {\n", int(i), j, i, i)
for k := uint(0); k < i; k++ {
if j&(1<<(i-1-k)) != 0 {
fmt.Printf("\twritebarrierptr(&dst[%d], src[%d])\n", k, k)
} else {
fmt.Printf("\tdst[%d] = src[%d]\n", k, k)
}
}
fmt.Printf("}\n")
}
}
}

View File

@ -164,7 +164,7 @@ func TestSwapPointer(t *testing.T) {
x.before = magicptr
x.after = magicptr
var j uintptr
for delta := uintptr(1); delta+delta > delta; delta += delta {
for delta := uintptr(1 << 16); delta+delta > delta; delta += delta {
k := SwapPointer(&x.i, unsafe.Pointer(delta))
if uintptr(x.i) != delta || uintptr(k) != j {
t.Fatalf("delta=%d i=%d j=%d k=%d", delta, x.i, j, k)
@ -456,7 +456,7 @@ func TestCompareAndSwapPointer(t *testing.T) {
magicptr := uintptr(m)
x.before = magicptr
x.after = magicptr
for val := uintptr(1); val+val > val; val += val {
for val := uintptr(1 << 16); val+val > val; val += val {
x.i = unsafe.Pointer(val)
if !CompareAndSwapPointer(&x.i, unsafe.Pointer(val), unsafe.Pointer(val+1)) {
t.Fatalf("should have swapped %#x %#x", val, val+1)
@ -595,7 +595,7 @@ func TestLoadPointer(t *testing.T) {
magicptr := uintptr(m)
x.before = magicptr
x.after = magicptr
for delta := uintptr(1); delta+delta > delta; delta += delta {
for delta := uintptr(1 << 16); delta+delta > delta; delta += delta {
k := LoadPointer(&x.i)
if k != x.i {
t.Fatalf("delta=%d i=%d k=%d", delta, x.i, k)
@ -731,7 +731,7 @@ func TestStorePointer(t *testing.T) {
x.before = magicptr
x.after = magicptr
v := unsafe.Pointer(uintptr(0))
for delta := uintptr(1); delta+delta > delta; delta += delta {
for delta := uintptr(1 << 16); delta+delta > delta; delta += delta {
StorePointer(&x.i, unsafe.Pointer(v))
if x.i != v {
t.Fatalf("delta=%d i=%d v=%d", delta, x.i, v)

View File

@ -9,20 +9,39 @@
package main
func printnl()
//go:noescape
func printpointer(**int)
//go:noescape
func printintpointer(*int)
//go:noescape
func printstringpointer(*string)
//go:noescape
func printstring(string)
//go:noescape
func printbytepointer(*byte)
func printint(int)
func f1() {
var x *int
print(&x) // ERROR "live at call to printpointer: x$"
print(&x) // ERROR "live at call to printpointer: x$"
printpointer(&x) // ERROR "live at call to printpointer: x$"
printpointer(&x) // ERROR "live at call to printpointer: x$"
}
func f2(b bool) {
if b {
print(0) // nothing live here
printint(0) // nothing live here
return
}
var x *int
print(&x) // ERROR "live at call to printpointer: x$"
print(&x) // ERROR "live at call to printpointer: x$"
printpointer(&x) // ERROR "live at call to printpointer: x$"
printpointer(&x) // ERROR "live at call to printpointer: x$"
}
func f3(b bool) {
@ -30,22 +49,22 @@ func f3(b bool) {
// live throughout the function, to avoid being poisoned
// in GODEBUG=gcdead=1 mode.
print(0) // ERROR "live at call to printint: x y$"
printint(0) // ERROR "live at call to printint: x y$"
if b == false {
print(0) // ERROR "live at call to printint: x y$"
printint(0) // ERROR "live at call to printint: x y$"
return
}
if b {
var x *int
print(&x) // ERROR "live at call to printpointer: x y$"
print(&x) // ERROR "live at call to printpointer: x y$"
printpointer(&x) // ERROR "live at call to printpointer: x y$"
printpointer(&x) // ERROR "live at call to printpointer: x y$"
} else {
var y *int
print(&y) // ERROR "live at call to printpointer: x y$"
print(&y) // ERROR "live at call to printpointer: x y$"
printpointer(&y) // ERROR "live at call to printpointer: x y$"
printpointer(&y) // ERROR "live at call to printpointer: x y$"
}
print(0) // ERROR "live at call to printint: x y$" "x \(type \*int\) is ambiguously live" "y \(type \*int\) is ambiguously live"
printint(0) // ERROR "live at call to printint: x y$" "x \(type \*int\) is ambiguously live" "y \(type \*int\) is ambiguously live"
}
// The old algorithm treated x as live on all code that
@ -56,20 +75,20 @@ func f3(b bool) {
func f4(b1, b2 bool) { // x not live here
if b2 {
print(0) // x not live here
printint(0) // x not live here
return
}
var z **int
x := new(int)
*x = 42
z = &x
print(**z) // ERROR "live at call to printint: x z$"
printint(**z) // ERROR "live at call to printint: x z$"
if b2 {
print(1) // ERROR "live at call to printint: x$"
printint(1) // ERROR "live at call to printint: x$"
return
}
for {
print(**z) // ERROR "live at call to printint: x z$"
printint(**z) // ERROR "live at call to printint: x z$"
}
}
@ -84,7 +103,7 @@ func f5(b1 bool) {
*y = 54
z = &y
}
print(**z) // ERROR "live at call to printint: x y$" "x \(type \*int\) is ambiguously live" "y \(type \*int\) is ambiguously live"
printint(**z) // ERROR "live at call to printint: x y$" "x \(type \*int\) is ambiguously live" "y \(type \*int\) is ambiguously live"
}
// confusion about the _ result used to cause spurious "live at entry to f6: _".
@ -155,8 +174,8 @@ func f11b() *int {
// At this point p is dead: the code here cannot
// get to the bottom of the function.
// This used to have a spurious "live at call to printint: p".
print(1) // nothing live here!
select { // ERROR "live at call to newselect: autotmp" "live at call to selectgo: autotmp"
printint(1) // nothing live here!
select { // ERROR "live at call to newselect: autotmp" "live at call to selectgo: autotmp"
case <-c: // ERROR "live at call to selectrecv: autotmp"
return nil
case <-c: // ERROR "live at call to selectrecv: autotmp"
@ -172,8 +191,8 @@ func f11c() *int {
if b {
// Unlike previous, the cases in this select fall through,
// so we can get to the println, so p is not dead.
print(1) // ERROR "live at call to printint: p"
select { // ERROR "live at call to newselect: autotmp.* p" "live at call to selectgo: autotmp.* p"
printint(1) // ERROR "live at call to printint: p"
select { // ERROR "live at call to newselect: autotmp.* p" "live at call to selectgo: autotmp.* p"
case <-c: // ERROR "live at call to selectrecv: autotmp.* p"
case <-c: // ERROR "live at call to selectrecv: autotmp.* p"
}
@ -209,7 +228,7 @@ func h13(string, string) string
func f14() {
x := g14()
print(&x) // ERROR "live at call to printpointer: x"
printstringpointer(&x) // ERROR "live at call to printstringpointer: x"
}
func g14() string
@ -217,8 +236,8 @@ func g14() string
func f15() {
var x string
_ = &x
x = g15() // ERROR "live at call to g15: x"
print(x) // ERROR "live at call to printstring: x"
x = g15() // ERROR "live at call to g15: x"
printstring(x) // ERROR "live at call to printstring: x"
}
func g15() string
@ -282,7 +301,7 @@ func f18() {
}
z = m2[g18()] // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
z = m2[g18()] // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
print(z)
printbytepointer(z)
}
var ch chan *byte
@ -296,7 +315,7 @@ func f19() {
}
z = <-ch // ERROR "live at call to chanrecv1: autotmp_[0-9]+$"
z = <-ch // ERROR "live at call to chanrecv1: autotmp_[0-9]+$"
print(z)
printbytepointer(z)
}
func f20() {
@ -316,7 +335,7 @@ func f21() {
}
z = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
z = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
print(z)
printbytepointer(z)
}
func f23() {
@ -328,7 +347,8 @@ func f23() {
}
z, ok = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess2: autotmp_[0-9]+$"
z, ok = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess2: autotmp_[0-9]+$"
print(z, ok)
printbytepointer(z)
print(ok)
}
func f24() {
@ -350,8 +370,8 @@ func f25(b bool) {
}
var x string
_ = &x
x = g15() // ERROR "live at call to g15: x"
print(x) // ERROR "live at call to printstring: x"
x = g15() // ERROR "live at call to g15: x"
printstring(x) // ERROR "live at call to printstring: x"
} // ERROR "live at call to deferreturn: x"
func g25()
@ -366,7 +386,7 @@ func f26(b bool) {
}
print26((*int)(nil), (*int)(nil), (*int)(nil)) // ERROR "live at call to print26: autotmp_[0-9]+$"
print26((*int)(nil), (*int)(nil), (*int)(nil)) // ERROR "live at call to print26: autotmp_[0-9]+$"
println()
printnl()
}
//go:noescape
@ -381,7 +401,7 @@ func f27(b bool) {
}
call27(func() { x++ }) // ERROR "live at call to call27: autotmp_[0-9]+$"
call27(func() { x++ }) // ERROR "live at call to call27: autotmp_[0-9]+$"
println()
printnl()
}
// but defer does escape to later execution in the function
@ -392,7 +412,7 @@ func f27defer(b bool) {
defer call27(func() { x++ }) // ERROR "live at call to deferproc: autotmp_[0-9]+$" "live at call to deferreturn: autotmp_[0-9]+$"
}
defer call27(func() { x++ }) // ERROR "live at call to deferproc: autotmp_[0-9]+ autotmp_[0-9]+$" "live at call to deferreturn: autotmp_[0-9]+ autotmp_[0-9]+$" "ambiguously live"
println() // ERROR "live at call to printnl: autotmp_[0-9]+ autotmp_[0-9]+$"
printnl() // ERROR "live at call to printnl: autotmp_[0-9]+ autotmp_[0-9]+$"
} // ERROR "live at call to deferreturn: autotmp_[0-9]+ autotmp_[0-9]+$"
// and newproc (go) escapes to the heap
@ -403,7 +423,7 @@ func f27go(b bool) {
go call27(func() { x++ }) // ERROR "live at call to newobject: &x" "live at call to newproc: &x$"
}
go call27(func() { x++ }) // ERROR "live at call to newobject: &x"
println()
printnl()
}
//go:noescape
@ -415,10 +435,10 @@ var s1, s2, s3, s4, s5, s6, s7, s8, s9, s10 string
func f28(b bool) {
if b {
print(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "live at call to concatstrings: autotmp_[0-9]+$" "live at call to printstring: autotmp_[0-9]+$"
printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "live at call to concatstrings: autotmp_[0-9]+$" "live at call to printstring: autotmp_[0-9]+$"
}
print(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "live at call to concatstrings: autotmp_[0-9]+$" "live at call to printstring: autotmp_[0-9]+$"
print(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "live at call to concatstrings: autotmp_[0-9]+$" "live at call to printstring: autotmp_[0-9]+$"
printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "live at call to concatstrings: autotmp_[0-9]+$" "live at call to printstring: autotmp_[0-9]+$"
printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "live at call to concatstrings: autotmp_[0-9]+$" "live at call to printstring: autotmp_[0-9]+$"
}
// map iterator should die on end of range loop
@ -426,14 +446,14 @@ func f28(b bool) {
func f29(b bool) {
if b {
for k := range m { // ERROR "live at call to mapiterinit: autotmp_[0-9]+$" "live at call to mapiternext: autotmp_[0-9]+$"
print(k) // ERROR "live at call to printstring: autotmp_[0-9]+$"
printstring(k) // ERROR "live at call to printstring: autotmp_[0-9]+$"
}
}
for k := range m { // ERROR "live at call to mapiterinit: autotmp_[0-9]+$" "live at call to mapiternext: autotmp_[0-9]+$"
print(k) // ERROR "live at call to printstring: autotmp_[0-9]+$"
printstring(k) // ERROR "live at call to printstring: autotmp_[0-9]+$"
}
for k := range m { // ERROR "live at call to mapiterinit: autotmp_[0-9]+$" "live at call to mapiternext: autotmp_[0-9]+$"
print(k) // ERROR "live at call to printstring: autotmp_[0-9]+$"
printstring(k) // ERROR "live at call to printstring: autotmp_[0-9]+$"
}
}
@ -446,14 +466,14 @@ func f30(b bool) {
// the copy of ptrarr and the internal iterator pointer.
if b {
for _, p := range ptrarr {
print(p) // ERROR "live at call to printpointer: autotmp_[0-9]+ autotmp_[0-9]+$"
printintpointer(p) // ERROR "live at call to printintpointer: autotmp_[0-9]+ autotmp_[0-9]+$"
}
}
for _, p := range ptrarr {
print(p) // ERROR "live at call to printpointer: autotmp_[0-9]+ autotmp_[0-9]+$"
printintpointer(p) // ERROR "live at call to printintpointer: autotmp_[0-9]+ autotmp_[0-9]+$"
}
for _, p := range ptrarr {
print(p) // ERROR "live at call to printpointer: autotmp_[0-9]+ autotmp_[0-9]+$"
printintpointer(p) // ERROR "live at call to printintpointer: autotmp_[0-9]+ autotmp_[0-9]+$"
}
}
@ -503,44 +523,44 @@ var m33 map[interface{}]int
func f33() {
if m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
println()
printnl()
return
} else {
println()
printnl()
}
println()
printnl()
}
func f34() {
if m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
println()
printnl()
return
}
println()
printnl()
}
func f35() {
if m33[nil] == 0 && m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
println()
printnl()
return
}
println()
printnl()
}
func f36() {
if m33[nil] == 0 || m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
println()
printnl()
return
}
println()
printnl()
}
func f37() {
if (m33[nil] == 0 || m33[nil] == 0) && m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
println()
printnl()
return
}
println()
printnl()
}
// select temps should disappear in the case bodies
@ -558,44 +578,44 @@ func f38(b bool) {
if b {
select { // ERROR "live at call"
case <-fc38(): // ERROR "live at call"
println()
printnl()
case fc38() <- *fi38(1): // ERROR "live at call"
println()
printnl()
case *fi38(2) = <-fc38(): // ERROR "live at call"
println()
printnl()
case *fi38(3), *fb38() = <-fc38(): // ERROR "live at call"
println()
printnl()
}
println()
printnl()
}
println()
printnl()
}
// issue 8097: mishandling of x = x during return.
func f39() (x []int) {
x = []int{1}
println() // ERROR "live at call to printnl: x"
printnl() // ERROR "live at call to printnl: x"
return x
}
func f39a() (x []int) {
x = []int{1}
println() // ERROR "live at call to printnl: x"
printnl() // ERROR "live at call to printnl: x"
return
}
func f39b() (x [10]*int) {
x = [10]*int{}
x[0] = new(int) // ERROR "live at call to newobject: x"
println() // ERROR "live at call to printnl: x"
printnl() // ERROR "live at call to printnl: x"
return x
}
func f39c() (x [10]*int) {
x = [10]*int{}
x[0] = new(int) // ERROR "live at call to newobject: x"
println() // ERROR "live at call to printnl: x"
printnl() // ERROR "live at call to printnl: x"
return
}
@ -615,13 +635,13 @@ func newT40() *T40 {
func bad40() {
t := newT40()
_ = t
println()
printnl()
}
func good40() {
ret := T40{}
ret.m = make(map[int]int) // ERROR "live at call to makemap: ret"
t := &ret
println() // ERROR "live at call to printnl: ret"
printnl() // ERROR "live at call to printnl: ret"
_ = t
}

View File

@ -12,6 +12,8 @@ package main
// issue 8142: lost 'addrtaken' bit on inlined variables.
// no inlining in this test, so just checking that non-inlined works.
func printnl()
type T40 struct {
m map[int]int
}
@ -24,7 +26,7 @@ func newT40() *T40 {
func bad40() {
t := newT40() // ERROR "live at call to makemap: ret"
println() // ERROR "live at call to printnl: ret"
printnl() // ERROR "live at call to printnl: ret"
_ = t
}
@ -32,6 +34,6 @@ func good40() {
ret := T40{}
ret.m = make(map[int]int) // ERROR "live at call to makemap: ret"
t := &ret
println() // ERROR "live at call to printnl: ret"
printnl() // ERROR "live at call to printnl: ret"
_ = t
}

View File

@ -268,11 +268,11 @@ TestCases:
name := m[1]
size, _ := strconv.Atoi(m[2])
// The limit was originally 128 but is now 384.
// The limit was originally 128 but is now 512.
// Instead of rewriting the test cases above, adjust
// the first stack frame to use up the extra 32 bytes.
if i == 0 {
size += 384 - 128
size += 512 - 128
}
if size%ptrSize == 4 {