Skip to content

Commit

Permalink
Remove WinRT weak handles support in the runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky committed Apr 29, 2020
1 parent 1de6a16 commit 4e0512d
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 568 deletions.
4 changes: 0 additions & 4 deletions src/coreclr/src/debug/daccess/daccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8251,10 +8251,6 @@ void CALLBACK DacHandleWalker::EnumCallbackSOS(PTR_UNCHECKED_OBJECTREF handle, u
data.Type = param->Type;
if (param->Type == HNDTYPE_DEPENDENT)
data.Secondary = GetDependentHandleSecondary(handle.GetAddr()).GetAddr();
#ifdef FEATURE_COMINTEROP
else if (param->Type == HNDTYPE_WEAK_WINRT)
data.Secondary = HndGetHandleExtraInfo(handle.GetAddr());
#endif // FEATURE_COMINTEROP
else
data.Secondary = 0;
data.AppDomain = param->AppDomain;
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/src/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7490,9 +7490,6 @@ UINT32 DacRefWalker::GetHandleWalkerMask()
#ifdef FEATURE_COMINTEROP
if ((mHandleMask & CorHandleWeakRefCount) || (mHandleMask & CorHandleStrongRefCount))
result |= (1 << HNDTYPE_REFCOUNTED);

if (mHandleMask & CorHandleWeakWinRT)
result |= (1 << HNDTYPE_WEAK_WINRT);
#endif // FEATURE_COMINTEROP

if (mHandleMask & CorHandleStrongDependent)
Expand Down Expand Up @@ -7666,10 +7663,6 @@ void CALLBACK DacHandleWalker::EnumCallbackDac(PTR_UNCHECKED_OBJECTREF handle, u
GetRefCountedHandleInfo((OBJECTREF)*handle, param->Type, &refCnt, NULL, NULL, NULL);
data.i64ExtraData = refCnt;
break;

case HNDTYPE_WEAK_WINRT:
data.dwType = (DWORD)CorHandleWeakWinRT;
break;
#endif

case HNDTYPE_DEPENDENT:
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3253,7 +3253,7 @@ HRESULT ClrDataAccess::GetHandleEnum(ISOSHandleEnum **ppHandleEnum)
unsigned int types[] = {HNDTYPE_WEAK_SHORT, HNDTYPE_WEAK_LONG, HNDTYPE_STRONG, HNDTYPE_PINNED, HNDTYPE_VARIABLE, HNDTYPE_DEPENDENT,
HNDTYPE_ASYNCPINNED, HNDTYPE_SIZEDREF,
#ifdef FEATURE_COMINTEROP
HNDTYPE_REFCOUNTED, HNDTYPE_WEAK_WINRT
HNDTYPE_REFCOUNTED
#endif
};

Expand Down Expand Up @@ -3291,7 +3291,7 @@ HRESULT ClrDataAccess::GetHandleEnumForGC(unsigned int gen, ISOSHandleEnum **ppH
unsigned int types[] = {HNDTYPE_WEAK_SHORT, HNDTYPE_WEAK_LONG, HNDTYPE_STRONG, HNDTYPE_PINNED, HNDTYPE_VARIABLE, HNDTYPE_DEPENDENT,
HNDTYPE_ASYNCPINNED, HNDTYPE_SIZEDREF,
#ifdef FEATURE_COMINTEROP
HNDTYPE_REFCOUNTED, HNDTYPE_WEAK_WINRT
HNDTYPE_REFCOUNTED
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/gc/gchandletable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Object* GCHandleManager::InterlockedCompareExchangeObjectInHandle(OBJECTHANDLE h
HandleType GCHandleManager::HandleFetchType(OBJECTHANDLE handle)
{
uint32_t type = ::HandleFetchType(handle);
assert(type >= HNDTYPE_WEAK_SHORT && type <= HNDTYPE_WEAK_WINRT);
assert(type >= HNDTYPE_WEAK_SHORT && type <= HNDTYPE_SIZEDREF);
return static_cast<HandleType>(type);
}

Expand Down
16 changes: 1 addition & 15 deletions src/coreclr/src/gc/gcinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,7 @@ typedef enum
* be calculated.
*
*/
HNDTYPE_SIZEDREF = 8,

/*
* WINRT WEAK HANDLES
*
* WinRT weak reference handles hold two different types of weak handles to any
* RCW with an underlying COM object that implements IWeakReferenceSource. The
* object reference itself is a short weak handle to the RCW. In addition an
* IWeakReference* to the underlying COM object is stored, allowing the handle
* to create a new RCW if the existing RCW is collected. This ensures that any
* code holding onto a WinRT weak reference can always access an RCW to the
* underlying COM object as long as it has not been released by all of its strong
* references.
*/
HNDTYPE_WEAK_WINRT = 9
HNDTYPE_SIZEDREF = 8
} HandleType;

typedef enum
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/src/gc/handletable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,6 @@ void HndDestroyHandleOfUnknownType(HHANDLETABLE hTable, OBJECTHANDLE handle)
// sanity check handle we are being asked to free
_ASSERTE(handle);

#ifdef FEATURE_COMINTEROP
// If we're being asked to destroy a WinRT weak handle, that will cause a leak
// of the IWeakReference* that it holds in its extra data. Instead of using this
// API use DestroyWinRTWeakHandle instead.
_ASSERTE(HandleFetchType(handle) != HNDTYPE_WEAK_WINRT);
#endif // FEATURE_COMINTEROP

// fetch the type and then free normally
HndDestroyHandle(hTable, HandleFetchType(handle), handle);
}
Expand Down
22 changes: 0 additions & 22 deletions src/coreclr/src/gc/objecthandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,6 @@ void CALLBACK ScanPointerForProfilerAndETW(_UNCHECKED_OBJECTREF *pObjRef, uintpt
break;
case HNDTYPE_WEAK_SHORT:
case HNDTYPE_WEAK_LONG:
#ifdef FEATURE_COMINTEROP
case HNDTYPE_WEAK_WINRT:
#endif // FEATURE_COMINTEROP
rootFlags |= kEtwGCRootFlagsWeakRef;
break;

Expand Down Expand Up @@ -520,7 +517,6 @@ static const uint32_t s_rgTypeFlags[] =
HNDF_EXTRAINFO, // HNDTYPE_DEPENDENT
HNDF_NORMAL, // HNDTYPE_ASYNCPINNED
HNDF_EXTRAINFO, // HNDTYPE_SIZEDREF
HNDF_EXTRAINFO, // HNDTYPE_WEAK_WINRT
};

int getNumberOfSlots()
Expand Down Expand Up @@ -1379,9 +1375,6 @@ void Ref_CheckAlive(uint32_t condemned, uint32_t maxgen, uintptr_t lp1)
uint32_t types[] =
{
HNDTYPE_WEAK_SHORT
#ifdef FEATURE_COMINTEROP
, HNDTYPE_WEAK_WINRT
#endif // FEATURE_COMINTEROP
};
uint32_t flags = (((ScanContext*) lp1)->concurrent) ? HNDGCF_ASYNC : HNDGCF_NORMAL;

Expand Down Expand Up @@ -1438,9 +1431,6 @@ void Ref_UpdatePointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Re
#if defined(FEATURE_COMINTEROP) || defined(FEATURE_REDHAWK)
HNDTYPE_REFCOUNTED,
#endif // FEATURE_COMINTEROP || FEATURE_REDHAWK
#ifdef FEATURE_COMINTEROP
HNDTYPE_WEAK_WINRT,
#endif // FEATURE_COMINTEROP
HNDTYPE_SIZEDREF,
};

Expand Down Expand Up @@ -1484,9 +1474,6 @@ void Ref_ScanHandlesForProfilerAndETW(uint32_t maxgen, uintptr_t lp1, handle_sca
#if defined(FEATURE_COMINTEROP) || defined(FEATURE_REDHAWK)
HNDTYPE_REFCOUNTED,
#endif // FEATURE_COMINTEROP || FEATURE_REDHAWK
#ifdef FEATURE_COMINTEROP
HNDTYPE_WEAK_WINRT,
#endif // FEATURE_COMINTEROP
HNDTYPE_PINNED,
// HNDTYPE_VARIABLE,
HNDTYPE_ASYNCPINNED,
Expand Down Expand Up @@ -1630,9 +1617,6 @@ void Ref_AgeHandles(uint32_t condemned, uint32_t maxgen, uintptr_t lp1)
#if defined(FEATURE_COMINTEROP) || defined(FEATURE_REDHAWK)
HNDTYPE_REFCOUNTED,
#endif // FEATURE_COMINTEROP || FEATURE_REDHAWK
#ifdef FEATURE_COMINTEROP
HNDTYPE_WEAK_WINRT,
#endif // FEATURE_COMINTEROP
HNDTYPE_ASYNCPINNED,
HNDTYPE_SIZEDREF,
};
Expand Down Expand Up @@ -1673,9 +1657,6 @@ void Ref_RejuvenateHandles(uint32_t condemned, uint32_t maxgen, uintptr_t lp1)
#if defined(FEATURE_COMINTEROP) || defined(FEATURE_REDHAWK)
HNDTYPE_REFCOUNTED,
#endif // FEATURE_COMINTEROP || FEATURE_REDHAWK
#ifdef FEATURE_COMINTEROP
HNDTYPE_WEAK_WINRT,
#endif // FEATURE_COMINTEROP
HNDTYPE_ASYNCPINNED,
HNDTYPE_SIZEDREF,
};
Expand Down Expand Up @@ -1715,9 +1696,6 @@ void Ref_VerifyHandleTable(uint32_t condemned, uint32_t maxgen, ScanContext* sc)
#if defined(FEATURE_COMINTEROP) || defined(FEATURE_REDHAWK)
HNDTYPE_REFCOUNTED,
#endif // FEATURE_COMINTEROP || FEATURE_REDHAWK
#ifdef FEATURE_COMINTEROP
HNDTYPE_WEAK_WINRT,
#endif // FEATURE_COMINTEROP
HNDTYPE_ASYNCPINNED,
HNDTYPE_SIZEDREF,
HNDTYPE_DEPENDENT,
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/src/vm/appdomain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,12 +1098,6 @@ class BaseDomain
WRAPPER_NO_CONTRACT;
return ::CreateRefcountedHandle(m_handleStore, object);
}

OBJECTHANDLE CreateWinRTWeakHandle(OBJECTREF object, IWeakReference* pWinRTWeakReference)
{
WRAPPER_NO_CONTRACT;
return ::CreateWinRTWeakHandle(m_handleStore, object, pWinRTWeakReference);
}
#endif // FEATURE_COMINTEROP

OBJECTHANDLE CreateVariableHandle(OBJECTREF object, UINT type)
Expand Down
41 changes: 0 additions & 41 deletions src/coreclr/src/vm/gchandleutilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,6 @@ inline OBJECTHANDLE CreateGlobalRefcountedHandle(OBJECTREF object)

// Special handle creation convenience functions

#ifdef FEATURE_COMINTEROP
inline OBJECTHANDLE CreateWinRTWeakHandle(IGCHandleStore* store, OBJECTREF object, IWeakReference* pWinRTWeakReference)
{
OBJECTHANDLE hnd = store->CreateHandleWithExtraInfo(OBJECTREFToObject(object), HNDTYPE_WEAK_WINRT, (void*)pWinRTWeakReference);
if (!hnd)
{
COMPlusThrowOM();
}

DiagHandleCreated(hnd, object);
return hnd;
}
#endif // FEATURE_COMINTEROP

// Creates a variable-strength handle
inline OBJECTHANDLE CreateVariableHandle(IGCHandleStore* store, OBJECTREF object, uint32_t type)
{
Expand Down Expand Up @@ -362,33 +348,6 @@ inline void DestroyTypedHandle(OBJECTHANDLE handle)
GCHandleUtilities::GetGCHandleManager()->DestroyHandleOfUnknownType(handle);
}

