Skip to content

Commit

Permalink
[Mono.Android] Use C#9 Function Pointer backend for JNI (#8234)
Browse files Browse the repository at this point in the history
Context: dotnet/java-interop@312fbf4

As per dotnet/java-interop@312fbf43:

> With a Release build, the Average Invocation time for
> JIFunctionPointersTiming takes 97% of the time as JIPinvokeTiming,
> i.e. is 3% faster.

Additionally, using C#9 Function Pointers means we can get rid of all
of the `java_interop_jnienv_*()` functions, which shrinks
`libmonodroid.so` by ~55KB for each ABI.

This also means that `Java.Interop.dll` can be used as-is on
Windows and macOS, providing a way to get a usable `Java.Interop.dll`
without needing to build the xamarin/Java.Interop repo.
(Though it's unlikely to be *that* useful without a
`Java.Runtime.Environment.dll` to actually bootstrap things…)
  • Loading branch information
jonpryor authored Aug 2, 2023
1 parent ae4f229 commit 180dd52
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 2,318 deletions.
1 change: 1 addition & 0 deletions external/Java.Interop.override.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<XamarinAndroidToolsDirectory>$(MSBuildThisFileDirectory)xamarin-android-tools</XamarinAndroidToolsDirectory>
<Standalone>True</Standalone>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,58 @@
"Size": 1024
},
"assemblies/Java.Interop.dll": {
"Size": 58895
"Size": 61886
},
"assemblies/Mono.Android.dll": {
"Size": 88112
"Size": 88044
},
"assemblies/Mono.Android.Runtime.dll": {
"Size": 5575
"Size": 5509
},
"assemblies/rc.bin": {
"Size": 1302
"Size": 1395
},
"assemblies/System.Console.dll": {
"Size": 6418
"Size": 6400
},
"assemblies/System.Linq.dll": {
"Size": 9212
"Size": 9199
},
"assemblies/System.Private.CoreLib.dll": {
"Size": 548643
"Size": 550507
},
"assemblies/System.Runtime.dll": {
"Size": 2633
"Size": 2621
},
"assemblies/System.Runtime.InteropServices.dll": {
"Size": 3733
"Size": 3858
},
"assemblies/UnnamedProject.dll": {
"Size": 2931
"Size": 2933
},
"classes.dex": {
"Size": 377064
},
"lib/arm64-v8a/libmono-component-marshal-ilgen.so": {
"Size": 97096
"Size": 97080
},
"lib/arm64-v8a/libmonodroid.so": {
"Size": 381088
"Size": 325320
},
"lib/arm64-v8a/libmonosgen-2.0.so": {
"Size": 3184096
"Size": 3189360
},
"lib/arm64-v8a/libSystem.IO.Compression.Native.so": {
"Size": 723560
},
"lib/arm64-v8a/libSystem.Native.so": {
"Size": 93856
"Size": 93920
},
"lib/arm64-v8a/libSystem.Security.Cryptography.Native.Android.so": {
"Size": 154904
},
"lib/arm64-v8a/libxamarin-app.so": {
"Size": 11608
"Size": 11576
},
"META-INF/BNDLTOOL.RSA": {
"Size": 1213
Expand Down Expand Up @@ -95,5 +95,5 @@
"Size": 1904
}
},
"PackageSize": 2787658
"PackageSize": 2783562
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,136 +5,136 @@
"Size": 3572
},
"assemblies/_Microsoft.Android.Resource.Designer.dll": {
"Size": 2102
"Size": 2101
},
"assemblies/FormsViewGroup.dll": {
"Size": 7112
},
"assemblies/Java.Interop.dll": {
"Size": 66808
"Size": 70026
},
"assemblies/Mono.Android.dll": {
"Size": 469914
"Size": 469836
},
"assemblies/Mono.Android.Runtime.dll": {
"Size": 5575
"Size": 5509
},
"assemblies/mscorlib.dll": {
"Size": 3870
"Size": 3859
},
"assemblies/netstandard.dll": {
"Size": 5585
"Size": 5575
},
"assemblies/rc.bin": {
"Size": 1302
"Size": 1395
},
"assemblies/System.Collections.Concurrent.dll": {
"Size": 11524
"Size": 11508
},
"assemblies/System.Collections.dll": {
"Size": 15415
"Size": 15408
},
"assemblies/System.Collections.NonGeneric.dll": {
"Size": 7461
"Size": 7451
},
"assemblies/System.ComponentModel.dll": {
"Size": 1946
"Size": 1935
},
"assemblies/System.ComponentModel.Primitives.dll": {
"Size": 2560
"Size": 2549
},
"assemblies/System.ComponentModel.TypeConverter.dll": {
"Size": 6044
"Size": 6031
},
"assemblies/System.Console.dll": {
"Size": 6588
"Size": 6572
},
"assemblies/System.Core.dll": {
"Size": 1996
"Size": 1984
},
"assemblies/System.Diagnostics.DiagnosticSource.dll": {
"Size": 12529
"Size": 12520
},
"assemblies/System.Diagnostics.TraceSource.dll": {
"Size": 6562
"Size": 6548
},
"assemblies/System.dll": {
"Size": 2350
"Size": 2341
},
"assemblies/System.Drawing.dll": {
"Size": 1944
"Size": 1934
},
"assemblies/System.Drawing.Primitives.dll": {
"Size": 11987
"Size": 11971
},
"assemblies/System.IO.Compression.Brotli.dll": {
"Size": 11196
"Size": 11188
},
"assemblies/System.IO.Compression.dll": {
"Size": 15877
"Size": 15864
},
"assemblies/System.IO.IsolatedStorage.dll": {
"Size": 9887
"Size": 9869
},
"assemblies/System.Linq.dll": {
"Size": 19570
"Size": 19560
},
"assemblies/System.Linq.Expressions.dll": {
"Size": 164694
"Size": 164682
},
"assemblies/System.Net.Http.dll": {
"Size": 69096
"Size": 69544
},
"assemblies/System.Net.Primitives.dll": {
"Size": 22443
"Size": 22431
},
"assemblies/System.Net.Requests.dll": {
"Size": 3609
"Size": 3599
},
"assemblies/System.ObjectModel.dll": {
"Size": 8124
"Size": 8113
},
"assemblies/System.Private.CoreLib.dll": {
"Size": 843541
"Size": 845111
},
"assemblies/System.Private.DataContractSerialization.dll": {
"Size": 192912
"Size": 192906
},
"assemblies/System.Private.Uri.dll": {
"Size": 43487
"Size": 43477
},
"assemblies/System.Private.Xml.dll": {
"Size": 215780
"Size": 215983
},
"assemblies/System.Private.Xml.Linq.dll": {
"Size": 16647
"Size": 16636
},
"assemblies/System.Runtime.dll": {
"Size": 2759
"Size": 2748
},
"assemblies/System.Runtime.InteropServices.dll": {
"Size": 3733
"Size": 3858
},
"assemblies/System.Runtime.Serialization.dll": {
"Size": 1872
"Size": 1861
},
"assemblies/System.Runtime.Serialization.Formatters.dll": {
"Size": 2490
"Size": 2480
},
"assemblies/System.Runtime.Serialization.Primitives.dll": {
"Size": 3769
"Size": 3758
},
"assemblies/System.Security.Cryptography.dll": {
"Size": 8111
"Size": 8099
},
"assemblies/System.Text.RegularExpressions.dll": {
"Size": 158602
"Size": 158865
},
"assemblies/System.Xml.dll": {
"Size": 1765
"Size": 1752
},
"assemblies/System.Xml.Linq.dll": {
"Size": 1782
"Size": 1771
},
"assemblies/UnnamedProject.dll": {
"Size": 4987
Expand Down Expand Up @@ -209,25 +209,25 @@
"Size": 3514720
},
"lib/arm64-v8a/libmono-component-marshal-ilgen.so": {
"Size": 97096
"Size": 97080
},
"lib/arm64-v8a/libmonodroid.so": {
"Size": 381088
"Size": 325320
},
"lib/arm64-v8a/libmonosgen-2.0.so": {
"Size": 3184096
"Size": 3189360
},
"lib/arm64-v8a/libSystem.IO.Compression.Native.so": {
"Size": 723560
},
"lib/arm64-v8a/libSystem.Native.so": {
"Size": 93856
"Size": 93920
},
"lib/arm64-v8a/libSystem.Security.Cryptography.Native.Android.so": {
"Size": 154904
},
"lib/arm64-v8a/libxamarin-app.so": {
"Size": 102800
"Size": 102752
},
"META-INF/android.support.design_material.version": {
"Size": 12
Expand Down Expand Up @@ -1916,5 +1916,5 @@
"Size": 325240
}
},
"PackageSize": 7982094
"PackageSize": 7977998
}
2 changes: 0 additions & 2 deletions src/monodroid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ if(ANDROID AND ENABLE_NET)
list(APPEND XAMARIN_MONODROID_SOURCES
${SOURCES_DIR}/monovm-properties.cc
${SOURCES_DIR}/pinvoke-override-api.cc
${SOURCES_DIR}/java_interop_api.c
${JAVA_INTEROP_SRC_PATH}/java-interop-util.cc
)
else()
Expand All @@ -553,7 +552,6 @@ else()
)

set(XAMARIN_INTERNAL_API_SOURCES
${SOURCES_DIR}/java_interop_api.c
${SOURCES_DIR}/internal-pinvoke-api.cc
${JAVA_INTEROP_SRC_PATH}/java-interop-util.cc
)
Expand Down
Loading

0 comments on commit 180dd52

Please sign in to comment.