chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] Heap size calculation in rereclaim2


From: Peter Bex
Subject: [Chicken-hackers] Heap size calculation in rereclaim2
Date: Tue, 13 Oct 2015 20:39:26 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Hi hackers,

This morning on IRC we were discussing the random breakage on Salmonella,
and Evan mentioned that he noticed that the crashes he observed were all
at the start of a program.  This made me think that perhaps the problem
is in how literal decoding is happening and allocated into the heap,
and I discovered https://bugs.call-cc.org/ticket/1221

I've done some debugging and it makes sense why it's failing:
C_rereclaim2() gets invoked with the size demanded by the literals
in the toplevel.  Just look at C_toplevel in the code generated by
the example program.

The example program demands a total of 1011010 words which is slightly
less than 8MiB on a 64-bit machine.  When starting the program with a
smallish heap, it'll immediately invoke C_rereclaim2 as follows:

  C_rereclaim2(1011010 * sizeof(C_word), 1);

Because double_plus (the second '1' argument) is set, it will trigger
this condition at the start of C_rereclaim2:

  if(double_plus) size = heap_size * 2 + size;

So the new heap size is 2 * 1M + 8M = 10M if the initial heap was 1M.

Then, it'll do some range checks and debug output, and then it splits
the heap in two halves:

  heap_size = size;         /* Total heap size of the two halves... */
  size /= 2;                /* ...each half is this big */

Unfortunately, this means the new heap will be 5M, which is too small
to hold 8M of data!

So, the cause is simple, but I'm not so sure about the fix.  I was
tempted to just change it to:

  if(double_plus) size = heap_size * 2 + size * 2;

But then I looked at the other invocations, and started to wonder
what the meaning is of the size and double_plus arguments.  In some
places, "size" is passed as the total intended size of the new heap,
while in other places, it is passed as the required _additional_ size
for the heap(!).  I think if this is the case, double_plus is always
set but I'm not 100% sure.

Am I correct in thinking that double_plus is misnamed and should really
be called "relative_size" or something?  Felix: Do you remember the
original meaning of these two parameters, how are they to be used?

Cheers,
Peter

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]