Skip to content

Commit 7880b81

Browse files
committed
Changes from #10065
1 parent 1f89124 commit 7880b81

File tree

5 files changed

+83
-36
lines changed

5 files changed

+83
-36
lines changed

src/Xamarin.Android.Build.Tasks/Utilities/TypeMapCecilAdapter.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ public static (TypeMapDebugDataSets dataSets, bool foundJniNativeRegistration) G
3232
var managedToJava = new List<TypeMapDebugEntry> ();
3333
var foundJniNativeRegistration = false;
3434

35-
foreach (var td in types) {
36-
foundJniNativeRegistration = JniAddNativeMethodRegistrationAttributeFound (foundJniNativeRegistration, td);
35+
var javaDuplicates = new Dictionary<string, List<TypeMapDebugEntry>> (StringComparer.Ordinal);
36+
var uniqueAssemblies = needUniqueAssemblies ? new Dictionary<string, TypeMapDebugAssembly> (StringComparer.OrdinalIgnoreCase) : null;
37+
foreach (TypeDefinition td in state.AllJavaTypes) {
38+
UpdateApplicationConfig (state, td);
3739

3840
TypeMapDebugEntry entry = GetDebugEntry (td, cache);
3941
HandleDebugDuplicates (javaDuplicates, entry, td, cache);
@@ -60,11 +62,11 @@ public static (TypeMapDebugDataSets dataSets, bool foundJniNativeRegistration) G
6062

6163
SyncDebugDuplicates (javaDuplicates);
6264

63-
return (new TypeMapDebugDataSets {
65+
return new TypeMapDebugDataSets {
6466
JavaToManaged = javaToManaged,
6567
ManagedToJava = managedToJava,
6668
UniqueAssemblies = uniqueAssemblies != null ? new List<TypeMapDebugAssembly> (uniqueAssemblies.Values) : null
67-
}, foundJniNativeRegistration);
69+
};
6870
}
6971

7072
public static ReleaseGenerationState GetReleaseGenerationState (NativeCodeGenState state)

src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Generate (bool debugBuild, bool skipJniAddNativeMethodRegistrationAt
153153

154154
void GenerateDebugNativeAssembly (string outputDirectory)
155155
{
156-
TypeMapDebugDataSets dataSets = state.GetDebugNativeEntries (needUniqueAssemblies: runtime == AndroidRuntime.CoreCLR);
156+
TypeMapDebugDataSets dataSets = TypeMapCecilAdapter.GetDebugNativeEntries (state, needUniqueAssemblies: runtime == AndroidRuntime.CoreCLR);
157157

158158
var data = new ModuleDebugData {
159159
EntryCount = (uint)dataSets.JavaToManaged.Count,

src/Xamarin.Android.Build.Tasks/Utilities/TypeMappingDebugNativeAssemblyGeneratorCLR.cs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ sealed class TypeMapContextDataProvider : NativeAssemblerStructContextDataProvid
2222
public override ulong GetBufferSize (object data, string fieldName)
2323
{
2424
var map_module = EnsureType<TypeMap> (data);
25-
return fieldName switch {
26-
"java_to_managed" => map_module.entry_count,
27-
"managed_to_java" => map_module.entry_count,
28-
_ => 0
29-
};
25+
if (String.Compare ("java_to_managed", fieldName, StringComparison.Ordinal) == 0 ||
26+
String.Compare ("managed_to_java", fieldName, StringComparison.Ordinal) == 0) {
27+
return map_module.entry_count;
28+
}
29+
30+
return 0;
3031
}
3132

32-
public override string? GetPointedToSymbolName (object data, string fieldName)
33+
public override string GetPointedToSymbolName (object data, string fieldName)
3334
{
3435
var map_module = EnsureType<TypeMap> (data);
3536

@@ -87,10 +88,10 @@ public override string GetComment (object data, string fieldName)
8788
sealed class TypeMapEntry
8889
{
8990
[NativeAssembler (UsesDataProvider = true)]
90-
public string from = String.Empty;
91+
public string from;
9192

9293
[NativeAssembler (UsesDataProvider = true)]
93-
public string? to;
94+
public string to;
9495
};
9596

9697
// Order of fields and their type must correspond *exactly* to that in
@@ -121,7 +122,7 @@ sealed class TypeMap
121122
sealed class TypeMapAssembly
122123
{
123124
[NativeAssembler (Ignore = true)]
124-
public string Name = String.Empty;
125+
public string Name;
125126

126127
[NativeAssembler (Ignore = true)]
127128
public Guid MVID;
@@ -135,13 +136,13 @@ sealed class TypeMapAssembly
135136
}
136137

137138
readonly TypeMapGenerator.ModuleDebugData data;
138-
StructureInfo? typeMapEntryStructureInfo;
139-
StructureInfo? typeMapStructureInfo;
140-
StructureInfo? typeMapAssemblyStructureInfo;
139+
StructureInfo typeMapEntryStructureInfo;
140+
StructureInfo typeMapStructureInfo;
141+
StructureInfo typeMapAssemblyStructureInfo;
141142
List<StructureInstance<TypeMapEntry>> javaToManagedMap;
142143
List<StructureInstance<TypeMapEntry>> managedToJavaMap;
143144
List<StructureInstance<TypeMapAssembly>> uniqueAssemblies;
144-
StructureInstance<TypeMap>? type_map;
145+
StructureInstance<TypeMap> type_map;
145146

146147
public TypeMappingDebugNativeAssemblyGeneratorCLR (TaskLoggingHelper log, TypeMapGenerator.ModuleDebugData data)
147148
: base (log)
@@ -161,10 +162,6 @@ protected override void Construct (LlvmIrModule module)
161162
{
162163
module.DefaultStringGroup = "tmd";
163164

164-
if (data.UniqueAssemblies == null) {
165-
throw new InvalidOperationException ("Internal error: unique assemblies collection must be present");
166-
}
167-
168165
MapStructures (module);
169166

170167
if (data.ManagedToJavaMap != null && data.ManagedToJavaMap.Count > 0) {
@@ -206,17 +203,7 @@ protected override void Construct (LlvmIrModule module)
206203
assemblyNamesBlob.AddRange (nameBytes);
207204
assemblyNamesBlob.Add (0);
208205
}
209-
uniqueAssemblies.Sort ((StructureInstance<TypeMapAssembly> a, StructureInstance<TypeMapAssembly> b) => {
210-
if (a.Instance == null) {
211-
return b.Instance == null ? 0 : -1;
212-
}
213-
214-
if (b.Instance == null) {
215-
return 1;
216-
}
217-
218-
return a.Instance.mvid_hash.CompareTo (b.Instance.mvid_hash);
219-
});
206+
uniqueAssemblies.Sort ((StructureInstance<TypeMapAssembly> a, StructureInstance<TypeMapAssembly> b) => a.Instance.mvid_hash.CompareTo (b.Instance.mvid_hash));
220207

221208
var map = new TypeMap {
222209
JavaToManagedCount = data.JavaToManagedMap == null ? 0 : data.JavaToManagedMap.Count,

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,9 +1880,39 @@ because xbuild doesn't support framework reference assemblies.
18801880

18811881
<!-- Create java needed for Mono runtime -->
18821882
<GeneratePackageManagerJava
1883-
MainAssembly="$(TargetPath)"
1884-
OutputDirectory="$(_AndroidIntermediateJavaSourceDirectory)mono"
1885-
ResolvedUserAssemblies="@(_ResolvedUserAssemblies)">
1883+
ResolvedAssemblies="@(_ResolvedAssemblies)"
1884+
ResolvedUserAssemblies="@(_ResolvedUserAssemblies)"
1885+
SatelliteAssemblies="@(_AndroidResolvedSatellitePaths)"
1886+
IntermediateOutputDirectory="$(IntermediateOutputPath)"
1887+
NativeLibraries="@(AndroidNativeLibrary);@(EmbeddedNativeLibrary);@(FrameworkNativeLibrary)"
1888+
MonoComponents="@(_MonoComponent)"
1889+
MainAssembly="$(TargetPath)"
1890+
OutputDirectory="$(_AndroidIntermediateJavaSourceDirectory)mono"
1891+
EnvironmentOutputDirectory="$(IntermediateOutputPath)android"
1892+
TargetFrameworkVersion="$(TargetFrameworkVersion)"
1893+
Manifest="$(IntermediateOutputPath)android\AndroidManifest.xml"
1894+
Environments="@(_EnvironmentFiles)"
1895+
AndroidAotMode="$(AndroidAotMode)"
1896+
AndroidAotEnableLazyLoad="$(AndroidAotEnableLazyLoad)"
1897+
EnableLLVM="$(EnableLLVM)"
1898+
HttpClientHandlerType="$(AndroidHttpClientHandlerType)"
1899+
TlsProvider="$(AndroidTlsProvider)"
1900+
Debug="$(AndroidIncludeDebugSymbols)"
1901+
AndroidSequencePointsMode="$(_SequencePointsMode)"
1902+
EnableSGenConcurrent="$(AndroidEnableSGenConcurrent)"
1903+
SupportedAbis="@(_BuildTargetAbis)"
1904+
AndroidPackageName="$(_AndroidPackage)"
1905+
EnablePreloadAssembliesDefault="$(_AndroidEnablePreloadAssembliesDefault)"
1906+
PackageNamingPolicy="$(AndroidPackageNamingPolicy)"
1907+
BoundExceptionType="$(AndroidBoundExceptionType)"
1908+
RuntimeConfigBinFilePath="$(_BinaryRuntimeConfigPath)"
1909+
UseAssemblyStore="$(_AndroidUseAssemblyStore)"
1910+
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
1911+
EnableManagedMarshalMethodsLookup="$(_AndroidUseManagedMarshalMethodsLookup)"
1912+
CustomBundleConfigFile="$(AndroidBundleConfigurationFile)"
1913+
TargetsCLR="$(_AndroidUseCLR)"
1914+
ProjectRuntimeConfigFilePath="$(ProjectRuntimeConfigFilePath)"
1915+
>
18861916
</GeneratePackageManagerJava>
18871917

18881918
<GenerateNativeApplicationConfigSources

src/native/clr/host/typemap.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,31 @@ auto TypeMapper::typemap_java_to_managed (const char *java_type_name, char const
400400

401401
return ret;
402402
}
403+
#endif // ndef DEBUG
404+
405+
[[gnu::flatten]]
406+
auto TypeMapper::typemap_java_to_managed (const char *java_type_name, char const** assembly_name, uint32_t *managed_type_token_id) noexcept -> bool
407+
{
408+
log_debug (LOG_ASSEMBLY, "typemap_java_to_managed: looking up type '{}'", optional_string (java_type_name));
409+
if (FastTiming::enabled ()) [[unlikely]] {
410+
internal_timing.start_event (TimingEventKind::JavaToManaged);
411+
}
412+
413+
if (java_type_name == nullptr) [[unlikely]] {
414+
log_warn (LOG_ASSEMBLY, "typemap: type name not specified in typemap_java_to_managed");
415+
return false;
416+
}
417+
418+
bool ret;
419+
#if defined(RELEASE)
420+
ret = typemap_java_to_managed_release (java_type_name, assembly_name, managed_type_token_id);
421+
#else
422+
ret = typemap_java_to_managed_debug (java_type_name, assembly_name, managed_type_token_id);
423+
#endif
424+
425+
if (FastTiming::enabled ()) [[unlikely]] {
426+
internal_timing.end_event ();
427+
}
428+
429+
return ret;
430+
}

0 commit comments

Comments
 (0)