Bug 26685 - SIGSEGV on recurring native api calls
Summary: SIGSEGV on recurring native api calls
Status: RESOLVED ANSWERED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 5.1
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-02-03 09:00 UTC by Alex
Modified: 2017-09-12 18:21 UTC (History)
3 users (show)

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


Attachments
Failing source code (9.06 KB, text/plain)
2015-02-03 09:00 UTC, Alex
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 ANSWERED

Description Alex 2015-02-03 09:00:32 UTC
Created attachment 9620 [details]
Failing source code

Very often we get SIGSEGV without the possibility to react to an exception when performing calls to wrapped native apis,
even though every call gets wrapped in a try/catch block.

It seems that the generated JNI types get corrupted over time, below a recent stacktrace.


[mono-rt] Stacktrace:
[mono-rt] 
[mono-rt]   at <unknown> <0xffffffff>
[mono-rt]   at (wrapper managed-to-native) object.wrapper_native_0x803392e9 (intptr,intptr) <IL 0x00026, 0xffffffff>
[mono-rt]   at Android.Runtime.JNIEnv.NewGlobalRef (intptr) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:514
[mono-rt]   at Java.Lang.Object.RegisterInstance (Android.Runtime.IJavaObject,intptr,Android.Runtime.JniHandleOwnership,intptr&) [0x00038] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:182
[mono-rt]   at Java.Lang.Object.SetHandle (intptr,Android.Runtime.JniHandleOwnership) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:166
[mono-rt]   at Java.Lang.Object..ctor (intptr,Android.Runtime.JniHandleOwnership) [0x00036] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:87
[mono-rt]   at Android.Content.Intent..ctor (intptr,Android.Runtime.JniHandleOwnership) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Content.Intent.cs:1097
[mono-rt]   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___intptr_int (object,intptr,intptr,intptr) <IL 0x0005e, 0xffffffff>
[mono-rt]   at <unknown> <0xffffffff>
[mono-rt]   at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) <IL 0x00030, 0xffffffff>
[mono-rt]   at System.Reflection.MonoCMethod.InternalInvoke (object,object[]) <IL 0x00007, 0x000a3>
[mono-rt]   at System.Reflection.MonoCMethod.DoInvoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x00099, 0x003c7>
[mono-rt]   at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x00007, 0x00087>
[mono-rt]   at System.Reflection.ConstructorInfo.Invoke (object[]) <IL 0x00015, 0x000df>
[mono-rt]   at Java.Interop.TypeManager.CreateProxy (System.Type,intptr,Android.Runtime.JniHandleOwnership) [0x00059] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:271
[mono-rt]   at Java.Interop.TypeManager.CreateInstance (intptr,Android.Runtime.JniHandleOwnership,System.Type) [0x001ea] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:249
[mono-rt]   at Java.Lang.Object.GetObject (intptr,Android.Runtime.JniHandleOwnership,System.Type) [0x000ba] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:333
[mono-rt]   at Java.Lang.Object._GetObject<T> (intptr,Android.Runtime.JniHandleOwnership) [0x0001a] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:313
[mono-rt]   at Java.Lang.Object.GetObject<T> (intptr,Android.Runtime.JniHandleOwnership) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:305
[mono-rt]   at Android.Content.ContextWrapper.RegisterReceiver (Android.Content.BroadcastReceiver,Android.Content.IntentFilter) [0x00089] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Content.ContextWrapper.cs:2169
[mono-rt]   at GKL.Android.Core.DeviceManager.GetBatteryStatus () [0x0000c] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKLAndroidLib\Classes\Core\DeviceManager.cs:252
[mono-rt]   at GKL.Android.Core.DeviceManager.get_BatteryIsCharging () [0x00002] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKLAndroidLib\Classes\Core\DeviceManager.cs:144
[mono-rt]   at GKL.Android.Scanner.App.Activities.MainActivity.RefreshUI () [0x00086] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKL_Scanner_App\Classes\Activities\MainActivity.cs:85
[mono-rt]   at GKL.Android.Scanner.App.Activities.BaseActivity.<RefreshUI>b__3 () [0x00041] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKL_Scanner_App\Classes\Activities\BaseActivity.cs:101
[mono-rt]   at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
[mono-rt]   at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:71
[mono-rt]   at (wrapper dynamic-method) object.d270d8f4-5586-440d-8318-4e290358b300 (intptr,intptr) <IL 0x00011, 0x0003b>
[mono-rt]   at (wrapper native-to-managed) object.d270d8f4-5586-440d-8318-4e290358b300 (intptr,intptr) <IL 0x00022, 0xffffffff>
[mono-rt] 
[mono-rt] =================================================================
[mono-rt] Got a SIGSEGV while executing native code. This usually indicates
[mono-rt] a fatal error in the mono runtime or one of the native libraries 
[mono-rt] used by your application.
[mono-rt] =================================================================
[mono-rt]
Comment 1 Jonathan Pryor 2015-02-03 11:58:51 UTC
Can you please attach `adb logcat` output at the time of the crash? It should contain relevant contextual information.

