Commit dd740343 authored by Dave Cheney's avatar Dave Cheney Committed by Russ Cox

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
parent 86c976ff
...@@ -211,14 +211,14 @@ void ...@@ -211,14 +211,14 @@ void
runtime·panic(Eface e) runtime·panic(Eface e)
{ {
Defer *d; Defer *d;
Panic *p; Panic p;
void *pc, *argp; void *pc, *argp;
p = runtime·mal(sizeof *p); runtime·memclr((byte*)&p, sizeof p);
p->arg = e; p.arg = e;
p->link = g->panic; p.link = g->panic;
p->stackbase = g->stackbase; p.stackbase = g->stackbase;
g->panic = p; g->panic = &p;
for(;;) { for(;;) {
d = g->defer; d = g->defer;
...@@ -231,11 +231,10 @@ runtime·panic(Eface e) ...@@ -231,11 +231,10 @@ runtime·panic(Eface e)
pc = d->pc; pc = d->pc;
runtime·newstackcall(d->fn, (byte*)d->args, d->siz); runtime·newstackcall(d->fn, (byte*)d->args, d->siz);
freedefer(d); freedefer(d);
if(p->recovered) { if(p.recovered) {
g->panic = p->link; g->panic = p.link;
if(g->panic == nil) // must be done with signal if(g->panic == nil) // must be done with signal
g->sig = 0; g->sig = 0;
runtime·free(p);
// Pass information about recovering frame to recovery. // Pass information about recovering frame to recovery.
g->sigcode0 = (uintptr)argp; g->sigcode0 = (uintptr)argp;
g->sigcode1 = (uintptr)pc; g->sigcode1 = (uintptr)pc;
......
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