[Haskell-cafe] how out of memory is handled in Haskell
dons at galois.com
Tue Jan 6 18:32:02 EST 2009
> I found how Erlang (or at least old versions of Erlang) handles out of
> memory failure: it just calls exit(1).
> How is this handled in GHC?
> - exit(1)?
> - abort()?
> - IO exception?
$ ./A +RTS -M2M
Current maximum heap size is 1998848 bytes (1 MB);
use `+RTS -M<size>' to increase it
Which is invoked via the OutOfHeapHook function:
OutOfHeapHook (lnat request_size, lnat heap_size) /* both sizes in bytes */
/* fprintf(stderr, "Heap exhausted;\nwhile trying to allocate %lu bytes in a %lu-byte heap;\nuse `+RTS -H<size>' to increase the total heap size.\n", */
(void)request_size; /* keep gcc -Wall happy */
fprintf(stderr, "Heap exhausted;\nCurrent maximum heap size is %lu bytes (%lu MB);\nuse `+RTS -M<size>' to increase it.\n",
heap_size, heap_size / (1024*1024));
Which you can modify yourself at link time.
It is invoked as:
OutOfHeapHook(0/*unknown request size*/,
RtsFlags.GcFlags.maxHeapSize * BLOCK_SIZE);
That is, your OutOfHeapHook is called, and then stg_exit is called to shut down the runtime with:
Where you can also set your own exitFn, before, if all else fails, exit() is called.
More information about the Haskell-Cafe