What device are you running this on? An emulator? Hardware device? (Which one?)

All I know for certain from the above stack trace is that the process is crashing during a call to JNIEnv::NewGlobalRef(). The most obvious explanation is that you're on an emulator and have created more than 2000 JNI Global References:

http://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Global_Reference_Messages
Comment 2 Alex 2015-02-04 05:03:56 UTC
I am running on hardware, Android 2.3.7, specifically this one: http://www.geofanci.com/en/pro_show.asp?id=246

I observed logcat with "adb shell setprop debug.mono.log gref" and it seems that grefc is stable around 150, thus not being even near the 50k limit on hardware (We dont use the emulator at all).

As of now I am trying to reproduce the SIGSEGV, without success. When it comes again, I'll post the detailed logcat.
Comment 3 Alex 2015-02-18 10:20:05 UTC
Even though I cant trigger this exception when gref logs are enabled (the gref count is currently stable around 300), this bug is still an issue to us. I guess its a timing issue.

[mono-rt] Stacktrace:
[mono-rt] 
[mono-rt]   at <unknown> <0xffffffff>
[mono-rt]   at (wrapper managed-to-native) object.wrapper_native_0x803392e9 (intptr,intptr) <IL 0x00026, 0xffffffff>
[mono-rt]   at Android.Runtime.JNIEnv.NewGlobalRef (intptr) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:514
[mono-rt]   at Java.Lang.Object.RegisterInstance (Android.Runtime.IJavaObject,intptr,Android.Runtime.JniHandleOwnership,intptr&) [0x00038] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:182
[mono-rt]   at Java.Lang.Object.SetHandle (intptr,Android.Runtime.JniHandleOwnership) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:166
[mono-rt]   at Java.Lang.Object..ctor (intptr,Android.Runtime.JniHandleOwnership) [0x00036] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:87
[mono-rt]   at Android.Content.Intent..ctor (intptr,Android.Runtime.JniHandleOwnership) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Content.Intent.cs:1097
[mono-rt]   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___intptr_int (object,intptr,intptr,intptr) <IL 0x0005e, 0xffffffff>
[mono-rt]   at <unknown> <0xffffffff>
[mono-rt]   at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) <IL 0x00030, 0xffffffff>
[mono-rt]   at System.Reflection.MonoCMethod.InternalInvoke (object,object[]) <IL 0x00007, 0x000a3>
[mono-rt]   at System.Reflection.MonoCMethod.DoInvoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x00099, 0x003c7>
[mono-rt]   at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x00007, 0x00087>
[mono-rt]   at System.Reflection.ConstructorInfo.Invoke (object[]) <IL 0x00015, 0x000df>
[mono-rt]   at Java.Interop.TypeManager.CreateProxy (System.Type,intptr,Android.Runtime.JniHandleOwnership) [0x00059] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:271
[mono-rt]   at Java.Interop.TypeManager.CreateInstance (intptr,Android.Runtime.JniHandleOwnership,System.Type) [0x001ea] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:249
[mono-rt]   at Java.Lang.Object.GetObject (intptr,Android.Runtime.JniHandleOwnership,System.Type) [0x000ba] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:333
[mono-rt]   at Java.Lang.Object._GetObject<T> (intptr,Android.Runtime.JniHandleOwnership) [0x0001a] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:313
[mono-rt]   at Java.Lang.Object.GetObject<T> (intptr,Android.Runtime.JniHandleOwnership) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:305
[mono-rt]   at Android.Content.ContextWrapper.RegisterReceiver (Android.Content.BroadcastReceiver,Android.Content.IntentFilter) [0x00089] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Content.ContextWrapper.cs:2169
[mono-rt]   at GKL.Android.Core.DeviceManager.GetBatteryStatus () [0x0000c] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKLAndroidLib\Classes\Core\DeviceManager.cs:203
[mono-rt]   at GKL.Android.Core.DeviceManager.get_BatteryLevel () [0x00002] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKLAndroidLib\Classes\Core\DeviceManager.cs:123
[mono-rt]   at GKL.Android.Scanner.App.Activities.BaseActivity.RefreshUI () [0x000e5] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKL_Scanner_App\Classes\Activities\BaseActivity.cs:157
[mono-rt]   at GKL.Android.Scanner.App.Activities.MainActivity.<>n__FabricatedMethoda () <IL 0x00001, 0x00043>
[mono-rt]   at GKL.Android.Scanner.App.Activities.MainActivity/<RefreshUI>d__2.MoveNext () [0x00021] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKL_Scanner_App\Classes\Activities\MainActivity.cs:77
[mono-rt]   at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<GKL.Android.Scanner.App.Activities.MainActivity/<RefreshUI>d__2> (GKL.Android.Scanner.App.Activities.MainActivity/<RefreshUI>d__2&) <IL 0x00022, 0x000bb>
[mono-rt]   at GKL.Android.Scanner.App.Activities.MainActivity.RefreshUI () <IL 0x00028, 0x001b3>
[mono-rt]   at GKL.Android.Scanner.App.Activities.BaseActivity.<RefreshUI>b__0 () [0x00002] in c:\Users\aschonefeld\Documents\Projects\xamarin-studio\GKL\Scanner\GKL_Scanner_App\Classes\Activities\BaseActivity.cs:126
[mono-rt]   at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
[mono-rt]   at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:71
[mono-rt]   at (wrapper dynamic-method) object.9ec5a57f-6256-431a-b92a-7eb1b69e7647 (intptr,intptr) <IL 0x00011, 0x0003b>
[mono-rt]   at (wrapper native-to-managed) object.9ec5a57f-6256-431a-b92a-7eb1b69e7647 (intptr,intptr) <IL 0x00022, 0xffffffff>
[mono-rt] 
[mono-rt] =================================================================
[mono-rt] Got a SIGSEGV while executing native code. This usually indicates
[mono-rt] a fatal error in the mono runtime or one of the native libraries 
[mono-rt] used by your application.
[mono-rt] =================================================================
[mono-rt]
Comment 4 Jonathan Pryor 2015-02-18 10:42:17 UTC
When you get a crash, please dump `adb logcat` to a file and attach it, particularly when it's a crash in JNIEnv.