#ifdef FEATURE_COMINTEROP
inline void DestroyWinRTWeakHandle(OBJECTHANDLE handle)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
CAN_TAKE_LOCK;
}
CONTRACTL_END;

// Release the WinRT weak reference if we have one. We're assuming that this will not reenter the
// runtime, since if we are pointing at a managed object, we should not be using HNDTYPE_WEAK_WINRT
// but rather HNDTYPE_WEAK_SHORT or HNDTYPE_WEAK_LONG.
void* pExtraInfo = GCHandleUtilities::GetGCHandleManager()->GetExtraInfoFromHandle(handle);
IWeakReference* pWinRTWeakReference = reinterpret_cast<IWeakReference*>(pExtraInfo);
if (pWinRTWeakReference != nullptr)
{
pWinRTWeakReference->Release();
}

DiagHandleDestroyed(handle);
GCHandleUtilities::GetGCHandleManager()->DestroyHandleOfType(handle, HNDTYPE_WEAK_WINRT);
}
#endif

// Handle holders/wrappers

#ifndef FEATURE_REDHAWK
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/marshalnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ FCIMPL2(LPVOID, MarshalNative::GCHandleInternalAlloc, Object *obj, int type)

OBJECTREF objRef(obj);

assert(type >= HNDTYPE_WEAK_SHORT && type <= HNDTYPE_WEAK_WINRT);
assert(type >= HNDTYPE_WEAK_SHORT && type <= HNDTYPE_SIZEDREF);

if (CORProfilerTrackGC())
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/runtimehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ PVOID QCALLTYPE RuntimeTypeHandle::GetGCHandle(QCall::TypeHandle pTypeHandle, IN
GCX_COOP();

TypeHandle th = pTypeHandle.AsTypeHandle();
assert(handleType >= HNDTYPE_WEAK_SHORT && handleType <= HNDTYPE_WEAK_WINRT);
assert(handleType >= HNDTYPE_WEAK_SHORT && handleType <= HNDTYPE_SIZEDREF);
objHandle = AppDomain::GetCurrentDomain()->CreateTypedHandle(NULL, static_cast<HandleType>(handleType));
th.GetLoaderAllocator()->RegisterHandleForCleanup(objHandle);

Expand Down
Loading

0 comments on commit 4e0512d

Please sign in to comment.