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

[Xamarin.Android.Build.Tasks] make "managed typemap" runtime agnostic #9911

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Mar 12, 2025

For NativeAOT, we implemented a "managed" typemap that is trimmer-safe.

In order to test its performance characteristics, we can make this typemap useable for Mono and CoreCLR as well:

  • Move NativeAotTypeManager, NativeAotValueManager, and TypeMapping types to Mono.Android.dll

  • Rename NativeAot* to Managed*

  • Add a new private $(_AndroidTypeMapImplementation) MSBuild property that can be set to llvm-ir or managed.

  • Add a new trimmer feature flag Microsoft.Android.Runtime.RuntimeFeature.ManagedTypeMap that when true uses the managed typemap on any runtime.

I added a test that verifies dotnet run succeeds for all typemap implementations.

Note that NativeAOT will only support the managed typemap.

@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/runtime-agnostic-typemap branch from 79061b4 to 32a898f Compare March 12, 2025 21:28
Comment on lines +86 to +89
if (TypemapImplementation != "llvm-ir") {
Log.LogDebugMessage ($"TypemapImplementation='{TypemapImplementation}' will write an empty native typemap.");
state = new NativeCodeGenState (state.TargetArch, new TypeDefinitionCache (), state.Resolver, [], [], state.Classifier);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of returning early, I made this write the native assembly with a typemap of 0 entries, this prevents the crash at runtime:

03-12 12:36:53.682 29155 29155 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "java_type_count" referenced by "/data/app/~~sPVK03Ot__92Sd7QEgoNXw==/com.companyname.helloandroid-EN9cYvEYQtDuCTIXF_jW0Q==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libmonodroid.so"...

@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/runtime-agnostic-typemap branch 3 times, most recently from a4a2896 to 5468780 Compare March 26, 2025 15:43
For NativeAOT, we implemented a "managed" typemap that is trimmer-safe.

In order to test its performance characteristics, we can make this
typemap useable for Mono and CoreCLR as well:

* Move `NativeAotTypeManager`, `NativeAotValueManager`, and
  `TypeMapping` types to `Mono.Android.dll`

* Rename `NativeAot*` to `Managed*`

* Add a new private `$(_AndroidTypeMapImplementation)` MSBuild
  property that can be set to `llvm-ir` or `managed`.

* Add a new trimmer feature flag
  `Android.Runtime.RuntimeFeature.ManagedTypeMap` that when `true`
  uses the managed typemap on any runtime.

I added a test that verifies `dotnet run` succeeds for all typemap
implementations.

Note that NativeAOT will *only* support the managed typemap.
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/runtime-agnostic-typemap branch from 827ff6b to ffef891 Compare March 27, 2025 13:56
@jonathanpeppers jonathanpeppers marked this pull request as ready for review March 27, 2025 16:10
Copy link
Contributor

@dellis1972 dellis1972 left a comment

Choose a reason for hiding this comment

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

Looks ok , what are the benefits of being able to use the managed typemap over the other one?

@jonathanpeppers
Copy link
Member Author

Looks ok , what are the benefits of being able to use the managed typemap over the other one?

We want to be able to test the performance of the managed typemap vs the native one. Ideally, we'd do this using the same runtime, so either Mono or CoreCLR.

@jonathanpeppers
Copy link
Member Author

This test is failing on all PRs currently:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants