Skip to content
7 changes: 0 additions & 7 deletions src/coreclr/vm/ceeload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4644,13 +4644,6 @@ void Module::EnumMemoryRegions(CLRDataEnumMemoryFlags flags,
#endif // FEATURE_METADATA_UPDATER
}

FieldDesc *Module::LookupFieldDef(mdFieldDef token)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(TypeFromToken(token) == mdtFieldDef);
return m_FieldDefToDescMap.GetElement(RidFromToken(token));
}

#endif // DACCESS_COMPILE


Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/vm/ceeload.h
Original file line number Diff line number Diff line change
Expand Up @@ -1278,18 +1278,7 @@ class Module : public ModuleBase
#endif // !DACCESS_COMPILE
#endif // FEATURE_CODE_VERSIONING

#ifndef DACCESS_COMPILE
FieldDesc *LookupFieldDef(mdFieldDef token)
{
WRAPPER_NO_CONTRACT;

_ASSERTE(TypeFromToken(token) == mdtFieldDef);
return m_FieldDefToDescMap.GetElement(RidFromToken(token));
}
#else // DACCESS_COMPILE
// FieldDesc isn't defined at this point so PTR_FieldDesc can't work.
FieldDesc *LookupFieldDef(mdFieldDef token);
#endif // DACCESS_COMPILE

#ifndef DACCESS_COMPILE
void EnsureFieldDefCanBeStored(mdFieldDef token)
Expand Down
29 changes: 28 additions & 1 deletion src/coreclr/vm/ceeload.inl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,34 @@ inline PTR_MethodDesc Module::LookupMethodDef(mdMethodDef token)
CONTRACTL_END

_ASSERTE(TypeFromToken(token) == mdtMethodDef);
return m_MethodDefToDescMap.GetElement(RidFromToken(token));
PTR_MethodDesc pResult = m_MethodDefToDescMap.GetElement(RidFromToken(token));
if (pResult == NULL)
{
MemoryBarrier(); // m_MethodDefToDescMap is initialized in a specific order with regard to the m_TypeDefToDescMap, and is used
// by reading the TypeDefToDescMap, and then if a value is found in there, reading from this map.
// Since those two reads are not dependent on each other it is possible for the compiler or CPU to reorder them.
// The MemoryBarrier here prevents that reordering.

pResult = m_MethodDefToDescMap.GetElement(RidFromToken(token));
}
return pResult;
}

FieldDesc *Module::LookupFieldDef(mdFieldDef token)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(TypeFromToken(token) == mdtFieldDef);
FieldDesc* pResult = m_FieldDefToDescMap.GetElement(RidFromToken(token));

if (pResult == NULL)
{
MemoryBarrier(); // m_FieldDefToDescMap is initialized in a specific order with regard to the m_TypeDefToDescMap, and is used
// by reading the TypeDefToDescMap, and then if a value is found in there, reading from this map.
// Since those two reads are not dependent on each other it is possible for the compiler or CPU to reorder them.
// The MemoryBarrier here prevents that reordering.
pResult = m_FieldDefToDescMap.GetElement(RidFromToken(token));
}
return pResult;
}

#ifdef FEATURE_CODE_VERSIONING
Expand Down
Loading