Commit 8c357ce2 authored by Russ Cox's avatar Russ Cox

fix another gc bug, one that i have only imagined,

not observed: do not use malloc to allocate stacks
during garbage collection, because it would make the
malloc data structures change underfoot.

R=r
DELTA=6  (3 added, 0 deleted, 3 changed)
OCL=30323
CL=30326
parent 36835c7a
...@@ -274,7 +274,7 @@ stackalloc(uint32 n) ...@@ -274,7 +274,7 @@ stackalloc(uint32 n)
uint32 *ref; uint32 *ref;
//return oldmal(n); //return oldmal(n);
if(m->mallocing) { if(m->mallocing || m->gcing) {
lock(&stacks); lock(&stacks);
if(stacks.size == 0) if(stacks.size == 0)
FixAlloc_Init(&stacks, n, SysAlloc, nil, nil); FixAlloc_Init(&stacks, n, SysAlloc, nil, nil);
...@@ -298,7 +298,7 @@ stackfree(void *v) ...@@ -298,7 +298,7 @@ stackfree(void *v)
{ {
//return; //return;
if(m->mallocing) { if(m->mallocing || m->gcing) {
lock(&stacks); lock(&stacks);
FixAlloc_Free(&stacks, v); FixAlloc_Free(&stacks, v);
unlock(&stacks); unlock(&stacks);
......
...@@ -215,6 +215,7 @@ gc(int32 force) ...@@ -215,6 +215,7 @@ gc(int32 force)
if(gcpercent < 0) if(gcpercent < 0)
return; return;
m->gcing = 1;
semacquire(&gcsema); semacquire(&gcsema);
gosave(&g->sched); // update g's stack pointer for scanstack gosave(&g->sched); // update g's stack pointer for scanstack
stoptheworld(); stoptheworld();
...@@ -228,4 +229,5 @@ gc(int32 force) ...@@ -228,4 +229,5 @@ gc(int32 force)
starttheworld(); starttheworld();
gosave(&g->sched); // update g's stack pointer for debugging gosave(&g->sched); // update g's stack pointer for debugging
semrelease(&gcsema); semrelease(&gcsema);
m->gcing = 0;
} }
...@@ -177,6 +177,7 @@ struct M ...@@ -177,6 +177,7 @@ struct M
int32 siz2; int32 siz2;
int32 id; int32 id;
int32 mallocing; int32 mallocing;
int32 gcing;
int32 locks; int32 locks;
Note havenextg; Note havenextg;
G* nextg; G* nextg;
......
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