What may be happening is a variation on Bug #25443 (still being investigated...), in which an invalid JNI handle is being passed to Android, and Android is aborting the process.

Application output will NOT contain any additional information; `adb logcat` WILL.
Comment 5 Alex 2015-02-19 04:13:02 UTC
Ok, now I got something useful, I think.

D/ConnectivityService( 1321): getMobileDataEnabled returning false

D/dalvikvm(24167): GREF has increased to 1901

D/ConnectivityService( 1321): getMobileDataEnabled returning false

D/ConnectivityService( 1321): getMobileDataEnabled returning false

D/ConnectivityService( 1321): getMobileDataEnabled returning false

D/ConnectivityService( 1321): getMobileDataEnabled returning false

D/ConnectivityService( 1321): getMobileDataEnabled returning false

D/ConnectivityService( 1321): getMobileDataEnabled returning false

D/ConnectivityService( 1321): getMobileDataEnabled returning false

D/dalvikvm(24167): GREF has increased to 2001

W/dalvikvm(24167): Last 10 entries in JNI global reference table:

W/dalvikvm(24167):  1991: 0x4062b588 cls=Ljava/lang/reflect/Method; (60 bytes)

W/dalvikvm(24167):  1992: 0x405d7cb0 cls=Ljava/lang/Boolean; (12 bytes)

W/dalvikvm(24167):  1993: 0x4062b6a0 cls=Landroid/content/IntentFilter; (52 bytes)

W/dalvikvm(24167):  1994: 0x40674020 cls=Landroid/content/Intent; (44 bytes)

W/dalvikvm(24167):  1995: 0x405d5a88 cls=Lmono/java/lang/RunnableImplementor; (12 bytes)

W/dalvikvm(24167):  1996: 0x40669bb8 cls=Landroid/content/IntentFilter; (44 bytes)

W/dalvikvm(24167):  1997: 0x40669c30 cls=Landroid/content/Intent; (44 bytes)

