Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mono.Android] add "built-in" delegate for _JniMarshal_PPII_L #8245

Merged

Conversation

jonathanpeppers
Copy link
Member

I noticed some methods appear when creating a new .aotprofile for .NET MAUI:

void System.Reflection.Emit.RuntimeILGenerator:.ctor (System.Reflection.Module,System.Reflection.Emit.ITokenGenerator,int)
void System.Reflection.Emit.RuntimeILGenerator:BeginCatchBlock (System.Type)
void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode,int)
void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode,System.Reflection.Emit.Label)
void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode,System.Reflection.Emit.LocalBuilder)
void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode,System.Reflection.MethodInfo)
void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode)

We generally don't want S.R.E to run at application startup. This can happen when Android.Runtime.JNINativeWrapper:CreateBuiltInDelegate doesn't find a match. We fallback to S.R.E in that case.

Running a dotnet new maui app w/ .NET 8 Preview 7 logs the message:

08-07 10:01:51.674 16590 16590 D monodroid-assembly: Falling back to System.Reflection.Emit for delegate type '_JniMarshal_PPII_L': IntPtr n_GetClipPath_II(IntPtr, IntPtr, Int32, Int32)

This may also coincide with AndroidEnableMarshalMethods being turned off by default. We would not have seen this log message when it was on.

After this change, we skip the S.R.E code path:

08-07 10:37:23.089 17661 17661 D Mono    : AOT NOT FOUND: (wrapper native-to-managed) Android.Runtime.JNINativeWrapper:Wrap_JniMarshal_PPII_L (intptr,intptr,int,int).

We should update the .aotprofile in xamarin-android and dotnet/maui after this change.

To update JNINativeWrapper.g.tt:

dotnet tool install -g dotnet-t4
t4 src\Mono.Android\Android.Runtime\JNINativeWrapper.g.tt -o src\Mono.Android\Android.Runtime\JNINativeWrapper.g.cs

Other changes:

  • Fixed code formatting, so we don't have empty tabs in output.

I noticed some methods appear when creating a new `.aotprofile` for .NET
MAUI:

    void System.Reflection.Emit.RuntimeILGenerator:.ctor (System.Reflection.Module,System.Reflection.Emit.ITokenGenerator,int)
    void System.Reflection.Emit.RuntimeILGenerator:BeginCatchBlock (System.Type)
    void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode,int)
    void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode,System.Reflection.Emit.Label)
    void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode,System.Reflection.Emit.LocalBuilder)
    void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode,System.Reflection.MethodInfo)
    void System.Reflection.Emit.RuntimeILGenerator:Emit (System.Reflection.Emit.OpCode)

We generally don't want S.R.E to run at application startup. This can
happen when `Android.Runtime.JNINativeWrapper:CreateBuiltInDelegate`
doesn't find a match. We fallback to S.R.E in that case.

Running a `dotnet new maui` app w/ .NET 8 Preview 7 logs the message:

    08-07 10:01:51.674 16590 16590 D monodroid-assembly: Falling back to System.Reflection.Emit for delegate type '_JniMarshal_PPII_L': IntPtr n_GetClipPath_II(IntPtr, IntPtr, Int32, Int32)

This may also coincide with `AndroidEnableMarshalMethods` being turned
off by default. We would not have seen this log message when it was on.

After this change, we skip the S.R.E code path:

    08-07 10:37:23.089 17661 17661 D Mono    : AOT NOT FOUND: (wrapper native-to-managed) Android.Runtime.JNINativeWrapper:Wrap_JniMarshal_PPII_L (intptr,intptr,int,int).

We should update the `.aotprofile` in xamarin-android and dotnet/maui
after this change.

To update `JNINativeWrapper.g.tt`:

    dotnet tool install -g dotnet-t4
    t4 src\Mono.Android\Android.Runtime\JNINativeWrapper.g.tt -o src\Mono.Android\Android.Runtime\JNINativeWrapper.g.cs

Other changes:

* Fixed code formatting, so we don't have empty tabs in output.
Comment on lines -274 to +280
<#= info.Return != "void" ? "return default;" : "" #>
<#= info.Return != "void" ? "\t\t\t\treturn default;" : "" #>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, the output file had several lines of tabs:

@jonathanpeppers jonathanpeppers merged commit 25b7c27 into dotnet:main Aug 7, 2023
49 checks passed
@jonathanpeppers jonathanpeppers deleted the JNINativeWrapper-net8p7 branch August 7, 2023 21:50
grendello added a commit to grendello/xamarin-android that referenced this pull request Aug 8, 2023
* main:
  Bump com.android.tools:r8 from 8.0.40 to 8.1.56 (dotnet#8240)
  Bump to dotnet/installer@1289a84a55 8.0.100-rc.1.23404.2 (dotnet#8242)
  [Mono.Android] add "built-in" delegate for _JniMarshal_PPII_L (dotnet#8245)
  [Mono.Android] Add `PackageInfoFlagsLong` (dotnet#8182)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants