]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: do not trigger GC on g0
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 21 Aug 2013 22:17:45 +0000 (02:17 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 21 Aug 2013 22:17:45 +0000 (02:17 +0400)
GC acquires worldsema, which is a goroutine-level semaphore
which parks goroutines. g0 can not be parked.
Fixes #6193.

R=khr, khr
CC=golang-dev
https://golang.org/cl/12880045

src/pkg/runtime/mgc0.c
src/pkg/runtime/stack.c

index 7b4c6a8ba14572fc625a21c48a4022af9954e2d6..cedf1996413ef6d72f1e365eef13cdf71c9f941c 100644 (file)
@@ -1614,12 +1614,7 @@ addroots(void)
                case Gdead:
                        break;
                case Grunning:
-                       if(gp != m->curg)
-                               runtime·throw("mark - world not stopped");
-                       if(g != m->g0)
-                               runtime·throw("gc not on g0");
-                       addstackroots(gp);
-                       break;
+                       runtime·throw("mark - world not stopped");
                case Grunnable:
                case Gsyscall:
                case Gwaiting:
@@ -2046,7 +2041,7 @@ runtime·gc(int32 force)
        // problems, don't bother trying to run gc
        // while holding a lock.  The next mallocgc
        // without a lock will do the gc instead.
-       if(!mstats.enablegc || m->locks > 0 || runtime·panicking)
+       if(!mstats.enablegc || g == m->g0 || m->locks > 0 || runtime·panicking)
                return;
 
        if(gcpercent == GcpercentUnknown) {     // first time through
@@ -2077,16 +2072,11 @@ runtime·gc(int32 force)
        // we don't need to scan gc's internal state).  Also an
        // enabler for copyable stacks.
        for(i = 0; i < (runtime·debug.gctrace > 1 ? 2 : 1); i++) {
-               if(g == m->g0) {
-                       // already on g0
-                       gc(&a);
-               } else {
-                       // switch to g0, call gc(&a), then switch back
-                       g->param = &a;
-                       g->status = Gwaiting;
-                       g->waitreason = "garbage collection";
-                       runtime·mcall(mgc);
-               }
+               // switch to g0, call gc(&a), then switch back
+               g->param = &a;
+               g->status = Gwaiting;
+               g->waitreason = "garbage collection";
+               runtime·mcall(mgc);
                // record a new start time in case we're going around again
                a.start_time = runtime·nanotime();
        }
@@ -2110,11 +2100,8 @@ runtime·gc(int32 force)
                }
                runtime·unlock(&finlock);
        }
-       if(g->preempt)  // restore the preemption request in case we've cleared it in newstack
-               g->stackguard0 = StackPreempt;
        // give the queued finalizers, if any, a chance to run
-       if(g != m->g0)
-               runtime·gosched();
+       runtime·gosched();
 }
 
 static void
index 32d6fd46507963500f781dfe8b5ce25b5333379b..dd823705da65d217ab13bce3634fe9a3fc8aae01 100644 (file)
@@ -105,7 +105,7 @@ runtime·stackalloc(uint32 n)
                m->stackinuse++;
                return v;
        }
-       return runtime·mallocgc(n, 0, FlagNoProfiling|FlagNoGC|FlagNoZero);
+       return runtime·mallocgc(n, 0, FlagNoProfiling|FlagNoGC|FlagNoZero|FlagNoInvokeGC);
 }
 
 void