Skip to content

Commit b9ea6b5

Browse files
committed
Remove "Precious" concept for SyncBlocks now that it's nearly impossible to get into said state (and any case where it kicks in would be a bug)
1 parent 16940c3 commit b9ea6b5

File tree

5 files changed

+4
-96
lines changed

5 files changed

+4
-96
lines changed

src/coreclr/vm/comcallablewrapper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,8 +2102,6 @@ ComCallWrapper* ComCallWrapper::CreateWrapper(OBJECTREF* ppObj)
21022102
// grab the sync block from the server
21032103
SyncBlock* pSyncBlock = pServer->GetSyncBlock();
21042104

2105-
pSyncBlock->SetPrecious();
2106-
21072105
// if the object belongs to a domain neutral class, need to allocate the wrapper in the default domain.
21082106
// The object is potentially agile so if allocate out of the current domain and then hand out to
21092107
// multiple domains we might never release the wrapper for that object and hence never unload the CCWC.

src/coreclr/vm/cominterfacemarshaler.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ void COMInterfaceMarshaler::CreateObjectRef(BOOL fDuplicate, OBJECTREF *pComObj,
124124
_ASSERTE(!"Creating a COM wrapper for WinRT delegates (which do not inherit from __ComObject) is not supported.");
125125
}
126126

127-
// make sure we "pin" the syncblock before switching to preemptive mode
128127
SyncBlock *pSB = (*pComObj)->GetSyncBlock();
129-
pSB->SetPrecious();
130128
DWORD dwSyncBlockIndex = pSB->GetSyncBlockIndex();
131129

132130
NewRCWHolder pNewRCW;

src/coreclr/vm/runtimecallablewrapper.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ OBJECTREF ComClassFactory::CreateAggregatedInstance(MethodTable* pMTClass, BOOL
377377

378378
RCWCache* pCache = RCWCache::GetRCWCache();
379379

380-
_ASSERTE(cref->GetSyncBlock()->IsPrecious()); // the object already has a CCW
381380
DWORD dwSyncBlockIndex = cref->GetSyncBlockIndex();
382381

383382
// create a wrapper for this COM object
@@ -1786,9 +1785,7 @@ void RCW::CreateDuplicateWrapper(MethodTable *pNewMT, RCWHolder* pNewRCW)
17861785

17871786
DWORD flags = 0;
17881787

1789-
// make sure we "pin" the syncblock before switching to preemptive mode
17901788
SyncBlock *pSB = NewWrapperObj->GetSyncBlock();
1791-
pSB->SetPrecious();
17921789
DWORD dwSyncBlockIndex = pSB->GetSyncBlockIndex();
17931790

17941791
pNewWrap = RCW::CreateRCW((IUnknown *)pAutoUnk, dwSyncBlockIndex, flags, pNewMT);

src/coreclr/vm/syncblk.cpp

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -828,29 +828,6 @@ void SyncBlockCache::DeleteSyncBlockMemory(SyncBlock *psb)
828828

829829
}
830830

