From 4c245af72efc34492ff0731fa1779f8dc6ae5e41 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 22 Jun 2020 18:49:22 -0700 Subject: [PATCH 1/2] Remove RCWAuxiliaryData --- src/coreclr/src/vm/runtimecallablewrapper.cpp | 323 ------------------ src/coreclr/src/vm/runtimecallablewrapper.h | 231 +------------ src/coreclr/src/vm/stubhelpers.cpp | 22 -- 3 files changed, 17 insertions(+), 559 deletions(-) diff --git a/src/coreclr/src/vm/runtimecallablewrapper.cpp b/src/coreclr/src/vm/runtimecallablewrapper.cpp index cc028577f0f518..ea93e6458ce117 100644 --- a/src/coreclr/src/vm/runtimecallablewrapper.cpp +++ b/src/coreclr/src/vm/runtimecallablewrapper.cpp @@ -948,37 +948,6 @@ void RCWCache::ReleaseWrappersWorker(LPVOID pCtxCookie) pWrap->DecoupleFromObject(); RemoveWrapper(pWrap); } - else if (!pWrap->IsFreeThreaded()) - { - // We have a non-zero pCtxCookie but this RCW was not created in that context. We still - // need to take a closer look at the RCW because its interface pointer cache may contain - // pointers acquired in the given context - and those need to be released here. - if (pWrap->m_pAuxiliaryData != NULL) - { - RCWAuxiliaryData::InterfaceEntryIterator it = pWrap->m_pAuxiliaryData->IterateInterfacePointers(); - while (it.Next()) - { - InterfaceEntry *pEntry = it.GetEntry(); - if (!pEntry->IsFree() && it.GetCtxCookie() == pCtxCookie) - { - RCWInterfacePointer intfPtr; - intfPtr.m_pUnk = pEntry->m_pUnknown; - intfPtr.m_pRCW = pWrap; - intfPtr.m_pCtxEntry = it.GetCtxEntryNoAddRef(); - - if (!pWrap->IsURTAggregated()) - InterfacePointerList.Push(intfPtr); - else - AggregatedInterfacePointerList.Push(intfPtr); - - // Reset the CtxEntry first, so we don't race with RCWAuxiliaryData::CacheInterfacePointer - // which may try to reuse the InterfaceEntry for another (pUnk, MT, CtxEntry) triplet. - it.ResetCtxEntry(); - pEntry->Free(); - } - } - } - } } } @@ -1429,150 +1398,6 @@ VOID RCWCleanupList::ReleaseRCWListRaw(RCW* pRCW) } } -// Destroys RCWAuxiliaryData. Note that we do not release interface pointers stored in the -// auxiliary interface pointer cache here. That needs to be done in the right COM context -// (see code:RCW::ReleaseAuxInterfacesCallBack). -RCWAuxiliaryData::~RCWAuxiliaryData() -{ - CONTRACTL - { - NOTHROW; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - if (m_prVariantInterfaces != NULL) - { - delete m_prVariantInterfaces; - } - - InterfaceEntryEx *pEntry = m_pInterfaceCache; - while (pEntry) - { - InterfaceEntryEx *pNextEntry = pEntry->m_pNext; - - delete pEntry; - pEntry = pNextEntry; - } - - if (VARIANCE_STUB_TARGET_IS_HANDLE(m_ohObjectVariantCallTarget_IEnumerable)) - { - DestroyHandle(m_ohObjectVariantCallTarget_IEnumerable); - } - if (VARIANCE_STUB_TARGET_IS_HANDLE(m_ohObjectVariantCallTarget_IReadOnlyList)) - { - DestroyHandle(m_ohObjectVariantCallTarget_IReadOnlyList); - } -} - -// Inserts variant interfaces to the cache. -void RCWAuxiliaryData::CacheVariantInterface(MethodTable *pMT) -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - CrstHolder ch(&m_VarianceCacheCrst); - - if (m_prVariantInterfaces == NULL) - { - m_prVariantInterfaces = new ArrayList(); - } - - if (pMT->HasVariance() && m_prVariantInterfaces->FindElement(0, pMT) == ArrayList::NOT_FOUND) - { - m_prVariantInterfaces->Append(pMT); - } - - // check implemented interfaces as well - MethodTable::InterfaceMapIterator it = pMT->IterateInterfaceMap(); - while (it.Next()) - { - MethodTable *pItfMT = it.GetInterface(); - if (pItfMT->HasVariance() && m_prVariantInterfaces->FindElement(0, pItfMT) == ArrayList::NOT_FOUND) - { - m_prVariantInterfaces->Append(pItfMT); - } - } -} - -// Inserts an interface pointer in the cache. -void RCWAuxiliaryData::CacheInterfacePointer(MethodTable *pMT, IUnknown *pUnk, LPVOID pCtxCookie) -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - InterfaceEntryEx *pEntry = NULL; - - // first, try to find a free entry to reuse - InterfaceEntryIterator it = IterateInterfacePointers(); - while (it.Next()) - { - InterfaceEntry *pEntry = it.GetEntry(); - if (pEntry->IsFree() && pEntry->Init(pMT, pUnk)) - { - // setting the cookie after "publishing" the entry is fine, at worst - // we may miss the cache if someone looks for this pMT concurrently - _ASSERTE_MSG(it.GetCtxCookie() == NULL, "Race condition detected, we are supposed to own the InterfaceEntry at this point"); - it.SetCtxCookie(pCtxCookie); - return; - } - } - - // create a new entry if a free one was not found - InterfaceEntryEx *pEntryEx = new InterfaceEntryEx(); - ZeroMemory(pEntryEx, sizeof(InterfaceEntryEx)); - - pEntryEx->m_BaseEntry.Init(pMT, pUnk); - - if (pCtxCookie != NULL) - { - pEntryEx->m_pCtxEntry = CtxEntryCache::GetCtxEntryCache()->FindCtxEntry(pCtxCookie, GetThread()); - } - else - { - pEntryEx->m_pCtxEntry = NULL; - } - - // and insert it into the linked list (the interlocked operation ensures that - // the list is walkable by other threads at all times) - InterfaceEntryEx *pNext; - do - { - pNext = VolatileLoad(&m_pInterfaceCache); // our candidate "next" - pEntryEx->m_pNext = pNext; - } - while (FastInterlockCompareExchangePointer(&m_pInterfaceCache, pEntryEx, pNext) != pNext); -} - -// Returns a cached interface pointer or NULL if there was no match. -IUnknown *RCWAuxiliaryData::FindInterfacePointer(MethodTable *pMT, LPVOID pCtxCookie) -{ - LIMITED_METHOD_CONTRACT; - - InterfaceEntryIterator it = IterateInterfacePointers(); - while (it.Next()) - { - InterfaceEntry *pEntry = it.GetEntry(); - if (!pEntry->IsFree() && pEntry->m_pMT == (IE_METHODTABLE_PTR)pMT && it.GetCtxCookie() == pCtxCookie) - { - return pEntry->m_pUnknown; - } - } - - return NULL; -} - const int RCW::s_rGCPressureTable[GCPressureSize_COUNT] = { 0, // GCPressureSize_None @@ -2128,11 +1953,6 @@ void RCW::Cleanup() RemoveMemoryPressure(); } - if (m_pAuxiliaryData != NULL) - { - delete m_pAuxiliaryData; - } - #ifdef _DEBUG m_cbRefCount = 0; m_SyncBlockIndex = 0; @@ -2517,17 +2337,6 @@ IUnknown* RCW::GetComIPForMethodTableFromCache(MethodTable* pMT) } } - if (m_pAuxiliaryData != NULL) - { - pUnk = m_pAuxiliaryData->FindInterfacePointer(pMT, (IsFreeThreaded() ? NULL : pCtxCookie)); - if (pUnk != NULL) - { - cbRef = SafeAddRef(pUnk); - LogInteropAddRef(pUnk, cbRef, "RCW::GetComIPForMethodTableFromCache: Addref because returning pUnk fetched from auxiliary interface pointer cache"); - RETURN pUnk; - } - } - // We're going to be making some COM calls, better initialize COM. EnsureComStarted(); @@ -2537,11 +2346,8 @@ IUnknown* RCW::GetComIPForMethodTableFromCache(MethodTable* pMT) if (pUnk == NULL) RETURN NULL; - bool fAllowOutOfContextCache = false; - // try to cache the interface pointer in the inline cache. This cache can only store interface pointers // returned from QI's in the same context where we created the RCW. - bool fInterfaceCached = false; if (GetWrapperCtxCookie() == pCtxCookie || IsFreeThreaded()) { for (i = 0; i < INTERFACE_ENTRY_CACHE_SIZE; i++) @@ -2556,29 +2362,11 @@ IUnknown* RCW::GetComIPForMethodTableFromCache(MethodTable* pMT) LogInteropAddRef(pUnk, cbRef, "RCW::GetComIPForMethodTableFromCache: Addref because storing pUnk in InterfaceEntry cache"); } - fInterfaceCached = true; break; } } } - if (!fInterfaceCached && fAllowOutOfContextCache) - { - // We couldn't insert into the inline cache, either because it didn't fit, or because - // we are in a wrong COM context. We'll use the RCWAuxiliaryData structure. - GetOrCreateAuxiliaryData()->CacheInterfacePointer(pMT, pUnk, (IsFreeThreaded() ? NULL : pCtxCookie)); - - // If the component is not aggregated then we need to ref-count - if (!IsURTAggregated()) - { - // Get an extra addref to hold this reference alive in our cache - cbRef = SafeAddRef(pUnk); - LogInteropAddRef(pUnk, cbRef, "RCW::GetComIPForMethodTableFromCache: Addref because storing pUnk in the auxiliary interface pointer cache"); - } - - fInterfaceCached = true; - } - RETURN pUnk; } @@ -2637,53 +2425,6 @@ HRESULT RCW::EnterContext(PFNCTXCALLBACK pCallbackFunc, LPVOID pData) return pCtxEntry->EnterContext(pCallbackFunc, pData); } -//--------------------------------------------------------------------- -// Callback called to release the interfaces in the auxiliary cache. -HRESULT __stdcall RCW::ReleaseAuxInterfacesCallBack(LPVOID pData) -{ - CONTRACT(HRESULT) - { - NOTHROW; - GC_TRIGGERS; - MODE_PREEMPTIVE; - PRECONDITION(CheckPointer(pData)); - POSTCONDITION(SUCCEEDED(RETVAL)); - } - CONTRACT_END; - - RCW* pWrap = (RCW*)pData; - - LPVOID pCurrentCtxCookie = GetCurrentCtxCookie(); - _ASSERTE(pCurrentCtxCookie != NULL); - - RCW_VTABLEPTR(pWrap); - - // we don't come here for free-threaded RCWs - _ASSERTE(!pWrap->IsFreeThreaded()); - - // we don't come here if there are no interfaces in the aux cache - _ASSERTE(pWrap->m_pAuxiliaryData != NULL); - - RCWAuxiliaryData::InterfaceEntryIterator it = pWrap->m_pAuxiliaryData->IterateInterfacePointers(); - while (it.Next()) - { - InterfaceEntry *pEntry = it.GetEntry(); - if (!pEntry->IsFree()) - { - if (pCurrentCtxCookie == it.GetCtxCookie()) - { - IUnknown *pUnk = it.GetEntry()->m_pUnknown; - - // make sure we never try to clean this up again - pEntry->Free(); - SafeReleasePreemp(pUnk, pWrap); - } - } - } - - RETURN S_OK; -} - //--------------------------------------------------------------------- // Callback called to release the IUnkEntry and the Interface entries. HRESULT __stdcall RCW::ReleaseAllInterfacesCallBack(LPVOID pData) @@ -2723,47 +2464,6 @@ HRESULT __stdcall RCW::ReleaseAllInterfacesCallBack(LPVOID pData) } } - // Free auxiliary interface entries if this is not an extensible RCW - if (!pWrap->IsURTAggregated() && pWrap->m_pAuxiliaryData != NULL) - { - RCWAuxiliaryData::InterfaceEntryIterator it = pWrap->m_pAuxiliaryData->IterateInterfacePointers(); - while (it.Next()) - { - InterfaceEntry *pEntry = it.GetEntry(); - if (!pEntry->IsFree()) - { - IUnknown *pUnk = it.GetEntry()->m_pUnknown; - - if (pCurrentCtxCookie == NULL || pCurrentCtxCookie == it.GetCtxCookie() || pWrap->IsFreeThreaded()) - { - // make sure we never try to clean this up again - pEntry->Free(); - SafeReleasePreemp(pUnk, pWrap); - } - else - { - // Retrieve the addref'ed context entry that the wrapper lives in. - CtxEntryHolder pCtxEntry = it.GetCtxEntry(); - - // Transition into the context to release the interfaces. - HRESULT hr = pCtxEntry->EnterContext(ReleaseAuxInterfacesCallBack, pWrap); - if (FAILED(hr)) - { - // The context is disconnected so we cannot transition into it to clean up. - // The only option we have left is to try and release the interfaces from - // the current context. This will work for context agile object's since we have - // a pointer to them directly. It will however fail for others since we only - // have a pointer to a proxy which is no longer attached to the object. - - // make sure we never try to clean this up again - pEntry->Free(); - SafeReleasePreemp(pUnk, pWrap); - } - } - } - } - } - RETURN S_OK; } @@ -2802,29 +2502,6 @@ void RCW::ReleaseAllInterfaces() } } -//--------------------------------------------------------------------- -// Returns RCWAuxiliaryData associated with this RCW. -PTR_RCWAuxiliaryData RCW::GetOrCreateAuxiliaryData() -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - if (m_pAuxiliaryData == NULL) - { - NewHolder pData = new RCWAuxiliaryData(); - if (InterlockedCompareExchangeT(&m_pAuxiliaryData, pData.GetValue(), NULL) == NULL) - { - pData.SuppressRelease(); - } - } - return m_pAuxiliaryData; -} - //--------------------------------------------------------------------- // Returns true if the RCW supports given "standard managed" interface. bool RCW::SupportsMngStdInterface(MethodTable *pItfMT) diff --git a/src/coreclr/src/vm/runtimecallablewrapper.h b/src/coreclr/src/vm/runtimecallablewrapper.h index 49868e3dc43d64..681ce3f325ae92 100644 --- a/src/coreclr/src/vm/runtimecallablewrapper.h +++ b/src/coreclr/src/vm/runtimecallablewrapper.h @@ -79,182 +79,6 @@ class Thread; enum {INTERFACE_ENTRY_CACHE_SIZE = 8}; -struct RCWAuxiliaryData; -typedef DPTR(RCWAuxiliaryData) PTR_RCWAuxiliaryData; - -#define VARIANCE_STUB_TARGET_USE_STRING ((OBJECTHANDLE)(INT_PTR)0x1) -#define VARIANCE_STUB_TARGET_USE_T ((OBJECTHANDLE)(INT_PTR)0x2) -#define VARIANCE_STUB_TARGET_IS_HANDLE(handle) (((INT_PTR)(handle) & ~0x3) != 0) - -// Additional RCW data used for generic interop and auxiliary interface pointer cache. -// This structure is lazily allocated and associated with the RCW via the m_pAuxiliaryData -// field. It's needed only if the RCW supports IEnumerable or another interface with -// variance, or if a QI result could not be saved in the inline interface pointer cache -// (code:RCW.m_aInterfaceEntries). -struct RCWAuxiliaryData -{ - RCWAuxiliaryData() - { - WRAPPER_NO_CONTRACT; - - m_pGetEnumeratorMethod = NULL; - m_prVariantInterfaces = NULL; - m_VarianceCacheCrst.Init(CrstLeafLock); - m_pInterfaceCache = NULL; - m_ohObjectVariantCallTarget_IEnumerable = NULL; - m_ohObjectVariantCallTarget_IReadOnlyList = NULL; - m_AuxFlags.m_dwFlags = 0; - } - - ~RCWAuxiliaryData(); - - struct InterfaceEntryEx; - typedef DPTR(InterfaceEntryEx) PTR_InterfaceEntryEx; - - // Augments code:InterfaceEntry with a next pointer and context entry field. - struct InterfaceEntryEx - { - PTR_InterfaceEntryEx m_pNext; - - InterfaceEntry m_BaseEntry; - PTR_CtxEntry m_pCtxEntry; - - ~InterfaceEntryEx() - { - WRAPPER_NO_CONTRACT; - if (m_pCtxEntry != NULL) - { - m_pCtxEntry->Release(); - } - } - }; - - // Iterator for cached interface entries. - class InterfaceEntryIterator - { - PTR_InterfaceEntryEx m_pCurrent; - bool m_fFirst; - - public: - inline InterfaceEntryIterator(PTR_RCWAuxiliaryData pAuxiliaryData) - { - LIMITED_METHOD_CONTRACT; - m_pCurrent = (pAuxiliaryData == NULL ? NULL : pAuxiliaryData->m_pInterfaceCache); - m_fFirst = true; - } - - // Move to the next item returning TRUE if an item exists or FALSE if we've run off the end - inline bool Next() - { - LIMITED_METHOD_CONTRACT; - if (m_fFirst) - { - m_fFirst = false; - } - else - { - m_pCurrent = m_pCurrent->m_pNext; - } - return (m_pCurrent != NULL); - } - - inline InterfaceEntry *GetEntry() - { - LIMITED_METHOD_CONTRACT; - return &m_pCurrent->m_BaseEntry; - } - - inline LPVOID GetCtxCookie() - { - LIMITED_METHOD_CONTRACT; - return (m_pCurrent->m_pCtxEntry == NULL ? NULL : m_pCurrent->m_pCtxEntry->GetCtxCookie()); - } - - inline CtxEntry *GetCtxEntry() - { - LIMITED_METHOD_CONTRACT; - - m_pCurrent->m_pCtxEntry->AddRef(); - return m_pCurrent->m_pCtxEntry; - } - - inline CtxEntry *GetCtxEntryNoAddRef() - { - LIMITED_METHOD_CONTRACT; - return m_pCurrent->m_pCtxEntry; - } - - inline void ResetCtxEntry() - { - LIMITED_METHOD_CONTRACT; - m_pCurrent->m_pCtxEntry = NULL; - } - -#ifndef DACCESS_COMPILE - inline void SetCtxCookie(LPVOID pCtxCookie) - { - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - CtxEntry *pCtxEntry = NULL; - if (pCtxCookie != NULL) - { - pCtxEntry = CtxEntryCache::GetCtxEntryCache()->FindCtxEntry(pCtxCookie, GetThread()); - } - m_pCurrent->m_pCtxEntry = pCtxEntry; - } -#endif // !DACCESS_COMPILE - }; - - void CacheVariantInterface(MethodTable *pMT); - - void CacheInterfacePointer(MethodTable *pMT, IUnknown *pUnk, LPVOID pCtxCookie); - IUnknown *FindInterfacePointer(MethodTable *pMT, LPVOID pCtxCookie); - - inline InterfaceEntryIterator IterateInterfacePointers() - { - LIMITED_METHOD_CONTRACT; - return InterfaceEntryIterator(dac_cast(this)); - } - - // GetEnumerator method of the first IEnumerable interface we successfully QI'ed for - PTR_MethodDesc m_pGetEnumeratorMethod; - - // Interfaces with variance that we successfully QI'ed for - ArrayList *m_prVariantInterfaces; - - // Lock to protect concurrent access to m_prVariantInterfaces - CrstExplicitInit m_VarianceCacheCrst; - - // Linked list of cached interface pointers - PTR_InterfaceEntryEx m_pInterfaceCache; - - // Cached object handles wrapping delegate objects that point to the right GetEnumerator/Indexer_Get - // stubs that should be used when calling these methods via IEnumerable/IReadOnlyList. - // Can also contain the special VARIANCE_STUB_TARGET_USE_STRING and VARIANCE_STUB_TARGET_USE_T values. - OBJECTHANDLE m_ohObjectVariantCallTarget_IEnumerable; // GetEnumerator - OBJECTHANDLE m_ohObjectVariantCallTarget_IReadOnlyList; // Indexer_Get - - // Rarely used RCW flags (keep the commonly used ones in code:RCW::RCWFlags) - union RCWAuxFlags - { - DWORD m_dwFlags; - - struct - { - // InterfaceVarianceBehavior for rarely used instantiations that could be supported via string: - DWORD m_InterfaceVarianceBehavior_OfIEnumerable:4; - DWORD m_InterfaceVarianceBehavior_OfIEnumerableOfChar:4; - }; - } - m_AuxFlags; -}; - typedef DPTR(RCW) PTR_RCW; //---------------------------------------------------------------------------- @@ -285,11 +109,9 @@ struct RCW { PTR_RCW m_pRCW; int m_InlineCacheIndex; - RCWAuxiliaryData::InterfaceEntryIterator m_AuxIterator; public: inline CachedInterfaceEntryIterator(PTR_RCW pRCW) - : m_AuxIterator(pRCW->m_pAuxiliaryData) { LIMITED_METHOD_CONTRACT; m_pRCW = pRCW; @@ -301,15 +123,14 @@ struct RCW { LIMITED_METHOD_CONTRACT; - if (m_InlineCacheIndex < INTERFACE_ENTRY_CACHE_SIZE) - { - // stop incrementing m_InlineCacheIndex once we reach INTERFACE_ENTRY_CACHE_SIZE - if (++m_InlineCacheIndex < INTERFACE_ENTRY_CACHE_SIZE) - { - return TRUE; - } - } - return m_AuxIterator.Next(); + if (m_InlineCacheIndex >= INTERFACE_ENTRY_CACHE_SIZE) + return FALSE; + + // stop incrementing m_InlineCacheIndex once we reach INTERFACE_ENTRY_CACHE_SIZE + if (++m_InlineCacheIndex < INTERFACE_ENTRY_CACHE_SIZE) + return TRUE; + + return FALSE; } inline InterfaceEntry *GetEntry() @@ -317,11 +138,10 @@ struct RCW LIMITED_METHOD_CONTRACT; _ASSERTE_MSG(m_InlineCacheIndex >= 0, "Iterator starts before the first element, you need to call Next"); - if (m_InlineCacheIndex < INTERFACE_ENTRY_CACHE_SIZE) - { - return &m_pRCW->m_aInterfaceEntries[m_InlineCacheIndex]; - } - return m_AuxIterator.GetEntry(); + if (m_InlineCacheIndex >= INTERFACE_ENTRY_CACHE_SIZE) + return NULL; + + return &m_pRCW->m_aInterfaceEntries[m_InlineCacheIndex]; } inline LPVOID GetCtxCookie() @@ -329,11 +149,10 @@ struct RCW LIMITED_METHOD_CONTRACT; _ASSERTE_MSG(m_InlineCacheIndex >= 0, "Iterator starts before the first element, you need to call Next"); - if (m_InlineCacheIndex < INTERFACE_ENTRY_CACHE_SIZE) - { - return m_pRCW->GetWrapperCtxCookie(); - } - return m_AuxIterator.GetCtxCookie(); + if (m_InlineCacheIndex >= INTERFACE_ENTRY_CACHE_SIZE) + return NULL; + + return m_pRCW->GetWrapperCtxCookie(); } }; @@ -390,11 +209,7 @@ struct RCW GCPressureSize_ProcessLocal = 1, GCPressureSize_MachineLocal = 2, GCPressureSize_Remote = 3, - GCPressureSize_WinRT_Base = 4, - GCPressureSize_WinRT_Low = 5, - GCPressureSize_WinRT_Medium = 6, - GCPressureSize_WinRT_High = 7, - GCPressureSize_COUNT = 8 + GCPressureSize_COUNT = 4 }; //--------------------------------------------------- @@ -654,11 +469,6 @@ struct RCW return CachedInterfaceEntryIterator(dac_cast(this)); } - //--------------------------------------------------------------------- - // Returns RCWAuxiliaryData associated with this RCW. Allocates the - // structure if it does not exist already. - PTR_RCWAuxiliaryData GetOrCreateAuxiliaryData(); - //--------------------------------------------------------------------- // Returns true iff pItfMT is a "standard managed" interface, such as // IEnumerator, and the RCW supports the interface through classic COM @@ -722,10 +532,6 @@ struct RCW } private: - //--------------------------------------------------------------------- - // Callback called to release the interfaces in the auxiliary cache. - static HRESULT __stdcall ReleaseAuxInterfacesCallBack(LPVOID pData); - //--------------------------------------------------------------------- // Callback called to release the IUnkEntry and the InterfaceEntries, static HRESULT __stdcall ReleaseAllInterfacesCallBack(LPVOID pData); @@ -793,9 +599,6 @@ struct RCW // Tracks concurrent access to this RCW to prevent using RCW instances that have already been released LONG m_cbUseCount; - // additional RCW data used for generic interop and advanced interface pointer caching (NULL unless needed) - PTR_RCWAuxiliaryData m_pAuxiliaryData; - PTR_RCW m_pNextRCW; // This field is useful for debugging purposes, please do not remove. The typical scenario is a crash in diff --git a/src/coreclr/src/vm/stubhelpers.cpp b/src/coreclr/src/vm/stubhelpers.cpp index 123885c071227d..d28031849fcf3b 100644 --- a/src/coreclr/src/vm/stubhelpers.cpp +++ b/src/coreclr/src/vm/stubhelpers.cpp @@ -251,14 +251,6 @@ FORCEINLINE static IUnknown *GetCOMIPFromRCW_GetIUnknownFromRCWCache(RCW *pRCW, } } - // also search the auxiliary cache if it's available - RCWAuxiliaryData *pAuxData = pRCW->m_pAuxiliaryData; - if (pAuxData != NULL) - { - LPVOID pCtxCookie = (pRCW->IsFreeThreaded() ? NULL : pOleTlsData->pCurrentCtx); - return pAuxData->FindInterfacePointer(pItfMT, pCtxCookie); - } - return NULL; } @@ -288,20 +280,6 @@ FORCEINLINE static IUnknown *GetCOMIPFromRCW_GetIUnknownFromRCWCache_NoIntercept } } - // also search the auxiliary cache if it's available - RCWAuxiliaryData *pAuxData = pRCW->m_pAuxiliaryData; - if (pAuxData != NULL) - { - LPVOID pCtxCookie = (pRCW->IsFreeThreaded() ? NULL : pOleTlsData->pCurrentCtx); - - IUnknown *pUnk = pAuxData->FindInterfacePointer(pItfMT, pCtxCookie); - if (pUnk != NULL) - { - *ppTarget = GetCOMIPFromRCW_GetTargetNoInterception(pUnk, pComInfo); - return pUnk; - } - } - return NULL; } From b2abcd5a63af42d8303c53720cd56aac98f7e2c6 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 22 Jun 2020 18:49:33 -0700 Subject: [PATCH 2/2] Remove unused functions --- src/coreclr/src/vm/comtoclrcall.cpp | 127 ---------------------------- src/coreclr/src/vm/comtoclrcall.h | 3 - src/coreclr/src/vm/dllimport.cpp | 3 - src/coreclr/src/vm/dllimport.h | 1 - src/coreclr/src/vm/interoputil.cpp | 37 -------- src/coreclr/src/vm/methodtable.h | 8 -- src/coreclr/src/vm/methodtable.inl | 15 ---- 7 files changed, 194 deletions(-) diff --git a/src/coreclr/src/vm/comtoclrcall.cpp b/src/coreclr/src/vm/comtoclrcall.cpp index 79686137624330..dc448070e3a145 100644 --- a/src/coreclr/src/vm/comtoclrcall.cpp +++ b/src/coreclr/src/vm/comtoclrcall.cpp @@ -272,49 +272,6 @@ OBJECTREF COMToCLRGetObjectAndTarget_Delegate(ComCallWrapper * pWrap, PCODE * pp return pDelObj->GetTarget(); } -// returns true on success, false otherwise -NOINLINE // keep the EH tax out of our caller -bool COMToCLRGetObjectAndTarget_WinRTCtor(Thread * pThread, MethodDesc * pRealMD, ComCallMethodDesc * pCMD, PCODE * ppManagedTargetOut, - OBJECTREF* pObjectOut, UINT64* pRetValOut) -{ - CONTRACTL - { - NOTHROW; - GC_TRIGGERS; - MODE_COOPERATIVE; - } - CONTRACTL_END; - - // Ctor is not virtual and operates on a newly created object. - _ASSERTE(!pCMD->IsVirtual()); - - *pObjectOut = NULL; - *ppManagedTargetOut = pRealMD->GetSingleCallableAddrOfCode(); - MethodTable *pMT = pRealMD->GetMethodTable(); - - // We should not see a unsealed class here - _ASSERTE(pMT->IsSealed()); - - // we know for sure that we are allocating a new object - - // @TODO: move this object allocation into the IL stub to avoid the try/catch and SO-intolerant region. - - bool fSuccess = true; - - EX_TRY - { - *pObjectOut = AllocateObject(pMT); - } - EX_CATCH - { - fSuccess = false; - *pRetValOut = SetupErrorInfo(GET_THROWABLE()); - } - EX_END_CATCH(SwallowAllExceptions); - - return fSuccess; -} - FORCEINLINE_NONDEBUG OBJECTREF COMToCLRGetObjectAndTarget_Virtual(ComCallWrapper * pWrap, MethodDesc * pRealMD, ComCallMethodDesc * pCMD, PCODE * ppManagedTargetOut) { @@ -1537,88 +1494,4 @@ MethodDesc* ComCall::GetILStubMethodDesc(FieldDesc *pFD, DWORD dwStubFlags) pFD); } -// static -MethodDesc *ComCall::GetCtorForWinRTFactoryMethod(MethodTable *pClsMT, MethodDesc *pMD) -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - PRECONDITION(pClsMT->IsSealed()); - } - CONTRACTL_END; - - PCCOR_SIGNATURE pSig; - DWORD cSig; - pMD->GetSig(&pSig, &cSig); - SigParser sig(pSig, cSig); - - ULONG numArgs; - - IfFailThrow(sig.GetCallingConv(NULL)); // calling convention - IfFailThrow(sig.GetData(&numArgs)); // number of args - IfFailThrow(sig.SkipExactlyOne()); // skip return type - - SigBuilder sigBuilder; - sigBuilder.AppendByte(IMAGE_CEE_CS_CALLCONV_HASTHIS); - sigBuilder.AppendData(numArgs); - - // ctor returns void - sigBuilder.AppendElementType(ELEMENT_TYPE_VOID); - - sig.GetSignature(&pSig, &cSig); - - // parameter types are identical for sealed classes - sigBuilder.AppendBlob((const PVOID)pSig, cSig); - - pSig = (PCCOR_SIGNATURE)sigBuilder.GetSignature(&cSig); - - MethodDesc *pCtorMD = MemberLoader::FindMethod(pClsMT, COR_CTOR_METHOD_NAME, pSig, cSig, pMD->GetModule()); - - if (pCtorMD == NULL) - { - SString ctorMethodName(SString::Utf8, COR_CTOR_METHOD_NAME); - COMPlusThrowNonLocalized(kMissingMethodException, ctorMethodName.GetUnicode()); - } - return pCtorMD; -} - -// static -MethodDesc *ComCall::GetStaticForWinRTFactoryMethod(MethodTable *pClsMT, MethodDesc *pMD) -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - PCCOR_SIGNATURE pSig; - DWORD cSig; - pMD->GetSig(&pSig, &cSig); - SigParser sig(pSig, cSig); - - IfFailThrow(sig.GetCallingConv(NULL)); // calling convention - - SigBuilder sigBuilder; - sigBuilder.AppendByte(IMAGE_CEE_CS_CALLCONV_DEFAULT); - - // number of parameters, return type, and parameter types are identical - sig.GetSignature(&pSig, &cSig); - sigBuilder.AppendBlob((const PVOID)pSig, cSig); - - pSig = (PCCOR_SIGNATURE)sigBuilder.GetSignature(&cSig); - - MethodDesc *pStaticMD = MemberLoader::FindMethod(pClsMT, pMD->GetName(), pSig, cSig, pMD->GetModule()); - - if (pStaticMD == NULL) - { - SString staticMethodName(SString::Utf8, pMD->GetName()); - COMPlusThrowNonLocalized(kMissingMethodException, staticMethodName.GetUnicode()); - } - return pStaticMD; -} - #endif // DACCESS_COMPILE diff --git a/src/coreclr/src/vm/comtoclrcall.h b/src/coreclr/src/vm/comtoclrcall.h index 88593d8c737eb1..2efcc606548dbd 100644 --- a/src/coreclr/src/vm/comtoclrcall.h +++ b/src/coreclr/src/vm/comtoclrcall.h @@ -87,9 +87,6 @@ class ComCall static MethodDesc* GetILStubMethodDesc(MethodDesc *pCallMD, DWORD dwStubFlags); static MethodDesc* GetILStubMethodDesc(FieldDesc *pFD, DWORD dwStubFlags); - static MethodDesc *GetCtorForWinRTFactoryMethod(MethodTable *pClsMT, MethodDesc *pMD); - static MethodDesc *GetStaticForWinRTFactoryMethod(MethodTable *pClsMT, MethodDesc *pMD); - private: ComCall() {LIMITED_METHOD_CONTRACT;}; // prevent "new"'s on this class diff --git a/src/coreclr/src/vm/dllimport.cpp b/src/coreclr/src/vm/dllimport.cpp index c351324bfb1121..0850877c8089cf 100644 --- a/src/coreclr/src/vm/dllimport.cpp +++ b/src/coreclr/src/vm/dllimport.cpp @@ -1532,9 +1532,6 @@ NDirectStubLinker::NDirectStubLinker( m_pCleanupFinallyBeginLabel(NULL), m_pCleanupFinallyEndLabel(NULL), m_pSkipExceptionCleanupLabel(NULL), -#ifdef FEATURE_COMINTEROP - m_dwWinRTFactoryObjectLocalNum(-1), -#endif // FEATURE_COMINTEROP m_fHasCleanupCode(FALSE), m_fHasExceptionCleanupCode(FALSE), m_fCleanupWorkListIsSetup(FALSE), diff --git a/src/coreclr/src/vm/dllimport.h b/src/coreclr/src/vm/dllimport.h index 035721fe697c32..042f79e8f23875 100644 --- a/src/coreclr/src/vm/dllimport.h +++ b/src/coreclr/src/vm/dllimport.h @@ -542,7 +542,6 @@ class NDirectStubLinker : public ILStubLinker #ifdef FEATURE_COMINTEROP DWORD m_dwTargetInterfacePointerLocalNum; DWORD m_dwTargetEntryPointLocalNum; - DWORD m_dwWinRTFactoryObjectLocalNum; #endif // FEATURE_COMINTEROP BOOL m_fHasCleanupCode; diff --git a/src/coreclr/src/vm/interoputil.cpp b/src/coreclr/src/vm/interoputil.cpp index b430bc94ec92a5..be2b589f5b6673 100644 --- a/src/coreclr/src/vm/interoputil.cpp +++ b/src/coreclr/src/vm/interoputil.cpp @@ -4520,43 +4520,6 @@ MethodTable* GetClassFromIProvideClassInfo(IUnknown* pUnk) #endif // FEATURE_COMINTEROP -static void DECLSPEC_NORETURN ThrowTypeLoadExceptionWithInner(MethodTable *pClassMT, LPCWSTR pwzName, HRESULT hr, unsigned resID) -{ - CONTRACTL - { - THROWS; - DISABLED(GC_NOTRIGGER); // Must sanitize first pass handling to enable this - MODE_ANY; - } - CONTRACTL_END; - - StackSString simpleName(SString::Utf8, pClassMT->GetAssembly()->GetSimpleName()); - - EEMessageException ex(hr); - EX_THROW_WITH_INNER(EETypeLoadException, (pwzName, simpleName.GetUnicode(), nullptr, resID), &ex); -} - -// -// Creates activation factory and wraps it with a RCW -// -void GetNativeWinRTFactoryObject(MethodTable *pMT, Thread *pThread, MethodTable *pFactoryIntfMT, BOOL bNeedUniqueRCW, ICOMInterfaceMarshalerCallback *pCallback, OBJECTREF *prefFactory) -{ - CONTRACTL - { - THROWS; - MODE_COOPERATIVE; - GC_TRIGGERS; - PRECONDITION(CheckPointer(pMT)); - PRECONDITION(CheckPointer(pThread)); - PRECONDITION(CheckPointer(pFactoryIntfMT, NULL_OK)); - PRECONDITION(CheckPointer(pCallback, NULL_OK)); - } - CONTRACTL_END; - - COMPlusThrow(kPlatformNotSupportedException, W("PlatformNotSupported_WinRT")); -} - #endif //#ifndef CROSSGEN_COMPILE - #endif // FEATURE_COMINTEROP diff --git a/src/coreclr/src/vm/methodtable.h b/src/coreclr/src/vm/methodtable.h index 141e9e58fb4b6b..243844ba97796c 100644 --- a/src/coreclr/src/vm/methodtable.h +++ b/src/coreclr/src/vm/methodtable.h @@ -2976,14 +2976,6 @@ class MethodTable // Get and cache the GUID for this interface/class void GetGuid(GUID *pGuid, BOOL bGenerateIfNotFound, BOOL bClassic = TRUE); -#ifdef FEATURE_COMINTEROP - // Get the GUID used for WinRT interop - // * for projection generic interfaces returns the equivalent WinRT type's GUID - // * for everything else returns the GetGuid(, TRUE) - BOOL GetGuidForWinRT(GUID *pGuid); - -#endif // FEATURE_COMINTEROP - // Convenience method - determine if the interface/class has a guid specified (even if not yet cached) BOOL HasExplicitGuid(); diff --git a/src/coreclr/src/vm/methodtable.inl b/src/coreclr/src/vm/methodtable.inl index 43e7109fee3289..21c1031bd2fce2 100644 --- a/src/coreclr/src/vm/methodtable.inl +++ b/src/coreclr/src/vm/methodtable.inl @@ -362,21 +362,6 @@ inline BOOL MethodTable::HasExplicitGuid() return (guid != GUID_NULL); } -//========================================================================================== -// Get the GUID used for WinRT interop -// * if the type is not a WinRT type or a redirected interfae return FALSE -inline BOOL MethodTable::GetGuidForWinRT(GUID *pGuid) -{ - CONTRACTL { - THROWS; - GC_TRIGGERS; - MODE_ANY; - SUPPORTS_DAC; - } CONTRACTL_END; - - return FALSE; -} - #endif // FEATURE_COMINTEROP //==========================================================================================