bc: reserve GC parking spaces for place-main thread

Don't try to park values when allocating a weak box or pair in a
future thread, since that creates a race on the parking spaces. A
future thread can't run a GC, so it's doesn't need to park.

Touching a future in a future allocates a weak box, so this bug could
have been responsible for many crahses.

Related to #3145
This commit is contained in:
Matthew Flatt 2020-05-02 08:43:18 -06:00
parent 303b410bc7
commit c59f72f101
2 changed files with 24 additions and 16 deletions

View File

@ -1744,14 +1744,18 @@ void *GC_malloc_pair(void *car, void *cdr)
if (TAKE_SLOW_PATH() || OVERFLOWS_GEN0(newptr)) { if (TAKE_SLOW_PATH() || OVERFLOWS_GEN0(newptr)) {
NewGC *gc = GC_get_GC(); NewGC *gc = GC_get_GC();
CHECK_PARK_UNUSED(gc); if (!GC_gen0_alloc_only) {
gc->park[0] = car; CHECK_PARK_UNUSED(gc);
gc->park[1] = cdr; gc->park[0] = car;
gc->park[1] = cdr;
}
pair = allocate(sizeof(Scheme_Simple_Object), PAGE_PAIR); pair = allocate(sizeof(Scheme_Simple_Object), PAGE_PAIR);
car = gc->park[0]; if (!GC_gen0_alloc_only) {
cdr = gc->park[1]; car = gc->park[0];
gc->park[0] = NULL; cdr = gc->park[1];
gc->park[1] = NULL; gc->park[0] = NULL;
gc->park[1] = NULL;
}
/* Future-local allocation can fail: */ /* Future-local allocation can fail: */
if (!pair) return NULL; if (!pair) return NULL;

View File

@ -113,7 +113,7 @@ void *GC_malloc_weak_array(size_t size_in_bytes, void *replace_val)
GCTYPE *gc = GC_get_GC(); GCTYPE *gc = GC_get_GC();
GC_Weak_Array *w; GC_Weak_Array *w;
/* Allcation might trigger GC, so we use park: */ /* Allocation might trigger GC, so we use park: */
CHECK_PARK_UNUSED(gc); CHECK_PARK_UNUSED(gc);
gc->park[0] = replace_val; gc->park[0] = replace_val;
@ -303,20 +303,24 @@ void *GC_malloc_weak_box(void *p, void **secondary, int soffset, int is_late)
GCTYPE *gc = GC_get_GC(); GCTYPE *gc = GC_get_GC();
GC_Weak_Box *w; GC_Weak_Box *w;
/* Allcation might trigger GC, so we use park: */ if (!GC_gen0_alloc_only) {
CHECK_PARK_UNUSED(gc); /* Allcation might trigger GC, so we use park: */
gc->park[0] = p; CHECK_PARK_UNUSED(gc);
gc->park[1] = secondary; gc->park[0] = p;
gc->park[1] = secondary;
}
w = (GC_Weak_Box *)GC_malloc_one_tagged(sizeof(GC_Weak_Box)); w = (GC_Weak_Box *)GC_malloc_one_tagged(sizeof(GC_Weak_Box));
/* Future-local allocation may fail: */ /* Future-local allocation may fail: */
if (!w) return NULL; if (!w) return NULL;
p = gc->park[0]; if (!GC_gen0_alloc_only) {
secondary = (void **)gc->park[1]; p = gc->park[0];
gc->park[0] = NULL; secondary = (void **)gc->park[1];
gc->park[1] = NULL; gc->park[0] = NULL;
gc->park[1] = NULL;
}
w->type = gc->weak_box_tag; w->type = gc->weak_box_tag;
w->val = p; w->val = p;