831-
// free a used sync block
832-
void SyncBlockCache::GCDeleteSyncBlock(SyncBlock *psb)
833-
{
834-
CONTRACTL
835-
{
836-
INSTANCE_CHECK;
837-
NOTHROW;
838-
GC_NOTRIGGER;
839-
MODE_ANY;
840-
}
841-
CONTRACTL_END;
842-
843-
// Destruct the SyncBlock, but don't reclaim its memory. (Overridden
844-
// operator delete).
845-
delete psb;
846-
847-
m_ActiveCount--;
848-
m_FreeCount++;
849-
850-
psb->m_Link.m_pNext = m_FreeBlockList;
851-
m_FreeBlockList = &psb->m_Link;
852-
}
853-
854831
void SyncBlockCache::GCWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2)
855832
{
856833
CONTRACTL
@@ -962,7 +939,7 @@ void SyncBlockCache::GCWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintp
962939
{
963940
(*scanProc) (keyv, NULL, lp1, lp2);
964941
SyncBlock *pSB = syncTableShadow[nb].m_SyncBlock;
965-
if (*keyv != 0 && (!pSB || !pSB->IsIDisposable()))
942+
if (*keyv != 0 && !pSB)
966943
{
967944
if (syncTableShadow[nb].m_Object != SyncTableEntry::GetSyncTableEntry()[nb].m_Object)
968945
DebugBreak ();
@@ -1067,7 +1044,7 @@ BOOL SyncBlockCache::GCWeakPtrScanElement (int nb, HANDLESCANPROC scanProc, LPAR
10671044

10681045
(*scanProc) (keyv, NULL, lp1, lp2);
10691046
SyncBlock *pSB = SyncTableEntry::GetSyncTableEntry()[nb].m_SyncBlock;
1070-
if ((*keyv == 0 ) || (pSB && pSB->IsIDisposable()))
1047+
if (*keyv == 0 )
10711048
{
10721049
#ifdef VERIFY_HEAP
10731050
if (g_pConfig->GetHeapVerifyLevel () & EEConfig::HEAPVERIFY_SYNCBLK)
@@ -1076,14 +1053,7 @@ BOOL SyncBlockCache::GCWeakPtrScanElement (int nb, HANDLESCANPROC scanProc, LPAR
10761053
}
10771054
#endif
10781055

1079-
if (*keyv)
1080-
{
1081-
_ASSERTE (pSB);
1082-
GCDeleteSyncBlock(pSB);
1083-
//clean the object syncblock header
1084-
((Object*)(*keyv))->GetHeader()->GCResetIndex();
1085-
}
1086-
else if (pSB)
1056+
if (pSB)
10871057
{
10881058

10891059
cleanup = TRUE;
@@ -1656,11 +1626,6 @@ SyncBlock *ObjHeader::GetSyncBlock()
16561626
SetIndex(BIT_SBLK_IS_HASH_OR_SYNCBLKINDEX | indx);
16571627
}
16581628

1659-
//If we had already an index, hold the syncblock
1660-
//for the lifetime of the object.
1661-
if (indexHeld)
1662-
syncBlock->SetPrecious();
1663-
16641629
LEAVE_SPIN_LOCK(this);
16651630
}
16661631
}
@@ -1679,7 +1644,6 @@ SyncBlock *ObjHeader::GetSyncBlock()
16791644
bool SyncBlock::SetInteropInfo(InteropSyncBlockInfo* pInteropInfo)
16801645
{
16811646
WRAPPER_NO_CONTRACT;
1682-
SetPrecious();
16831647

16841648
// We could be agile, but not have noticed yet. We can't assert here
16851649
// that we live in any given domain, nor is this an appropriate place
@@ -1701,9 +1665,6 @@ void SyncBlock::SetEnCInfo(EnCSyncBlockInfo *pEnCInfo)
17011665
{
17021666
WRAPPER_NO_CONTRACT;
17031667

1704-
// We can't recreate the field contents, so this SyncBlock can never go away
1705-
SetPrecious();
1706-
17071668
// Store the field info (should only ever happen once)
17081669
_ASSERTE( m_pEnCInfo == NULL );
17091670
m_pEnCInfo = pEnCInfo;
@@ -1734,8 +1695,6 @@ OBJECTHANDLE SyncBlock::GetOrCreateLock(OBJECTREF lockObj)
17341695
return m_Lock;
17351696
}
17361697

1737-
SetPrecious();
1738-
17391698
// We need to create a new lock
17401699
DWORD thinLock = m_thinLock;
17411700
OBJECTHANDLEHolder lockHandle = GetAppDomain()->CreateHandle(lockObj);

src/coreclr/vm/syncblk.h

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -467,23 +467,9 @@ class SyncBlock
467467
DWORD GetSyncBlockIndex()
468468
{
469469
LIMITED_METHOD_CONTRACT;
470-
return m_dwSyncIndex & ~SyncBlockPrecious;
470+
return m_dwSyncIndex;
471471
}
472472

473-
// As soon as a syncblock acquires some state that cannot be recreated, we latch
474-
// a bit.
475-
void SetPrecious()
476-
{
477-
WRAPPER_NO_CONTRACT;
478-
m_dwSyncIndex |= SyncBlockPrecious;
479-
}
480-
481-
BOOL IsPrecious()
482-
{
483-
LIMITED_METHOD_CONTRACT;
484-
return (m_dwSyncIndex & SyncBlockPrecious) != 0;
485-
}
486-
487473
// Get the lock information for this sync block.
488474
// Returns false when the lock is not locked or has not been created yet.
489475
BOOL TryGetLockInfo(DWORD *pThreadId, DWORD *pRecursionLevel);
@@ -496,15 +482,6 @@ class SyncBlock
496482

497483
OBJECTHANDLE GetOrCreateLock(OBJECTREF lockObj);
498484

499-
// True is the syncblock and its index are disposable.
500-
// If new members are added to the syncblock, this
501-
// method needs to be modified accordingly
502-
BOOL IsIDisposable()
503-
{
504-
WRAPPER_NO_CONTRACT;
505-
return !IsPrecious() && m_thinLock == 0u;
506-
}
507-
508485
// Gets the InteropInfo block, creates a new one if none is present.
509486
InteropSyncBlockInfo* GetInteropInfo()
510487
{
@@ -571,8 +548,6 @@ class SyncBlock
571548
DWORD result = InterlockedCompareExchange((LONG*)&m_dwHashCode, hashCode, 0);
572549
if (result == 0)
573550
{
574-
// the sync block now holds a hash code, which we can't afford to lose.
575-
SetPrecious();
576551
return hashCode;
577552
}
578553
else
@@ -590,13 +565,6 @@ class SyncBlock
590565
// We've already destructed. But retain the memory.
591566
}
592567

593-
enum
594-
{
595-
// This bit indicates that the syncblock is valuable and can neither be discarded
596-
// nor re-created.
597-
SyncBlockPrecious = 0x80000000,
598-
};
599-
600568
BOOL HasCOMBstrTrailByte()
601569
{
602570
LIMITED_METHOD_CONTRACT;
@@ -610,7 +578,6 @@ class SyncBlock
610578
{
611579
WRAPPER_NO_CONTRACT;
612580
m_BSTRTrailByte = trailByte;
613-
SetPrecious();
614581
}
615582

616583
private:
@@ -727,9 +694,6 @@ class SyncBlockCache
727694
// returns the sync block memory to the free pool but does not destruct sync block (must own cache lock already)
728695
void DeleteSyncBlockMemory(SyncBlock *sb);
729696

730-
// return sync block to cache or delete, called from GC
731-
void GCDeleteSyncBlock(SyncBlock *sb);
732-
733697
void GCWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2);
734698

735699
void GCDone(BOOL demoting, int max_gen);
@@ -864,14 +828,6 @@ class ObjHeader
864828
InterlockedAnd((LONG*)&m_SyncBlockValue, ~(BIT_SBLK_IS_HASH_OR_SYNCBLKINDEX | BIT_SBLK_IS_HASHCODE | MASK_SYNCBLOCKINDEX));
865829
}
866830

867-
// Used only GC
868-
void GCResetIndex()
869-
{
870-
LIMITED_METHOD_CONTRACT;
871-
872-
m_SyncBlockValue.RawValue() &=~(BIT_SBLK_IS_HASH_OR_SYNCBLKINDEX | BIT_SBLK_IS_HASHCODE | MASK_SYNCBLOCKINDEX);
873-
}
874-
875831
// For now, use interlocked operations to twiddle bits in the bitfield portion.
876832
// If we ever have high-performance requirements where we can guarantee that no
877833
// other threads are accessing the ObjHeader, this can be reconsidered for those

0 commit comments

Comments
 (0)