summaryrefslogtreecommitdiff
path: root/rts/hooks/OutOfHeap.c
blob: 3058cdd856116328853760528921b81d0832b7f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* -----------------------------------------------------------------------------
 *
 * User-overridable RTS hooks.
 *
 * ---------------------------------------------------------------------------*/

#include "PosixSource.h"
#include "Rts.h"
#include "Hooks.h"
#include "RtsFlags.h"
#include <stdio.h>

void
OutOfHeapHook (W_ request_size, W_ heap_size) /* both sizes in bytes */
{
    (void)request_size;   /* keep gcc -Wall happy */
    if (heap_size > 0) {
        errorBelch("Heap exhausted;");
        errorBelch("Current maximum heap size is %" FMT_Word
                   " bytes (%" FMT_Word " MB).",
                   heap_size, heap_size / (1024*1024));

        if (rtsConfig.rts_opts_suggestions == true) {

            if (rtsConfig.rts_opts_enabled == RtsOptsAll) {
                errorBelch("Use `+RTS -M<size>' to increase it.");
            } else {
                errorBelch("Relink with -rtsopts and "
                           "use `+RTS -M<size>' to increase it.");
            }

        }
    } else {
        errorBelch("Out of memory.\n");
    }
}