W/dalvikvm(24167):  1998: 0x40672200 cls=Landroid/content/IntentFilter; (44 bytes)

W/dalvikvm(24167):  1999: 0x40672278 cls=Landroid/content/Intent; (44 bytes)

W/dalvikvm(24167):  2000: 0x4067ac10 cls=Ljava/lang/String; (28 bytes)

W/dalvikvm(24167): JNI global reference table summary (2001 entries):

W/dalvikvm(24167):    70 of Ljava/lang/Class; 164B (55 unique)

W/dalvikvm(24167):    54 of Ljava/lang/Class; 188B (24 unique)

W/dalvikvm(24167):    10 of Ljava/lang/Class; 212B (9 unique)

W/dalvikvm(24167):     1 of Ljava/lang/Class; 220B

W/dalvikvm(24167):    14 of Ljava/lang/Class; 236B (9 unique)

W/dalvikvm(24167):     3 of Ljava/lang/Class; 260B (2 unique)

W/dalvikvm(24167):    13 of Ljava/lang/Class; 284B (9 unique)

W/dalvikvm(24167):     1 of Ljava/lang/Class; 292B

W/dalvikvm(24167):     8 of Ljava/lang/Class; 308B (7 unique)

W/dalvikvm(24167):     5 of Ljava/lang/Class; 332B (4 unique)

W/dalvikvm(24167):     1 of Ljava/lang/Class; 356B

W/dalvikvm(24167):     2 of Ljava/lang/Class; 380B (1 unique)

W/dalvikvm(24167):     2 of Ljava/lang/Class; 428B (2 unique)

W/dalvikvm(24167):     2 of Ljava/lang/Class; 452B (2 unique)

W/dalvikvm(24167):     1 of Ljava/lang/Class; 476B

W/dalvikvm(24167):     5 of Ljava/lang/Class; 500B (3 unique)

W/dalvikvm(24167):     2 of Ljava/lang/Class; 548B (2 unique)

W/dalvikvm(24167):     1 of Ljava/lang/Class; 572B

W/dalvikvm(24167):     2 of Ljava/lang/Class; 596B (2 unique)

W/dalvikvm(24167):     1 of Ljava/lang/Class; 620B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 668B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 692B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 820B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 836B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 932B

W/dalvikvm(24167):     2 of Ljava/lang/Class; 956B (2 unique)

W/dalvikvm(24167):     2 of Ljava/lang/Class; 1004B (1 unique)

W/dalvikvm(24167):     1 of Ljava/lang/Class; 1028B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 1052B

W/dalvikvm(24167):     3 of Ljava/lang/Class; 1172B (2 unique)

W/dalvikvm(24167):     1 of Ljava/lang/Class; 1220B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 1316B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 2732B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 3428B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 3572B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 4196B

W/dalvikvm(24167):     1 of Ljava/lang/Class; 4796B

W/dalvikvm(24167):    97 of Ljava/lang/reflect/Method; 60B (97 unique)

W/dalvikvm(24167):     5 of Ljava/lang/reflect/Method; 68B (5 unique)

W/dalvikvm(24167):   102 of Ljava/lang/Boolean; 12B (102 unique)

W/dalvikvm(24167):     2 of Ljava/lang/String; 28B (2 unique)

W/dalvikvm(24167):     2 of Ldalvik/system/VMRuntime; 12B (1 unique)

W/dalvikvm(24167):     2 of Ljava/io/File; 20B (2 unique)

W/dalvikvm(24167):    20 of Ljava/lang/ref/WeakReference; 28B (20 unique)

W/dalvikvm(24167):    13 of Ljava/util/ArrayList; 20B (13 unique)

W/dalvikvm(24167):     1 of Landroid/app/ActivityThread$ProviderClientRecord; 28B

W/dalvikvm(24167):     3 of Landroid/content/pm/PackageInfo; 100B (3 unique)

W/dalvikvm(24167):     1 of Ldalvik/system/PathClassLoader; 44B

W/dalvikvm(24167):   161 of Landroid/os/StatFs; 12B (161 unique)

W/dalvikvm(24167):     1 of Landroid/app/ActivityThread$ApplicationThread; 28B

W/dalvikvm(24167):     1 of Landroid/app/ContextImpl$ApplicationContentResolver; 20B

W/dalvikvm(24167):     1 of Landroid/app/ContextImpl$ApplicationPackageManager; 20B

