Commit dfdd1ba0 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: do not trigger GC on g0

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
parent 87fdb8fb
...@@ -1614,12 +1614,7 @@ addroots(void) ...@@ -1614,12 +1614,7 @@ addroots(void)
case Gdead: case Gdead:
break; break;
case Grunning: case Grunning:
if(gp != m->curg) runtime·throw("mark - world not stopped");
runtime·throw("mark - world not stopped");
if(g != m->g0)
runtime·throw("gc not on g0");
addstackroots(gp);
break;
case Grunnable: case Grunnable:
case Gsyscall: case Gsyscall:
case Gwaiting: case Gwaiting:
...@@ -2046,7 +2041,7 @@ runtime·gc(int32 force) ...@@ -2046,7 +2041,7 @@ runtime·gc(int32 force)
// problems, don't bother trying to run gc // problems, don't bother trying to run gc
// while holding a lock. The next mallocgc // while holding a lock. The next mallocgc
// without a lock will do the gc instead. // 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; return;
if(gcpercent == GcpercentUnknown) { // first time through if(gcpercent == GcpercentUnknown) { // first time through
...@@ -2077,16 +2072,11 @@ runtime·gc(int32 force) ...@@ -2077,16 +2072,11 @@ runtime·gc(int32 force)
// we don't need to scan gc's internal state). Also an // we don't need to scan gc's internal state). Also an
// enabler for copyable stacks. // enabler for copyable stacks.
for(i = 0; i < (runtime·debug.gctrace > 1 ? 2 : 1); i++) { for(i = 0; i < (runtime·debug.gctrace > 1 ? 2 : 1); i++) {
if(g == m->g0) { // switch to g0, call gc(&a), then switch back
// already on g0 g->param = &a;
gc(&a); g->status = Gwaiting;
} else { g->waitreason = "garbage collection";
// switch to g0, call gc(&a), then switch back runtime·mcall(mgc);
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 // record a new start time in case we're going around again
a.start_time = runtime·nanotime(); a.start_time = runtime·nanotime();
} }
...@@ -2110,11 +2100,8 @@ runtime·gc(int32 force) ...@@ -2110,11 +2100,8 @@ runtime·gc(int32 force)
} }
runtime·unlock(&finlock); 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 // give the queued finalizers, if any, a chance to run
if(g != m->g0) runtime·gosched();
runtime·gosched();
} }
static void static void
......
...@@ -105,7 +105,7 @@ runtime·stackalloc(uint32 n) ...@@ -105,7 +105,7 @@ runtime·stackalloc(uint32 n)
m->stackinuse++; m->stackinuse++;
return v; return v;
} }
return runtime·mallocgc(n, 0, FlagNoProfiling|FlagNoGC|FlagNoZero); return runtime·mallocgc(n, 0, FlagNoProfiling|FlagNoGC|FlagNoZero|FlagNoInvokeGC);
} }
void void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment