heap overflow should generate an exception
Heap overflow should produce a HeapOverflow
exception that can be caught, rather than shutting down the entire RTS immediately.
[Original ticket description follows. The submitter happened to expose another bug, which was that heap overflow was not detected at all when a single allocation exceeded the maximum heap size. The program below now exits with a "Heap exhausted" message.]
I want to use the -M option for the goals that are stated in the manual.
./TestProgram +RTS -M5m -RTS
Expected output:
Something like "out of heap space"
Actual result:
Machine going into a state where it swaps memory
This is the code for TestProgram:
import Control.Monad.ST
import Data.Array.ST
import Data.Array.MArray
import Data.Array.Base(unsafeNewArray_)
main = print (runST (do make_empty_table >> return ()))
make_empty_table:: ST s (STArray s (Int, Int) (Maybe ep))
make_empty_table =
unsafeNewArray_ ((1, 1), (16384, 16384))
This was tested with 6.9.20071018 on an athlon-xp, and confirmed by dcoutts also on x86-64 with ghc-6.8.0.20071015.