}
// Replace an async pin handle with one from default domain
-void SegmentRelocateAsyncPinHandles (TableSegment *pSegment, HandleTable *pTargetTable)
+bool SegmentRelocateAsyncPinHandles (TableSegment *pSegment, HandleTable *pTargetTable)
{
CONTRACTL
{
GC_NOTRIGGER;
- THROWS;
+ NOTHROW;
MODE_COOPERATIVE;
}
CONTRACTL_END;
if (uBlock == BLOCK_INVALID)
{
// There is no pinning handles.
- return;
+ return true;
}
for (uBlock = 0; uBlock < pSegment->bEmptyLine; uBlock ++)
{
BashMTForPinnedObject(ObjectToOBJECTREF(value));
overlapped->m_pinSelf = HndCreateHandle((HHANDLETABLE)pTargetTable, HNDTYPE_ASYNCPINNED, ObjectToOBJECTREF(value));
+ if (!overlapped->m_pinSelf)
+ {
+ // failed to allocate a new handle - callers have to handle this.
+ return false;
+ }
+
*pValue = NULL;
}
pValue ++;
} while (pValue != pLast);
}
+
+ return true;
}
// Mark all non-pending AsyncPinHandle ready for cleanup.
BOOL fGotException = FALSE;
TableSegment *pSegment = pTable->pSegmentList;
+ bool wasSuccessful = true;
#ifdef _DEBUG
// on debug builds, execute the OOM path 10% of the time.
#endif
// Step 1: replace pinning handles with ones from default domain
- EX_TRY
+ while (pSegment)
{
- while (pSegment)
+ wasSuccessful = wasSuccessful && SegmentRelocateAsyncPinHandles (pSegment, pTargetTable);
+ if (!wasSuccessful)
{
- SegmentRelocateAsyncPinHandles (pSegment, pTargetTable);
- pSegment = pSegment->pNextSegment;
+ break;
}
+
+ pSegment = pSegment->pNextSegment;
}
- EX_CATCH
- {
- fGotException = TRUE;
- }
- EX_END_CATCH(SwallowAllExceptions);
- if (!fGotException)
+ if (wasSuccessful)
{
return;
}
{
CONTRACTL
{
- THROWS;
+ NOTHROW;
WRAPPER(GC_TRIGGERS);
- INJECT_FAULT(COMPlusThrowOM());
}
CONTRACTL_END;
inline OBJECTHANDLE CreateHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_DEFAULT);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_DEFAULT);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateWeakHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_DEFAULT);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_DEFAULT);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateShortWeakHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_SHORT);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_SHORT);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateLongWeakHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_LONG);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_LONG);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateStrongHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_STRONG);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_STRONG);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreatePinningHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_PINNED);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_PINNED);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateAsyncPinningHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_ASYNCPINNED);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_ASYNCPINNED);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateRefcountedHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_REFCOUNTED);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_REFCOUNTED);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateSizedRefHandle(IGCHandleStore* store, OBJECTREF object)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_SIZEDREF);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_SIZEDREF);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateSizedRefHandle(IGCHandleStore* store, OBJECTREF object, int heapToAffinitizeTo)
{
- return store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_SIZEDREF, heapToAffinitizeTo);
+ OBJECTHANDLE hnd = store->CreateHandleOfType(OBJECTREFToObject(object), HNDTYPE_SIZEDREF, heapToAffinitizeTo);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
// Global handle creation convenience functions
inline OBJECTHANDLE CreateGlobalHandle(OBJECTREF object)
{
CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
- return GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_DEFAULT);
+ OBJECTHANDLE hnd = GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_DEFAULT);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateGlobalWeakHandle(OBJECTREF object)
{
- return GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_DEFAULT);
+ OBJECTHANDLE hnd = GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_DEFAULT);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateGlobalShortWeakHandle(OBJECTREF object)
{
CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
- return GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_SHORT);
+ OBJECTHANDLE hnd = GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_SHORT);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateGlobalLongWeakHandle(OBJECTREF object)
{
- return GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_LONG);
+ OBJECTHANDLE hnd = GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_LONG);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateGlobalStrongHandle(OBJECTREF object)
{
CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
- return GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_STRONG);
+ OBJECTHANDLE hnd = GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_STRONG);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateGlobalPinningHandle(OBJECTREF object)
{
- return GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_PINNED);
+ OBJECTHANDLE hnd = GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_PINNED);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
inline OBJECTHANDLE CreateGlobalRefcountedHandle(OBJECTREF object)
{
- return GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_REFCOUNTED);
+ OBJECTHANDLE hnd = GCHandleUtilities::GetGCHandleManager()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_REFCOUNTED);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
// Special handle creation convenience functions
#ifdef FEATURE_COMINTEROP
inline OBJECTHANDLE CreateWinRTWeakHandle(IGCHandleStore* store, OBJECTREF object, IWeakReference* pWinRTWeakReference)
{
- return store->CreateHandleWithExtraInfo(OBJECTREFToObject(object), HNDTYPE_WEAK_WINRT, (void*)pWinRTWeakReference);
+ OBJECTHANDLE hnd = store->CreateHandleWithExtraInfo(OBJECTREFToObject(object), HNDTYPE_WEAK_WINRT, (void*)pWinRTWeakReference);
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
#endif // FEATURE_COMINTEROP
// Creates a variable-strength handle
inline OBJECTHANDLE CreateVariableHandle(IGCHandleStore* store, OBJECTREF object, uint32_t type)
{
- return store->CreateHandleWithExtraInfo(OBJECTREFToObject(object), HNDTYPE_VARIABLE, (void*)((uintptr_t)type));
+ OBJECTHANDLE hnd = store->CreateHandleWithExtraInfo(OBJECTREFToObject(object), HNDTYPE_VARIABLE, (void*)((uintptr_t)type));
+ if (!hnd)
+ {
+ COMPlusThrowOM();
+ }
+
+ return hnd;
}
// Handle object manipulation convenience functions