how out of memory is handled in Haskell
Hi. Here: http://damienkatz.net/2008/03/what_sucks_abou.html 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? Thanks Manlio Perillo
manlio_perillo:
Hi.
Here: http://damienkatz.net/2008/03/what_sucks_abou.html
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?
GHC: $ ./A +RTS -M2M Heap exhausted; Current maximum heap size is 1998848 bytes (1 MB); use `+RTS -M<size>' to increase it Which is invoked via the OutOfHeapHook function: #include "Rts.h" #include <stdio.h> void 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: void heapOverflow(void) { OutOfHeapHook(0/*unknown request size*/, RtsFlags.GcFlags.maxHeapSize * BLOCK_SIZE); stg_exit(EXIT_HEAPOVERFLOW); } That is, your OutOfHeapHook is called, and then stg_exit is called to shut down the runtime with: void stg_exit(int n) { #ifdef PAR if (exit_started) return; exit_started=rtsTrue; shutdownParallelSystem(n); #endif if (exitFn) (*exitFn)(n); exit(n); } Where you can also set your own exitFn, before, if all else fails, exit() is called. -- Don
Manlio Perillo ha scritto:
[...]
How is this handled in GHC? - exit(1)? - abort()? - IO exception?
Ok, found it by myself: http://hackage.haskell.org/trac/ghc/ticket/1791 It is also explicitly documented in: http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.htm... and it's very strange that I have not seen it, sorry. Manlio Perillo
participants (2)
-
Don Stewart -
Manlio Perillo