Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Remove unnecessary ILStubCreatorHelperHolder concept
  • Loading branch information
ChrisAhna committed Jan 4, 2023
commit 4c8b8f0219ced455d3aa82a609ff83897d1e0825
45 changes: 10 additions & 35 deletions src/coreclr/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4790,20 +4790,6 @@ namespace
m_amTracker.SuppressRelease();
}

DEBUG_NOINLINE static void HolderEnter(ILStubCreatorHelper *pThis)
{
WRAPPER_NO_CONTRACT;
ANNOTATION_SPECIAL_HOLDER_CALLER_NEEDS_DYNAMIC_CONTRACT;
pThis->GetStubMethodDesc();
}

DEBUG_NOINLINE static void HolderLeave(ILStubCreatorHelper *pThis)
{
WRAPPER_NO_CONTRACT;
ANNOTATION_SPECIAL_HOLDER_CALLER_NEEDS_DYNAMIC_CONTRACT;
pThis->RemoveILStubCacheEntry();
}

private:
MethodDesc* m_pTargetMD;
NDirectStubParameters* m_pParams;
Expand All @@ -4814,8 +4800,6 @@ namespace
bool m_bILStubCreator; // Only the creator can remove the ILStub from the Cache
}; //ILStubCreatorHelper

typedef Wrapper<ILStubCreatorHelper*, ILStubCreatorHelper::HolderEnter, ILStubCreatorHelper::HolderLeave> ILStubCreatorHelperHolder;

MethodDesc* CreateInteropILStub(
ILStubState* pss,
StubSigDesc* pSigDesc,
Expand Down Expand Up @@ -4889,8 +4873,8 @@ namespace
pSigDesc->m_pMT
);

// The following two ILStubCreatorHelperHolder are to recover the status when an
// exception happen during the generation of the IL stubs. We need to free the
// The following ILStubCreatorHelper is to recover the status when an
// exception happens during the generation of the IL stubs. We need to free the
// memory allocated and restore the ILStubCache.
//
// The following block is logically divided into two phases. The first phase is
Expand All @@ -4900,7 +4884,7 @@ namespace
//
// ilStubCreatorHelper contains an instance of AllocMemTracker which tracks the
// allocated memory during the creation of MethodDesc so that we are able to remove
// them when releasing the ILStubCreatorHelperHolder or destructing ILStubCreatorHelper
// them when destructing ILStubCreatorHelper

// When removing IL Stub from Cache, we have a constraint that only the thread which
// creates the stub can remove it. Otherwise, any thread hits cache and gets the stub will
Expand All @@ -4913,10 +4897,8 @@ namespace
ListLockHolder pILStubLock(pLoaderModule->GetDomain()->GetILStubGenLock());

{
// The holder will free the allocated MethodDesc and restore the ILStubCache
// if exception happen.
ILStubCreatorHelperHolder pCreateOrGetStubHolder(&ilStubCreatorHelper);
pStubMD = pCreateOrGetStubHolder->GetStubMD();
ilStubCreatorHelper.GetStubMethodDesc();
pStubMD = ilStubCreatorHelper.GetStubMD();

///////////////////////////////
//
Expand All @@ -4930,16 +4912,11 @@ namespace

ListLockEntryLockHolder pEntryLock(pEntry, FALSE);

// We can release the holder for the first phase now
pCreateOrGetStubHolder.SuppressRelease();

// We have the entry lock we need to use, so we can release the global lock.
pILStubLock.Release();

{
// The holder will free the allocated MethodDesc and restore the ILStubCache
// if exception happen. The reason to get the holder again is to
ILStubCreatorHelperHolder pGenILHolder(&ilStubCreatorHelper);
ilStubCreatorHelper.GetStubMethodDesc();

if (!pEntryLock.DeadlockAwareAcquire())
{
Expand All @@ -4964,11 +4941,11 @@ namespace
pILStubLock.Acquire();

// Assure that pStubMD we have now has not been destroyed by other threads
pGenILHolder->GetStubMethodDesc();
ilStubCreatorHelper.GetStubMethodDesc();

while (pStubMD != pGenILHolder->GetStubMD())
while (pStubMD != ilStubCreatorHelper.GetStubMD())
{
pStubMD = pGenILHolder->GetStubMD();
pStubMD = ilStubCreatorHelper.GetStubMD();

pEntry.Assign(ListLockEntry::Find(pILStubLock, pStubMD, "il stub gen lock"));
pEntryLock.Assign(pEntry, FALSE);
Expand All @@ -4994,7 +4971,7 @@ namespace

pILStubLock.Acquire();

pGenILHolder->GetStubMethodDesc();
ilStubCreatorHelper.GetStubMethodDesc();
}
}

Expand Down Expand Up @@ -5084,8 +5061,6 @@ namespace

// Link the MethodDesc onto the method table with the lock taken
AddMethodDescChunkWithLockTaken(&params, pStubMD);

pGenILHolder.SuppressRelease();
}
}
}
Expand Down