-
Notifications
You must be signed in to change notification settings - Fork 560
[Xamarin.Android.Build.Tasks] make "managed typemap" runtime agnostic #9911
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
Conversation
79061b4
to
32a898f
Compare
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); | ||
} |
There was a problem hiding this comment.
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"...
a4a2896
to
5468780
Compare
827ff6b
to
ffef891
Compare
There was a problem hiding this 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?
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. |
This test is failing on all PRs currently: Fixed by: |
ObjectReferenceManager = new AndroidObjectReferenceManager (); | ||
TypeManager = typeManager ?? new AndroidTypeManager (jniAddNativeMethodRegistrationAttributePresent); | ||
ValueManager = valueManager ?? new AndroidValueManager (); | ||
if (RuntimeFeature.ManagedTypeMap) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should "harmonize" with the AndroidRuntime
and related changes in e347cd3#diff-fbdea37924116ed116877313911e8766b915953b4a9c026bd49f11ba37deb815R26
For example, if this should only be controlled by RuntimeFeature.ManagedTypeMap
, then do we still need the JniRuntime.JniTypeManager? typeManager, JniRuntime.JniValueManager? valueManager
parameters to AndroidRuntimeOptions
and AndroidRuntime
? If not, we can remove those parameters.
Alternatively, maybe the RuntimeFeature.ManagedTypeMap
check should instead happen in JNIEnvInit.cs
?
android/src/Mono.Android/Android.Runtime/JNIEnvInit.cs
Lines 113 to 120 in d1380d9
androidRuntime = new AndroidRuntime ( | |
args->env, | |
args->javaVm, | |
args->grefLoader, | |
null, | |
RuntimeType != DotNetRuntimeType.MonoVM ? new ManagedValueManager () : null, | |
args->jniAddNativeMethodRegistrationAttributePresent != 0 | |
); |
should perhaps instead be:
JniRuntime.JniTypeManager? typeManager;
JniRuntime.JniValueManager? valueManager;
if (RuntimeFeature.ManagedTypeMap || RuntimeType != DotNetRuntimeType.MonoVM) {
typeManager = new ManagedTypeManager ();
valueManager = new ManagedValueManager ();
} else {
typeManager = new AndroidTypeManager (jniAddNativeMethodRegistrationAttributePresent);
valueManager = new AndroidValueManager ();
}
androidRuntime = new AndroidRuntime (
args->env,
args->javaVm,
args->grefLoader,
typeManager,
valueManager,
args->jniAddNativeMethodRegistrationAttributePresent != 0
);
Draft commit message: Context: 684ede6a79da5b95eb9347c319683d8855f84d09
Context: b11471bc574876e148ff40757c5d273fd6fbde9e
For NativeAOT, we implemented a "managed" typemap that is trimmer-safe;
see 684ede6a and b11471bc.
In order to test its performance characteristics, make this typemap
useable for Mono and CoreCLR as well:
* Move `NativeAotTypeManager`, `NativeAotValueManager`, and
`TypeMapping` types to `Mono.Android.dll`
* Rename `NativeAot*` types 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`;
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.
Update `JNIEnvInit.RegisterJniNatives()` to *not* require that
`androidRuntime.TypeManager` be an `AndroidTypeManager`; this allows
`ManagedTypeManager` to be used on MonoVM and CoreCLR. |
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.
b164936
to
a827552
Compare
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
, andTypeMapping
types toMono.Android.dll
Rename
NativeAot*
toManaged*
Add a new private
$(_AndroidTypeMapImplementation)
MSBuild property that can be set tollvm-ir
ormanaged
.Add a new trimmer feature flag
Microsoft.Android.Runtime.RuntimeFeature.ManagedTypeMap
that whentrue
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.