>From 370ef34495b6d63f912fb65a1b78de787e184ba1 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Mon, 14 Oct 2013 22:14:34 +0200 Subject: [PATCH 3/3] Hopefully fix #1045 by growing both halves of the heap by stack_size instead of growing them by half the stack_size --- runtime.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/runtime.c b/runtime.c index 2c622cb..0ed18de 100644 --- a/runtime.c +++ b/runtime.c @@ -3295,8 +3295,13 @@ C_regparm void C_fcall C_rereclaim2(C_uword size, int double_plus) if(size < MINIMAL_HEAP_SIZE) size = MINIMAL_HEAP_SIZE; - /* Heap must at least grow enough to accommodate first generation (nursery) */ - if(size - heap_size < stack_size) size = heap_size + stack_size; + /* + * Heap must at least grow enough to accommodate first generation + * (nursery). Because we're calculating the total heap size here + * (fromspace *AND* tospace), we have to double the stack size, + * otherwise we'd accommodate only half the stack in the tospace. + */ + if(size - heap_size < stack_size * 2) size = heap_size + stack_size * 2; if(size > C_maximal_heap_size) size = C_maximal_heap_size; @@ -3313,9 +3318,17 @@ C_regparm void C_fcall C_rereclaim2(C_uword size, int double_plus) (C_word)tospace_start, (C_word)tospace_limit); } - heap_size = size; - size /= 2; - + heap_size = size; /* Total heap size of the two halves... */ + size /= 2; /* ...each half is this big */ + + /* + * Start by allocating the new heap's fromspace. After remarking, + * allocate the other half of the new heap (its tospace). + * + * To clarify: what we call "new_space" here is what will eventually + * be cycled over to "fromspace" when re-reclamation has finished + * (that is, after the old one has been freed). + */ if ((new_heapspace = heap_alloc (size, &new_tospace_start)) == NULL) panic(C_text("out of memory - cannot allocate heap segment")); new_heapspace_size = size; -- 1.8.3.4