Merge ReadyToRunInfo::GenericMethodIterator in to ReadyToRunInfo::MethodIterator...
authorDavid Mason <davmason@microsoft.com>
Wed, 3 Jul 2019 01:30:43 +0000 (18:30 -0700)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2019 01:30:43 +0000 (18:30 -0700)
src/vm/eventtrace.cpp
src/vm/readytoruninfo.cpp
src/vm/readytoruninfo.h
src/vm/zapsig.cpp

index f97ef52..36235d6 100644 (file)
@@ -6849,17 +6849,6 @@ VOID ETW::MethodLog::SendEventsForNgenMethods(Module *pModule, DWORD dwEventOpti
             }
         }
 
-        ReadyToRunInfo::GenericMethodIterator gmi(pModule->GetReadyToRunInfo());
-        while (gmi.Next())
-        {
-            // Call GetMethodDesc_NoRestore instead of GetMethodDesc to avoid restoring methods at shutdown.
-            MethodDesc *hotDesc = (MethodDesc *)gmi.GetMethodDesc_NoRestore();
-            if (hotDesc != NULL)
-            {
-                ETW::MethodLog::SendMethodEvent(hotDesc, dwEventOptions, FALSE);
-            }
-        }
-
         return;
     }
 #endif // FEATURE_READYTORUN
index f995193..3136845 100644 (file)
@@ -814,95 +814,16 @@ done:
     return pEntryPoint;
 }
 
-BOOL ReadyToRunInfo::MethodIterator::Next()
-{
-    CONTRACTL
-    {
-        GC_TRIGGERS;
-        THROWS;
-        MODE_ANY;
-    }
-    CONTRACTL_END;
-
-    while (++m_methodDefIndex < (int)m_pInfo->m_methodDefEntryPoints.GetCount())
-    {
-        uint offset;
-        if (m_pInfo->m_methodDefEntryPoints.TryGetAt(m_methodDefIndex, &offset))
-            return TRUE;
-    }
-    return FALSE;
-}
-
-MethodDesc * ReadyToRunInfo::MethodIterator::GetMethodDesc()
-{
-    STANDARD_VM_CONTRACT;
-
-    return MemberLoader::GetMethodDescFromMethodDef(m_pInfo->m_pModule, mdtMethodDef | (m_methodDefIndex + 1), FALSE);
-}
-
-MethodDesc * ReadyToRunInfo::MethodIterator::GetMethodDesc_NoRestore()
-{
-    CONTRACTL
-    {
-        GC_TRIGGERS;
-        THROWS;
-        MODE_ANY;
-    }
-    CONTRACTL_END;
-
-    uint offset;
-    if (!m_pInfo->m_methodDefEntryPoints.TryGetAt(m_methodDefIndex, &offset))
-    {
-        return NULL;
-    }
 
-    uint id;
-    offset = m_pInfo->m_nativeReader.DecodeUnsigned(offset, &id);
-
-    if (id & 1)
-    {
-        if (id & 2)
-        {
-            uint val;
-            m_pInfo->m_nativeReader.DecodeUnsigned(offset, &val);
-            offset -= val;
-        }
-
-        id >>= 2;
-    }
-    else
-    {
-        id >>= 1;
-    }
-
-    _ASSERTE(id < m_pInfo->m_nRuntimeFunctions);
-    PCODE pEntryPoint = dac_cast<TADDR>(m_pInfo->m_pLayout->GetBase()) + m_pInfo->m_pRuntimeFunctions[id].BeginAddress;
-
-    return m_pInfo->GetMethodDescForEntryPoint(pEntryPoint);
-}
-
-PCODE ReadyToRunInfo::MethodIterator::GetMethodStartAddress()
+void ReadyToRunInfo::MethodIterator::ParseGenericMethodSignatureAndRid(uint *pOffset, RID *pRid)
 {
-    STANDARD_VM_CONTRACT;
-
-    PCODE ret = m_pInfo->GetEntryPoint(GetMethodDesc(), NULL, FALSE);
-    _ASSERTE(ret != NULL);
-    return ret;
-}
-
-BOOL ReadyToRunInfo::GenericMethodIterator::Next()
-{
-    m_current = m_enum.GetNext();
-    return !m_current.IsNull();
-}
-
-MethodDesc *ReadyToRunInfo::GenericMethodIterator::GetMethodDesc_NoRestore()
-{
-    _ASSERTE(!m_current.IsNull());
+    _ASSERTE(!m_genericParser.IsNull());
 
     HRESULT hr = S_OK;
+    *pOffset = -1;
+    *pRid = -1;
 
-    PCCOR_SIGNATURE pBlob = (PCCOR_SIGNATURE)m_current.GetBlob();
+    PCCOR_SIGNATURE pBlob = (PCCOR_SIGNATURE)m_genericParser.GetBlob();
     SigPointer sig(pBlob);
 
     DWORD methodFlags = 0;
@@ -910,7 +831,7 @@ MethodDesc *ReadyToRunInfo::GenericMethodIterator::GetMethodDesc_NoRestore()
     hr = sig.GetData(&methodFlags);
     if (FAILED(hr))
     {
-        return NULL;
+        return;
     }
 
     if (methodFlags & ENCODE_METHOD_SIG_OwnerType)
@@ -918,18 +839,17 @@ MethodDesc *ReadyToRunInfo::GenericMethodIterator::GetMethodDesc_NoRestore()
         hr = sig.SkipExactlyOne();
         if (FAILED(hr))
         {
-            return NULL;
+            return;
         }
     }
 
     _ASSERTE((methodFlags & ENCODE_METHOD_SIG_SlotInsteadOfToken) == 0);
     _ASSERTE((methodFlags & ENCODE_METHOD_SIG_MemberRefToken) == 0);
 
