Skip to content

Commit

Permalink
Bump to xamarin/Java.Interop/main@cf80deb7 (#7664)
Browse files Browse the repository at this point in the history
Changes: dotnet/java-interop@f8d77fa...cf80deb

  * dotnet/java-interop@cf80deb7: [Java.Interop.Tools.JavaCallableWrappers] use IMetadataResolver more (dotnet/java-interop#1069)
  * dotnet/java-interop@5c5dc086: [generator] enum map.csv can set `@deprecated-since` for enum values (dotnet/java-interop#1070)

Any place we used:

  * `TypeDefinitionCache?`
  * `IMetadataResolver?`

As of dotnet/java-interop@cf80deb7, Java.Interop no longer allows
`null` values for these parameters, so overloads which were]
`[Obsolete]` now emit errors instead of warnings:

	[Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)]
	public static MethodDefinition GetBaseDefinition (this MethodDefinition method) =>
	    GetBaseDefinition (method, resolver: null!);

This results in 3 compiler errors in xamarin-android:

	src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(65,11):
	  error CS0619: 'TypeDefinitionRocks.IsSubclassOf(TypeDefinition, string)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'
	src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(268,12):
	  error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'
	src\Xamarin.Android.Build.Tasks\Utilities\ManifestDocumentElement.cs(28,11):
	  error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'

After these changes, it appears we will improve the performance
further of apps that use:

  * `ApplicationAttribute.BackupAgent`
  * `ApplicationAttribute.Name`
  * `AndroidManifest.xml` attributes that take a `System.Type` values

Additionally, fix a `NullReferenceException` in the linker:

	Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
	   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.GetBaseType(TypeDefinition type, IMetadataResolver resolver) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 21
	   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.GetTypeAndBaseTypes(TypeDefinition type, IMetadataResolver resolver)+MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 36
	   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName, IMetadataResolver resolver) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 87
	   at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessType(TypeDefinition type) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs:line 81
	   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
	   at Mono.Linker.Steps.MarkStep.MarkField(FieldDefinition field, DependencyInfo& reason, MessageOrigin& origin)
	   at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason)
	   at Mono.Linker.Steps.MarkStep.MarkEntireAssembly(AssemblyDefinition assembly)
	   at Mono.Linker.Steps.MarkStep.MarkAssembly(AssemblyDefinition assembly, DependencyInfo reason)
	   at Mono.Linker.Steps.MarkStep.MarkModule(ModuleDefinition module, DependencyInfo reason)
	   at Mono.Linker.Steps.MarkStep.ProcessMarkedPending()
	   at Mono.Linker.Steps.MarkStep.Initialize()
	   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
	   at Mono.Linker.Pipeline.Process(LinkContext context)
	   at Mono.Linker.Driver.Run(ILogger customLogger)
	   at Mono.Linker.Driver.Main(String[] args)

This was caused by removing `null` checks in Java.Interop.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
jonathanpeppers and dependabot[bot] authored Jan 9, 2023
1 parent cc70ce2 commit 59e7adc
Show file tree
Hide file tree
Showing 22 changed files with 124 additions and 121 deletions.
2 changes: 1 addition & 1 deletion external/Java.Interop
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class FixAbstractMethodsStep :
#if ILLINK
public override void Initialize (LinkContext context, MarkContext markContext)
{
this.cache = context;
base.Initialize (context, markContext);
markContext.RegisterMarkTypeAction (type => ProcessType (type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ public static ActivityAttribute FromTypeDefinition (TypeDefinition type)
return self;
}

internal XElement ToElement (IAssemblyResolver resolver, string packageName, int targetSdkVersion)
internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache, int targetSdkVersion)
{
return mapping.ToElement (this, specified, packageName, type, resolver, targetSdkVersion);
return mapping.ToElement (this, specified, packageName, cache, type, resolver, targetSdkVersion);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ partial class ApplicationAttribute {
"BackupAgent",
"backupAgent",
(self, value) => self._BackupAgent = (string) value,
(self, p, r) => {
(self, p, r, cache) => {
var typeDef = ManifestDocumentElement.ResolveType (self._BackupAgent, p, r);

if (!typeDef.IsSubclassOf ("Android.App.Backup.BackupAgent"))
if (!typeDef.IsSubclassOf ("Android.App.Backup.BackupAgent", cache))
throw new InvalidOperationException (
string.Format ("The Type '{0}', referenced by the Android.App.ApplicationAttribute.BackupAgent property, must be a subclass of the type Android.App.Backup.BackupAgent.",
typeDef.FullName));

return ManifestDocumentElement.ToString (typeDef);
return ManifestDocumentElement.ToString (typeDef, cache);
}
}, {
"BackupInForeground",
Expand Down Expand Up @@ -256,16 +256,16 @@ public static ApplicationAttribute FromCustomAttributeProvider (ICustomAttribute
return self;
}

internal XElement ToElement (IAssemblyResolver resolver, string packageName)
internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, provider, resolver);
return mapping.ToElement (this, specified, packageName, cache, provider, resolver);
}

static string ToNameAttribute (ApplicationAttribute self)
static string ToNameAttribute (ApplicationAttribute self, ICustomAttributeProvider provider, IAssemblyResolver resolver, TypeDefinitionCache cache)
{
var type = self.provider as TypeDefinition;
if (string.IsNullOrEmpty (self.Name) && type != null)
return JavaNativeTypeManager.ToJniName (type).Replace ('/', '.');
return JavaNativeTypeManager.ToJniName (type, cache).Replace ('/', '.');

return self.Name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public static BroadcastReceiverAttribute FromTypeDefinition (TypeDefinition type
return self;
}

public XElement ToElement (string packageName)
public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ public static ContentProviderAttribute FromTypeDefinition (TypeDefinition type)
return self;
}

public XElement ToElement (string packageName)
public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public static IEnumerable<GrantUriPermissionAttribute> FromTypeDefinition (TypeD
}
}

public XElement ToElement (string packageName)
public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public void SetTargetPackage (string package)
specified.Add ("TargetPackage");
}

