Bug 31934 - Mono GC crashes with assertion exception
Summary: Mono GC crashes with assertion exception
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: GC ()
Version: 4.0.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL: https://github.com/Microsoft/visualfs...
Depends on:
Blocks:
 
Reported: 2015-07-14 14:15 UTC by henrik
Modified: 2015-09-23 15:28 UTC (History)
7 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description henrik 2015-07-14 14:15:00 UTC
Run this code in fsharpi:

``` fsharp
let mapping : ('a -> 'b) -> ('r -> 'b -> 'r) -> ('r -> 'a -> 'r) =
  fun f red1 state item -> red1 state (f item)

let conjRed xs x = xs @ [x]

let xlist (tr : ('r -> 'b -> 'r) -> ('r -> 'a -> 'r)) =
  List.fold (tr conjRed) []

let xmap : ('a -> 'b) -> 'a list -> 'b list =
  fun f -> xlist <| mapping f

// transducer
let xform (r1 : ('r -> int -> 'r)) : ('r -> int -> 'r) =
  mapping ((+) 1) r1 // << filtering (fun x -> x % 2 = 0) << flatmapping (fun x -> printfn "fm: %A" x ; [0 .. x])

printfn "%A" <| xlist xform [1..5] // crashes
printfn "%A" <| xlist (mapping ((+) 1)) [1..5] // doesn't crash
```

One crash:

