From c3d1d753b3444871d42b6856d7a748ad33225d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 29 Nov 2022 07:23:06 +0900 Subject: [PATCH] Generate diagnosable failfast in GVM resolution (#78904) If the program hits the conditions in #77070, generate a failfast message that makes it possible to create a workaround. Instead of: ``` Process terminated. Generic virtual method pointer lookup failure. Declaring type handle: MethodTable:0x00007FF66E8587B8 Target type handle: MethodTable:0x00007FF66E858810 Method name: Serialize Instantiation: Argument 00000000: MethodTable:0x00007FF66E85DA08 ``` Generate: ``` Process terminated. Generic virtual method pointer lookup failure. Declaring type handle: EETypeRva:0x005438B8(MemoryPackFormatter2`1[MemPackObject]) Target type handle: EETypeRva:0x00543910(MemoryPackableFormatter2`1[MemPackObject]) Method name: Serialize Instantiation: Argument 00000000: EETypeRva:0x00529B38(System.Buffers.ArrayBufferWriter`1[System.Byte]) ``` The workaround is then: ```xml ``` --- .../TypeLoaderEnvironment.GVMResolution.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.GVMResolution.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.GVMResolution.cs index 99f7272b3ec9..7c411f987bd9 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.GVMResolution.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.GVMResolution.cs @@ -72,13 +72,13 @@ public bool TryGetGenericVirtualTargetForTypeAndSlot(RuntimeTypeHandle targetHan var sb = new System.Text.StringBuilder(); sb.AppendLine("Generic virtual method pointer lookup failure."); sb.AppendLine(); - sb.AppendLine("Declaring type handle: " + declaringType.LowLevelToStringRawEETypeAddress()); - sb.AppendLine("Target type handle: " + targetHandle.LowLevelToStringRawEETypeAddress()); + sb.AppendLine("Declaring type handle: " + RuntimeAugments.GetLastResortString(declaringType)); + sb.AppendLine("Target type handle: " + RuntimeAugments.GetLastResortString(targetHandle)); sb.AppendLine("Method name: " + methodNameAndSignature.Name); sb.AppendLine("Instantiation:"); for (int i = 0; i < genericArguments.Length; i++) { - sb.AppendLine(" Argument " + i.LowLevelToString() + ": " + genericArguments[i].LowLevelToStringRawEETypeAddress()); + sb.AppendLine(" Argument " + i.LowLevelToString() + ": " + RuntimeAugments.GetLastResortString(genericArguments[i])); } Environment.FailFast(sb.ToString()); @@ -616,13 +616,13 @@ private unsafe bool ResolveGenericVirtualMethodTarget_Static(RuntimeTypeHandle t var sb = new System.Text.StringBuilder(); sb.AppendLine("Generic virtual method pointer lookup failure."); sb.AppendLine(); - sb.AppendLine("Declaring type handle: " + declaringType.LowLevelToStringRawEETypeAddress()); - sb.AppendLine("Target type handle: " + targetTypeHandle.LowLevelToStringRawEETypeAddress()); + sb.AppendLine("Declaring type handle: " + RuntimeAugments.GetLastResortString(declaringType)); + sb.AppendLine("Target type handle: " + RuntimeAugments.GetLastResortString(targetTypeHandle)); sb.AppendLine("Method name: " + targetMethodNameAndSignature.Name); sb.AppendLine("Instantiation:"); for (int i = 0; i < genericArguments.Length; i++) { - sb.AppendLine(" Argument " + i.LowLevelToString() + ": " + genericArguments[i].LowLevelToStringRawEETypeAddress()); + sb.AppendLine(" Argument " + i.LowLevelToString() + ": " + RuntimeAugments.GetLastResortString(genericArguments[i])); } Environment.FailFast(sb.ToString());