public XElement ToElement (string packageName)
public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
Expand Down Expand Up @@ -62,9 +62,9 @@ public static LayoutAttribute FromTypeDefinition (TypeDefinition type)
return self;
}

internal XElement ToElement (IAssemblyResolver resolver, string packageName)
internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, type, resolver);
return mapping.ToElement (this, specified, packageName, cache, type, resolver);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public static IEnumerable<MetaDataAttribute> FromCustomAttributeProvider (ICusto
}
}

public XElement ToElement (string packageName)
public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public static IEnumerable<PermissionAttribute> FromCustomAttributeProvider (ICus
}
}

internal XElement ToElement (string packageName)
internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}

internal class PermissionAttributeComparer : IEqualityComparer<PermissionAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public static IEnumerable<PermissionGroupAttribute> FromCustomAttributeProvider
}
}

internal XElement ToElement (string packageName)
internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}

internal class PermissionGroupAttributeComparer : IEqualityComparer<PermissionGroupAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static IEnumerable<PermissionTreeAttribute> FromCustomAttributeProvider (
}
}

internal XElement ToElement (string packageName)
internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}

internal class PermissionTreeAttributeComparer : IEqualityComparer<PermissionTreeAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public static ServiceAttribute FromTypeDefinition (TypeDefinition type)
return self;
}

public XElement ToElement (string packageName)
public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ partial class SupportsGLTextureAttribute
};


internal XElement ToElement (string packageName)
internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}

ICollection<string> specified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ partial class UsesConfigurationAttribute {
}
};

internal XElement ToElement (string packageName)
internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}

ICollection<string> specified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ internal string GLESVesionAsString ()
return String.Format("0x{0}", GLESVersion.ToString("X8"));
}

internal XElement ToElement (string packageName)
internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}

ICollection<string> specified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public static IEnumerable<UsesLibraryAttribute> FromCustomAttributeProvider (ICu
}
}

public XElement ToElement (string packageName)
public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public static IEnumerable<UsesPermissionAttribute> FromCustomAttributeProvider (
}
}

public XElement ToElement (string packageName)
public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName);
return mapping.ToElement (this, specified, packageName, cache);
}

internal class UsesPermissionComparer : IEqualityComparer<UsesPermissionAttribute>
Expand Down
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ bool CreateJavaSources (IEnumerable<TypeDefinition> javaTypes, TypeDefinitionCac
jti.Generate (writer);
if (useMarshalMethods) {
if (classifier.FoundDynamicallyRegisteredMethods (t)) {
Log.LogWarning ($"Type '{t.GetAssemblyQualifiedName ()}' will register some of its Java override methods dynamically. This may adversely affect runtime performance. See preceding warnings for names of dynamically registered methods.");
Log.LogWarning ($"Type '{t.GetAssemblyQualifiedName (cache)}' will register some of its Java override methods dynamically. This may adversely affect runtime performance. See preceding warnings for names of dynamically registered methods.");
}
}
writer.Flush ();
Expand Down
Loading

0 comments on commit 59e7adc

Please sign in to comment.