Skip to content

Commit a983fbb

Browse files
authored
[Mono.Android] Print type & member remapping info (#7844)
Context: f6f11a5 Context: f99fc81 How do we diagnose type & member remapping issues? If (when) things don't work as anticipated, what do we do? If a method is remapped *and* the remapped-to method cannot be found, then [Java.Interop will write a message to stderr][0]: warning: For declared method `java/lang/Object.remappedToToString.()Ljava/lang/String;`, could not find requested method `java/lang/Object.toString.()Ljava/lang/String;`! which is a scenario we think/assume Shouldn't Happen™. If it *does* happen, we believe that the above message will be sufficient to fix the problem. However, in the "happy" path in which the replacement method is found *or* the "less-happy" path in which *nothing happens*, how do we get insight to check or verify what's going on? Update `AndroidTypeManager.GetStaticMethodFallbackTypesCore()` and `AndroidTypeManager.GetReplacementMethodInfoCore()` so that they print out *successful* type & member remapping when the "assembly" log category is enabled: adb shell setprop debug.mono.log default,assembly When the assembly log category is enabled, invocations of `AndroidTypeManager.GetStaticMethodFallbackTypesCore()` will print messages such as the following to `adb logcat`: D monodroid-assembly : Remapping type `com/xamarin/interop/RenameClassBase1` to one of { `com/xamarin/interop/DesugarRenameClassBase1`, `com/xamarin/interop/RenameClassBase1$-CC` } When the assembly log category is enabled, invocations of `AndroidTypeManager.GetReplacementMethodInfoCore()` will print messages such as the following to `adb logcat` *when a replacement method will be attempted*: D monodroid-assembly : Remapping method `java/lang/Object.remappedToToString()Ljava/lang/String;` to `java/lang/Object.toString.()Ljava/lang/String;`; param-count: 0; instance-to-static? false This will hopefully provide enough information to reason through type and member remapping behavior. [0]: https://github.com/xamarin/java.interop/blob/77800dda83c2db4d90b501c00069abc9880caaeb/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs#L123
1 parent 5d46685 commit a983fbb

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Mono.Android/Android.Runtime/AndroidRuntime.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,16 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
317317
var typeWithPrefix = desugarType.ToString ();
318318
var typeWithSuffix = $"{jniSimpleReference}$-CC";
319319

320-
return new[]{
320+
var replacements = new[]{
321321
GetReplacementTypeCore (typeWithPrefix) ?? typeWithPrefix,
322322
GetReplacementTypeCore (typeWithSuffix) ?? typeWithSuffix,
323323
};
324+
325+
if (Logger.LogAssembly) {
326+
var message = $"Remapping type `{jniSimpleReference}` to one one of {{ `{replacements[0]}`, `{replacements[1]}` }}";
327+
Logger.Log (LogLevel.Debug, "monodroid-assembly", message);
328+
}
329+
return replacements;
324330
}
325331

326332
protected override string? GetReplacementTypeCore (string jniSimpleReference)
@@ -350,11 +356,19 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
350356

351357
var method = new JniRemappingReplacementMethod ();
352358
method = Marshal.PtrToStructure<JniRemappingReplacementMethod>(retInfo);
359+
var newSignature = jniMethodSignature;
353360

354361
int? paramCount = null;
355362
if (method.is_static) {
356363
paramCount = JniMemberSignature.GetParameterCountFromMethodSignature (jniMethodSignature) + 1;
357-
jniMethodSignature = $"(L{jniSourceType};" + jniMethodSignature.Substring ("(".Length);
364+
newSignature = $"(L{jniSourceType};" + jniMethodSignature.Substring ("(".Length);
365+
}
366+
367+
if (Logger.LogAssembly) {
368+
var message = $"Remapping method `{jniSourceType}.{jniMethodName}{jniMethodSignature}` to " +
369+
$"`{method.target_type}.{method.target_name}{newSignature}`; " +
370+
$"param-count: {paramCount}; instance-to-static? {method.is_static}";
371+
Logger.Log (LogLevel.Debug, "monodroid-assembly", message);
358372
}
359373

360374
return new JniRuntime.ReplacementMethodInfo {
@@ -363,7 +377,7 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
363377
SourceJniMethodSignature = jniMethodSignature,
364378
TargetJniType = method.target_type,
365379
TargetJniMethodName = method.target_name,
366-
TargetJniMethodSignature = jniMethodSignature,
380+
TargetJniMethodSignature = newSignature,
367381
TargetJniMethodParameterCount = paramCount,
368382
TargetJniMethodInstanceToStatic = method.is_static,
369383
};

0 commit comments

Comments
 (0)