-
Notifications
You must be signed in to change notification settings - Fork 562
[native] NativeAOT runtime #10461
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
[native] NativeAOT runtime #10461
Changes from all commits
a12b468
a8219ea
f26572c
ab8022f
b715c08
7283f26
22fd8f8
52a14d3
e2b8af3
6001975
0fd2d86
0db919c
3c13a60
94a8b96
a04ba61
1c39ab7
a03f64c
3dc1087
8bb773e
75ab6cb
1bafefa
dd37395
71bfea0
3cbfa4f
cf4140f
68b9a88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash -e | ||
CONFIG=Release | ||
APK="bin/${CONFIG}/net10.0-android/net.dot.hellonativeaot-Signed.apk" | ||
PACKAGE="net.dot.hellonativeaot" | ||
ACTIVITY="my.MainActivity" | ||
|
||
FAILED=no | ||
rm -rf bin obj | ||
../../dotnet-local.sh build -c ${CONFIG} -bl || FAILED=yes | ||
../../dotnet-local.sh msbuild -v:diag msbuild.binlog > msbuild.txt | ||
if [ "${FAILED}" == "yes" ]; then | ||
echo Build failed | ||
exit 1 | ||
fi | ||
|
||
if [ -n "${1}" ]; then | ||
exit 0 | ||
fi | ||
|
||
adb uninstall "${PACKAGE}" || true | ||
adb install -r -d --no-streaming --no-fastdeploy "${APK}" | ||
#adb shell setprop debug.mono.log default,assembly,timing=bare | ||
adb logcat -G 128M | ||
adb logcat -c | ||
adb shell am start -S --user "0" -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "${PACKAGE}/${ACTIVITY}" -W | ||
echo "Waiting for the app to start..." | ||
sleep 5 | ||
adb logcat -d > log.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,8 @@ public AndroidRuntimeOptions (IntPtr jnienv, | |
} | ||
} | ||
|
||
class AndroidObjectReferenceManager : JniRuntime.JniObjectReferenceManager { | ||
// TODO: this shouldn't be public | ||
public class AndroidObjectReferenceManager : JniRuntime.JniObjectReferenceManager { | ||
Comment on lines
+105
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only thing we'll need to fix ASAP next week. |
||
public override int GlobalReferenceCount { | ||
get {return RuntimeNativeMethods._monodroid_gref_get ();} | ||
} | ||
|
@@ -186,7 +187,7 @@ public override JniObjectReference CreateGlobalReference (JniObjectReference val | |
var from = log ? new StringBuilder (new StackTrace (true).ToString ()) : null; | ||
int gc = RuntimeNativeMethods._monodroid_gref_log_new (value.Handle, ctype, r.Handle, ntype, tname, tid, from, 1); | ||
if (gc >= JNIEnvInit.gref_gc_threshold) { | ||
Logger.Log (LogLevel.Info, "monodroid-gc", gc + " outstanding GREFs. Performing a full GC!"); | ||
Logger.Log (LogLevel.Debug, "monodroid-gc", gc + " outstanding GREFs. Performing a full GC!"); | ||
System.GC.Collect (); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,10 @@ static Type TypeGetType (string typeName) => | |
internal static void InitializeJniRuntime (JniRuntime runtime) | ||
{ | ||
androidRuntime = runtime; | ||
gref_gc_threshold = RuntimeNativeMethods._monodroid_max_gref_get (); | ||
if (gref_gc_threshold != int.MaxValue) { | ||
gref_gc_threshold = checked((gref_gc_threshold * 9) / 10); | ||
} | ||
Comment on lines
+86
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this taking 90% of this number for all runtimes? Do we need this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other runtimes set |
||
SetSynchronizationContext (); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. | |
<Project> | ||
|
||
<UsingTask TaskName="Xamarin.Android.Tasks.SetNdkPathForIlc" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" /> | ||
<UsingTask TaskName="Xamarin.Android.Tasks.GenerateNativeAotLibraryLoadAssemblerSources" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" /> | ||
<UsingTask TaskName="Xamarin.Android.Tasks.GenerateNativeAotEnvironmentAssemblerSources" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" /> | ||
|
||
<!-- Default property values for NativeAOT --> | ||
<PropertyGroup> | ||
|
@@ -93,6 +95,9 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. | |
<ItemGroup> | ||
<!-- Android needs a proper soname property or it will refuse to load the library --> | ||
<LinkerArg Include=""-Wl,-soname,lib$(TargetName)$(NativeBinaryExt)"" /> | ||
<LinkerArg Include="-Wl,--error-unresolved-symbols" /> | ||
<LinkerArg Include="-Wl,--no-undefined" /> | ||
|
||
<!-- Required for [UnmanagedCallersOnly] to work inside this assembly --> | ||
<UnmanagedEntryPointsAssembly Include="Microsoft.Android.Runtime.NativeAOT" /> | ||
<!-- Give ILLink's output to ILC --> | ||
|
@@ -110,7 +115,85 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. | |
<ResolvedFileToPublish Include="$(_NdkSysrootDir)libc++_shared.so" RuntimeIdentifier="$(RuntimeIdentifier)" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be removed? Are we statically linking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're not right now because NativeAOT has a compatibility library that conflicts with static There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it makes sense to split that off into separate PR. I suppose you can remove the shim There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to keep both references to |
||
<!-- Satellite assemblies --> | ||
<IlcSatelliteAssembly Include="$(_OuterIntermediateSatelliteAssembliesWithTargetPath)" /> | ||
|
||
<LinkerArg Include="@(RuntimePackAsset->WithMetadataValue('Filename', 'libnaot-android.$(Configuration.ToLower())-static-$(Configuration.ToLower())'))" /> | ||
<LinkerArg Include="$(_NdkSysrootDir)libc++_shared.so" /> | ||
|
||
<!-- Every p/invoke using the `xa-internal-api` "library" will be called directly --> | ||
<DirectPInvoke Include="xa-internal-api" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_PrepareNativeAotAndroidAppInputs"> | ||
<ItemGroup> | ||
<_PrivateBuildTargetAbi Condition=" '$(RuntimeIdentifier)' == 'android-arm64' " Include="arm64-v8a" /> | ||
<_PrivateBuildTargetAbi Condition=" '$(RuntimeIdentifier)' == 'android-x64' " Include="x86_64" /> | ||
</ItemGroup> | ||
|
||
<PrepareAbiItems | ||
BuildTargetAbis="@(_PrivateBuildTargetAbi)" | ||
NativeSourcesDir="$(_NativeAssemblySourceDir)" | ||
Debug="$(AndroidIncludeDebugSymbols)" | ||
Mode="jni_init"> | ||
<Output TaskParameter="AssemblySources" ItemName="_PrivateJniInitFuncsAssemblySource" /> | ||
</PrepareAbiItems> | ||
|
||
<PrepareAbiItems | ||
BuildTargetAbis="@(_PrivateBuildTargetAbi)" | ||
NativeSourcesDir="$(_NativeAssemblySourceDir)" | ||
Debug="$(AndroidIncludeDebugSymbols)" | ||
Mode="environment"> | ||
<Output TaskParameter="AssemblySources" ItemName="_PrivateEnvironmentAssemblySource" /> | ||
</PrepareAbiItems> | ||
|
||
<ItemGroup> | ||
<_PrivateJniInitFuncsNativeObjectFile Include="@(_PrivateJniInitFuncsAssemblySource->'$([System.IO.Path]::ChangeExtension('%(Identity)', '.o'))')"> | ||
<abi>%(_PrivateJniInitFuncsAssemblySource.abi)</abi> | ||
</_PrivateJniInitFuncsNativeObjectFile> | ||
|
||
<_PrivateEnvironmentNativeObjectFile Include="@(_PrivateEnvironmentAssemblySource->'$([System.IO.Path]::ChangeExtension('%(Identity)', '.o'))')"> | ||
<abi>%(_PrivateEnvironmentAssemblySource.abi)</abi> | ||
</_PrivateEnvironmentNativeObjectFile> | ||
|
||
<_PrivateAndroidNaotResolvedAssemblyFiles Include="@(ResolvedFileToPublish->Distinct())" Condition=" '%(ResolvedFileToPublish.Extension)' == '.dll' " /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target | ||
Name="_GenerateNativeAotAndroidAppAssemblerSources" | ||
DependsOnTargets="_GenerateEnvironmentFiles;_PrepareNativeAotAndroidAppInputs" | ||
Inputs="@(_PrivateAndroidNaotResolvedAssemblyFiles);@(AndroidEnvironment);@(LibraryEnvironments)" | ||
Outputs="@(_PrivateJniInitFuncsAssemblySource);@(_PrivateJniInitFuncsNativeObjectFile);@(_PrivateEnvironmentAssemblySource);@(_PrivateEnvironmentNativeObjectFile)"> | ||
<GenerateNativeAotLibraryLoadAssemblerSources | ||
ResolvedAssemblies="@(_PrivateAndroidNaotResolvedAssemblyFiles)" | ||
CustomJniInitFunctions="@(AndroidStaticJniInitFunction)" | ||
OutputSources="@(_PrivateJniInitFuncsAssemblySource)" /> | ||
|
||
<GenerateNativeAotEnvironmentAssemblerSources | ||
Debug="$(AndroidIncludeDebugSymbols)" | ||
Environments="@(AndroidEnvironment);@(LibraryEnvironments)" | ||
HttpClientHandlerType="$(AndroidHttpClientHandlerType)" | ||
OutputSources="@(_PrivateEnvironmentAssemblySource)" | ||
RID="$(RuntimeIdentifier)" /> | ||
|
||
<CompileNativeAssembly | ||
Sources="@(_PrivateJniInitFuncsAssemblySource);@(_PrivateEnvironmentAssemblySource)" | ||
DebugBuild="$(AndroidIncludeDebugSymbols)" | ||
WorkingDirectory="$(_NativeAssemblySourceDir)" | ||
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)" /> | ||
|
||
<ItemGroup> | ||
<LinkerArg Include="@(_PrivateJniInitFuncsNativeObjectFile)" /> | ||
<LinkerArg Include="@(_PrivateEnvironmentNativeObjectFile)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<!-- Make sure we have a chance to generate our application-specific static library before linking | ||
takes place. We must run after `IlcCompile`, which is a dependency of `LinkNative` --> | ||
<Target | ||
Name="_GenerateNativeAotAndroidAppLibrary" | ||
AfterTargets="IlcCompile" | ||
DependsOnTargets="_GenerateNativeAotAndroidAppAssemblerSources"> | ||
</Target> | ||
|
||
<Target Name="_AndroidFixNativeLibraryFileName" AfterTargets="ComputeFilesToPublish"> | ||
|
Uh oh!
There was an error while loading. Please reload this page.