Bug 5561 - LINQ query failing on device with System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.OrderedEnumerable`1
Summary: LINQ query failing on device with System.ExecutionEngineException: Attempting...
Status: RESOLVED DUPLICATE of bug 3902
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-06-06 20:50 UTC by Omri Gazitt
Modified: 2012-06-11 01:27 UTC (History)
3 users (show)

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


Attachments
tarball of a simple repro project for the LINQ OrderBy failure (4.73 KB, application/x-gzip)
2012-06-06 20:50 UTC, Omri Gazitt
Details


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 Developer Community or GitHub 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 DUPLICATE of bug 3902

Description Omri Gazitt 2012-06-06 20:50:16 UTC
Created attachment 2025 [details]
tarball of a simple repro project for the LINQ OrderBy failure

Here's another set of LINQ queries that work in the emulator but fail on the device because they try to codegen on the device.

Attached is a tarball of a simple repro project.  The failure cases are documented in a comment.  


----

Below is the spew from running mtouch --logdev (as per poupou's instructions on stackoverflow :-))


Jun  6 17:31:31 Omris-iPad kernel[0] <Debug>: launchd[2166] Container: /private/var/mobile/Applications/285795A1-B140-4BED-995B-18A96BB7CABE [69] (sandbox)


Jun  6 17:32:31 Omris-iPad ReportCrash[2170] <Notice>: Formulating crash report for process SortRepro[2166]


Jun  6 17:32:31 Omris-iPad com.apple.launchd[1] (UIKitApplication:sortrepro[0xe800][2166]) <Warning>: (UIKitApplication:sortrepro[0xe800]) Job appears to have crashed: Abort trap: 6


Jun  6 17:32:31 Omris-iPad SpringBoard[51] <Warning>: Application 'SortRepro' exited abnormally with signal 6: Abort trap: 6


Jun  6 17:32:31 Omris-iPad ReportCrash[2170] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/SortRepro_2012-06-06-173230_Omris-iPad.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0


----
Below is the exception text / stacktrace from the output window:


Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.OrderedEnumerable`1<SortRepro.Item>:CreateOrderedEnumerable<bool> (System.Func`2<SortRepro.Item, bool>,System.Collections.Generic.IComparer`1<bool>,bool)' while running with --aot-only.

  at System.Linq.Enumerable.ThenBy[Item,Boolean] (IOrderedEnumerable`1 source, System.Func`2 keySelector, IComparer`1 comparer) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2838 
  at System.Linq.Enumerable.ThenBy[Item,Boolean] (IOrderedEnumerable`1 source, System.Func`2 keySelector) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2830 
  at SortRepro.SortReproViewController.Sort (System.String sort) [0x00186] in /Users/ogazitt/Projects/SortRepro/SortRepro/SortReproViewController.cs:106 
  at SortRepro.SortReproViewController+<ViewDidLoad>c__AnonStorey0.<>m__1 () [0x00000] in /Users/ogazitt/Projects/SortRepro/SortRepro/SortReproViewController.cs:68 
  at MonoTouch.Dialog.StringElement.Selected (MonoTouch.Dialog.DialogViewController dvc, MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x0000b] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/Elements.cs:689 
  at MonoTouch.Dialog.DialogViewController.Selected (MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:518 
  at MonoTouch.Dialog.DialogViewController+Source.RowSelected (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00019] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:364 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at SortRepro.Application.Main (System.String[] args) [0x00000] in /Users/ogazitt/Projects/SortRepro/SortRepro/Main.cs:17 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.OrderedEnumerable`1<SortRepro.Item>:CreateOrderedEnumerable<bool> (System.Func`2<SortRepro.Item, bool>,System.Collections.Generic.IComparer`1<bool>,bool)' while running with --aot-only.

  at System.Linq.Enumerable.ThenBy[Item,Boolean] (IOrderedEnumerable`1 source, System.Func`2 keySelector, IComparer`1 comparer) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2838 
  at System.Linq.Enumerable.ThenBy[Item,Boolean] (IOrderedEnumerable`1 source, System.Func`2 keySelector) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2830 
  at SortRepro.SortReproViewController.Sort (System.String sort) [0x00186] in /Users/ogazitt/Projects/SortRepro/SortRepro/SortReproViewController.cs:106 
  at SortRepro.SortReproViewController+<ViewDidLoad>c__AnonStorey0.<>m__1 () [0x00000] in /Users/ogazitt/Projects/SortRepro/SortRepro/SortReproViewController.cs:68 
  at MonoTouch.Dialog.StringElement.Selected (MonoTouch.Dialog.DialogViewController dvc, MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x0000b] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/Elements.cs:689 
  at MonoTouch.Dialog.DialogViewController.Selected (MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:518 
  at MonoTouch.Dialog.DialogViewController+Source.RowSelected (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00019] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:364 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at SortRepro.Application.Main (System.String[] args) [0x00000] in /Users/ogazitt/Projects/SortRepro/SortRepro/Main.cs:17 
Terminating runtime due to unhandled exception
Stacktrace:


Native stacktrace:

	0   SortRepro                           0x00470174 mono_handle_native_sigsegv + 280
	1   SortRepro                           0x00492ec8 sigabrt_signal_handler + 180
	2   libsystem_c.dylib                   0x34dbc7ed _sigtramp + 48
	3   libsystem_c.dylib                   0x34db220f pthread_kill + 54
	4   libsystem_c.dylib                   0x34dab29f abort + 94
	5   SortRepro                           0x0054c018 monoeg_g_logv + 152
	6   SortRepro                           0x0054c064 monoeg_assertion_message + 52
	7   SortRepro                           0x00459b40 mono_thread_abort + 148
	8   SortRepro                           0x0046fd40 mono_handle_exception_internal + 3188
	9   SortRepro                           0x0046ff44 mono_handle_exception + 24
	10  SortRepro                           0x00491adc mono_arm_throw_exception + 172
	11  SortRepro                           0x003821dc throw_exception + 48
	12  SortRepro                           0x0045c108 mono_jit_compile_method + 68
	13  SortRepro                           0x005036dc mono_compile_method + 56
	14  SortRepro                           0x00473514 common_call_trampoline + 1364
	15  SortRepro                           0x004715e8 mono_vcall_trampoline + 228
	16  SortRepro                           0x003820e8 generic_trampoline_vcall + 136
	17  SortRepro                           0x0002a8a4 System_Linq_Enumerable_ThenBy_SortRepro_Item_bool_System_Linq_IOrderedEnumerable_1_SortRepro_Item_System_Func_2_SortRepro_Item_bool + 144
	18  SortRepro                           0x0001d45c SortRepro_SortReproViewController_Sort_string + 2672
	19  SortRepro                           0x0002094c SortRepro_SortReproViewController__ViewDidLoadc__AnonStorey0__m__1 + 140
	20  SortRepro                           0x000b1bb8 MonoTouch_Dialog_StringElement_Selected_MonoTouch_Dialog_DialogViewController_MonoTouch_UIKit_UITableView_MonoTouch_Foundation_NSIndexPath + 72
	21  SortRepro                           0x000a6fbc MonoTouch_Dialog_DialogViewController_Selected_MonoTouch_Foundation_NSIndexPath + 148
	22  SortRepro                           0x000a8128 MonoTouch_Dialog_DialogViewController_Source_RowSelected_MonoTouch_UIKit_UITableView_MonoTouch_Foundation_NSIndexPath + 96
	23  SortRepro                           0x0034ee04 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
	24  SortRepro                           0x0045c7b4 mono_jit_runtime_invoke + 1644
	25  SortRepro                           0x00504c40 mono_runtime_invoke + 128
	26  SortRepro                           0x00561394 monotouch_trampoline + 3196
	27  UIKit                               0x3330693d -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 944
	28  UIKit                               0x33380627 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 158
	29  Foundation                          0x34f7a933 __NSFireDelayedPerform + 414
	30  CoreFoundation                      0x35b28a33 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
	31  CoreFoundation                      0x35b28699 __CFRunLoopDoTimer + 364
	32  CoreFoundation                      0x35b2726f __CFRunLoopRun + 1206
	33  CoreFoundation                      0x35aaa4a5 CFRunLoopRunSpecific + 300
	34  CoreFoundation                      0x35aaa36d CFRunLoopRunInMode + 104
	35  GraphicsServices                    0x33845439 GSEventRunModal + 136
	36  UIKit                               0x33282cd5 UIApplicationMain + 1080
	37  SortRepro                           0x000fa2dc wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
	38  SortRepro                           0x0001b0f0 SortRepro_Application_Main_string__ + 152
	39  SortRepro                           0x0034ee04 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
	40  SortRepro                           0x0045c7b4 mono_jit_runtime_invoke + 1644
	41  SortRepro                           0x00504c40 mono_runtime_invoke + 128
	42  SortRepro                           0x00508eec mono_runtime_exec_main + 436
	43  SortRepro                           0x0050db60 mono_runtime_run_main + 756
	44  SortRepro                           0x00460b3c mono_jit_exec + 140
	45  SortRepro                           0x00458d58 main + 2116
	46  SortRepro                           0x00002ab8 start + 40

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
Comment 1 Sebastien Pouliot 2012-06-07 11:12:38 UTC
Confirmed as already fixed in 5.3.x (unstable).

*** This bug has been marked as a duplicate of bug 3902 ***
Comment 2 Omri Gazitt 2012-06-07 12:39:11 UTC
Thanks Poupou, I just tried running with 5.3.3 and likewise confirmed that all my test cases are working. 

Can you please let me know if there are rewrites for the queries I have in the repro project that work on the stable (5.2.11) release?  I try to stay on the stable branches, and even then, I sometimes revert (e.g. I found that 5.2.12 regressed my app - it appears slower and caused some app failures for me).
Comment 3 Sebastien Pouliot 2012-06-07 13:08:52 UTC
> Can you please let me know if there are rewrites for the queries I have in the repro project that work on the stable (5.2.11) release?

I can try - but I'll be short on time before WWDC. 

The most general workaround is to replace value-types with classes. Often calling ToString on the value-type is enough (but the performance impact of creating strings can be visible depending on your queries).

> I sometimes revert (e.g. I found that 5.2.12 regressed my app - it appears slower and caused some app failures for me).

There were very few changes (fixes) between 5.2.11 and 5.2.12. Can you describe your issue (in another bug report) and slowness ? It would help to ensure it won't be present in 5.2.13+
Comment 4 Omri Gazitt 2012-06-11 01:27:00 UTC
Thanks again - I confirmed that .OrderBy(i => i.BooleanField.ToString()).ThenBy(i => i.IntegerField.ToString()) works around the failures experienced with 5.2.11.  It does seem a bit slower (perhaps since more objects are created, the query forces a GC?)