Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions src/coreclr/vm/syncblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ class SyncBlockArray
BYTE m_Blocks[MAXSYNCBLOCK * sizeof (SyncBlock)];
};

// For in-place constructor
BYTE g_SyncBlockCacheInstance[sizeof(SyncBlockCache)];
SyncBlockCache g_SyncBlockCacheInstance;

SPTR_IMPL (SyncBlockCache, SyncBlockCache, s_pSyncBlockCache);

#ifndef DACCESS_COMPILE



#ifndef TARGET_UNIX
// static
SLIST_HEADER InteropSyncBlockInfo::s_InteropInfoStandbyList;
Expand Down Expand Up @@ -463,27 +460,7 @@ size_t BitMapSize (size_t cacheSize)
//
// ***************************************************************************

SyncBlockCache::SyncBlockCache()
: m_pCleanupBlockList(NULL),
m_FreeBlockList(NULL),

// NOTE: CRST_UNSAFE_ANYMODE prevents a GC mode switch when entering this crst.
// If you remove this flag, we will switch to preemptive mode when entering
// g_criticalSection, which means all functions that enter it will become
// GC_TRIGGERS. (This includes all uses of LockHolder around SyncBlockCache::GetSyncBlockCache().
// So be sure to update the contracts if you remove this flag.
m_CacheLock(CrstSyncBlockCache, (CrstFlags) (CRST_UNSAFE_ANYMODE | CRST_DEBUGGER_THREAD)),

m_FreeCount(0),
m_ActiveCount(0),
m_SyncBlocks(0),
m_FreeSyncBlock(0),
m_FreeSyncTableIndex(1),
m_FreeSyncTableList(0),
m_SyncTableSize(SYNC_TABLE_INITIAL_SIZE),
m_OldSyncTables(0),
m_bSyncBlockCleanupInProgress(FALSE),
m_EphemeralBitmap(0)
void SyncBlockCache::Init()
{
CONTRACTL
{
Expand All @@ -494,11 +471,30 @@ SyncBlockCache::SyncBlockCache()
INJECT_FAULT(COMPlusThrowOM());
}
CONTRACTL_END;
}

m_pCleanupBlockList = NULL;
m_FreeBlockList = NULL;

// NOTE: CRST_UNSAFE_ANYMODE prevents a GC mode switch when entering this crst.
// If you remove this flag, we will switch to preemptive mode when entering
// g_criticalSection, which means all functions that enter it will become
// GC_TRIGGERS. (This includes all uses of LockHolder around SyncBlockCache::GetSyncBlockCache().
// So be sure to update the contracts if you remove this flag.
m_CacheLock.Init(CrstSyncBlockCache, (CrstFlags) (CRST_UNSAFE_ANYMODE | CRST_DEBUGGER_THREAD));

m_FreeCount = 0;
m_ActiveCount = 0;
m_SyncBlocks = 0;
m_FreeSyncBlock = 0;
m_FreeSyncTableIndex = 1;
m_FreeSyncTableList = 0;
m_SyncTableSize = SYNC_TABLE_INITIAL_SIZE;
m_OldSyncTables = 0;
m_bSyncBlockCleanupInProgress = FALSE;
m_EphemeralBitmap = 0;
}

// This method is NO longer called.
SyncBlockCache::~SyncBlockCache()
void SyncBlockCache::Destroy()
{
CONTRACTL
{
Expand All @@ -514,6 +510,8 @@ SyncBlockCache::~SyncBlockCache()
//<TODO>@todo we can clear this fast too I guess</TODO>
m_pCleanupBlockList = NULL;

m_CacheLock.Destroy();

// destruct all arrays
while (m_SyncBlocks)
{
Expand Down Expand Up @@ -655,7 +653,8 @@ void SyncBlockCache::Start()
#endif

SyncTableEntry::GetSyncTableEntry()[0].m_SyncBlock = 0;
SyncBlockCache::GetSyncBlockCache() = new (&g_SyncBlockCacheInstance) SyncBlockCache;
SyncBlockCache::GetSyncBlockCache() = &g_SyncBlockCacheInstance;
g_SyncBlockCacheInstance.Init();

SyncBlockCache::GetSyncBlockCache()->m_EphemeralBitmap = bm;

Expand All @@ -681,7 +680,7 @@ void SyncBlockCache::Stop()
// sync blocks which are live and thus must have their critical sections destroyed.
if (SyncBlockCache::GetSyncBlockCache())
{
delete SyncBlockCache::GetSyncBlockCache();
SyncBlockCache::GetSyncBlockCache()->Destroy();
SyncBlockCache::GetSyncBlockCache() = 0;
}

Expand Down
18 changes: 4 additions & 14 deletions src/coreclr/vm/syncblk.h
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ class SyncBlockCache
private:
PTR_SLink m_pCleanupBlockList; // list of sync blocks that need cleanup
SLink* m_FreeBlockList; // list of free sync blocks
Crst m_CacheLock; // cache lock
CrstStatic m_CacheLock; // cache lock
DWORD m_FreeCount; // count of active sync blocks
DWORD m_ActiveCount; // number active
SyncBlockArray *m_SyncBlocks; // Array of new SyncBlocks.
Expand Down Expand Up @@ -1345,19 +1345,9 @@ class SyncBlockCache
SPTR_DECL(SyncBlockCache, s_pSyncBlockCache);
static SyncBlockCache*& GetSyncBlockCache();

void *operator new(size_t size, void *pInPlace)
{
LIMITED_METHOD_CONTRACT;
return pInPlace;
}

void operator delete(void *p)
{
LIMITED_METHOD_CONTRACT;
}

SyncBlockCache();
~SyncBlockCache();
// Note: No constructors/destructors - global instance
void Init();
void Destroy();

static void Attach();
static void Detach();
Expand Down