From d30a448f3500f5951aec2ce014e7cdfdbe201484 Mon Sep 17 00:00:00 2001 From: Andrew Horton Date: Sun, 15 Dec 2013 15:55:04 +0000 Subject: [PATCH] Bump GC_collect_at_heapsize in GC_add_to_heap. In the normal case it is recalculated straight after. But in the case where it's called directly from alloc_mark_stack, it isn't. If the mark stack gets very large, this can cause GC_should_collect to always return true, and GC_alloc_large to get stuck in a loop calling GC_collect_or_expand. --- alloc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/alloc.c b/alloc.c index b9039e09..8ca6bb28 100644 --- a/alloc.c +++ b/alloc.c @@ -1078,6 +1078,16 @@ GC_INNER void GC_add_to_heap(struct hblk *p, size_t bytes) phdr -> hb_flags = 0; GC_freehblk(p); GC_heapsize += bytes; + + /* Normally the caller calculates a new GC_collect_at_heapsize, + * but this is also called directly from alloc_mark_stack, so + * adjust here. It will be recalculated when called from + * GC_expand_hp_inner. + */ + GC_collect_at_heapsize += bytes; + if (GC_collect_at_heapsize < GC_heapsize /* wrapped */) + GC_collect_at_heapsize = (word)(-1); + if ((word)p <= (word)GC_least_plausible_heap_addr || GC_least_plausible_heap_addr == 0) { GC_least_plausible_heap_addr = (void *)((ptr_t)p - sizeof(word)); -- 2.49.0