-    RID rid;
-    hr = sig.GetData(&rid);
+    hr = sig.GetData(pRid);
     if (FAILED(hr))
     {
-        return NULL;
+        return;
     }
     
     if (methodFlags & ENCODE_METHOD_SIG_MethodInstantiation)
@@ -938,7 +858,7 @@ MethodDesc *ReadyToRunInfo::GenericMethodIterator::GetMethodDesc_NoRestore()
         hr = sig.GetData(&numGenericArgs);
         if (FAILED(hr))
         {
-            return NULL;
+            return;
         }
     
         for (DWORD i = 0; i < numGenericArgs; i++)
@@ -946,7 +866,7 @@ MethodDesc *ReadyToRunInfo::GenericMethodIterator::GetMethodDesc_NoRestore()
             hr = sig.SkipExactlyOne();
             if (FAILED(hr))
             {
-                return NULL;
+                return;
             }
         }
     }
@@ -955,8 +875,89 @@ MethodDesc *ReadyToRunInfo::GenericMethodIterator::GetMethodDesc_NoRestore()
     PCCOR_SIGNATURE pSigNew;
     DWORD cbSigNew;
     sig.GetSignature(&pSigNew, &cbSigNew);
-    uint offset = m_current.GetOffset() + (uint)(pSigNew - pBlob);
+
+    m_genericCurrentSig = pBlob;
+    *pOffset = m_genericParser.GetOffset() + (uint)(pSigNew - pBlob);
+}
+
+BOOL ReadyToRunInfo::MethodIterator::Next()
+{
+    CONTRACTL
+    {
+        GC_TRIGGERS;
+        THROWS;
+        MODE_ANY;
+    }
+    CONTRACTL_END;
+
+    // Enumerate non-generic methods
+    while (++m_methodDefIndex < (int)m_pInfo->m_methodDefEntryPoints.GetCount())
+    {
+        uint offset;
+        if (m_pInfo->m_methodDefEntryPoints.TryGetAt(m_methodDefIndex, &offset))
+        {
+            return TRUE;
+        }
+    }
+
+    // Enumerate generic instantiations
+    m_genericParser = m_genericEnum.GetNext();
+    if (!m_genericParser.IsNull())
+    {
+        ParseGenericMethodSignatureAndRid(&m_genericCurrentOffset, &m_genericCurrentRid);
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
+MethodDesc * ReadyToRunInfo::MethodIterator::GetMethodDesc()
+{
+    STANDARD_VM_CONTRACT;
+
+    mdMethodDef methodToken = mdTokenNil;
+    if (m_methodDefIndex < (int)m_pInfo->m_methodDefEntryPoints.GetCount())
+    {
+        methodToken = mdtMethodDef | (m_methodDefIndex + 1);
+        return MemberLoader::GetMethodDescFromMethodDef(m_pInfo->m_pModule, methodToken, FALSE);
+    }
+    else
+    {
+        _ASSERTE(m_genericCurrentOffset > 0 && m_genericCurrentSig != NULL);
+        return ZapSig::DecodeMethod(m_pInfo->m_pModule, m_pInfo->m_pModule, m_genericCurrentSig);
+    }
     
+}
+
+MethodDesc * ReadyToRunInfo::MethodIterator::GetMethodDesc_NoRestore()
+{
+    CONTRACTL
+    {
+        GC_TRIGGERS;
+        THROWS;
+        MODE_ANY;
+    }
+    CONTRACTL_END;
+
+    uint offset;
+    if (m_methodDefIndex < (int)m_pInfo->m_methodDefEntryPoints.GetCount())
+    {
+        if (!m_pInfo->m_methodDefEntryPoints.TryGetAt(m_methodDefIndex, &offset))
+        {
+            return NULL;
+        }
+    }
+    else
+    {
+        if (m_genericCurrentOffset <= 0)
+        {
+            // Failed to parse generic info.
+            return NULL;
+        }
+
+        offset = m_genericCurrentOffset;
+    }
+
     uint id;
     offset = m_pInfo->m_nativeReader.DecodeUnsigned(offset, &id);
 
@@ -982,6 +983,15 @@ MethodDesc *ReadyToRunInfo::GenericMethodIterator::GetMethodDesc_NoRestore()
     return m_pInfo->GetMethodDescForEntryPoint(pEntryPoint);
 }
 
+PCODE ReadyToRunInfo::MethodIterator::GetMethodStartAddress()
+{
+    STANDARD_VM_CONTRACT;
+
+    PCODE ret = m_pInfo->GetEntryPoint(GetMethodDesc(), NULL, FALSE);
+    _ASSERTE(ret != NULL);
+    return ret;
+}
+
 DWORD ReadyToRunInfo::GetFieldBaseOffset(MethodTable * pMT)
 {
     STANDARD_VM_CONTRACT;
index 597bf68..8bf781f 100644 (file)
@@ -117,31 +117,23 @@ public:
         ReadyToRunInfo * m_pInfo;
         int m_methodDefIndex;
 
-    public:
-        MethodIterator(ReadyToRunInfo * pInfo) : 
-            m_pInfo(pInfo), 
-            m_methodDefIndex(-1)
-        {
-        }
+        NativeFormat::NativeHashtable::AllEntriesEnumerator m_genericEnum;
+        NativeFormat::NativeParser m_genericParser;
+        uint m_genericCurrentOffset;
+        RID m_genericCurrentRid;
+        PCCOR_SIGNATURE m_genericCurrentSig;
 
-        BOOL Next();
-
-        MethodDesc * GetMethodDesc();
-        MethodDesc * GetMethodDesc_NoRestore();
-        PCODE GetMethodStartAddress();
-    };
-
-    class GenericMethodIterator
-    {
-        ReadyToRunInfo *m_pInfo;
-        NativeFormat::NativeHashtable::AllEntriesEnumerator m_enum;
-        NativeFormat::NativeParser m_current;
+        void ParseGenericMethodSignatureAndRid(uint *offset, RID *rid);
 
     public:
-        GenericMethodIterator(ReadyToRunInfo *pInfo) :
+        MethodIterator(ReadyToRunInfo * pInfo) : 
             m_pInfo(pInfo), 
-            m_enum(),
-            m_current()
+            m_methodDefIndex(-1),
+            m_genericEnum(),
+            m_genericParser(),
+            m_genericCurrentOffset(-1),
+            m_genericCurrentRid(-1),
+            m_genericCurrentSig(NULL)
         {
             NativeFormat::PTR_NativeHashtable pHash = NULL;
             if (!pInfo->m_instMethodEntryPoints.IsNull())
@@ -149,11 +141,14 @@ public:
                 pHash = NativeFormat::PTR_NativeHashtable(&pInfo->m_instMethodEntryPoints);
             }
 
-            m_enum = NativeFormat::NativeHashtable::AllEntriesEnumerator(pHash);
+            m_genericEnum = NativeFormat::NativeHashtable::AllEntriesEnumerator(pHash);
         }
 
         BOOL Next();
+
+        MethodDesc * GetMethodDesc();
         MethodDesc * GetMethodDesc_NoRestore();
+        PCODE GetMethodStartAddress();
     };
 
     static DWORD GetFieldBaseOffset(MethodTable * pMT);
index 125ff7e..98ed89d 100644 (file)
@@ -913,11 +913,13 @@ MethodDesc *ZapSig::DecodeMethod(Module *pReferencingModule,
     if (ppTH != NULL)
         *ppTH = thOwner;
 
+#ifndef CROSSGEN_COMPILE
     // Ensure that the methoddescs dependencies have been walked sufficiently for type forwarders to be resolved.
     // This method is actually basically a nop for dependencies which are ngen'd, but is real work for jitted
     // dependencies. (However, this shouldn't be meaningful work that wouldn't happen in any case very soon.)
     pMethod->PrepareForUseAsADependencyOfANativeImage();
-
+#endif // CROSSGEN_COMPILE
+    
     Instantiation inst;
 
     // Instantiate the method if needed, or create a stub to a static method in a generic class.