Bug 25990 - JIT Crash on Lollipop with SIGSEGV error
Summary: JIT Crash on Lollipop with SIGSEGV error
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.20.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: 4.20.x (C4SR3)
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2015-01-13 14:57 UTC by Dominic N [MSFT]
Modified: 2015-03-12 09:19 UTC (History)
8 users (show)

Tags:
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 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:
VERIFIED FIXED

Description Dominic N [MSFT] 2015-01-13 14:57:49 UTC
## Overview:

A customer is having an issue with an application on Android 5.0 only where it crashes with a SIGSEGV error against Mono. I can confirm the error as well as that the app works on Android KitKat 4.4.


## Steps to reproduce:

1. Open attached sample project
2. Run on Android Lollipop device


## Expected results:

Application runs without issue.


## Actual results:

Application crashes on Lollipop devices with segmentation fault in Mono


## Additional information:

Please test on device. App requires Google Play Services. I've tested on a Nexus 5 for the Lollipop device.

App and fault log will be added separately as private comments.
Comment 2 Ram Chandra 2015-01-14 05:07:39 UTC
I have checked this issue and I am able to reproduce this issue at our end.

When I run the attach sample on android device (5.0) I observed that application is crashed on Nexus 5 (XA 5.0). I have checked the application output and I observed that there is an exception i.e. 

>UNHANDLED EXCEPTION:
[MonoDroid] System.NullReferenceException: Object reference not set to an instance of an object

Exception detail: https://gist.github.com/RamChBachkheti/fc474cf570f81c73b137
Application output https://gist.github.com/RamChBachkheti/6db4a68ce3609cb4d044
Device logs:  https://gist.github.com/RamChBachkheti/0bc84445bbfe67bcfda1

Additional Info: I have checked the same on Samsung S5 (4.4.2)  and getting same behavior.

Please let me know if I can provide more info to this issue.
Environment Info:

=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: 8.6.0.51 (Trial Edition)
Hash: dfb682f
Branch: 
Build date: 2015-01-08 13:39:32-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Trial Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
	Supported Android versions:
		1.6    (API level 4)
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.12.0.3 (Trial Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.10.0
Darwin Jatin66s-iMac.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 5 Jonathan Pryor 2015-01-21 14:18:36 UTC
I observe a different error condition; I get a SIGSEGV, not a NullReferenceException:

> E/mono-rt ( 9025): =================================================================
> E/mono-rt ( 9025): Got a SIGSEGV while executing native code. This usually indicates
> E/mono-rt ( 9025): a fatal error in the mono runtime or one of the native libraries 
> E/mono-rt ( 9025): used by your application.
> E/mono-rt ( 9025): =================================================================
> E/mono-rt ( 9025): 
> F/libc    ( 9025): Fatal signal 11 (SIGSEGV), code 1, fault addr 0xd4 in tid 9081 (pool-1-thread-3)
> I/DEBUG   (  688): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
> I/DEBUG   (  688): Build fingerprint: 'google/hammerhead/hammerhead:5.0.1/LRX22C/1602158:user/release-keys'
> I/DEBUG   (  688): Revision: '11'
> I/DEBUG   (  688): ABI: 'arm'
> I/DEBUG   (  688): pid: 9025, tid: 9081, name: pool-1-thread-3  >>> org.ou.jewniversity <<<
> I/DEBUG   (  688): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xd4
> I/DEBUG   (  688):     r0 00000000  r1 b5042f20  r2 9d4f9c04  r3 00000091
> I/DEBUG   (  688):     r4 b5042f20  r5 b5042f20  r6 a323fc1c  r7 00000000
> I/DEBUG   (  688):     r8 9d4f9ce8  r9 9da09400  sl 00000000  fp 9d4f9bcc
> I/DEBUG   (  688):     ip a323fc3c  sp 9d4f9a80  lr a2f9b868  pc a2f9b888  cpsr 200f0010
> I/DEBUG   (  688): 
> I/DEBUG   (  688): backtrace:
> I/DEBUG   (  688):     #00 pc 0001f888  /data/app/org.ou.jewniversity-1/lib/arm/libmonosgen-2.0.so
> I/DEBUG   (  688):     #01 pc 0001f864  /data/app/org.ou.jewniversity-1/lib/arm/libmonosgen-2.0.so
> I/DEBUG   (  688): 
> I/DEBUG   (  688): Tombstone written to: /data/tombstones/tombstone_08

I see the above via `adb logcat`, not the Application Output window.

Does anybody else see a SIGSEGV?

Furthermore, it dies when attempting to register methods with JNI for the type "OU.CrossPlatform.Campus.Server.CollegeListItem, Jewniversity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null".

I don't currently understand why we die with this particular type and not any of the others.

One question, though: why are you binding and using the com.parse Java library instead of using the existing Parse.NET library? https://parse.com/products/dotnet
Comment 6 liron.kopinsky 2015-01-22 09:18:21 UTC
I'm not using the Parse.Net library because it doesn't support Push notifications.
Comment 7 liron.kopinsky 2015-01-25 02:53:34 UTC
I don't have access to the modified attached project, but the crash on BaseActivity.cs:175 is not related to this issue - probably something is messed up in the attachment. You can bypass that by just adding a null-check or something like that. The fundamental crash comes when calling Find or FindInBackground into the parse library.
Comment 8 liron.kopinsky 2015-02-04 02:53:46 UTC
Any forward progress here?
Comment 11 Zoltan Varga 2015-02-14 02:35:21 UTC
@joao, could you look at this ?
Comment 12 liron.kopinsky 2015-02-16 13:41:54 UTC
What happened to comments 9 and 10? Also, I have an app ready for release but is waiting on this issue. Please try and move this forward!
Comment 13 João Matos 2015-02-23 10:49:47 UTC
Should be fixed in monodroid/aee077ef2528ce8d8c2a19954e5d1f0f793cd3c2.
Comment 14 liron.kopinsky 2015-02-23 10:56:11 UTC
Great. What do I need to do to upgrade Xamarin to use that?
Comment 15 João Matos 2015-02-23 12:19:04 UTC
You'll need to wait for the next version of Monodroid.
Comment 16 Zoltan Varga 2015-02-23 13:57:46 UTC
We are targeting this for a future service release.
Comment 17 liron.kopinsky 2015-02-23 14:03:02 UTC
Are we talking days/weeks or months?
Comment 18 Jonathan Pryor 2015-02-23 14:21:22 UTC
@liron.kopinsky:

> Are we talking days/weeks or months?

I don't know. It's certainly not _days_; weeks or months is more likely.

That said, I think we have a workaround:

The problem is that the "wrong" thread is being used to invoke the CollegeListItem Java type's static initializer; it appears to be some "new" thread.

The workaround is to force the "right" thread to invoke the Java static initializer. (At least, this appeared to work in my simpler testcase.)

Instead of:

>     ParseObject.RegisterSubclass(CollegeListItem.Class);
>     ParseObject.RegisterSubclass(CollegeResourceItem.Class);
>     Parse.Initialize(c, Constants.ParseAppId, Constants.ParseNativeClientKey);

Please try:

>     Parse.Initialize(c, Constants.ParseAppId, Constants.ParseNativeClientKey);
>     try {new CollegeListItem();} catch (Exception e) {Console.WriteLine ("Ignoring; {0}", e);}
>     try {new CollegeResourceItem();} catch (Exception e) {Console.WriteLine ("Ignoring; {0}", e);}
>     ParseObject.RegisterSubclass(CollegeListItem.Class);
>     ParseObject.RegisterSubclass(CollegeResourceItem.Class);
Comment 19 liron.kopinsky 2015-02-23 14:24:32 UTC
Thanks, I'll give that a try.
Comment 20 liron.kopinsky 2015-02-25 04:39:04 UTC
That seemed to fix it. Thanks. Glad this finally got figured out.

Would love to know what the fix was in the mono code.
Comment 21 João Matos 2015-02-25 06:44:13 UTC
There was no need to modify Mono itself, just the layer that mixes the Mono VM with the Java VM.

The problem is that a new thread needed to be registered with the runtime before invoking managed code. Before Android 5 this never seemed to be a problem because the Java runtime re-used threads but it seems now with the ART runtime we're called on threads that were unknown to the runtime before and so we just needed to let the VM know about them before invoking code.
Comment 22 Mohit Kheterpal 2015-03-12 09:19:28 UTC
I have checked this issue and able to reproduce it with stable XA 4.20.0.28 and observed that this issue is fixed with latest build of C4SR3 i.e. mono-android-4.20.0-38_38ac51a9d0866c7726a7484d82632c82c8221594

Hence closing this issue.

Thanks