W/dalvikvm(24167):     2 of Landroid/app/ContextImpl$SharedPreferencesImpl; 60B (2 unique)

W/dalvikvm(24167):     1 of Landroid/content/ContentProvider$Transport; 28B

W/dalvikvm(24167):     1 of Landroid/app/ReceiverRestrictedContext; 12B

W/dalvikvm(24167):     2 of Landroid/app/LoadedApk$ReceiverDispatcher$InnerReceiver; 28B (2 unique)

W/dalvikvm(24167):   377 of Landroid/content/Intent; 44B (377 unique)

W/dalvikvm(24167):    22 of Landroid/content/Intent; 52B (22 unique)

W/dalvikvm(24167):   361 of Landroid/content/IntentFilter; 44B (361 unique)

W/dalvikvm(24167):    30 of Landroid/content/IntentFilter; 52B (30 unique)

W/dalvikvm(24167):     1 of Landroid/content/pm/ApplicationInfo; 116B

W/dalvikvm(24167):     1 of Landroid/database/ContentObserver$Transport; 28B

W/dalvikvm(24167):     1 of Ljava/lang/Runtime; 28B

W/dalvikvm(24167):     1 of Landroid/location/LocationManager; 28B

W/dalvikvm(24167):    21 of Landroid/widget/TextView; 628B (21 unique)

W/dalvikvm(24167):     1 of Landroid/os/PowerManager; 20B

W/dalvikvm(24167):     1 of Landroid/telephony/TelephonyManager; 20B

W/dalvikvm(24167):     1 of Landroid/net/ConnectivityManager; 12B

W/dalvikvm(24167):   416 of Landroid/net/NetworkInfo; 52B (416 unique)

W/dalvikvm(24167):    46 of Landroid/net/NetworkInfo; 60B (46 unique)

W/dalvikvm(24167):     2 of Landroid/net/Uri$StringUri; 60B (2 unique)

W/dalvikvm(24167):     2 of Ljava/net/Proxy; 20B (1 unique)

W/dalvikvm(24167):     1 of Landroid/view/inputmethod/InputMethodManager$1; 28B

W/dalvikvm(24167):     3 of Landroid/os/Looper; 28B (3 unique)

W/dalvikvm(24167):     1 of Landroid/os/PowerManager$WakeLock; 44B

W/dalvikvm(24167):     1 of Landroid/view/inputmethod/InputMethodManager$ControlledInputConnectionWrapper; 36B

W/dalvikvm(24167):     2 of Landroid/view/ViewRoot$1; 12B (2 unique)

W/dalvikvm(24167):     2 of Landroid/view/ViewRoot$W; 28B (2 unique)

W/dalvikvm(24167):     4 of Landroid/view/WindowManagerImpl; 20B (1 unique)

W/dalvikvm(24167):     1 of Landroid/view/accessibility/AccessibilityManager$1; 28B

W/dalvikvm(24167):     7 of Landroid/widget/LinearLayout; 332B (7 unique)

W/dalvikvm(24167):     1 of Landroid/widget/Button; 628B

W/dalvikvm(24167):     6 of Landroid/widget/FrameLayout; 340B (6 unique)

W/dalvikvm(24167):    10 of Landroid/widget/ImageButton; 332B (10 unique)

W/dalvikvm(24167):     6 of Landroid/widget/ImageView; 332B (6 unique)

W/dalvikvm(24167):     1 of Ljava/security/cert/CertificateFactory; 20B

W/dalvikvm(24167):     2 of Lcom/android/internal/policy/impl/PhoneLayoutInflater; 36B (2 unique)

W/dalvikvm(24167):     2 of Lcom/android/internal/policy/impl/PhoneWindow; 204B (2 unique)

W/dalvikvm(24167):     2 of Lorg/apache/harmony/xnet/provider/jsse/TrustManagerImpl; 28B (1 unique)

W/dalvikvm(24167):     1 of Lgkl/android/scanner/app/core/ScannerApp; 20B

W/dalvikvm(24167):     1 of Lxamarin/insightscore/NetworkChangeReceiver; 44B

W/dalvikvm(24167):     1 of Lxamarin/insightscore/NativeUnhandledExceptionHandler; 12B

W/dalvikvm(24167):    10 of Lmono/android/view/View_OnClickListenerImplementor; 12B (10 unique)

W/dalvikvm(24167):     1 of Ljava/net/ProxySelectorImpl; 12B

