Fix add/edit for generic methods scenario (#85655)
authorAaron Robinson <arobins@microsoft.com>
Tue, 2 May 2023 21:37:05 +0000 (14:37 -0700)
committerGitHub <noreply@github.com>
Tue, 2 May 2023 21:37:05 +0000 (14:37 -0700)
Ensure the canonical MethodTable is always used.

src/coreclr/vm/methoditer.cpp
src/coreclr/vm/methodtable.cpp
src/coreclr/vm/runtimehandles.cpp

index 1da1dbf..82def6a 100644 (file)
@@ -24,7 +24,7 @@ BOOL LoadedMethodDescIterator::Next(
     {
         NOTHROW;
         GC_NOTRIGGER;
-        MODE_PREEMPTIVE;
+        MODE_ANY;
     }
     CONTRACTL_END
 
@@ -203,15 +203,11 @@ MethodDesc *LoadedMethodDescIterator::Current()
         return m_mainMD;
     }
 
-    MethodTable *pMT = m_typeIteratorEntry->GetTypeHandle().GetMethodTable();
+    MethodTable *pMT = m_typeIteratorEntry->GetTypeHandle().GetMethodTable()->GetCanonicalMethodTable();
     PREFIX_ASSUME(pMT != NULL);
-    _ASSERTE(pMT);
-
-    return pMT->GetMethodDescForSlot(m_mainMD->GetSlot());
+    return pMT->GetParallelMethodDesc(m_mainMD);
 }
 
-// Initialize the iterator. It will cover generics + prejitted;
-// but it is not EnC aware.
 void
 LoadedMethodDescIterator::Start(
     AppDomain * pAppDomain,
index a5391fb..d40eb08 100644 (file)
@@ -8770,6 +8770,7 @@ namespace
             GC_NOTRIGGER;
             MODE_ANY;
             PRECONDITION(pMT != NULL);
+            PRECONDITION(pMT->IsCanonicalMethodTable());
             PRECONDITION(pDefMD != NULL);
             PRECONDITION(pDefMD->IsEnCAddedMethod());
             PRECONDITION(pDefMD->GetSlot() == MethodTable::NO_SLOT);
index 5972c88..e0eba7e 100644 (file)
@@ -2413,7 +2413,8 @@ FCIMPL2(MethodDesc*, RuntimeMethodHandle::GetMethodFromCanonical, MethodDesc *pM
     REFLECTCLASSBASEREF refType = (REFLECTCLASSBASEREF)ObjectToOBJECTREF(pTypeUNSAFE);
 
     TypeHandle instType = refType->GetType();
-    MethodDesc* pMDescInCanonMT = instType.GetMethodTable()->GetParallelMethodDesc(pMethod);
+    MethodTable* pCanonMT = instType.GetMethodTable()->GetCanonicalMethodTable();
+    MethodDesc* pMDescInCanonMT = pCanonMT->GetParallelMethodDesc(pMethod);
 
     return pMDescInCanonMT;
 }