```
* Assertion at sgen-alloc.c:460, condition `*p == NULL' not met
Stacktrace:
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_specific (intptr) <0xffffffff>
  at <StartupCode$FSI_0010>.$FSI_0010.main@ () <0x000cf>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <0xffffffff>
  at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000d0>
  at System.MonoType.InvokeMember (string,System.Reflection.BindingFlags,System.Reflection.Binder,object,object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,string[]) <0x003b0>
  at System.Reflection.Emit.TypeBuilder.InvokeMember (string,System.Reflection.BindingFlags,System.Reflection.Binder,object,object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,string[]) <0x00066>
  at System.Type.InvokeMember (string,System.Reflection.BindingFlags,System.Reflection.Binder,object,object[],System.Globalization.CultureInfo) <0x0005a>
  at Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter/execEntryPtFun@1986-1.Invoke (Microsoft.FSharp.Core.Unit) <0x00083>
  at Microsoft.FSharp.Compiler.Interactive.Shell/clo@883-37.Invoke (Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit, Microsoft.FSharp.Core.FSharpOption`1<System.Exception>>) <0x00019>
  at Microsoft.FSharp.Primitives.Basics.List.iter<T> (Microsoft.FSharp.Core.FSharpFunc`2<T, Microsoft.FSharp.Core.Unit>,Microsoft.FSharp.Collections.FSharpList`1<T>) <0x00038>
  at Microsoft.FSharp.Collections.ListModule.Iterate<T> (Microsoft.FSharp.Core.FSharpFunc`2<T, Microsoft.FSharp.Core.Unit>,Microsoft.FSharp.Collections.FSharpList`1<T>) <0x00027>
  at Microsoft.FSharp.Compiler.Interactive.Shell.arg10@882 (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit, Microsoft.FSharp.Core.FSharpOption`1<System.Exception>>>,Microsoft.FSharp.Core.Unit) <0x00057>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler.ProcessInputs (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/ParsedInput>,bool,bool,bool,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/Ident>) <0x006e7>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler.EvalParsedDefinitions (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,bool,bool,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/SynModuleDecl>) <0x001d7>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler.EvalParsedExpression (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Compiler.Ast/SynExpr) <0x0005f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/clo@1590-45.Invoke (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x012ef>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.InteractiveCatch<a> (Microsoft.FSharp.Core.FSharpFunc`2<a, System.Tuple`2<a, Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionStepStatus>>,a) <0x00039>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.ExecInteraction (bool,Microsoft.FSharp.Compiler.Build/TcConfig,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction) <0x00067>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.ExecInteractions (bool,Microsoft.FSharp.Compiler.Build/TcConfig,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Core.FSharpOption`1<Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction>) <0x005f3>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.MainThreadProcessParsedInteraction (bool,Microsoft.FSharp.Core.FSharpOption`1<Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction>,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x00133>
  at Microsoft.FSharp.Compiler.Interactive.Shell/res@1782.Invoke (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x00033>
  at Microsoft.FSharp.Compiler.Interactive.Shell/runCodeOnMainThread@2021-2.Invoke (Microsoft.FSharp.Core.Unit) <0x0003b>
  at <StartupCode$FSharp-Compiler-Interactive-Settings>.$Fsiaux/Microsoft-FSharp-Compiler-Interactive-IEventLoop-Invoke@47.Invoke (Microsoft.FSharp.Core.Unit) <0x0001a>
  at <StartupCode$FSharp-Compiler-Interactive-Settings>.$Fsiaux/run@38-4.Invoke (Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit, object>) <0x00039>
  at Microsoft.FSharp.Primitives.Basics.List.iter<T> (Microsoft.FSharp.Core.FSharpFunc`2<T, Microsoft.FSharp.Core.Unit>,Microsoft.FSharp.Collections.FSharpList`1<T>) <0x00038>
  at Microsoft.FSharp.Collections.ListModule.Iterate<T> (Microsoft.FSharp.Core.FSharpFunc`2<T, Microsoft.FSharp.Core.Unit>,Microsoft.FSharp.Collections.FSharpList`1<T>) <0x00027>
  at <StartupCode$FSharp-Compiler-Interactive-Settings>.$Fsiaux.run@35 (Microsoft.FSharp.Compiler.Interactive.SimpleEventLoop,Microsoft.FSharp.Core.Unit) <0x000cb>
  at Microsoft.FSharp.Compiler.Interactive.SimpleEventLoop.Microsoft-FSharp-Compiler-Interactive-IEventLoop-Run () <0x0001f>
  at Microsoft.FSharp.Compiler.Interactive.Shell.runLoop@2066 (Microsoft.FSharp.Compiler.Interactive.Shell/FsiConsoleOutput,Microsoft.FSharp.Core.Unit) <0x00205>
  at Microsoft.FSharp.Compiler.Interactive.Shell.DriveFsiEventLoop (Microsoft.FSharp.Compiler.Interactive.Shell/FsiConsoleOutput) <0x0001b>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiEvaluationSession.Run () <0x00bd7>
  at Microsoft.FSharp.Compiler.Interactive.Shell.evaluateSession@2382 (string[],Microsoft.FSharp.Core.Unit) <0x0009b>
  at Microsoft.FSharp.Compiler.Interactive.Shell.MainMain (string[]) <0x00127>
  at Microsoft.FSharp.Compiler.Interactive.Main.FsiMain (string[]) <0x00013>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0xffffffff>
Native stacktrace:
	0   mono                                0x0018b956 mono_handle_native_sigsegv + 342
	1   mono                                0x001dbfa1 sigabrt_signal_handler + 129
	2   libsystem_platform.dylib            0x9102d03b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   libsystem_c.dylib                   0x9c405eee abort + 156
	5   mono                                0x0032b8e1 monoeg_log_default_handler + 129
	6   mono                                0x0032b9db monoeg_assertion_message + 107
	7   mono                                0x002ed8a3 mono_gc_try_alloc_obj_nolock + 739
	8   mono                                0x002ed4bd mono_gc_alloc_obj + 77
	9   mono                                0x002a4834 mono_object_new_specific + 228
	10  ???                                 0x005a8ad9 0x0 + 5933785
	11  ???                                 0x04f8fef8 0x0 + 83427064
	12  ???                                 0x005a860c 0x0 + 5932556
	13  mono                                0x000dac5f mono_jit_runtime_invoke + 751
	14  mono                                0x0029d25f mono_runtime_invoke + 127
	15  mono                                0x002a40ed mono_runtime_invoke_array + 941
	16  mono                                0x00214fac ves_icall_InternalInvoke + 892
	17  ???                                 0x0070faf0 0x0 + 7404272
	18  mscorlib.dll.dylib                  0x0195c031 System_Reflection_MonoMethod_Invoke_object_System_Reflection_BindingFlags_System_Reflection_Binder_object___System_Globalization_CultureInfo + 209
	19  mscorlib.dll.dylib                  0x01aa3e91 System_MonoType_InvokeMember_string_System_Reflection_BindingFlags_System_Reflection_Binder_object_object___System_Reflection_ParameterModifier___System_Globalization_CultureInfo_string__ + 945
	20  mscorlib.dll.dylib                  0x01946417 System_Reflection_Emit_TypeBuilder_InvokeMember_string_System_Reflection_BindingFlags_System_Reflection_Binder_object_object___System_Reflection_ParameterModifier___System_Globalization_CultureInfo_string__ + 103
	21  mscorlib.dll.dylib                  0x01ad883b System_Type_InvokeMember_string_System_Reflection_BindingFlags_System_Reflection_Binder_object_object___System_Globalization_CultureInfo + 91
	22  ???                                 0x04b2f3ac 0x0 + 78836652
	23  ???                                 0x04b2f24a 0x0 + 78836298
	24  ???                                 0x033edc59 0x0 + 54451289
	25  ???                                 0x033edc10 0x0 + 54451216
	26  ???                                 0x04b2f220 0x0 + 78836256
	27  ???                                 0x048aa0f8 0x0 + 76194040
	28  ???                                 0x048a7ae8 0x0 + 76184296
	29  ???                                 0x04f4c5a8 0x0 + 83150248
	30  ???                                 0x04c58400 0x0 + 80053248
	31  ???                                 0x048a771a 0x0 + 76183322
	32  ???                                 0x04c57068 0x0 + 80048232
	33  ???                                 0x04c56d64 0x0 + 80047460
	34  ???                                 0x04c563a4 0x0 + 80044964
	35  ???                                 0x04c5625c 0x0 + 80044636
	36  ???                                 0x04c56224 0x0 + 80044580
	37  ???                                 0x04c561e3 0x0 + 80044515
	38  ???                                 0x04c560e2 0x0 + 80044258
	39  ???                                 0x033edc59 0x0 + 54451289
	40  ???                                 0x033edc10 0x0 + 54451216
	41  ???                                 0x04bc4304 0x0 + 79446788
	42  ???                                 0x04bc4220 0x0 + 79446560
	43  ???                                 0x04bc3e06 0x0 + 79445510
	44  ???                                 0x04bc3bec 0x0 + 79444972
	45  ???                                 0x048a72d0 0x0 + 76182224
	46  ???                                 0x005a8764 0x0 + 5932900
	47  ???                                 0x005a8078 0x0 + 5931128
	48  ???                                 0x005a7e24 0x0 + 5930532
	49  ???                                 0x005a7eff 0x0 + 5930751
	50  mono                                0x000dac5f mono_jit_runtime_invoke + 751
	51  mono                                0x0029d25f mono_runtime_invoke + 127
	52  mono                                0x002a32e1 mono_runtime_exec_main + 401
	53  mono                                0x002a3084 mono_runtime_run_main + 660
	54  mono                                0x0015567d mono_jit_exec + 93
	55  mono                                0x00157950 mono_main + 7904
	56  mono                                0x000ccfd0 main + 768
	57  mono                                0x000cccc5 start + 53
	58  ???                                 0x00000005 0x0 + 5
Debug info from gdb:
"monobt" command installed
(lldb) command source -s 1 '/tmp/mono-gdb-commands.miT1K6'
```

Putting `inline` on xform makes it work.
Comment 1 henrik 2015-07-15 03:12:47 UTC
4.0.1
Comment 2 henrik 2015-07-15 03:18:47 UTC
4.0.2 I mean, good morning...
Comment 3 Mark Probst 2015-07-22 15:32:59 UTC
Try running with

  MONO_GC_DEBUG=nursery-canaries
Comment 4 henrik 2015-07-28 12:31:08 UTC
Output:

MONO_GC_DEBUG=nursery-canaries mono --debug -O=-aot /usr/local/Cellar/fsharp/3.1.1.32/lib/mono/4.5/fsi.exe --exename:fsharpi test.fsx


/Users/h/dev/logibit/YoMoney/test.fsx(7,17): warning FS0064: This construct causes code to be less generic than indicated by the type annotations. The type variable 'r has been constrained to be type ''b list'.
[2; 3; 4; 5; 6]
[2; 3; 4; 5; 6]
Comment 5 henrik 2015-07-28 12:36:42 UTC
-
Comment 6 Mark Probst 2015-07-28 16:01:27 UTC
So if you run with `nursery-carnaries` it runs correctly?  Or is that output incorrect?

I assume you're running the same program both times?
Comment 7 henrik 2015-07-28 16:02:38 UTC
Yes, it works with the flag.

Yes, I'm running the same program, the one pasted at the top – just a few lines of F#. Paste them in an fsx file and run `fsharpi test.fsx` to repro.
Comment 8 Zoltan Varga 2015-07-29 18:09:07 UTC
This seems to work with mono master.
Comment 9 Vlad Brezae 2015-07-29 18:54:49 UTC
This could be fixed by https://github.com/mono/mono/commit/501f0aa
Comment 10 henrik 2015-08-11 03:56:12 UTC
This still crashes in mono 4.0.3 inside F# interactive Xamarin Studio, but doesn't crash with fsharpi from the command line.

The XS interactive setting for the fsharpi binary is default, which is greyed out: /Library/Frameworks/Mono.framework/Versions/4.0.3/bin/fsharpi
Comment 11 henrik 2015-08-13 17:33:21 UTC
Could you provide guidance about how to build Xamarin Studio and F# together to create a working development environment? I feel the pain of this bug every day. Sorry for bothering you, none the less.
Comment 12 Zoltan Varga 2015-08-14 02:08:42 UTC
You might be able to use these nightly mono packages:
http://download.mono-project.com/archive/nightly/macos-10-x86/
Comment 13 henrik 2015-08-14 08:17:49 UTC
@Zoltan: exactly what the doctor prescribed!
Comment 14 Mark Probst 2015-09-23 12:41:16 UTC
Is this bug fixed now?
Comment 15 henrik 2015-09-23 15:28:56 UTC
Yes, I'd say so!