Ticket #1791 (new feature request)

Opened 4 years ago

Last modified 3 years ago

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: 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

  Changed 4 years ago by simonmar

  • owner set to igloo
  • type changed from bug to merge
  • component changed from Compiler to Runtime System
  • milestone set to 6.8 branch

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

  Changed 4 years ago by simonmar

  • testcase set to outofmem2

  Changed 4 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Merged

  Changed 4 years ago by guest

  • status changed from closed to reopened
  • type changed from merge to bug
  • resolution fixed deleted

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.

follow-up: ↓ 7   Changed 4 years ago by simonmar

  • owner igloo deleted
  • status changed from reopened to new
  • type changed from bug to feature request
  • summary changed from -M option does not work to heap overflow should generate an exception

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?

  Changed 4 years ago by igloo

  • milestone changed from 6.8 branch to 6.10 branch

in reply to: ↑ 5   Changed 4 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?

  Changed 3 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

  Changed 3 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

  Changed 3 years ago by igloo

  • milestone changed from 6.10 branch to _|_
Note: See TracTickets for help on using tickets.