From: Dave Cheney Date: Mon, 24 Feb 2014 16:09:19 +0000 (-0500) Subject: runtime: stack allocate Panic structure during runtime.panic X-Git-Tag: go1.3beta1~613 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=dd740343e0dec4f998575a49b6a90b14db6b8749;p=gostls13.git runtime: stack allocate Panic structure during runtime.panic Update #7347 When runtime.panic is called the *Panic is malloced from the heap. This can lead to a gc cycle while panicing which can make a bad situation worse. It appears to be possible to stack allocate the Panic and avoid malloc'ing during a panic. Ref: https://groups.google.com/d/topic/golang-dev/OfxqpklGkh0/discussion LGTM=minux.ma, dvyukov, rsc R=r, minux.ma, gobot, rsc, dvyukov CC=golang-codereviews https://golang.org/cl/66830043 --- diff --git a/src/pkg/runtime/panic.c b/src/pkg/runtime/panic.c index 73185273cb..f4f2148d54 100644 --- a/src/pkg/runtime/panic.c +++ b/src/pkg/runtime/panic.c @@ -211,14 +211,14 @@ void runtime·panic(Eface e) { Defer *d; - Panic *p; + Panic p; void *pc, *argp; - - p = runtime·mal(sizeof *p); - p->arg = e; - p->link = g->panic; - p->stackbase = g->stackbase; - g->panic = p; + + runtime·memclr((byte*)&p, sizeof p); + p.arg = e; + p.link = g->panic; + p.stackbase = g->stackbase; + g->panic = &p; for(;;) { d = g->defer; @@ -231,11 +231,10 @@ runtime·panic(Eface e) pc = d->pc; runtime·newstackcall(d->fn, (byte*)d->args, d->siz); freedefer(d); - if(p->recovered) { - g->panic = p->link; + if(p.recovered) { + g->panic = p.link; if(g->panic == nil) // must be done with signal g->sig = 0; - runtime·free(p); // Pass information about recovering frame to recovery. g->sigcode0 = (uintptr)argp; g->sigcode1 = (uintptr)pc;