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

NativeAOT TODO list #9784

Open
8 tasks
jonathanpeppers opened this issue Feb 12, 2025 · 3 comments
Open
8 tasks

NativeAOT TODO list #9784

jonathanpeppers opened this issue Feb 12, 2025 · 3 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Milestone

Comments

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Feb 12, 2025

What do we need to do for NativeAOT?

  • dotnet new android && dotnet publish -p:PublishAot=true
  • dotnet new maui runs: [WIP] turn NativeAOT sample into a .NET MAUI app #9747
  • Parse Android system properties like debug.mono.log, to disable lref/gref logging
  • MSBuild warning for non-Mono runtimes, that says "experimental"
  • Default $(PublishAotUsingRuntimePack)=true, and see what xamarin/xamarin-macios does
  • Get Mono.Android-Tests running on NativeAOT
  • Mono-specific startup settings like Timezone notifications, unhandled exceptions, System.Threading.Tasks SyncContext.
  • Solve all NativeAOT trimmer warnings
@jonathanpeppers jonathanpeppers added the Area: App+Library Build Issues when building Library projects or Application projects. label Feb 12, 2025
@jonathanpeppers jonathanpeppers self-assigned this Feb 12, 2025
@dotnet-policy-service dotnet-policy-service bot added the needs-triage Issues that need to be assigned. label Feb 12, 2025
@jonathanpeppers jonathanpeppers removed the needs-triage Issues that need to be assigned. label Feb 12, 2025
@jonathanpeppers jonathanpeppers added this to the .NET 10 milestone Feb 12, 2025
@jonpryor
Copy link
Member

Alternate "MVP 1.1" typemap idea, for posterity: instead of a Dictionary<string, Type>, have two fields:

  1. Dictionary<string, RuntimeTypeHandle> or string[]+RuntimeTypeHandle[] pair, plus
  2. Dictionary<string, Type>

The linker step would populate (1), which might be faster because RuntimeTypeHandle is a stuct.

At runtime, consult (2) first, and if a type mapping doesn't exist, use (1) to lookup the RuntimeTypeHandle + Type.GetTypeFromHandle(RuntimeTypeHandle), caching the result in (2).

Questions:

  • Can we lookup the RuntimeTypeHandle value from Cecil?
  • The caching will require locking. What kind of overhead will this imply?

@jonathanpeppers
Copy link
Member Author

jonathanpeppers commented Feb 12, 2025

There must be a way to use a TypeHandle with Mono.Cecil, as the IL "typemap MVP 1.0" is writing is doing this:

/*
* IL_0000: ldarg.0
* IL_0001: ldfld class [System.Runtime]System.Collections.Generic.IDictionary`2<string, class [System.Runtime]System.Type> Microsoft.Android.Runtime.NativeAotTypeManager::TypeMappings
* IL_0006: ldstr "java/lang/Object"
* IL_000b: ldtoken [Mono.Android]Java.Lang.Object
* IL_0010: call class [System.Runtime]System.Type [System.Runtime]System.Type::GetTypeFromHandle(valuetype [System.Runtime]System.RuntimeTypeHandle)
* IL_0015: callvirt instance void class [System.Runtime]System.Collections.Generic.IDictionary`2<string, class [System.Runtime]System.Type>::Add(!0, !1)
*/
il.Emit (Mono.Cecil.Cil.OpCodes.Ldarg_0);
il.Emit (Mono.Cecil.Cil.OpCodes.Ldfld, field);
il.Emit (Mono.Cecil.Cil.OpCodes.Ldstr, javaKey);
il.Emit (Mono.Cecil.Cil.OpCodes.Ldtoken, module.ImportReference (typeDefinition));
il.Emit (Mono.Cecil.Cil.OpCodes.Call, getTypeFromHandle);
il.Emit (Mono.Cecil.Cil.OpCodes.Callvirt, addMethod);

@filipnavara
Copy link
Member

Ldtoken returns RuntimeTypeHandle so you can use that in the dictionary. It's, however, not a pattern that can be represented in C# and ILSpy will not decode it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests

3 participants