Opened 7 years ago

Closed 7 years ago

Last modified 3 months ago

#1010 closed merge (fixed)

ghci crashes when running out of heap.

Reported by: tullsen@… Owned by: igloo
Priority: normal Milestone: 6.6.1
Component: Compiler Version: 6.6
Keywords: Cc:
Operating System: MacOS X Architecture: x86
Type of failure: Difficulty: Unknown
Test Case: bug10101 Blocked By:
Blocking: Related Tickets:

Description

This may be the same as ticket:1004, but the program is smaller (just running out of heap)
and there's some more data points.

Running compiled code works fine (i.e., exits cleanly):

$ ghc -O2 Main.hs 
$ ./a.out +RTS -M3M
Heap exhausted;
Current maximum heap size is 2998272 bytes (2 Mb);
use `+RTS -M<size>' to increase it.

running fully compiled code from ghci also exits cleanly:

$ ghci Main.hs +RTS -M5M
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> main
Heap exhausted;
Current maximum heap size is 4997120 bytes (4 Mb);
use `+RTS -M<size>' to increase it.

but invoking compiled code from ghci gives various infelicitious results:

$ ghci Main.hs +RTS -M5M
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> test 1000000
<interactive>: internal error: scavenge_mark_stack: unimplemented/strange closure type 3660 @ 0x1b1f0a4
    (GHC version 6.6 for i386_apple_darwin)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

$ ghci Main.hs +RTS -M5M
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> test 1000000
<interactive>: internal error: stg_ap_p_ret
    (GHC version 6.6 for i386_apple_darwin)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug


$ ghci Main.hs +RTS -M3M
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> test 100000
Illegal instruction


$ ghci Main.hs +RTS -M4M
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> test 1000000
 Bus error

I think you get the idea.

The program is this:

module Main where

break2 p (x:xs) = if p x then 
                    ([],x:xs)
                  else
                    let (b1,b2) = break2 p xs
                    in  (x : b1, b2)
break2 p []     = ([],[])

surprise xs = b1 ++ "\n surprise " ++ b2
               where
               (b1,b2) = break2 (=='\n') xs

test n = length $ surprise $ [head (show i) | i <-[1..n] ] ++ "\n the end"

main = print $ test 1000000

As an aside: I expected this program to run in constant space. AFAIK GHC evaluates "THUNK_SELECTORS" and
thus eliminates the space leak in this infamous example [Hughes83][Wadler87][Sparud93] etc, but clearly this program is leaky!

Change History (6)

comment:1 Changed 7 years ago by igloo

  • Milestone set to 6.6.1

The HEAD is segfaulting for me when asked to evaluate test 1000000 on Linux/amd64.

comment:2 Changed 7 years ago by simonmar

  • Owner set to simonmar

I'm looking at this.

comment:3 Changed 7 years ago by simonmar

  • Test Case set to bug10101
  • Type changed from bug to merge

Fixed, to merge:

Wed Feb 14 12:04:01 GMT 2007  Simon Marlow <simonmar@microsoft.com>
  * fix closure_sizeW_() for AP closures

and the test:

Wed Feb 14 12:21:24 GMT 2007  Simon Marlow <simonmar@microsoft.com>
  * add test for bug #1010

the test program also illustrates a nasty O(n2) case in the compacting GC which I knew about but we don't have a ticket for, so I'll add one.

comment:4 Changed 7 years ago by simonmar

  • Owner changed from simonmar to igloo

comment:5 Changed 7 years ago by igloo

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

Merged.

comment:6 Changed 3 months ago by Simon Marlow <simonmar@…>

Note: See TracTickets for help on using tickets.