W/dalvikvm(24167):     1 of Lgkl/android/core/DeviceManager; 12B

W/dalvikvm(24167):     1 of Landroid/net/wifi/WifiManager; 20B

W/dalvikvm(24167):     1 of Landroid/location/LocationManager$ListenerTransport; 36B

W/dalvikvm(24167):     1 of Lgkl/android/scanner/app/activities/InitializationActivity; 236B

W/dalvikvm(24167):     1 of Lgkl/android/scanner/app/activities/MainActivity; 236B

W/dalvikvm(24167):     1 of Lmono/java/lang/RunnableImplementor; 12B

W/dalvikvm(24167):     1 of Landroid/os/DropBoxManager; 12B

W/dalvikvm(24167):     2 of Lmono/android/runtime/InputStreamAdapter; 12B (2 unique)

W/dalvikvm(24167):     2 of Lgkl/android/scanner/app/push/PushNotificationService; 68B (2 unique)

W/dalvikvm(24167):     2 of Lorg/apache/harmony/security/provider/cert/X509CertImpl; 84B (2 unique)

W/dalvikvm(24167):     1 of Landroid/app/ActivityManager; 20B

W/dalvikvm(24167): Memory held directly by tracked refs is 161456 bytes

E/dalvikvm(24167): Excessive JNI global references (2001)

E/dalvikvm(24167): VM aborting

E/mono-rt (24167): Stacktrace:

E/mono-rt (24167): 

E/mono-rt (24167):   at <unknown> <0xffffffff>

E/mono-rt (24167):   at (wrapper managed-to-native) object.wrapper_native_0x803392e9 (intptr,intptr) <0xffffffff>

E/mono-rt (24167):   at Android.Runtime.JNIEnv.NewGlobalRef (intptr) <0x00043>

E/mono-rt (24167):   at Java.Lang.Object.RegisterInstance (Android.Runtime.IJavaObject,intptr,Android.Runtime.JniHandleOwnership,intptr&) <0x0008f>

E/mono-rt (24167):   at Java.Lang.Object.SetHandle (intptr,Android.Runtime.JniHandleOwnership) <0x0002f>

E/mono-rt (24167):   at Java.Lang.String..ctor (string) <0x0031f>

E/mono-rt (24167):   at Android.Widget.TextView.set_Text (string) <0x0003b>

E/mono-rt (24167):   at GKL.Android.Scanner.App.Activities.BaseActivity.RefreshUI () <0x00373>

E/mono-rt (24167):   at GKL.Android.Scanner.App.Activities.MainActivity.<>n__FabricatedMethod10 () <0x00013>

E/mono-rt (24167):   at GKL.Android.Scanner.App.Activities.MainActivity/<RefreshUI>d__8.MoveNext () <0x0007b>

E/mono-rt (24167):   at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<GKL.Android.Scanner.App.Activities.MainActivity/<RefreshUI>d__8> (GKL.Android.Scanner.App.Activities.MainActivity/<RefreshUI>d__8&) <0x0004f>

E/mono-rt (24167):   at GKL.Android.Scanner.App.Activities.MainActivity.RefreshUI () <0x000c3>

E/mono-rt (24167):   at GKL.Android.Scanner.App.Activities.BaseActivity.<RefreshUI>b__0 () <0x0002b>

E/mono-rt (24167):   at Java.Lang.Thread/RunnableImplementor.Run () <0x0003f>

E/mono-rt (24167):   at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <0x00047>

E/mono-rt (24167):   at (wrapper dynamic-method) object.50eabafb-76ba-499b-9df5-3bb616009df8 (intptr,intptr) <0x0003b>

E/mono-rt (24167):   at (wrapper native-to-managed) object.50eabafb-76ba-499b-9df5-3bb616009df8 (intptr,intptr) <0xffffffff>

E/mono-rt (24167): 

E/mono-rt (24167): =================================================================

E/mono-rt (24167): Got a SIGSEGV while executing native code. This usually indicates

E/mono-rt (24167): a fatal error in the mono runtime or one of the native libraries 

E/mono-rt (24167): used by your application.

E/mono-rt (24167): =================================================================

E/mono-rt (24167): 

I/DEBUG   (12159): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

I/DEBUG   (12159): Build fingerprint: 'marvell/dkb/dkb:2.3.7/GWK74/20130506.170057:eng/test-keys'

I/DEBUG   (12159): pid: 24167, tid: 24167  >>> gkl.android.Scanner <<<

