runtime: .NET 7 exception on Android with EnableLLVM=true

Description

Run with LLVM on an arm64 device, and you can run into:

07-22 09:59:55.062  4374  4374 F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.PlatformNotSupportedException: Arg_PlatformNotSupported
07-22 09:59:55.062  4374  4374 F mono-rt :    at System.Text.ASCIIUtility.GetIndexOfFirstNonAsciiByte_Intrinsified(Byte* , UIntPtr )
07-22 09:59:55.062  4374  4374 F mono-rt :    at System.Text.Unicode.Utf8Utility.GetPointerToFirstInvalidByte(Byte* , Int32 , Int32& , Int32& )
07-22 09:59:55.062  4374  4374 F mono-rt :    at System.Text.UTF8Encoding.GetCharCount(Byte* , Int32 )
07-22 09:59:55.062  4374  4374 F mono-rt :    at System.String.CreateStringFromEncoding(Byte* , Int32 , Encoding )
07-22 09:59:55.062  4374  4374 F mono-rt :    at System.Text.Encoding.GetString(Byte* , Int32 )
07-22 09:59:55.062  4374  4374 F mono-rt :    at System.String.CreateStringForSByteConstructor(Byte* , Int32 )
07-22 09:59:55.062  4374  4374 F mono-rt :    at System.String.Ctor(SByte* value)
07-22 09:59:55.062  4374  4374 F mono-rt :    at Java.Interop.TypeManager.GetClassName(IntPtr )
07-22 09:59:55.062  4374  4374 F mono-rt :    at Android.Runtime.JNIEnv.RegisterJniNatives(IntPtr , Int32 , IntPtr , IntPtr , Int32 )

Somewhere here:

https://github.com/dotnet/runtime/blob/b31a48ae77cf20729387383d15e207f838b0a076/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs#L88

So I think AdvSimd.Arm64.IsSupported is true, but because GetIndexOfFirstNonAsciiByte_Intrinsified() is not in the AOT profile (it’s running under JIT), we get the above exception. It’s possible that the above code should also work under JIT.

/cc @fanyang-mono

Reproduction Steps

  1. dotnet new android
  2. dotnet build -t:Run -c Release -p:EnableLLVM=true to run on an arm64 device (in my case a Pixel 5)

Expected behavior

You can use Profiled AOT + LLVM together on Android.

Actual behavior

We get an exception when trying to use Profiled AOT + LLVM together on Android.

Regression?

I don’t hit this same exception in .NET 6, but maybe it’s just luck?

Known Workarounds

You can turn off profiled AOT, such as -p:AndroidEnableProfiledAot=false or don’t use LLVM.

Configuration

.NET 7.0.100-rc.1.22374.1

Other information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (14 by maintainers)

Commits related to this issue

Most upvoted comments

The issue is: the code that decides if we should use an optimized version of an algorithm sees different IsSupported values than the code that implements the specialized version of the algorithm.

My suggestion was to make sure we always LLVM AOT the implementation, regardless of whether it is used by the profile, so that no fallback to the JIT occurs.