We have an application that start some tasks of an array (of System.Threading.Tasks.Task). At the end, it waits the end of tasks using code below:
Dim tasks As New List(Of Task)
For Each fator As String In Fatores
tasks.Add( _
Task.Run(Sub()
Calcular(New Object() {fator,})
End Sub))
Next
Task.WaitAll(tasks.ToArray())
During the execution I extracted a full dump of application. Using !Threads I got list below (finalized was removed).
ID
OSID ThreadOBJ State GC Mode GC Alloc Context Domain Count Apt Exception
0 1 60d8 000000000045e540 26020 Preemptive 000000014DE5FE38:000000014DE5FFD0 00000000004492e0 0 STA
2 2 3c90 00000000004896d0 2b220 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 MTA (Finalizer)
5 3 309c 000000001d6ba3f0 102a220 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 MTA (Threadpool Worker)
7 4 743c 000000001d6eb920 202b220 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 MTA
8 5 7528 000000001d794080 202b220 Preemptive 000000014DE596F8:000000014DE59FD0 00000000004492e0 0 MTA
9 6 53f4 000000001d7bd720 21220 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 Ukn
10 17 239c 000000001fa04160 202b020 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 MTA
12 1134 20ec 0000000000474380 8029220 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 MTA (Threadpool Completion Port)
15 649 2e2c 00000000247fdd00 1029220 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 MTA (Threadpool Worker)
17 650 28ac 0000000000478bb0 1029220 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 MTA (Threadpool Worker)
16 651 47c8 000000006069d5a0 1029220 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 MTA (Threadpool Worker)
XXXX 706 0 000000001fb2f9f0 1039820 Preemptive 0000000000000000:0000000000000000 00000000004492e0 0 Ukn (Threadpool Worker)
22 705 5dd0 000000001fb301c0 1029220 Preemptive 000000014DE5C098:000000014DE5DFD0 00000000004492e0 0 MTA (Threadpool Worker)
Using command ~*e!clrstack I could find task list at this line
000000002083ead0 000007fee6c3bf95 System.Threading.Tasks.Task.WaitAllBlockingCore(System.Collections.Generic.List`1, Int32, System.Threading.CancellationToken) [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Task.cs # 5193]
000000002083eb70 000007fee6c3bbd0 System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[], Int32, System.Threading.CancellationToken) [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Task.cs # 5109]
And I got task list in the parameters below
0:010> !dumparray 0000000120ca19d8 000000002083eb70 000007fee6c3bbd0 System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[], Int32, System.Threading.CancellationToken) [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Task.cs # 5109]
PARAMETERS:
tasks (0x000000002083ec90) = 0x0000000120ca19d8
millisecondsTimeout (0x000000002083ec98) = 0x00000000ffffffff
cancellationToken = <no data>
Name: System.Threading.Tasks.Task[]
MethodTable: 000007fee6f424c8
EEClass: 000007fee5e31238
Size: 72(0x48) bytes
Array: Rank 1, Number of elements 6, Type CLASS
Element Methodtable: 000007fee642c650
[0] 0000000120ca1048
[1] 0000000120ca11f0
[2] 0000000120ca1398
[3] 0000000120ca1540
[4] 0000000120ca16e8
[5] 0000000120ca1890
Each task have structure below, where appears that only active tasks have the field m_taskID filled
0:010> !DumpObj /d 0000000120ca1048
Name: System.Threading.Tasks.Task
MethodTable: 000007fee642c650
EEClass: 000007fee5e36a30
Size: 72(0x48) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
MT Field Offset Type VT Attr Value Name
000007fee6419540 4001a16 38 System.Int32 1 instance 42082 m_taskId
000007fee64170f0 4001a17 8 System.Object 0 instance 0000000000000000 m_action
000007fee64170f0 4001a18 10 System.Object 0 instance 0000000000000000 m_stateObject
000007fee64202b8 4001a19 18 ...sks.TaskScheduler 0 instance 0000000003e83d28 m_taskScheduler
000007fee642c650 4001a1a 20 ...eading.Tasks.Task 0 instance 0000000000000000 m_parent
000007fee6419540 4001a1b 3c System.Int32 1 instance 16982024 m_stateFlags
000007fee64170f0 4001a2e 28 System.Object 0 instance 0000000003e83da8 m_continuationObject
000007fee64247e8 4001a33 30 ...tingentProperties 0 instance 0000000120ca1148 m_contingentProperties
000007fee6419540 4001a14 f30 System.Int32 1 shared static s_taskIdCounter
>> Domain:Value 00000000004492e0:42084 <<
000007fee6430ac8 4001a15 e80 ...Tasks.TaskFactory 0 shared static s_factory
>> Domain:Value 00000000004492e0:0000000003e83d80 <<
000007fee64170f0 4001a2f e88 System.Object 0 shared static s_taskCompletionSentinel
>> Domain:Value 00000000004492e0:0000000003e83da8 <<
000007fee6439b50 4001a30 f34 System.Boolean 1 shared static s_asyncDebuggingEnabled
>> Domain:Value 00000000004492e0:0 <<
000007fee5d942c8 4001a31 e90 ....Task, mscorlib]] 0 shared static s_currentActiveTasks
>> Domain:Value 00000000004492e0:0000000003e83dc0 <<
000007fee64170f0 4001a32 e98 System.Object 0 shared static s_activeTasksLock
>> Domain:Value 00000000004492e0:0000000003e83e10 <<
000007fee6492148 4001a34 ea0 ...bject, mscorlib]] 0 shared static s_taskCancelCallback
>> Domain:Value 00000000004492e0:0000000003e83e28 <<
000007fee6492288 4001a35 ea8 ...rties, mscorlib]] 0 shared static s_createContingentProperties
>> Domain:Value 00000000004492e0:0000000003e83e68 <<
000007fee642c650 4001a36 eb0 ...eading.Tasks.Task 0 shared static s_completedTask
>> Domain:Value 00000000004492e0:0000000000000000 <<
000007fee6492320 4001a37 eb8 ....Task, mscorlib]] 0 shared static s_IsExceptionObservedByParentPredicate
>> Domain:Value 00000000004492e0:0000000003e83ec0 <<
000007fee6427a38 4001a38 ec0 ...g.ContextCallback 0 shared static s_ecCallback
>> Domain:Value 00000000004492e0:0000000003e84910 <<
000007fee64923b0 4001a39 ec8 ...bject, mscorlib]] 0 shared static s_IsTaskContinuationNullPredicate
>> Domain:Value 00000000004492e0:0000000003e83f00 <<
000007fee642c650 4001a12 28 ...eading.Tasks.Task 0 shared TLstatic t_currentTask
>> Thread:Value 60d8:0000000000000000 239c:0000000000000000 2e2c:0000000120ca1540 28ac:0000000120ca16e8 47c8:0000000120ca1890 <<
000007fee649d940 4001a13 30 ....Tasks.StackGuard 0 shared TLstatic t_stackGuard
>> Thread:Value 60d8:0000000005d88880 239c:0000000003fbbdd8 2e2c:0000000000000000 28ac:0000000000000000 47c8:0000000000000000 <<
I would like to know how to correlate this task with right thread on the list above. The fields t_currentTask and t_stackGuard at end has all valid threads
, includind STA (Windows Form) where tasks were started. I took a look in another tasks of the array and the last 2 fields are the same in all of them, giiving no clues about related thread. I can identify (by method names in !clrstack of threads) which threads are executing tasks, but I was unable to relate task X thread.
Could anyone help me to do that? Thanks in advance!
I found some Microsoft people who helped me. I can only find it if the thread where the task is running is "alive". Just trace the instance in the heap, as below. However, contrary to what I assumed, the Task objects that were with m_taskId = 0 were the running Tasks. So if there is any process locked waiting for some Task, if I do not find it anywhere it's because it aborted and did not report the status to who was waiting for its conclusion.
0:010> !DumpArray /d 0000000120ca19d8
Name: System.Threading.Tasks.Task[]
MethodTable: 000007fee6f424c8
EEClass: 000007fee5e31238
Size: 72(0x48) bytes
Array: Rank 1, Number of elements 6, Type CLASS
Element Methodtable: 000007fee642c650
[0] 0000000120ca1048
[1] 0000000120ca11f0
[2] 0000000120ca1398
[3] 0000000120ca1540
[4] 0000000120ca16e8
[5] 0000000120ca1890
0:010> !gcroot 0000000120ca1890
Thread 239c:
000000002083ead0 000007fee6c3bf95 System.Threading.Tasks.Task.WaitAllBlockingCore(System.Collections.Generic.List`1<System.Threading.Tasks.Task>, Int32, System.Threading.CancellationToken) [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Task.cs # 5193]
rbp+10: 000000002083eb70
-> 0000000120ca1a20 System.Collections.Generic.List`1[[System.Threading.Tasks.Task, mscorlib]]
-> 0000000120ca1a48 System.Threading.Tasks.Task[]
-> 0000000120ca1890 System.Threading.Tasks.Task
000000002083eb70 000007fee6c3bbd0 System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[], Int32, System.Threading.CancellationToken) [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Task.cs # 5109]
rbp+10: 000000002083ec90
-> 0000000120ca19d8 System.Threading.Tasks.Task[]
-> 0000000120ca1890 System.Threading.Tasks.Task
Thread 47c8:
000000002059e020 000007fee629c686 System.Threading.Tasks.Task.Execute() [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Task.cs # 2498]
rbp+10: 000000002059e060
-> 0000000120ca1890 System.Threading.Tasks.Task
000000002059e060 000007fee6274750 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [f:\dd\ndp\clr\src\BCL\system\threading\executioncontext.cs # 954]
r14:
-> 0000000120ca1890 System.Threading.Tasks.Task
000000002059e160 000007fee629c928 System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef) [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Task.cs # 2827]
rbp+18: 000000002059e218 (interior)
-> 0000000120cb0fe8 System.Object[]
-> 0000000120ca1890 System.Threading.Tasks.Task
000000002059e160 000007fee629c928 System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef) [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Task.cs # 2827]
rbp+10: 000000002059e210
-> 0000000120ca1890 System.Threading.Tasks.Task
000000002059e250 000007fee627f74e System.Threading.ThreadPoolWorkQueue.Dispatch() [f:\dd\ndp\clr\src\BCL\system\threading\threadpool.cs # 820]
rbp-20: 000000002059e2c0
-> 0000000120ca1890 System.Threading.Tasks.Task
Found 7 unique roots (run '!GCRoot -all' to see all roots).
That's it
Related
We have some API integration tests that take ~30 minutes to run a test class with 19 rows in the where: table. We're trying to speed this up using Spock's (experimental) Parellel Execution feature. We are using a simple SpockConfig.groovy file:
runner {
parallel {
enabled true
fixed(4)
}
}
This still took ~30 minutes on a GitLab runner. Is there any way to log something out so we can verify that the test is running in parallel? Or am I misunderstanding the nature of Spock's parallelization?
You can parallelise Spock testing on several levels, i.e. per specification (test class) or per feature (test method). The per-method setting also means that in iterated (unrolled) tests, iterations can run in parallel. Here is some proof:
import static org.spockframework.runtime.model.parallel.ExecutionMode.CONCURRENT
runner {
parallel {
enabled true
// These values are the default already, specifying them is redundant
// defaultSpecificationExecutionMode = CONCURRENT
// defaultExecutionMode = CONCURRENT
fixed 4
}
}
package de.scrum_master.testing
import spock.lang.Specification
import static java.lang.System.currentTimeMillis
import static java.lang.Thread.currentThread
class ParallelExecutionTest extends Specification {
static long startTime = currentTimeMillis()
static volatile int execCount = 0
def "feature-A-#count"() {
given:
def i = ++execCount
printf "%5d %2d [%s] >> %s%n", currentTimeMillis() - startTime, i, currentThread().name, specificationContext.currentIteration.displayName
sleep 1000
printf "%5d %2d [%s] << %s%n", currentTimeMillis() - startTime, i, currentThread().name, specificationContext.currentIteration.displayName
where:
count << (1..8)
}
def "feature-B-#count"() {
given:
def i = ++execCount
printf "%5d %2d [%s] >> %s%n", currentTimeMillis() - startTime, i, currentThread().name, specificationContext.currentIteration.displayName
sleep 1000
printf "%5d %2d [%s] << %s%n", currentTimeMillis() - startTime, i, currentThread().name, specificationContext.currentIteration.displayName
where:
count << (1..8)
}
}
The output would look something like this (I used the volatile variable in order to more easily sort the log output in my editor into groups of threads running simultaneously in groups of 4:
68 1 [ForkJoinPool-1-worker-3] >> feature-B-1
68 2 [ForkJoinPool-1-worker-2] >> feature-A-5
68 3 [ForkJoinPool-1-worker-1] >> feature-B-6
68 4 [ForkJoinPool-1-worker-4] >> feature-B-2
1177 1 [ForkJoinPool-1-worker-3] << feature-B-1
1177 3 [ForkJoinPool-1-worker-1] << feature-B-6
1179 4 [ForkJoinPool-1-worker-4] << feature-B-2
1180 2 [ForkJoinPool-1-worker-2] << feature-A-5
1191 5 [ForkJoinPool-1-worker-3] >> feature-B-3
1199 6 [ForkJoinPool-1-worker-4] >> feature-B-4
1200 7 [ForkJoinPool-1-worker-1] >> feature-B-5
1204 8 [ForkJoinPool-1-worker-2] >> feature-A-6
2199 5 [ForkJoinPool-1-worker-3] << feature-B-3
2205 7 [ForkJoinPool-1-worker-1] << feature-B-5
2213 6 [ForkJoinPool-1-worker-4] << feature-B-4
2213 8 [ForkJoinPool-1-worker-2] << feature-A-6
2203 9 [ForkJoinPool-1-worker-3] >> feature-B-7
2207 10 [ForkJoinPool-1-worker-1] >> feature-A-1
2217 11 [ForkJoinPool-1-worker-4] >> feature-B-8
2222 12 [ForkJoinPool-1-worker-2] >> feature-A-8
3205 9 [ForkJoinPool-1-worker-3] << feature-B-7
3213 10 [ForkJoinPool-1-worker-1] << feature-A-1
3229 12 [ForkJoinPool-1-worker-2] << feature-A-8
3230 11 [ForkJoinPool-1-worker-4] << feature-B-8
3208 13 [ForkJoinPool-1-worker-3] >> feature-A-2
3216 14 [ForkJoinPool-1-worker-1] >> feature-A-3
3234 15 [ForkJoinPool-1-worker-4] >> feature-A-4
3237 16 [ForkJoinPool-1-worker-2] >> feature-A-7
4214 13 [ForkJoinPool-1-worker-3] << feature-A-2
4230 14 [ForkJoinPool-1-worker-1] << feature-A-3
4245 15 [ForkJoinPool-1-worker-4] << feature-A-4
4245 16 [ForkJoinPool-1-worker-2] << feature-A-7
As you can clearly see, with your own settings you can expect that multiple features and even multiple iterations in your spec run concurrently. If in your case the concurrent iterations take as long to finish as running the test sequentially, it could mean that those tests spend a lot of time using a shared resource which is synchronised or in some other way can only be used by one caller at the same time. So probably not Spock is the problem here, but the shared resource or the way you synchronise on it.
My (xamarin.iOS) app always crashes after a while with the below error
Message:
mono-rt: Stack overflow in unmanaged: IP: 0x29c2cc, fault addr:
0xb0aedf4c
mono-rt: Stack overflow in unmanaged: IP: 0x29c2cc, fault addr:
0xb0aecdcc
The requested operation caused a stack overflow.
Stack Trace:
at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)
at System.Threading.Tasks.Task.HandleGenericException (System.Exception e) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:640
at System.Threading.Tasks.Task.ThreadStart () [0x00123] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:445
at System.Threading.Tasks.Task.Execute () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:514
at System.Threading.Tasks.TpScheduler.TaskExecuterCallback (System.Object obj) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs:59
Native
mono-rt: 0 RTouchIpad 0x001492d7 mono_handle_native_sigsegv + 327
mono-rt: 1 RTouchIpad 0x00153bfa sigabrt_signal_handler + 122
mono-rt: 2 libsystem_platform.dylib 0x056fbdeb _sigtramp + 43
mono-rt: 3 ??? 0xffffffff 0x0 + 4294967295
mono-rt: 4 libsystem_sim_c.dylib 0x05414e12 abort + 127
mono-rt: 5 RTouchIpad 0x002b8f33 monotouch_unhandled_exception_handler + 291
mono-rt: 6 RTouchIpad 0x00149afb mono_invoke_unhandled_exception_hook + 91
mono-rt: 7 RTouchIpad 0x00148b2c mono_handle_exception_internal + 6620
mono-rt: 8 RTouchIpad 0x00147149 mono_handle_exception + 41
mono-rt: 9 RTouchIpad 0x000e30b9 mono_x86_throw_exception + 137
mono-rt: 10 ??? 0x0fbbde57 0x0 + 263970391
mono-rt: 11 RTouchIpad 0x00148eb9 mono_altstack_restore_prot + 9
mono-rt: 12 ??? 0x0fbbd83c 0x0 + 263968828
mono-rt: 13 ??? 0x148185b0 0x0 + 344032688
mono-rt: 14 ??? 0x13fcbcd0 0x0 + 335330512
mono-rt: 15 ??? 0x13fcb558 0x0 + 335328600
mono-rt: 16 ??? 0x13fcb4fc 0x0 + 335328508
mono-rt: 17 ??? 0x0ff64827 0x0 + 267798567
mono-rt: 18 RTouchIpad 0x001797db mono_jit_runtime_invoke + 843
mono-rt: 19 RTouchIpad 0x002102ff mono_runtime_invoke + 127
mono-rt: 20 RTouchIpad 0x002153ec mono_runtime_delegate_invoke + 92
mono-rt: 21 RTouchIpad 0x002450ee async_invoke_thread + 2446
mono-rt: 22 RTouchIpad 0x00250028 start_wrapper + 376
mono-rt: 23 RTouchIpad 0x00285aa0 inner_start_thread + 240
mono-rt: 24 RTouchIpad 0x0029ed5d GC_start_routine + 93
mono-rt: 25 libsystem_pthread.dylib 0x057ea5fb _pthread_body + 144
mono-rt: 26 libsystem_pthread.dylib 0x057ea485 _pthread_struct_init + 0
mono-rt: 27 libsystem_pthread.dylib 0x057efcf2 thread_start + 34
mono-rt:
=================================================================
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.
=================================================================
Any idea how to best solve this issue?
Such crashes are often caused by a memory corruption inside the application. This is not easy to diagnose unless there's a (symbolicated) crash report (which will include every threads).
You can try to run your application under Instruments and it might pinpoint something unusual.
You can also file a bug report and include a reproducible test case (or, at a minimum, the symbolicated crash report).
I have a class derived from UIControl called MyObject and I also have a List that holds several objects on MyObject type.
All these objects are added as SubViews in ViewDidLoad overridden method of UIViewController before calling base.ViewDidLoad (); (I don't know if this is important).
The thing is that at certain periods I want to remove several objects because I don't need them anymore. Here is what steps I take:
- First of all I remove that object from my generic list collection
- Then I remove it from view using RemoveFromSuperview() method.
At this point everything works well, but I also want to get rid of it from memory because I don't need it anymore and I also need to add some more objects so I have to free some memory. So I call Dispose() method on that object.
As soon as I do it I get a nasty exception:
Stacktrace:
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSendSuper_RectangleF (intptr,intptr,System.Drawing.RectangleF) <IL 0x00025, 0xffffffff>
at MonoTouch.UIKit.UIView.set_Frame (System.Drawing.RectangleF) [0x00021] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.g.cs:1179
at BubbleBuster.Lib.UI.Gameplay.Bubble.Update (System.Drawing.RectangleF) [0x001a2] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Lib/UI/Gameplay/Bubble.cs:141
at BubbleBuster.Lib.UI.Gameplay.BubbleCollection/<Update>c__AnonStorey2.<>m__4 (BubbleBuster.Lib.UI.Gameplay.Bubble) [0x00014] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Lib/UI/Gameplay/BubbleCollection.cs:21
at System.Collections.Generic.List`1.ForEach (System.Action`1<T>) [0x00018] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/List.cs:360
at BubbleBuster.Lib.UI.Gameplay.BubbleCollection.Update (System.Drawing.RectangleF) [0x00014] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Lib/UI/Gameplay/BubbleCollection.cs:19
at BubbleBuster.Lib.UI.Screens.WelcomeScreen.<UpdateTime_Elapsed>m__1 () [0x00000] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Lib/UI/Screens/WelcomeScreen.cs:44
at MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSAction.cs:48
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x0004e, 0xffffffff>
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
Thread started:
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at BubbleBuster.Application.Main (string[]) [0x00000] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Main.cs:17
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
0 BubbleBusterApp 0x0009094c mono_handle_native_sigsegv + 284
1 BubbleBusterApp 0x00005cd8 mono_sigsegv_signal_handler + 248
2 libsystem_c.dylib 0x9923959b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 ??? 0x0e2662b8 0x0 + 237396664
5 ??? 0x0e2661dc 0x0 + 237396444
6 ??? 0x0e2651c6 0x0 + 237392326
7 ??? 0x0e269920 0x0 + 237410592
8 ??? 0x0e24f8e2 0x0 + 237304034
9 ??? 0x0e2697e4 0x0 + 237410276
10 ??? 0x0e269678 0x0 + 237409912
11 ??? 0x0e2695e0 0x0 + 237409760
12 ??? 0x09fe9a90 0x0 + 167680656
13 BubbleBusterApp 0x0000a042 mono_jit_runtime_invoke + 722
14 BubbleBusterApp 0x00169f4e mono_runtime_invoke + 126
15 BubbleBusterApp 0x00206748 monotouch_trampoline + 3416
16 CoreFoundation 0x011d6e42 -[NSObject performSelector:withObject:] + 66
17 Foundation 0x017509df __NSThreadPerformPerform + 254
18 CoreFoundation 0x011a994f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
19 CoreFoundation 0x0110cb43 __CFRunLoopDoSources0 + 243
20 CoreFoundation 0x0110c424 __CFRunLoopRun + 1012
21 CoreFoundation 0x0110bd84 CFRunLoopRunSpecific + 212
22 CoreFoundation 0x0110bc9b CFRunLoopRunInMode + 123
23 GraphicsServices 0x047c47d8 GSEventRunModal + 190
24 GraphicsServices 0x047c488a GSEventRun + 103
25 UIKit 0x02258626 UIApplicationMain + 1163
26 ??? 0x0d7c4a05 0x0 + 226249221
27 ??? 0x0d53cf18 0x0 + 223596312
28 ??? 0x0d53cc10 0x0 + 223595536
29 ??? 0x0d53cd66 0x0 + 223595878
30 BubbleBusterApp 0x0000a042 mono_jit_runtime_invoke + 722
31 BubbleBusterApp 0x00169f4e mono_runtime_invoke + 126
32 BubbleBusterApp 0x0016e034 mono_runtime_exec_main + 420
33 BubbleBusterApp 0x00173455 mono_runtime_run_main + 725
34 BubbleBusterApp 0x00067245 mono_jit_exec + 149
35 BubbleBusterApp 0x002116a5 main + 2837
36 BubbleBusterApp 0x00003095 start + 53
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
From here:
at MonoTouch.UIKit.UIView.set_Frame (System.Drawing.RectangleF) [0x00021] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.g.cs:1179
it looks like you're setting Frame on a view that has already been freed.
When you create the view, set it's tag to 333 i.e.
To dispose the view:
MyCreatedView.ViewWithTag(333).RemoveFromSuperview();
Where -MyCreatedView- is the parent view of the view you want to get rid of.
I am trying to play an mp3 file with the following code.
AVAudioPlayer player = new AVAudioPlayer();
NSUrl mediaFile = NSUrl.FromFilename(monkeySound);
player = AVAudioPlayer.FromUrl(mediaFile);
player.Delegate = new PlayerDelegate();
if(player.PrepareToPlay()){
player.Play();
}
private class PlayerDelegate:AVAudioPlayerDelegate {
public PlayerDelegate(){
}
public override void FinishedPlaying (AVAudioPlayer player, bool flag)
{
//Some Stuff Done Here
}
}
This is the error I get:
Stacktrace:
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr)
at MonoTouch.Foundation.NSObject/MonoTouch_Disposer.Drain (MonoTouch.Foundation.NSObject) [0x0002a] in /Users/plasma/Source/iphone/monotouch/Foundation/NSObject.cs:305
at (wrapper runtime-invoke) .runtime_invoke_void_this__object (object,intptr,intptr,intptr)
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26
at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:31
at MonkeyShot.Application.Main (string[]) [0x00000] in /Users/fencer04/Projects/MonkeyShot/MonkeyShot/Main.cs:14
at (wrapper runtime-invoke) .runtime_invoke_void_object (object,intptr,intptr,intptr)
Native stacktrace:
0 MonkeyShot 0x000d0d25 mono_handle_native_sigsegv + 343
1 MonkeyShot 0x0000f6f4 mono_sigsegv_signal_handler + 322
2 libSystem.B.dylib 0x992a345b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 AVFoundation 0x0047c28d -[AVAudioPlayer privCommonCleanup] + 50
5 AVFoundation 0x0047c339 -[AVAudioPlayer dealloc] + 51
6 ??? 0x0a2af91c 0x0 + 170588444
7 ??? 0x0a2cab1c 0x0 + 170699548
8 ??? 0x077520d6 0x0 + 125116630
9 MonkeyShot 0x0000f4af mono_jit_runtime_invoke + 1332
10 MonkeyShot 0x001ed319 mono_runtime_invoke + 137
11 MonkeyShot 0x0029da57 monotouch_trampoline + 2527
12 Foundation 0x0140d94e __NSThreadPerformPerform + 251
13 CoreFoundation 0x00e9f8ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
14 CoreFoundation 0x00dfd88b __CFRunLoopDoSources0 + 571
15 CoreFoundation 0x00dfcd86 __CFRunLoopRun + 470
16 CoreFoundation 0x00dfc840 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x00dfc761 CFRunLoopRunInMode + 97
18 GraphicsServices 0x0404b1c4 GSEventRunModal + 217
19 GraphicsServices 0x0404b289 GSEventRun + 115
20 UIKit 0x01cdfc93 UIApplicationMain + 1160
21 ??? 0x09d530a3 0x0 + 164966563
22 ??? 0x09d52e74 0x0 + 164966004
23 ??? 0x09d52474 0x0 + 164963444
24 ??? 0x09d522cc 0x0 + 164963020
25 ??? 0x09d5241e 0x0 + 164963358
26 MonkeyShot 0x0000f4af mono_jit_runtime_invoke + 1332
27 MonkeyShot 0x001ed319 mono_runtime_invoke + 137
28 MonkeyShot 0x001efa00 mono_runtime_exec_main + 669
29 MonkeyShot 0x001eedea mono_runtime_run_main + 843
30 MonkeyShot 0x000a3083 mono_jit_exec + 200
31 MonkeyShot 0x002a1697 main + 3838
32 MonkeyShot 0x00002809 _start + 208
33 MonkeyShot 0x00002738 start + 40
Debug info from gdb:
/tmp/mono-gdb-commands.0GDVJY:1: Error in sourced command file:
unable to debug self
===============================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
I don't know if this is your issue, but I had some issues using the C#-style delegate methods and AVAudioPlayer. If this is similar to my issue, using the "WeakDelegate" construct and exporting methods might be useful.
When running the below code, the app crashes (after ~30 seconds) with the below stacktrace. I find this very odd since I would expect the garbage collector to clean up this memory. Our application has a similar pattern and crashes with a similar stacktrace.
Commenting out the line that instantiates the NSObject member makes the app run without crash. Commenting out the line that instantiates the byte array makes the app run MUCH longer, but it still crashes.
Instruments reports a pretty well constant Live Bytes for the app and instrumenting causes the app to run much longer without crashing, but it does still crash (after ~10 minutes). The constant Live Bytes makes me feel like the garbage collector is working.
Code:
using System.Threading;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace MyExample
{
public class Application
{
static void Main (string[] args)
{
UIApplication.Main(args);
}
}
public partial class AppDelegate : UIApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Thread testThread = new Thread(BreakMe);
testThread.Start();
window.MakeKeyAndVisible();
return true;
}
private void BreakMe()
{
while(true)
{
using (var arPool = new NSAutoreleasePool())
{
MyGarbage garbage = new MyGarbage();
}
}
}
private class MyGarbage
{
byte[] _Foo = new byte[100000];
NSObject _Bar = new NSObject();
}
}
}
Application Output:
Mprotect failed at 0x493c000 (length 4096) with errno 12
Stacktrace:
at (wrapper managed-to-native) System.Array.CreateInstanceImpl (System.Type,int[],int[]) <0xffffffff>
at System.Array.CreateInstance (System.Type,int[]) <0x000bc>
at System.Array.CreateInstance (System.Type,int) <0x00057>
at System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider,System.Type,bool) <0x000db>
at System.MonoCustomAttrs.GetCustomAttribute (System.Reflection.ICustomAttributeProvider,System.Type,bool) <0x00033>
at System.Attribute.GetCustomAttribute (System.Reflection.MemberInfo,System.Type,bool) <0x0003f>
at MonoTouch.ObjCRuntime.Class.GetHandle (System.Type) <0x00037>
at MonoTouch.Foundation.NSObject.AllocIfNeeded () <0x00063>
at MonoTouch.Foundation.NSObject..ctor (MonoTouch.Foundation.NSObjectFlag) <0x00027>
at MonoTouch.Foundation.NSAutoreleasePool..ctor () <0x00037>
at MyExample.AppDelegate.BreakMe () [0x00000] in Main.cs:30
at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000cb>
Native stacktrace:
0 MyExample 0x002db308 mono_handle_native_sigsegv + 404
1 MyExample 0x002fa5dc sigabrt_signal_handler + 148
2 libsystem_c.dylib 0x369c972f _sigtramp + 42
3 libsystem_c.dylib 0x369be3bb pthread_kill + 58
4 libsystem_c.dylib 0x369b6bff abort + 78
5 MyExample 0x0041e484 GC_remap + 200
6 MyExample 0x00411ee4 GC_allochblk_nth + 1536
7 MyExample 0x00411894 GC_allochblk + 96
8 MyExample 0x0041d94c GC_new_hblk + 116
9 MyExample 0x00413c3c GC_allocobj + 188
10 MyExample 0x0041859c GC_generic_malloc_inner + 352
11 MyExample 0x004187ac GC_generic_malloc + 132
12 MyExample 0x00418c60 GC_malloc + 208
13 MyExample 0x003a67dc mono_object_allocate + 64
14 MyExample 0x003a7240 mono_array_new_full + 828
15 MyExample 0x00341324 ves_icall_System_Array_CreateInstanceImpl + 896
16 MyExample 0x0012cf3c (wrapper managed-to-native) System.Array:CreateInstanceImpl (System.Type,int[],int[]) + 80
17 MyExample 0x0012d23c System.Array:CreateInstance (System.Type,int) + 88
18 MyExample 0x0018b70c System.MonoCustomAttrs:GetCustomAttributes (System.Reflection.ICustomAttributeProvider,System.Type,bool) + 220
19 MyExample 0x0018b560 System.MonoCustomAttrs:GetCustomAttribute (System.Reflection.ICustomAttributeProvider,System.Type,bool) + 52
20 MyExample 0x00131fd0 System.Attribute:GetCustomAttribute (System.Reflection.MemberInfo,System.Type,bool) + 64
21 MyExample 0x000795ec MonoTouch.ObjCRuntime.Class:GetHandle (System.Type) + 56
22 MyExample 0x00077e60 MonoTouch.Foundation.NSObject:AllocIfNeeded () + 100
23 MyExample 0x0007779c MonoTouch.Foundation.NSObject:.ctor (MonoTouch.Foundation.NSObjectFlag) + 40
24 MyExample 0x00074d10 MonoTouch.Foundation.NSAutoreleasePool:.ctor () + 56
25 MyExample 0x00002c34 MyExample.AppDelegate:BreakMe () + 164
26 MyExample 0x001f3e3c (wrapper runtime-invoke) object:runtime_invoke_dynamic (intptr,intptr,intptr,intptr) + 204
27 MyExample 0x002c4658 mono_jit_runtime_invoke + 3032
28 MyExample 0x003a34a8 mono_runtime_invoke + 140
29 MyExample 0x003a48f0 mono_runtime_delegate_invoke + 136
30 MyExample 0x003cb31c start_wrapper + 752
31 MyExample 0x003f09a0 thread_start_routine + 240
32 MyExample 0x0041f9ac GC_start_routine + 132
33 libsystem_c.dylib 0x369be311 _pthread_start + 248
34 libsystem_c.dylib 0x369bfbbc start_wqthread + 0
The true answer to this is, is suspect, the issue resolved in Why is our MonoTouch app breaking in the garbage collector? It is not out of memory which was a memory manager issue. The stack trace is very familiar to me.
You have put the allocator in a race with the garbage collector. If you make a simple change to your demo and add:
System.GC.Collect ();
In the loop, you will see it no longer crashes.
Whats happening here is you are allocating as fast as possible. When the GC runs out of memory its expanding the heap and collecting. The next few times the loop runs it runs a bit longer before having to collect again due to the expaned heap, but eventually the race is lost.
Making the minor modification I stated above allowed the test to run for 10 minutes here before I gave up.