I/DEBUG   (12159): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadd00d

I/DEBUG   (12159):  r0 fffffec4  r1 deadd00d  r2 00000026  r3 00000000

I/DEBUG   (12159):  r4 803a45c0  r5 000000ba  r6 803890e3  r7 803a45c0

I/DEBUG   (12159):  r8 005b5a20  r9 431ece10  10 431ecdf8  fp be8e4c58

I/DEBUG   (12159):  ip 803a4720  sp be8e4b20  lr afd1941d  pc 80345a4a  cpsr 20000030

I/DEBUG   (12159):          #00  pc 00045a4a  /system/lib/libdvm.so

I/DEBUG   (12159):          #01  pc 0004a232  /system/lib/libdvm.so

I/DEBUG   (12159):          #02  pc 0004a3a2  /system/lib/libdvm.so

I/DEBUG   (12159):          #03  pc 0003934a  /system/lib/libdvm.so

I/DEBUG   (12159): 

I/DEBUG   (12159): code around pc:

I/DEBUG   (12159): 80345a28 447a4479 ed0cf7d1 20004c09 ee34f7d1 

I/DEBUG   (12159): 80345a38 447c4808 6bdb5823 d0002b00 49064798 

I/DEBUG   (12159): 80345a48 700a2226 eea0f7d1 000436b7 00045275 

I/DEBUG   (12159): 80345a58 0005eb82 fffffec4 deadd00d b510b40e 

I/DEBUG   (12159): 80345a68 4c0a4b09 447bb083 aa05591b 6b5bca02 

I/DEBUG   (12159): 

I/DEBUG   (12159): code around lr:

I/DEBUG   (12159): afd193fc b0834a0d 589c447b 26009001 686768a5 

I/DEBUG   (12159): afd1940c 220ce008 2b005eab 1c28d003 47889901 

I/DEBUG   (12159): afd1941c 35544306 d5f43f01 2c006824 b003d1ee 

I/DEBUG   (12159): afd1942c bdf01c30 00028100 ffffff88 1c0fb5f0 

I/DEBUG   (12159): afd1943c 43551c3d a904b087 1c16ac01 604d9004 

I/DEBUG   (12159): 

I/DEBUG   (12159): stack:

I/DEBUG   (12159):     be8e4ae0  00000015  

I/DEBUG   (12159):     be8e4ae4  afd184af  /system/lib/libc.so

I/DEBUG   (12159):     be8e4ae8  afd4270c  /system/lib/libc.so

I/DEBUG   (12159):     be8e4aec  afd426b8  /system/lib/libc.so

I/DEBUG   (12159):     be8e4af0  00000000  

I/DEBUG   (12159):     be8e4af4  afd1941d  /system/lib/libc.so

I/DEBUG   (12159):     be8e4af8  431ece10  

I/DEBUG   (12159):     be8e4afc  afd18481  /system/lib/libc.so

I/DEBUG   (12159):     be8e4b00  00ba2980  [heap]

I/DEBUG   (12159):     be8e4b04  0005eb82  [heap]

I/DEBUG   (12159):     be8e4b08  000000ba  

I/DEBUG   (12159):     be8e4b0c  803890e3  /system/lib/libdvm.so

I/DEBUG   (12159):     be8e4b10  803a45c0  /system/lib/libdvm.so

I/DEBUG   (12159):     be8e4b14  afd184df  /system/lib/libc.so

I/DEBUG   (12159):     be8e4b18  e3a070ad  

I/DEBUG   (12159):     be8e4b1c  ef9000ad  

I/DEBUG   (12159): #00 be8e4b20  803a9d08  

I/DEBUG   (12159):     be8e4b24  8034a237  /system/lib/libdvm.so

I/DEBUG   (12159): #01 be8e4b28  000007d1  

I/DEBUG   (12159):     be8e4b2c  4067ac10  /dev/ashmem/dalvik-heap (deleted)

I/DEBUG   (12159):     be8e4b30  4067ac10  /dev/ashmem/dalvik-heap (deleted)

I/DEBUG   (12159):     be8e4b34  803a45c0  /system/lib/libdvm.so

I/DEBUG   (12159):     be8e4b38  4067ac10  /dev/ashmem/dalvik-heap (deleted)

I/DEBUG   (12159):     be8e4b3c  0000cea0  [heap]

I/DEBUG   (12159):     be8e4b40  4067ac10  /dev/ashmem/dalvik-heap (deleted)

