diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc index a415e51ee10..440fba739f4 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc @@ -5,55 +5,55 @@ "Size": 3032 }, "assemblies/Java.Interop.dll": { - "Size": 58990 + "Size": 58920 }, "assemblies/Mono.Android.dll": { - "Size": 87490 + "Size": 87624 }, "assemblies/Mono.Android.Runtime.dll": { - "Size": 5860 + "Size": 5862 }, "assemblies/rc.bin": { "Size": 1182 }, "assemblies/System.Console.dll": { - "Size": 6627 + "Size": 6594 }, "assemblies/System.Linq.dll": { - "Size": 9252 + "Size": 9259 }, "assemblies/System.Private.CoreLib.dll": { - "Size": 470830 + "Size": 478515 }, "assemblies/System.Runtime.dll": { - "Size": 2626 + "Size": 2632 }, "assemblies/System.Runtime.InteropServices.dll": { - "Size": 2267 + "Size": 2272 }, "assemblies/UnnamedProject.dll": { - "Size": 3629 + "Size": 3633 }, "classes.dex": { "Size": 18968 }, "lib/arm64-v8a/libmonodroid.so": { - "Size": 434632 + "Size": 379008 }, "lib/arm64-v8a/libmonosgen-2.0.so": { - "Size": 3076080 + "Size": 3077928 }, "lib/arm64-v8a/libSystem.IO.Compression.Native.so": { "Size": 723840 }, "lib/arm64-v8a/libSystem.Native.so": { - "Size": 94136 + "Size": 94232 }, "lib/arm64-v8a/libSystem.Security.Cryptography.Native.Android.so": { "Size": 149552 }, "lib/arm64-v8a/libxamarin-app.so": { - "Size": 16128 + "Size": 16336 }, "META-INF/BNDLTOOL.RSA": { "Size": 1213 @@ -65,19 +65,19 @@ "Size": 2667 }, "res/drawable-hdpi-v4/icon.png": { - "Size": 4762 + "Size": 2178 }, "res/drawable-mdpi-v4/icon.png": { - "Size": 2200 + "Size": 1490 }, "res/drawable-xhdpi-v4/icon.png": { - "Size": 7462 + "Size": 3098 }, "res/drawable-xxhdpi-v4/icon.png": { - "Size": 13092 + "Size": 4674 }, "res/drawable-xxxhdpi-v4/icon.png": { - "Size": 20118 + "Size": 6832 }, "res/layout/main.xml": { "Size": 544 @@ -89,5 +89,5 @@ "Size": 1904 } }, - "PackageSize": 2590859 + "PackageSize": 2549899 } \ No newline at end of file diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleLegacy.apkdesc b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleLegacy.apkdesc index cb7562922f1..3ad34c64338 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleLegacy.apkdesc +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleLegacy.apkdesc @@ -8,19 +8,19 @@ "Size": 68913 }, "assemblies/Mono.Android.dll": { - "Size": 265169 + "Size": 265160 }, "assemblies/mscorlib.dll": { - "Size": 769018 + "Size": 769019 }, "assemblies/System.Core.dll": { - "Size": 28199 + "Size": 28198 }, "assemblies/System.dll": { - "Size": 9180 + "Size": 9179 }, "assemblies/UnnamedProject.dll": { - "Size": 2882 + "Size": 2880 }, "classes.dex": { "Size": 370828 @@ -32,7 +32,7 @@ "Size": 750976 }, "lib/arm64-v8a/libmonodroid.so": { - "Size": 332936 + "Size": 277520 }, "lib/arm64-v8a/libmonosgen-2.0.so": { "Size": 4039176 @@ -74,5 +74,5 @@ "Size": 1724 } }, - "PackageSize": 4003540 + "PackageSize": 3987156 } \ No newline at end of file diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsDotNet.apkdesc b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsDotNet.apkdesc index 1ba0e20a20c..6fa5f4b1cae 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsDotNet.apkdesc +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsDotNet.apkdesc @@ -8,19 +8,19 @@ "Size": 7314 }, "assemblies/Java.Interop.dll": { - "Size": 66843 + "Size": 66793 }, "assemblies/Mono.Android.dll": { - "Size": 444299 + "Size": 444690 }, "assemblies/Mono.Android.Runtime.dll": { - "Size": 5921 + "Size": 5862 }, "assemblies/mscorlib.dll": { - "Size": 3860 + "Size": 3859 }, "assemblies/netstandard.dll": { - "Size": 5576 + "Size": 5575 }, "assemblies/rc.bin": { "Size": 1182 @@ -29,106 +29,106 @@ "Size": 10725 }, "assemblies/System.Collections.dll": { - "Size": 15465 + "Size": 15460 }, "assemblies/System.Collections.NonGeneric.dll": { - "Size": 7638 + "Size": 7633 }, "assemblies/System.ComponentModel.dll": { - "Size": 2158 + "Size": 2157 }, "assemblies/System.ComponentModel.Primitives.dll": { - "Size": 2649 + "Size": 2648 }, "assemblies/System.ComponentModel.TypeConverter.dll": { - "Size": 6206 + "Size": 6205 }, "assemblies/System.Console.dll": { - "Size": 6760 + "Size": 6759 }, "assemblies/System.Core.dll": { - "Size": 1988 + "Size": 1987 }, "assemblies/System.Diagnostics.TraceSource.dll": { - "Size": 6745 + "Size": 6742 }, "assemblies/System.dll": { - "Size": 2344 + "Size": 2343 }, "assemblies/System.Drawing.dll": { - "Size": 2029 + "Size": 2028 }, "assemblies/System.Drawing.Primitives.dll": { - "Size": 12160 + "Size": 12095 }, "assemblies/System.IO.Compression.dll": { - "Size": 16797 + "Size": 16984 }, "assemblies/System.IO.IsolatedStorage.dll": { - "Size": 10155 + "Size": 10162 }, "assemblies/System.Linq.dll": { - "Size": 19493 + "Size": 19494 }, "assemblies/System.Linq.Expressions.dll": { - "Size": 163967 + "Size": 163942 }, "assemblies/System.Net.Http.dll": { - "Size": 67013 + "Size": 65586 }, "assemblies/System.Net.Primitives.dll": { "Size": 22021 }, "assemblies/System.Net.Requests.dll": { - "Size": 3745 + "Size": 3743 }, "assemblies/System.ObjectModel.dll": { - "Size": 8173 + "Size": 8166 }, "assemblies/System.Private.CoreLib.dll": { - "Size": 775898 + "Size": 780751 }, "assemblies/System.Private.DataContractSerialization.dll": { - "Size": 192465 + "Size": 192055 }, "assemblies/System.Private.Uri.dll": { - "Size": 42550 + "Size": 42554 }, "assemblies/System.Private.Xml.dll": { - "Size": 215747 + "Size": 215680 }, "assemblies/System.Private.Xml.Linq.dll": { - "Size": 16813 + "Size": 16807 }, "assemblies/System.Runtime.dll": { "Size": 2794 }, "assemblies/System.Runtime.InteropServices.dll": { - "Size": 2273 + "Size": 2272 }, "assemblies/System.Runtime.Serialization.dll": { - "Size": 1950 + "Size": 1949 }, "assemblies/System.Runtime.Serialization.Formatters.dll": { - "Size": 2683 + "Size": 2681 }, "assemblies/System.Runtime.Serialization.Primitives.dll": { - "Size": 3856 + "Size": 3854 }, "assemblies/System.Security.Cryptography.dll": { - "Size": 7949 + "Size": 7947 }, "assemblies/System.Text.RegularExpressions.dll": { - "Size": 154213 + "Size": 155427 }, "assemblies/System.Xml.dll": { "Size": 1837 }, "assemblies/System.Xml.Linq.dll": { - "Size": 1862 + "Size": 1861 }, "assemblies/UnnamedProject.dll": { - "Size": 117372 + "Size": 117398 }, "assemblies/Xamarin.AndroidX.Activity.dll": { "Size": 5872 @@ -200,22 +200,22 @@ "Size": 3090508 }, "lib/arm64-v8a/libmonodroid.so": { - "Size": 434632 + "Size": 379008 }, "lib/arm64-v8a/libmonosgen-2.0.so": { - "Size": 3078808 + "Size": 3077928 }, "lib/arm64-v8a/libSystem.IO.Compression.Native.so": { "Size": 723840 }, "lib/arm64-v8a/libSystem.Native.so": { - "Size": 94136 + "Size": 94232 }, "lib/arm64-v8a/libSystem.Security.Cryptography.Native.Android.so": { "Size": 149552 }, "lib/arm64-v8a/libxamarin-app.so": { - "Size": 333376 + "Size": 333336 }, "META-INF/android.support.design_material.version": { "Size": 12 @@ -782,7 +782,7 @@ "Size": 470 }, "res/drawable-hdpi-v4/icon.png": { - "Size": 4762 + "Size": 2178 }, "res/drawable-hdpi-v4/notification_bg_low_normal.9.png": { "Size": 212 @@ -992,7 +992,7 @@ "Size": 309 }, "res/drawable-mdpi-v4/icon.png": { - "Size": 2200 + "Size": 1490 }, "res/drawable-mdpi-v4/notification_bg_low_normal.9.png": { "Size": 215 @@ -1220,7 +1220,7 @@ "Size": 593 }, "res/drawable-xhdpi-v4/icon.png": { - "Size": 7462 + "Size": 3098 }, "res/drawable-xhdpi-v4/notification_bg_low_normal.9.png": { "Size": 221 @@ -1385,7 +1385,7 @@ "Size": 868 }, "res/drawable-xxhdpi-v4/icon.png": { - "Size": 13092 + "Size": 4674 }, "res/drawable-xxxhdpi-v4/abc_btn_check_to_on_mtrl_000.png": { "Size": 275 @@ -1472,7 +1472,7 @@ "Size": 1155 }, "res/drawable-xxxhdpi-v4/icon.png": { - "Size": 20118 + "Size": 6832 }, "res/drawable/abc_btn_borderless_material.xml": { "Size": 588 @@ -1970,5 +1970,5 @@ "Size": 341228 } }, - "PackageSize": 7971397 + "PackageSize": 7930437 } \ No newline at end of file diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsLegacy.apkdesc b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsLegacy.apkdesc index ac496de717d..e7d03c442f3 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsLegacy.apkdesc +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsLegacy.apkdesc @@ -11,25 +11,25 @@ "Size": 69956 }, "assemblies/Mono.Android.dll": { - "Size": 572709 + "Size": 572698 }, "assemblies/Mono.Security.dll": { - "Size": 68432 + "Size": 68433 }, "assemblies/mscorlib.dll": { - "Size": 915408 + "Size": 915407 }, "assemblies/System.Core.dll": { - "Size": 164046 + "Size": 164047 }, "assemblies/System.dll": { - "Size": 388864 + "Size": 388865 }, "assemblies/System.Drawing.Common.dll": { "Size": 12365 }, "assemblies/System.Net.Http.dll": { - "Size": 110693 + "Size": 110692 }, "assemblies/System.Numerics.dll": { "Size": 15683 @@ -38,13 +38,13 @@ "Size": 186660 }, "assemblies/System.ServiceModel.Internals.dll": { - "Size": 26594 + "Size": 26593 }, "assemblies/System.Xml.dll": { - "Size": 395656 + "Size": 395657 }, "assemblies/UnnamedProject.dll": { - "Size": 116899 + "Size": 116985 }, "assemblies/Xamarin.AndroidX.Activity.dll": { "Size": 7697 @@ -65,19 +65,19 @@ "Size": 131930 }, "assemblies/Xamarin.AndroidX.DrawerLayout.dll": { - "Size": 15426 + "Size": 15425 }, "assemblies/Xamarin.AndroidX.Fragment.dll": { "Size": 43135 }, "assemblies/Xamarin.AndroidX.Legacy.Support.Core.UI.dll": { - "Size": 6715 + "Size": 6714 }, "assemblies/Xamarin.AndroidX.Lifecycle.Common.dll": { "Size": 7062 }, "assemblies/Xamarin.AndroidX.Lifecycle.LiveData.Core.dll": { - "Size": 7193 + "Size": 7194 }, "assemblies/Xamarin.AndroidX.Lifecycle.ViewModel.dll": { "Size": 4873 @@ -92,7 +92,7 @@ "Size": 6268 }, "assemblies/Xamarin.AndroidX.SwipeRefreshLayout.dll": { - "Size": 11271 + "Size": 11272 }, "assemblies/Xamarin.AndroidX.ViewPager.dll": { "Size": 19424 @@ -107,7 +107,7 @@ "Size": 56878 }, "assemblies/Xamarin.Forms.Xaml.dll": { - "Size": 55801 + "Size": 55799 }, "assemblies/Xamarin.Google.Android.Material.dll": { "Size": 43497 @@ -122,7 +122,7 @@ "Size": 750976 }, "lib/arm64-v8a/libmonodroid.so": { - "Size": 332936 + "Size": 277520 }, "lib/arm64-v8a/libmonosgen-2.0.so": { "Size": 4039176 @@ -1883,5 +1883,5 @@ "Size": 341040 } }, - "PackageSize": 9521310 + "PackageSize": 9504926 } \ No newline at end of file diff --git a/src/monodroid/jni/embedded-assemblies.cc b/src/monodroid/jni/embedded-assemblies.cc index 3550435dc75..82b7607f437 100644 --- a/src/monodroid/jni/embedded-assemblies.cc +++ b/src/monodroid/jni/embedded-assemblies.cc @@ -35,6 +35,7 @@ #include "mono-image-loader.hh" #include "xamarin-app.hh" #include "cpp-util.hh" +#include "monodroid-glue-internal.hh" #include "startup-aware-lock.hh" #include "timing-internal.hh" #include "search.hh" @@ -73,6 +74,13 @@ void EmbeddedAssemblies::set_assemblies_prefix (const char *prefix) assemblies_prefix_override = prefix != nullptr ? utils.strdup_new (prefix) : nullptr; } +force_inline void +EmbeddedAssemblies::set_assembly_data_and_size (uint8_t* source_assembly_data, uint32_t source_assembly_data_size, uint8_t*& dest_assembly_data, uint32_t& dest_assembly_data_size) noexcept +{ + dest_assembly_data = source_assembly_data; + dest_assembly_data_size = source_assembly_data_size; +} + force_inline void EmbeddedAssemblies::get_assembly_data (uint8_t *data, uint32_t data_size, [[maybe_unused]] const char *name, uint8_t*& assembly_data, uint32_t& assembly_data_size) noexcept { @@ -91,17 +99,18 @@ EmbeddedAssemblies::get_assembly_data (uint8_t *data, uint32_t data_size, [[mayb CompressedAssemblyDescriptor &cad = compressed_assemblies.descriptors[header->descriptor_index]; assembly_data_size = data_size - sizeof(CompressedAssemblyHeader); if (!cad.loaded) { + StartupAwareLock decompress_lock (assembly_decompress_mutex); + + if (cad.loaded) { + set_assembly_data_and_size (reinterpret_cast(cad.data), cad.uncompressed_file_size, assembly_data, assembly_data_size); + return; + } + if (XA_UNLIKELY (cad.data == nullptr)) { log_fatal (LOG_ASSEMBLY, "Invalid compressed assembly descriptor at %u: no data", header->descriptor_index); Helpers::abort_application (); } - bool log_timing = FastTiming::enabled () && !FastTiming::is_bare_mode (); - size_t decompress_time_index; - if (XA_UNLIKELY (log_timing)) { - decompress_time_index = internal_timing->start_event (TimingEventKind::AssemblyDecompression); - } - if (header->uncompressed_length != cad.uncompressed_file_size) { if (header->uncompressed_length > cad.uncompressed_file_size) { log_fatal (LOG_ASSEMBLY, "Compressed assembly '%s' is larger than when the application was built (expected at most %u, got %u). Assemblies don't grow just like that!", name, cad.uncompressed_file_size, header->uncompressed_length); @@ -115,11 +124,6 @@ EmbeddedAssemblies::get_assembly_data (uint8_t *data, uint32_t data_size, [[mayb const char *data_start = reinterpret_cast(data + sizeof(CompressedAssemblyHeader)); int ret = LZ4_decompress_safe (data_start, reinterpret_cast(cad.data), static_cast(assembly_data_size), static_cast(cad.uncompressed_file_size)); - if (XA_UNLIKELY (log_timing)) { - internal_timing->end_event (decompress_time_index, true /* uses_more_info */); - internal_timing->add_more_info (decompress_time_index, name); - } - if (ret < 0) { log_fatal (LOG_ASSEMBLY, "Decompression of assembly %s failed with code %d", name, ret); Helpers::abort_application (); @@ -131,13 +135,12 @@ EmbeddedAssemblies::get_assembly_data (uint8_t *data, uint32_t data_size, [[mayb } cad.loaded = true; } - assembly_data = reinterpret_cast(cad.data); - assembly_data_size = cad.uncompressed_file_size; + + set_assembly_data_and_size (reinterpret_cast(cad.data), cad.uncompressed_file_size, assembly_data, assembly_data_size); } else #endif { - assembly_data = data; - assembly_data_size = data_size; + set_assembly_data_and_size (data, data_size, assembly_data, assembly_data_size); } } @@ -357,9 +360,6 @@ EmbeddedAssemblies::assembly_store_open_from_bundles (dynamic_local_stringdata_size, assembly_runtime_info.descriptor->debug_data_size, - assembly_runtime_info.descriptor->config_data_size + assembly_runtime_info.descriptor->config_data_size, + name.get () ); } diff --git a/src/monodroid/jni/embedded-assemblies.hh b/src/monodroid/jni/embedded-assemblies.hh index 58f12334e49..4b4c3324dae 100644 --- a/src/monodroid/jni/embedded-assemblies.hh +++ b/src/monodroid/jni/embedded-assemblies.hh @@ -223,9 +223,10 @@ namespace xamarin::android::internal { #else // def NET static MonoAssembly* open_from_bundles_refonly (MonoAssemblyName *aname, char **assemblies_path, void *user_data); #endif // ndef NET - static void get_assembly_data (uint8_t *data, uint32_t data_size, const char *name, uint8_t*& assembly_data, uint32_t& assembly_data_size) noexcept; - static void get_assembly_data (XamarinAndroidBundledAssembly const& e, uint8_t*& assembly_data, uint32_t& assembly_data_size) noexcept; - static void get_assembly_data (AssemblyStoreSingleAssemblyRuntimeData const& e, uint8_t*& assembly_data, uint32_t& assembly_data_size) noexcept; + void set_assembly_data_and_size (uint8_t* source_assembly_data, uint32_t source_assembly_data_size, uint8_t*& dest_assembly_data, uint32_t& dest_assembly_data_size) noexcept; + void get_assembly_data (uint8_t *data, uint32_t data_size, const char *name, uint8_t*& assembly_data, uint32_t& assembly_data_size) noexcept; + void get_assembly_data (XamarinAndroidBundledAssembly const& e, uint8_t*& assembly_data, uint32_t& assembly_data_size) noexcept; + void get_assembly_data (AssemblyStoreSingleAssemblyRuntimeData const& e, uint8_t*& assembly_data, uint32_t& assembly_data_size) noexcept; void zip_load_entries (int fd, const char *apk_name, monodroid_should_register should_register); void zip_load_individual_assembly_entries (std::vector const& buf, uint32_t num_entries, monodroid_should_register should_register, ZipEntryLoadState &state) noexcept; @@ -333,6 +334,7 @@ namespace xamarin::android::internal { AssemblyStoreHeader *index_assembly_store_header = nullptr; AssemblyStoreHashEntry *assembly_store_hashes; + std::mutex assembly_decompress_mutex; }; }