]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: optimize calls to addroot()
authorJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Tue, 19 Mar 2013 18:57:15 +0000 (19:57 +0100)
committerJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Tue, 19 Mar 2013 18:57:15 +0000 (19:57 +0100)
R=golang-dev, rsc
CC=dvyukov, golang-dev
https://golang.org/cl/7879043

src/pkg/runtime/mgc0.c

index 39beed9f9e8eb773875f52570cc42aaf3e3f8287..ce362934c916ac524968f70f9b2c9039e4a9a1b9 100644 (file)
@@ -1357,7 +1357,7 @@ addstackroots(G *gp)
                        runtime·printf("scanstack inconsistent: g%D#%d sp=%p not in [%p,%p]\n", gp->goid, n, sp, guard-StackGuard, stk);
                        runtime·throw("scanstack");
                }
-               addroot((Obj){sp, (byte*)stk - sp, 0});
+               addroot((Obj){sp, (byte*)stk - sp, (uintptr)defaultProg | PRECISE | LOOP});
                sp = (byte*)stk->gobuf.sp;
                guard = stk->stackguard;
                stk = (Stktop*)stk->stackbase;
@@ -1399,14 +1399,17 @@ addroots(void)
        for(spanidx=0; spanidx<runtime·mheap->nspan; spanidx++) {
                s = allspans[spanidx];
                if(s->state == MSpanInUse) {
+                       // The garbage collector ignores type pointers stored in MSpan.types:
+                       //  - Compiler-generated types are stored outside of heap.
+                       //  - The reflect package has runtime-generated types cached in its data structures.
+                       //    The garbage collector relies on finding the references via that cache.
                        switch(s->types.compression) {
                        case MTypes_Empty:
                        case MTypes_Single:
                                break;
                        case MTypes_Words:
                        case MTypes_Bytes:
-                               // TODO(atom): consider using defaultProg instead of 0
-                               addroot((Obj){(byte*)&s->types.data, sizeof(void*), 0});
+                               markonly((byte*)s->types.data);
                                break;
                        }
                }