I/DEBUG   (12159):     be8e4b44  8034a3a7  /system/lib/libdvm.so

I/BootReceiver( 1321): Copying /data/tombstones/tombstone_07 to DropBox (SYSTEM_TOMBSTONE)

I/ActivityManager( 1321): Process gkl.android.Scanner (pid 24167) has died.

W/GpsLocationProvider( 1321): Unneeded remove listener for uid 1000

I/WindowManager( 1321): WIN DEATH: Window{408684f0 gkl.android.Scanner/gkl.android.scanner.app.activities.InitializationActivity paused=false}

I/WindowManager( 1321): WIN DEATH: Window{40876070 gkl.android.Scanner/gkl.android.scanner.app.activities.MainActivity paused=false}

D/Zygote  ( 1098): Process 24167 terminated by signal (11)
Comment 6 Alex 2015-02-19 04:15:57 UTC
I guess the interesting line is this one:

E/dalvikvm(24167): Excessive JNI global references (2001)

If '2001' is the gref count that doesnt make sense though, since the app was running on hardware, where it says at launch:

[monodroid-gc] GREF GC Threshold: 46800
Comment 7 Jonathan Pryor 2015-02-19 15:19:43 UTC
> E/dalvikvm(24167): Excessive JNI global references (2001)
...
> If '2001' is the gref count that doesnt make sense though, since the app
> was running on hardware, where it says at launch:

What hardware device is this?

Xamarin.Android simply checks the ro.hardware system property to determine if it's an emulator or hardware ("goldfish" means "emulator"). That's all. (Yes, this is stupid, but I don't know of a way to accurately and dynamically determine the actual limit that doesn't involve crashing the process...)

It is thus entirely possible for your hardware vendor to "mis-build" their Android source so that it retains the emulator's 2000 GREF limit instead of the "normal" hardware limit of 52000. (I believe 

Comment #5 shows that the 2000 GREF limit *is* in effect:

> D/dalvikvm(24167): GREF has increased to 2001
...
> W/dalvikvm(24167): JNI global reference table summary (2001 entries):
> W/dalvikvm(24167):    70 of Ljava/lang/Class; 164B (55 unique)
> W/dalvikvm(24167):    54 of Ljava/lang/Class; 188B (24 unique)

Lots of java.lang.Class instances are being created; this may be an unfortunate Xamarin.Android "tax"; as currently implemented, every Java.Lang.Object subclass contains a java.lang.Class of the corresponding type as a GREF, e.g. there will be a Class instance held for all time for your Activity class.

Other instances suggest that you could use some more deliberate cleanup via `using` blocks, Dispose(), or System.GC.Collect() calls: 

> W/dalvikvm(24167):   416 of Landroid/net/NetworkInfo; 52B (416 unique)
> W/dalvikvm(24167):    46 of Landroid/net/NetworkInfo; 60B (46 unique)
Comment 8 Alex 2015-02-20 09:44:32 UTC
Our hardware is this one: http://www.geofanci.com/en/pro_show.asp?id=246 on Android 2.3.7Mr1

ro.hardware gives "pxa910-based"
Comment 9 Jonathan Pryor 2015-02-20 12:35:24 UTC
> ro.hardware gives "pxa910-based"

i.e. it's not "goldfish", meaning Xamarin.Android will believe it's not an emulator, and thus will assume a GREF limit of 52000.

Which is wrong because this device has a limit of 2000.

Can you get in touch with the manufacturer and ask about the GREF limit? 2000 is crazy.

Assuming you need to stick within the GREF limit, you'll need to rigorously track the GREFs you create and work to reduce the GREF count as much as possible, as suggested in Comment #7, with `using` blocks, Dispose() calls, and GC.Collect().

In the forthcoming Xamarin.Android 5.1, you'll also be able to set the debug.mono.max_grefc system property to override the auto-detected GREF limit. You could thus create a new file in your project with a Build action of AndroidEnvironment with the line:

    debug.mono.max_grefc=2000

This will cause your app to act as if there were a 2000 GREF limit -- which there is, on this hardware -- and perform automatic GC's at ~90% of the limit.

Neither of those workarounds is ideal. :-(
Comment 10 Jon Douglas [MSFT] 2017-09-12 18:21:07 UTC
Marking this issue as RESOLVED ANSWERED due to https://bugzilla.xamarin.com/show_bug.cgi?id=26685#c9