pieterderycke / Jace

Jace.NET is a calculation engine for the .NET platform.
MIT License
436 stars 94 forks source link

Under Mono 3.2.8, Jace.Benchmark crashes with failed system assertion #8

Closed rummelsworth closed 6 years ago

rummelsworth commented 10 years ago

With a freshly downloaded and cleanly built Jace.NET solution (https://github.com/pieterderycke/Jace/commit/2c0033aac56dba919a97db8d2a2702b95c9baf1e) and using Mono 3.2.8 on Lubuntu 14.04, running the Jace.Benchmark project causes a crash of some sort during the last "Compiled Mode" section just after the threads are started. Reliably reproducible for me.

Here is a transcript of the application output, including assertion failure message and stacktrace:

Loaded assembly: /home/bb/Jace-master/Jace.Benchmark/bin/Debug/Jace.Benchmark.exe
Loaded assembly: /home/bb/Jace-master/Jace.Benchmark/bin/Debug/Jace.dll
Jace.NET Benchmark Application

--------------------
Function: 2+3*7/23
Number Of Tests: 1,000,000

Interpreted Mode:
Loaded assembly: /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll [External]
Loaded assembly: /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll [External]
Total duration: 00:00:05.3861940
Compiled Mode:
Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
Total duration: 00:00:05.3827540
--------------------
Function: (var1 + var2 * 3)/(2+3) - something
Number Of Tests: 1,000,000

Interpreted Mode:
Total duration: 00:00:04.4561450
Compiled Mode:
Total duration: 00:00:03.5664070
--------------------
Random Generated Functions: 1,000
Number Of Variables Of Each Function: 3
Number Of Executions For Each Function: 10,000
Total Number Of Executions: 10,000,000
Parallel: True

Interpreted Mode:
Thread started:  #2
Thread started:  #3
Thread finished:  #2
Thread finished:  #3
Total duration: 00:00:28.6792790
Compiled Mode:
Thread started:  #4
Thread started:  #5
* Assertion at mini-codegen.c:2307, condition `sp < 8' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Delegate.CreateDelegate_internal (System.Type,object,System.Reflection.MethodInfo,bool) <IL 0x00024, 0xffffffff>
  at System.Delegate.CreateDelegate (System.Type,object,System.Reflection.MethodInfo,bool,bool) <IL 0x00344, 0x00caf>
  at System.Delegate.CreateDelegate (System.Type,System.Reflection.MethodInfo,bool) <IL 0x00005, 0x00043>
  at System.Delegate.CreateDelegate (System.Type,System.Reflection.MethodInfo) <IL 0x00003, 0x0002f>
  at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type) <IL 0x00032, 0x000d3>
  at Jace.Execution.DynamicCompiler.BuildFormulaInternal (Jace.Operations.Operation,Jace.Execution.IFunctionRegistry) [0x0003d] in /home/bb/Jace-master/Jace/Execution/DynamicCompiler.cs:47
  at Jace.Execution.DynamicCompiler.BuildFormula (Jace.Operations.Operation,Jace.Execution.IFunctionRegistry) [0x00017] in /home/bb/Jace-master/Jace/Execution/DynamicCompiler.cs:30
  at Jace.CalculationEngine/<BuildFormula>c__AnonStorey0.<>m__0 (string) [0x0001c] in /home/bb/Jace-master/Jace/CalculationEngine.cs:303
  at Jace.Util.MemoryCache`2/<GetOrAdd>c__AnonStorey0.<>m__0 (TKey) [0x00013] in /home/bb/Jace-master/Jace/Util/MemoryCache.cs:137
  at System.Collections.Concurrent.ConcurrentDictionary`2/<GetOrAdd>c__AnonStorey3.<>m__0 () <IL 0x00012, 0x00039>
  at (wrapper delegate-invoke) System.Func`1<System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>.invoke_TResult__this__ () <IL 0x00054, 0xffffffff>
  at System.Collections.Concurrent.SplitOrderedList`2<string, System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>.ListInsert (System.Collections.Concurrent.SplitOrderedList`2/Node<string, System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>,System.Collections.Concurrent.SplitOrderedList`2/Node<string, System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>,System.Collections.Concurrent.SplitOrderedList`2/Node<string, System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>&,System.Func`1<System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>) <IL 0x00068, 0x001cf>
  at System.Collections.Concurrent.SplitOrderedList`2<string, System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>.InsertInternal (uint,string,System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>,System.Func`1<System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>,System.Collections.Concurrent.SplitOrderedList`2/Node<string, System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>&) <IL 0x00039, 0x0014f>
  at System.Collections.Concurrent.SplitOrderedList`2<string, System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>.InsertOrGet (uint,string,System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>,System.Func`1<System.Collections.Generic.KeyValuePair`2<string, Jace.Util.MemoryCache`2/CacheItem<string, System.Func`2<System.Collections.Generic.Dictionary`2<string, double>, double>>>>) <IL 0x00008, 0x0006f>
  at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd (TKey,System.Func`2<TKey, TValue>) <IL 0x00058, 0x0022e>
  at Jace.Util.MemoryCache`2.GetOrAdd (TKey,System.Func`2<TKey, TValue>) [0x0003e] in /home/bb/Jace-master/Jace/Util/MemoryCache.cs:133
  at Jace.CalculationEngine.BuildFormula (string,Jace.Operations.Operation) [0x00028] in /home/bb/Jace-master/Jace/CalculationEngine.cs:303
  at Jace.CalculationEngine.Build (string) [0x00042] in /home/bb/Jace-master/Jace/CalculationEngine.cs:159
  at Jace.Execution.FormulaBuilder.Build () [0x0002f] in /home/bb/Jace-master/Jace/Execution/FormulaBuilder.cs:80
  at Jace.Benchmark.Program/<BenchMarkCalculationEngineRandomFunctionBuild>c__AnonStorey0.<>m__0 (string) [0x00034] in /home/bb/Jace-master/Jace.Benchmark/Program.cs:128
  at System.Threading.Tasks.Parallel/<ForEach>c__AnonStorey6`1.<>m__0 (TSource,System.Threading.Tasks.ParallelLoopState,object) <IL 0x00007, 0x0002d>
  at System.Threading.Tasks.Parallel/<ForEach>c__AnonStorey5`2.<>m__0 () <IL 0x000e5, 0x00394>
  at System.Threading.Tasks.TaskActionInvoker/ActionInvoke.Invoke (System.Threading.Tasks.Task,object,System.Threading.Tasks.Task) <IL 0x00006, 0x00029>
  at System.Threading.Tasks.Task.InnerInvoke () <IL 0x0003f, 0x000ad>
  at System.Threading.Tasks.Task.ThreadStart () <IL 0x00098, 0x002eb>
  at System.Threading.Tasks.Task.Execute () <IL 0x00001, 0x00027>
  at System.Threading.Tasks.TpScheduler.<QueueTask>m__0 (object) <IL 0x00006, 0x00043>
  at System.Threading.Thread.StartInternal () <IL 0x0003c, 0x000bf>
  at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x0004e, 0xffffffff>

Native stacktrace:

    /usr/bin/mono() [0x8105b4a]
    [0xb771740c]
    [0xb7717424]
    /lib/i386-linux-gnu/libc.so.6(gsignal+0x47) [0xb750c827]
    /lib/i386-linux-gnu/libc.so.6(abort+0x143) [0xb750fc53]
    /usr/bin/mono() [0x8288b23]
    /usr/bin/mono() [0x8288bb3]
    /usr/bin/mono() [0x8100a10]
    /usr/bin/mono() [0x80659b9]
    /usr/bin/mono() [0x8066dd1]
    /usr/bin/mono() [0x8068de4]
    /usr/bin/mono() [0x8069aee]
    /usr/bin/mono() [0x8186398]
    [0xb5bf62e4]
    [0xb5bf4b30]
    [0xb5bf3e54]
    [0xb5bf3de0]
    [0xb5bf3584]
    [0xb5846180]
    [0xb5845f44]
    [0xb584388a]
    [0xb58431d9]
    [0xb5842eea]
    [0xb5843078]
    [0xb5bc2bb0]
    [0xb5842c68]
    [0xb5842a80]
    [0xb584282f]
    [0xb58423b8]
    [0xb5842174]
    [0xb5bf858c]
    [0xb5bf8260]
    [0xb561d20c]
    [0xb561ce7e]
    [0xb561af2d]
    [0xb561ab82]
    [0xb561ab36]
    [0xb561a584]
    [0xb561a278]
    [0xb561a21c]
    [0xb561a1a0]
    [0xb5e1b18d]
    /usr/bin/mono() [0x8069bf0]

Debug info from gdb:

Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
No threads.

=================================================================
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.
=================================================================
pieterderycke commented 10 years ago

On first taught I would say that it is a bug in Mono. It seems to occur in the DynamicCompiler of Jace. In this component MSIL is generated at runtime to create a delegate. This is less used feature of .NET so maybe the Mono implementation contains bugs. I assume you do not have the issue when you use Jace in interpreted mode on Mono?

Would you be willing to create a bug ticket for the Mono team and share the link here for follow-up?

rummelsworth commented 10 years ago

I've never seen the assertion message occur in the interpreted mode sections.

Here's the link to the Xamarin Bugzilla filing:

https://bugzilla.xamarin.com/show_bug.cgi?id=23392