Skip to content

Commit

Permalink
Better FastDev handling
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Nov 25, 2024
1 parent 0fd503c commit cf19401
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class GeneratePackageManagerJava : AndroidTask
public string AndroidSequencePointsMode { get; set; }
public bool EnableSGenConcurrent { get; set; }
public string? CustomBundleConfigFile { get; set; }
public bool FastDevEnabled { get; set; }

bool _Debug {
get {
Expand Down Expand Up @@ -314,6 +315,7 @@ void AddEnvironment ()
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
MarshalMethodsEnabled = EnableMarshalMethods,
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
FastDevEnabled = FastDevEnabled,
};
LLVMIR.LlvmIrModule appConfigModule = appConfigAsmGen.Construct ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public sealed class ApplicationConfig
public bool broken_exception_transitions;
public bool jni_add_native_method_registration_attribute_present;
public bool have_runtime_config_blob;
public bool fastdev_enabled;
public bool marshal_methods_enabled;
public bool ignore_split_configs;
public byte bound_stream_io_exception_type;
Expand All @@ -65,7 +66,7 @@ public sealed class ApplicationConfig
public string android_package_name = String.Empty;
}

const uint ApplicationConfigFieldCount = 24;
const uint ApplicationConfigFieldCount = 25;

const string ApplicationConfigSymbolName = "application_config";
const string AppEnvironmentVariablesSymbolName = "app_environment_variables";
Expand Down Expand Up @@ -239,87 +240,92 @@ static ApplicationConfig ReadApplicationConfig (EnvironmentFile envFile)
ret.have_runtime_config_blob = ConvertFieldToBool ("have_runtime_config_blob", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 7: // marshal_methods_enabled: bool / .byte
case 7: // fastdev_enabled: bool / .byte
AssertFieldType (envFile.Path, parser.SourceFilePath, ".byte", field [0], item.LineNumber);
ret.fastdev_enabled = ConvertFieldToBool ("fastdev_enabled", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 8: // marshal_methods_enabled: bool / .byte
AssertFieldType (envFile.Path, parser.SourceFilePath, ".byte", field [0], item.LineNumber);
ret.marshal_methods_enabled = ConvertFieldToBool ("marshal_methods_enabled", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 8: // ignore_split_configs: bool / .byte
case 9: // ignore_split_configs: bool / .byte
AssertFieldType (envFile.Path, parser.SourceFilePath, ".byte", field [0], item.LineNumber);
ret.ignore_split_configs = ConvertFieldToBool ("ignore_split_configs", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 9: // bound_stream_io_exception_type: byte / .byte
case 10: // bound_stream_io_exception_type: byte / .byte
AssertFieldType (envFile.Path, parser.SourceFilePath, ".byte", field [0], item.LineNumber);
ret.bound_stream_io_exception_type = ConvertFieldToByte ("bound_stream_io_exception_type", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 10: // package_naming_policy: uint32_t / .word | .long
case 11: // package_naming_policy: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.package_naming_policy = ConvertFieldToUInt32 ("package_naming_policy", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 11: // environment_variable_count: uint32_t / .word | .long
case 12: // environment_variable_count: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.environment_variable_count = ConvertFieldToUInt32 ("environment_variable_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 12: // system_property_count: uint32_t / .word | .long
case 13: // system_property_count: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.system_property_count = ConvertFieldToUInt32 ("system_property_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 13: // number_of_assemblies_in_apk: uint32_t / .word | .long
case 14: // number_of_assemblies_in_apk: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.number_of_assemblies_in_apk = ConvertFieldToUInt32 ("number_of_assemblies_in_apk", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 14: // number_of_assembly_store_files: uint32_t / .word | .long
case 15: // number_of_assembly_store_files: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.number_of_assembly_store_files = ConvertFieldToUInt32 ("number_of_assembly_store_files", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 15: // number_of_dso_cache_entries: uint32_t / .word | .long
case 16: // number_of_dso_cache_entries: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.number_of_dso_cache_entries = ConvertFieldToUInt32 ("number_of_dso_cache_entries", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 16: // number_of_aot_cache_entries: uint32_t / .word | .long
case 17: // number_of_aot_cache_entries: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.number_of_aot_cache_entries = ConvertFieldToUInt32 ("number_of_aot_cache_entries", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 17: // android_runtime_jnienv_class_token: uint32_t / .word | .long
case 18: // android_runtime_jnienv_class_token: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.android_runtime_jnienv_class_token = ConvertFieldToUInt32 ("android_runtime_jnienv_class_token", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 18: // jnienv_initialize_method_token: uint32_t / .word | .long
case 19: // jnienv_initialize_method_token: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.jnienv_initialize_method_token = ConvertFieldToUInt32 ("jnienv_initialize_method_token", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 19: // jnienv_registerjninatives_method_token: uint32_t / .word | .long
case 20: // jnienv_registerjninatives_method_token: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.jnienv_registerjninatives_method_token = ConvertFieldToUInt32 ("jnienv_registerjninatives_method_token", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 20: // jni_remapping_replacement_type_count: uint32_t / .word | .long
case 21: // jni_remapping_replacement_type_count: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.jni_remapping_replacement_type_count = ConvertFieldToUInt32 ("jni_remapping_replacement_type_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 21: // jni_remapping_replacement_method_index_entry_count: uint32_t / .word | .long
case 22: // jni_remapping_replacement_method_index_entry_count: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.jni_remapping_replacement_method_index_entry_count = ConvertFieldToUInt32 ("jni_remapping_replacement_method_index_entry_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 22: // mono_components_mask: uint32_t / .word | .long
case 23: // mono_components_mask: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.mono_components_mask = ConvertFieldToUInt32 ("mono_components_mask", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 23: // android_package_name: string / [pointer type]
case 24: // android_package_name: string / [pointer type]
Assert.IsTrue (expectedPointerTypes.Contains (field [0]), $"Unexpected pointer field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
pointers.Add (field [1].Trim ());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sealed class ApplicationConfig
public bool broken_exception_transitions;
public bool jni_add_native_method_registration_attribute_present;
public bool have_runtime_config_blob;
public bool fastdev_enabled;
public bool marshal_methods_enabled;
public bool ignore_split_configs;
public byte bound_stream_io_exception_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ sealed class XamarinAndroidBundledAssembly
public List<ITaskItem> NativeLibraries { get; set; }
public bool MarshalMethodsEnabled { get; set; }
public bool IgnoreSplitConfigs { get; set; }
public bool FastDevEnabled { get; set; }

public ApplicationConfigNativeAssemblyGenerator (IDictionary<string, string> environmentVariables, IDictionary<string, string> systemProperties, TaskLoggingHelper log)
: base (log)
Expand Down Expand Up @@ -225,6 +226,7 @@ protected override void Construct (LlvmIrModule module)
broken_exception_transitions = BrokenExceptionTransitions,
jni_add_native_method_registration_attribute_present = JniAddNativeMethodRegistrationAttributePresent,
have_runtime_config_blob = HaveRuntimeConfigBlob,
fastdev_enabled = FastDevEnabled,
marshal_methods_enabled = MarshalMethodsEnabled,
ignore_split_configs = IgnoreSplitConfigs,
bound_stream_io_exception_type = (byte)BoundExceptionType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
***********************************************************************************************
Xamarin.Android.Common.targets
Expand Down Expand Up @@ -161,6 +161,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' And '$(Optimize)' != 'True' And '$(_XASupportsFastDev)' == 'True' ">False</EmbedAssembliesIntoApk>
<EmbedAssembliesIntoApk Condition=" '$(_XASupportsFastDev)' == 'False' ">True</EmbedAssembliesIntoApk>
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' ">True</EmbedAssembliesIntoApk>
<_XAFastDevEnabled Condition=" '$(_XASupportsFastDev)' == 'True' And '$(EmbedAssembliesIntoApk)' != 'True' ">True</_XAFastDevEnabled>
<_XAFastDevEnabled Condition=" '$(_XAFastDevEnabled)' == '' ">False</_XAFastDevEnabled>
<AndroidPreferNativeLibrariesWithDebugSymbols Condition=" '$(AndroidPreferNativeLibrariesWithDebugSymbols)' == '' ">False</AndroidPreferNativeLibrariesWithDebugSymbols>
<AndroidSkipJavacVersionCheck Condition="'$(AndroidSkipJavacVersionCheck)' == ''">False</AndroidSkipJavacVersionCheck>
<AndroidBuildApplicationPackage Condition=" '$(AndroidBuildApplicationPackage)' == ''">False</AndroidBuildApplicationPackage>
Expand Down Expand Up @@ -1742,6 +1744,7 @@ because xbuild doesn't support framework reference assemblies.
RuntimeConfigBinFilePath="$(_BinaryRuntimeConfigPath)"
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
CustomBundleConfigFile="$(AndroidBundleConfigurationFile)"
FastDevEnabled="$(_XAFastDevEnabled)"
>
</GeneratePackageManagerJava>
<Touch Files="$(_AndroidStampDirectory)_GeneratePackageManagerJava.stamp" AlwaysCreate="True" />
Expand Down
10 changes: 5 additions & 5 deletions src/native/monodroid/embedded-assemblies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ template<LoaderData TLoaderData>
force_inline MonoAssembly*
EmbeddedAssemblies::open_from_bundles (MonoAssemblyName* aname, TLoaderData loader_data, [[maybe_unused]] MonoError *error, bool ref_only) noexcept
{
#if defined (DEBUG)
if (assembly_store_hashes == nullptr) {
// With FastDev we might not have any assembly stores present
return nullptr;
if constexpr (SharedConstants::debug_build) {
if (application_config.fastdev_enabled && assembly_store_hashes == nullptr) {
// With FastDev we might not have any assembly stores present
return nullptr;
}
}
#endif

const char *culture = mono_assembly_name_get_culture (aname);
const char *asmname = mono_assembly_name_get_name (aname);
Expand Down
6 changes: 6 additions & 0 deletions src/native/monodroid/embedded-assemblies.hh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ namespace xamarin::android::internal {

void ensure_valid_assembly_stores () const noexcept
{
if constexpr (SharedConstants::debug_build) {
if (application_config.fastdev_enabled) {
return;
}
}

abort_unless (assembly_store_hashes != nullptr, "Invalid or incomplete assembly store data");
}

Expand Down
1 change: 1 addition & 0 deletions src/native/xamarin-app-stub/application_dso_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const ApplicationConfig application_config = {
.broken_exception_transitions = false,
.jni_add_native_method_registration_attribute_present = false,
.have_runtime_config_blob = false,
.fastdev_enabled = false,
.marshal_methods_enabled = false,
.ignore_split_configs = false,
.bound_exception_type = 0, // System
Expand Down
1 change: 1 addition & 0 deletions src/native/xamarin-app-stub/xamarin-app.hh
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ struct ApplicationConfig
bool broken_exception_transitions;
bool jni_add_native_method_registration_attribute_present;
bool have_runtime_config_blob;
bool fastdev_enabled;
bool marshal_methods_enabled;
bool ignore_split_configs;
uint8_t bound_exception_type;
Expand Down

0 comments on commit cf19401

Please sign in to comment.