]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: clean up scanning of Gs
authorKeith Randall <khr@golang.org>
Mon, 28 Apr 2014 16:47:09 +0000 (12:47 -0400)
committerKeith Randall <khr@golang.org>
Mon, 28 Apr 2014 16:47:09 +0000 (12:47 -0400)
Use a real type for Gs instead of scanning them conservatively.
Zero the schedlink pointer when it is dead.

Update #7820

LGTM=rsc
R=rsc, dvyukov
CC=golang-codereviews
https://golang.org/cl/89360043

src/pkg/runtime/malloc.h
src/pkg/runtime/mgc0.go
src/pkg/runtime/proc.c

index 62e1f8f56eaa0169c34e73d30d96f7c53a6fe88a..dbea7ad1358d8275723454621397ac7ee9e092b1 100644 (file)
@@ -631,6 +631,7 @@ BitVector   runtime·stackmapdata(StackMap *stackmap, int32 n);
 
 // defined in mgc0.go
 void   runtime·gc_m_ptr(Eface*);
+void   runtime·gc_g_ptr(Eface*);
 void   runtime·gc_itab_ptr(Eface*);
 
 void   runtime·memorydump(void);
index b15054662225636e1aeb3b1bc11a155d0e15b4f2..00b271016652b2adddbcd4030b76a3e4d48bac3e 100644 (file)
@@ -9,6 +9,11 @@ func gc_m_ptr(ret *interface{}) {
        *ret = (*m)(nil)
 }
 
+// Called from C. Returns the Go type *g.
+func gc_g_ptr(ret *interface{}) {
+       *ret = (*g)(nil)
+}
+
 // Called from C. Returns the Go type *itab.
 func gc_itab_ptr(ret *interface{}) {
        *ret = (*itab)(nil)
index 52b02d94bb4b2741d92edf046e2ffc93b0446fea..7500e8a5f9db2a1afb2d749dd90a18e42cdaca12 100644 (file)
@@ -687,6 +687,21 @@ runtime·allocm(P *p)
        return mp;
 }
 
+static G*
+allocg(void)
+{
+       G *gp;
+       static Type *gtype;
+       
+       if(gtype == nil) {
+               Eface e;
+               runtime·gc_g_ptr(&e);
+               gtype = ((PtrType*)e.type)->elem;
+       }
+       gp = runtime·cnew(gtype);
+       return gp;
+}
+
 static M* lockextra(bool nilokay);
 static void unlockextra(M*);
 
@@ -1746,7 +1761,7 @@ runtime·malg(int32 stacksize)
                runtime·throw("runtime: bad stack.h");
        }
 
-       newg = runtime·malloc(sizeof(G));
+       newg = allocg();
        if(stacksize >= 0) {
                stacksize = runtime·round2(StackSystem + stacksize);
                if(g == m->g0) {