Opened 7 years ago

Last modified 15 months ago

#1791 new feature request

heap overflow should generate an exception

Reported by: guest Owned by:
Priority: normal Milestone:
Component: Runtime System Version: 6.8
Keywords: Cc: iampure@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: outofmem2 Blocked By:
Blocking: Related Tickets:

Description

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.

Change History (11)

comment:1 Changed 7 years ago by simonmar

  • Component changed from Compiler to Runtime System
  • Milestone set to 6.8 branch
  • Owner set to igloo
  • Type changed from bug to merge

Fixed, thanks!

Wed Oct 24 10:54:20 BST 2007  Simon Marlow <simonmar@microsoft.com>
  * FIX #1791: fail with out-of-heap when allocating more than the max heap size in one go

comment:2 Changed 7 years ago by simonmar

  • Test Case set to outofmem2

comment:3 Changed 6 years ago by igloo

  • Resolution set to fixed
  • Status changed from new to closed

Merged

comment:4 Changed 6 years ago by guest

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Type changed from merge to bug

I actually expected to get an exception stating "out of heap", like it also works for stack overflows. I have a catch all exception catcher, but this one isn't triggered. Also the actual output doesn't state it's an exception, so I guess it really is not. So, I am reopening it again. Again, to be clear: I want that

Control.Exception.catch 
         action 
         (\exception -> do 
           appendFile "/home/me/exception" (show exception)
           return Nothing)

where action contains the code that overflows the heap does not result in a complete program failure, it should just be a _local_ problem (i.e. an exception). This also means that the test case is likely to be wrong.

comment:5 follow-up: Changed 6 years ago by simonmar

  • Owner igloo deleted
  • Status changed from reopened to new
  • Summary changed from -M option does not work to heap overflow should generate an exception
  • Type changed from bug to feature request

Correct - heap overflow doesn't currently generate an exception. It's something we should really do, but it isn't completely clear how to do it. For example, in order to run the exception handler, you need some heap space. So perhaps you want a "soft" and a "hard" limit on heap space, and to get an exception when the "soft" limit is reached.

Another question is: which thread(s) should get the exception?

comment:6 Changed 6 years ago by igloo

  • Milestone changed from 6.8 branch to 6.10 branch

comment:7 in reply to: ↑ 5 Changed 6 years ago by demetrix

Replying to simonmar:

Another question is: which thread(s) should get the exception?

Why not the thread currently executing IO action which failed to allocate memory? Such behaviour would be the same as in almost any other programming language. Perhaps the only potential problem here is when additional threads are spawned not explicitely with forkIO or forkOS but rather implicitely with par - maybe in that case the thread which forces the evaluation of the "parallel" value should get the exception?

comment:8 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:9 Changed 6 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple

comment:10 Changed 5 years ago by igloo

  • Milestone changed from 6.10 branch to _|_

comment:11 Changed 15 months ago by morabbin

  • Type of failure set to None/Unknown

HeapOverflow is defined in Control.Exception.Base, and noted as not being thrown by GHC currently. Seems like a stable point to leave this issue.

Note: See TracTickets for help on using tickets.