diff options
author | Javran Cheng <Javran.c@gmail.com> | 2015-04-17 10:52:00 +1000 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2015-04-17 12:06:54 +1000 |
commit | 51af102e5c6c56e0987432aa5a21fe10e24090e9 (patch) | |
tree | 5e8a94af428f03b981d51e67c050b816f8e5b239 | |
parent | 3b90d8c8cfb4f56cec3eb5e1ede12c22a9e28d79 (diff) | |
download | haskell-51af102e5c6c56e0987432aa5a21fe10e24090e9.tar.gz |
Better hints when RTS options not available (Trac #9579)
This patch provides user with a better hint when most RTS options
are not available (not compiled with `-rtsopts`).
A new field "rtsOptsEnabled" is added into RtsFlags.MiscFlags to
tell the availablity of RTS options.
Some concerns:
* Unlike other flag fields in "libraries/base/GHC/RTS/Flags.hsc",
"RtsOptsEnabled" is defined in "includes/RtsAPI.h" and lacks
constant macros. Therefore In "GHC.RTS", "RtsOptsEnabled" simply
derives Enum instance and reads as of type "CInt".
* There are other ways to change RTS options (e.g. `-with-rtsopts`),
but it might be too verbose to mention.
Test Plan: validate
Reviewers: austin, hvr, thomie, simonmar
Reviewed By: thomie
Subscribers: thomie, rwbarton
Differential Revision: https://phabricator.haskell.org/D767
GHC Trac Issues: #9579
-rw-r--r-- | rts/ProfHeap.c | 9 | ||||
-rw-r--r-- | rts/hooks/OutOfHeap.c | 14 | ||||
-rw-r--r-- | rts/hooks/StackOverflow.c | 10 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/Makefile | 27 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/OutOfHeap.hs | 10 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/StackOverflow.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/T9579_outofheap_rtsall.stderr | 3 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/T9579_outofheap_rtsnone.stderr | 3 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/T9579_outofheap_rtssome.stderr | 3 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/T9579_stackoverflow_rtsall.stderr | 2 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/T9579_stackoverflow_rtsnone.stderr | 2 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/T9579_stackoverflow_rtssome.stderr | 2 | ||||
-rw-r--r-- | testsuite/tests/rts/T9579/all.T | 29 |
13 files changed, 111 insertions, 7 deletions
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c index 8d3f408c3a..ba1adcd5d0 100644 --- a/rts/ProfHeap.c +++ b/rts/ProfHeap.c @@ -9,6 +9,7 @@ #include "PosixSource.h" #include "Rts.h" +#include "RtsFlags.h" #include "RtsUtils.h" #include "Profiling.h" #include "ProfHeap.h" @@ -279,7 +280,13 @@ nextEra( void ) era++; if (era == max_era) { - errorBelch("maximum number of censuses reached; use +RTS -i to reduce"); + if (rtsConfig.rts_opts_enabled == RtsOptsAll) { + errorBelch("maximum number of censuses reached;\n" + "use +RTS -i to reduce"); + } else { + errorBelch("maximum number of censuses reached;\n" + "Relink with -rtsopts and use `+RTS -i` to reduce"); + } stg_exit(EXIT_FAILURE); } diff --git a/rts/hooks/OutOfHeap.c b/rts/hooks/OutOfHeap.c index 501bccddb7..bb8752846f 100644 --- a/rts/hooks/OutOfHeap.c +++ b/rts/hooks/OutOfHeap.c @@ -7,19 +7,23 @@ #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 */ { - /* 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 */ if (heap_size > 0) { - errorBelch("Heap exhausted;\nCurrent maximum heap size is %" FMT_Word " bytes (%" FMT_Word " MB);\nuse `+RTS -M<size>' to increase it.", - heap_size, heap_size / (1024*1024)); + errorBelch("Heap exhausted;\n" + "Current maximum heap size is %" FMT_Word + " bytes (%" FMT_Word " MB);\n" + "%s `+RTS -M<size>' to increase it.", + heap_size, heap_size / (1024*1024), + ((rtsConfig.rts_opts_enabled == RtsOptsAll) + ? "use" + : "relink with -rtsopts and use")); } else { errorBelch("out of memory"); } } - diff --git a/rts/hooks/StackOverflow.c b/rts/hooks/StackOverflow.c index 1095b1b81d..1ae8603eec 100644 --- a/rts/hooks/StackOverflow.c +++ b/rts/hooks/StackOverflow.c @@ -7,11 +7,19 @@ #include "PosixSource.h" #include "Rts.h" #include "Hooks.h" +#include "RtsFlags.h" #include <stdio.h> void StackOverflowHook (W_ stack_size) /* in bytes */ { - fprintf(stderr, "Stack space overflow: current size %" FMT_Word " bytes.\nUse `+RTS -Ksize -RTS' to increase it.\n", stack_size); + fprintf(stderr, + "Stack space overflow: current size %" FMT_Word " bytes.\n" + "%s `+RTS -Ksize -RTS' to increase it.\n", + stack_size, + ((rtsConfig.rts_opts_enabled == RtsOptsAll) + ? "Use" + : "Relink with -rtsopts and use") + ); } diff --git a/testsuite/tests/rts/T9579/Makefile b/testsuite/tests/rts/T9579/Makefile new file mode 100644 index 0000000000..b9700477a9 --- /dev/null +++ b/testsuite/tests/rts/T9579/Makefile @@ -0,0 +1,27 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +T9579_stackoverflow_rtsnone: + '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=none -fforce-recomp -with-rtsopts -K1m \ + StackOverflow.hs -o T9579_stackoverflow_rtsnone + +T9579_stackoverflow_rtssome: + '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=some -fforce-recomp -with-rtsopts -K1m \ + StackOverflow.hs -o T9579_stackoverflow_rtssome + +T9579_stackoverflow_rtsall: + '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all -fforce-recomp -with-rtsopts -K1m \ + StackOverflow.hs -o T9579_stackoverflow_rtsall + +T9579_outofheap_rtsnone: + '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=none -fforce-recomp -with-rtsopts -M1m \ + OutOfHeap.hs -o T9579_outofheap_rtsnone + +T9579_outofheap_rtssome: + '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=some -fforce-recomp -with-rtsopts -M1m \ + OutOfHeap.hs -o T9579_outofheap_rtssome + +T9579_outofheap_rtsall: + '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all -fforce-recomp -with-rtsopts -M1m \ + OutOfHeap.hs -o T9579_outofheap_rtsall diff --git a/testsuite/tests/rts/T9579/OutOfHeap.hs b/testsuite/tests/rts/T9579/OutOfHeap.hs new file mode 100644 index 0000000000..7f0b7d6f2b --- /dev/null +++ b/testsuite/tests/rts/T9579/OutOfHeap.hs @@ -0,0 +1,10 @@ +import qualified Data.Array.Unboxed as UA +import Data.Word + +main :: IO () +main = print (UA.listArray (1, 2^(20::Int)) (repeat 0) + :: UA.UArray Int Word64) + -- this unboxed array should at least take: + -- 2^20 * 64 bits + -- = 8 * (2^20 bytes) + -- = 8 MiB (in heap) diff --git a/testsuite/tests/rts/T9579/StackOverflow.hs b/testsuite/tests/rts/T9579/StackOverflow.hs new file mode 100644 index 0000000000..cbfc8e4682 --- /dev/null +++ b/testsuite/tests/rts/T9579/StackOverflow.hs @@ -0,0 +1,4 @@ +main :: IO () +main = main' () + where + main' _ = main >> main' () diff --git a/testsuite/tests/rts/T9579/T9579_outofheap_rtsall.stderr b/testsuite/tests/rts/T9579/T9579_outofheap_rtsall.stderr new file mode 100644 index 0000000000..4fb0b86715 --- /dev/null +++ b/testsuite/tests/rts/T9579/T9579_outofheap_rtsall.stderr @@ -0,0 +1,3 @@ +T9579_outofheap_rtsall: Heap exhausted; +Current maximum heap size is 1048576 bytes (1 MB); +use `+RTS -M<size>' to increase it. diff --git a/testsuite/tests/rts/T9579/T9579_outofheap_rtsnone.stderr b/testsuite/tests/rts/T9579/T9579_outofheap_rtsnone.stderr new file mode 100644 index 0000000000..ce7e05f0bc --- /dev/null +++ b/testsuite/tests/rts/T9579/T9579_outofheap_rtsnone.stderr @@ -0,0 +1,3 @@ +T9579_outofheap_rtsnone: Heap exhausted; +Current maximum heap size is 1048576 bytes (1 MB); +relink with -rtsopts and use `+RTS -M<size>' to increase it. diff --git a/testsuite/tests/rts/T9579/T9579_outofheap_rtssome.stderr b/testsuite/tests/rts/T9579/T9579_outofheap_rtssome.stderr new file mode 100644 index 0000000000..25b88e4dd9 --- /dev/null +++ b/testsuite/tests/rts/T9579/T9579_outofheap_rtssome.stderr @@ -0,0 +1,3 @@ +T9579_outofheap_rtssome: Heap exhausted; +Current maximum heap size is 1048576 bytes (1 MB); +relink with -rtsopts and use `+RTS -M<size>' to increase it. diff --git a/testsuite/tests/rts/T9579/T9579_stackoverflow_rtsall.stderr b/testsuite/tests/rts/T9579/T9579_stackoverflow_rtsall.stderr new file mode 100644 index 0000000000..fd7fe19357 --- /dev/null +++ b/testsuite/tests/rts/T9579/T9579_stackoverflow_rtsall.stderr @@ -0,0 +1,2 @@ +Stack space overflow: current size 99136 bytes. +Use `+RTS -Ksize -RTS' to increase it. diff --git a/testsuite/tests/rts/T9579/T9579_stackoverflow_rtsnone.stderr b/testsuite/tests/rts/T9579/T9579_stackoverflow_rtsnone.stderr new file mode 100644 index 0000000000..0287e365c5 --- /dev/null +++ b/testsuite/tests/rts/T9579/T9579_stackoverflow_rtsnone.stderr @@ -0,0 +1,2 @@ +Stack space overflow: current size 99136 bytes. +Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it. diff --git a/testsuite/tests/rts/T9579/T9579_stackoverflow_rtssome.stderr b/testsuite/tests/rts/T9579/T9579_stackoverflow_rtssome.stderr new file mode 100644 index 0000000000..0287e365c5 --- /dev/null +++ b/testsuite/tests/rts/T9579/T9579_stackoverflow_rtssome.stderr @@ -0,0 +1,2 @@ +Stack space overflow: current size 99136 bytes. +Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it. diff --git a/testsuite/tests/rts/T9579/all.T b/testsuite/tests/rts/T9579/all.T new file mode 100644 index 0000000000..8b6880c8e3 --- /dev/null +++ b/testsuite/tests/rts/T9579/all.T @@ -0,0 +1,29 @@ +test('T9579_stackoverflow_rtsnone', + [exit_code(2)], + run_command, + ['$MAKE -s --no-print-directory T9579_stackoverflow_rtsnone && ./T9579_stackoverflow_rtsnone']) + +test('T9579_stackoverflow_rtssome', + [exit_code(2)], + run_command, + ['$MAKE -s --no-print-directory T9579_stackoverflow_rtssome && ./T9579_stackoverflow_rtssome']) + +test('T9579_stackoverflow_rtsall', + [exit_code(2)], + run_command, + ['$MAKE -s --no-print-directory T9579_stackoverflow_rtsall && ./T9579_stackoverflow_rtsall']) + +test('T9579_outofheap_rtsnone', + [exit_code(251)], + run_command, + ['$MAKE -s --no-print-directory T9579_outofheap_rtsnone && ./T9579_outofheap_rtsnone']) + +test('T9579_outofheap_rtssome', + [exit_code(251)], + run_command, + ['$MAKE -s --no-print-directory T9579_outofheap_rtssome && ./T9579_outofheap_rtssome']) + +test('T9579_outofheap_rtsall', + [exit_code(251)], + run_command, + ['$MAKE -s --no-print-directory T9579_outofheap_rtsall && ./T9579_outofheap_rtsall']) |