Bug 41970 - OutOfMemoryException while working with seq
Summary: OutOfMemoryException while working with seq
Status: CONFIRMED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2016-06-18 11:24 UTC by arctiq1
Modified: 2016-09-14 01:28 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description arctiq1 2016-06-18 11:24:04 UTC
Running this code as a whole causes a OutOfMemoryException, while in parts it works as expected:

//Part 1
type Enu = A=1
//Part 2
[|Enu.A|]
seq[ Enu.A ] |> Seq.windowed 1 |> Seq.map id
Should result in seq<Enu[]>, but results in OutOfMemoryException, when executed all at once.

Related information

On windows with fsi 14.0.23413.0 it works, on fedora with fsharpi version from repository it doesn't.
mono --version
Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Tue Mar 15 11:39:54 EDT 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            sgen
Comment 1 arctiq1 2016-06-18 11:30:42 UTC
The stack trace:
System.OutOfMemoryException: Out of memory
  at (wrapper alloc) System.Object:AllocVector (intptr,intptr)
  at <StartupCode$FSI_0002>.$FSI_0002.main@ () <0x40853530 + 0x00032> in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x7f5f0d3f3940 + 0x000a3> in <filename unknown>:0 
Stopped due to error
Comment 2 Marek Safar 2016-06-21 18:01:25 UTC
This could be tail optimization issue
Comment 3 Bernhard Urban 2016-09-06 23:48:35 UTC
There's a fix recently around tail call optimizations https://bugzilla.xamarin.com/show_bug.cgi?id=42606

Can you try if that fixes your issue?
Comment 4 arctiq1 2016-09-07 19:00:10 UTC
Updating to 4.6.0 does not fix the issue.
Comment 5 Bernhard Urban 2016-09-07 20:52:31 UTC
not sure if I'm doing this right:
https://gist.github.com/lewurm/cafd31a295f346c15b716d7ce16d27d4

can you help me reproducing it?
Comment 6 arctiq1 2016-09-07 21:28:48 UTC
Sure, I think what you are doing is executing the code in parts (using ;;) - which works.
However if you copy the entire snippet and execute it afterwards thusly

type Enu = A=1
[|Enu.A|]
seq[ Enu.A ] |> Seq.windowed 1 |> Seq.map id;;

it will throw an exception.
Hope this helps.
Comment 7 Marek Safar 2016-09-12 15:52:24 UTC
More info provided
Comment 8 Rodrigo Kumpera 2016-09-14 01:27:47 UTC
mono 4.6 crashes with:

#6  0x002efd18 in mono_gc_make_descr_for_array (vector=1, numbits=1073741823, elem_size=<value temporarily unavailable, due to optimizations>) at sgen-descriptor.c:174
#7  0x002a9520 in mono_class_compute_gc_descriptor (klass=0x7efb0018) at object.c:1047
#8  0x002a7f2e in mono_class_vtable_full (domain=0x0, klass=0x7efb0018, error=0x0) at object.c:2068
#9  0x002aa3b1 in mono_class_vtable (domain=0x7d113470, klass=0x7efb0018) at object.c:1882
#10 0x000dfe41 in mono_method_to_ir (cfg=0x0, method=0x1, start_bblock=<value temporarily unavailable, due to optimizations>, end_bblock=<value temporarily unavailable, due to optimizations>, return_var=0x0, is_virtual_call=<value temporarily unavailable, due to optimizations>) at method-to-ir.c:11892

This looks like a SRE issue.

Zoltan, can you take a look?

Note You need to log in before you can comment on or make changes to this bug.