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
30 changes: 27 additions & 3 deletions src/coreclr/vm/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,13 @@ HRESULT EEClass::AddMethod(MethodTable * pMT, mdMethodDef methodDef, RVA newRVA,

LoaderAllocator* pAllocator = pMT->GetLoaderAllocator();

DWORD classification = mcIL;

// Create a new MethodDescChunk to hold the new MethodDesc
// Create the chunk somewhere we'll know is within range of the VTable
MethodDescChunk *pChunk = MethodDescChunk::CreateChunk(pAllocator->GetHighFrequencyHeap(),
1, // methodDescCount
mcInstantiated,
classification,
TRUE /* fNonVtableSlot */,
TRUE /* fNativeCodeSlot */,
pMT,
Expand All @@ -605,20 +607,38 @@ HRESULT EEClass::AddMethod(MethodTable * pMT, mdMethodDef methodDef, RVA newRVA,
// Use a local StackingAllocator instead.
StackingAllocator stackingAllocator;

MethodTableBuilder::bmtInternalInfo bmtInternal;
bmtInternal.pModule = pMT->GetModule();
bmtInternal.pInternalImport = NULL;
bmtInternal.pParentMT = NULL;

MethodTableBuilder builder(pMT,
pClass,
&stackingAllocator,
&dummyAmTracker);

builder.SetBMTData(pMT->GetLoaderAllocator(),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
&bmtInternal);

EX_TRY
{
INDEBUG(LPCSTR debug_szFieldName);
INDEBUG(if (FAILED(pImport->GetNameOfMethodDef(methodDef, &debug_szFieldName))) { debug_szFieldName = "Invalid MethodDef record"; });
builder.InitMethodDesc(pNewMD,
mcInstantiated, // Use instantiated methoddesc for EnC added methods to get space for slot
classification,
methodDef,
dwImplFlags,
dwMemberAttrs,
TRUE, // fEnC
TRUE, // fEnC
newRVA,
pImport,
NULL
Expand All @@ -628,6 +648,10 @@ HRESULT EEClass::AddMethod(MethodTable * pMT, mdMethodDef methodDef, RVA newRVA,
);

pNewMD->SetTemporaryEntryPoint(pAllocator, &dummyAmTracker);

// [TODO] if an exception is thrown, asserts will fire in EX_CATCH_HRESULT()
// during an EnC operation due to the debugger thread not being able to
// transition to COOP mode.
}
EX_CATCH_HRESULT(hr);
if (S_OK != hr)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/clsload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2010,10 +2010,10 @@ VOID ClassLoader::Init(AllocMemTracker *pamTracker)
// type in one of the modules governed by the loader.
// The process of creating these types may be reentrant. The ordering has
// not yet been sorted out, and when we sort it out we should also modify the
// ordering for m_AvailableTypesLock in BaseDomain.
// ordering for m_AvailableTypesLock below.
m_AvailableClassLock.Init(
CrstAvailableClass,
CRST_REENTRANCY);
CrstFlags(CRST_REENTRANCY | CRST_DEBUGGER_THREAD));

// This lock is taken within the classloader whenever we have to insert a new param. type into the table.
m_AvailableTypesLock.Init(
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/codeversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ bool CodeVersionManager::IsMethodSupported(PTR_MethodDesc pMethodDesc)
!pMethodDesc->GetLoaderAllocator()->IsCollectible() &&

// EnC has its own way of versioning
!pMethodDesc->IsEnCMethod();
!pMethodDesc->InEnCEnabledModule();
}

//---------------------------------------------------------------------------------------
Expand Down
13 changes: 8 additions & 5 deletions src/coreclr/vm/eetwain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ HRESULT EECodeManager::FixContextForEnC(PCONTEXT pCtx,
}
}

oldMethodVarsSortedBase = new (nothrow) ICorDebugInfo::NativeVarInfo[oldNumVars];
oldMethodVarsSortedBase = new (nothrow) ICorDebugInfo::NativeVarInfo[oldNumVars];
if (!oldMethodVarsSortedBase)
{
hr = E_FAIL;
Expand Down Expand Up @@ -1108,7 +1108,8 @@ HRESULT EECodeManager::FixContextForEnC(PCONTEXT pCtx,
if (pOldVar->startOffset <= oldMethodOffset &&
pOldVar->endOffset > oldMethodOffset)
{
oldMethodVarsSorted[(int)varNumber] = *pOldVar;
// Indexing should be performed with a signed value - could be negative.
oldMethodVarsSorted[(int32_t)varNumber] = *pOldVar;
}
}

Expand Down Expand Up @@ -1160,7 +1161,8 @@ HRESULT EECodeManager::FixContextForEnC(PCONTEXT pCtx,
if (pNewVar->startOffset <= newMethodOffset &&
pNewVar->endOffset > newMethodOffset)
{
newMethodVarsSorted[(int)varNumber] = *pNewVar;
// Indexing should be performed with a signed valued - could be negative.
newMethodVarsSorted[(int32_t)varNumber] = *pNewVar;
}
}

Expand Down Expand Up @@ -1190,8 +1192,9 @@ HRESULT EECodeManager::FixContextForEnC(PCONTEXT pCtx,
memset(rgVal1, 0, sizeof(SIZE_T) * newNumVars);
memset(rgVal2, 0, sizeof(SIZE_T) * newNumVars);

unsigned varsToGet = (oldNumVars > newNumVars) ? newNumVars
: oldNumVars;
unsigned varsToGet = (oldNumVars > newNumVars)
? newNumVars
: oldNumVars;

// 2) Get all the info about current variables, registers, etc.

Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/vm/encee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue(
// Update the module's EnC version number
++m_applyChangesCount;

LOG((LF_ENC, LL_INFO100, "EACM::AEAC:\n"));
LOG((LF_ENC, LL_INFO100, "EACM::AEAC: Apply count %d\n", m_applyChangesCount));

#ifdef _DEBUG
// Debugging hook to optionally break when this method is called
Expand All @@ -130,10 +130,10 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue(
static BOOL dumpChanges = -1;

if (dumpChanges == -1)

dumpChanges = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EncDumpApplyChanges);

if (dumpChanges> 0) {
if (dumpChanges> 0)
{
SString fn;
int ec;
fn.Printf("ApplyChanges.%d.dmeta", m_applyChangesCount);
Expand Down Expand Up @@ -323,7 +323,7 @@ HRESULT EditAndContinueModule::UpdateMethod(MethodDesc *pMethod)
//
// Note that this only works since we've very carefully made sure that _all_ references
// to the Method's code must be to the call/jmp blob immediately in front of the
// MethodDesc itself. See MethodDesc::IsEnCMethod()
// MethodDesc itself. See MethodDesc::InEnCEnabledModule()
//
pMethod->ResetCodeEntryPointForEnC();

Expand Down
20 changes: 14 additions & 6 deletions src/coreclr/vm/genmeth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,17 @@ static MethodDesc* CreateMethodDesc(LoaderAllocator *pAllocator,
pMD->SetIsIntrinsic();
}

#ifdef EnC_SUPPORTED
if (pTemplateMD->IsEnCAddedMethod())
{
pMD->SetIsEnCAddedMethod();
}
#endif // EnC_SUPPORTED

pMD->SetMemberDef(token);
pMD->SetSlot(pTemplateMD->GetSlot());

#ifdef _DEBUG
pMD->m_pszDebugMethodName = pTemplateMD->m_pszDebugMethodName;
//<NICE> more info here</NICE>
pMD->m_pszDebugMethodSignature = "<generic method signature>";
pMD->m_pszDebugClassName = "<generic method class name>";
Expand Down Expand Up @@ -1351,19 +1357,21 @@ MethodDesc * MethodDesc::FindOrCreateTypicalSharedInstantiation(BOOL allowCreate
}

//@GENERICSVER: Set the typical (ie. formal) instantiation
void InstantiatedMethodDesc::SetupGenericMethodDefinition(IMDInternalImport *pIMDII,
void InstantiatedMethodDesc::SetupGenericMethodDefinition(IMDInternalImport* pIMDII,
LoaderAllocator* pAllocator,
AllocMemTracker *pamTracker,
Module *pModule,
AllocMemTracker* pamTracker,
Module* pModule,
mdMethodDef tok)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
GC_NOTRIGGER;
INJECT_FAULT(COMPlusThrowOM(););
PRECONDITION(CheckPointer(pModule));
PRECONDITION(CheckPointer(pIMDII));
PRECONDITION(CheckPointer(pAllocator));
PRECONDITION(CheckPointer(pamTracker));
PRECONDITION(CheckPointer(pModule));
}
CONTRACTL_END;

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5994,7 +5994,7 @@ bool CEEInfo::getStringChar(CORINFO_OBJECT_HANDLE obj, int index, uint16_t* valu
result = true;
}
}

EE_TO_JIT_TRANSITION();

return result;
Expand Down Expand Up @@ -8957,7 +8957,7 @@ void CEEInfo::getFunctionEntryPoint(CORINFO_METHOD_HANDLE ftnHnd,
if (ret == NULL)
{
// should never get here for EnC methods or if interception via remoting stub is required
_ASSERTE(!ftn->IsEnCMethod());
_ASSERTE(!ftn->InEnCEnabledModule());

ret = (void *)ftn->GetAddrOfSlot();

Expand Down Expand Up @@ -11708,7 +11708,7 @@ bool CEEInfo::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE fieldHnd, uint8_t
UINT size = field->GetSize();
_ASSERTE(baseAddr > 0);
_ASSERTE(size > 0);

if (size >= (UINT)bufferSize && valueOffset >= 0 && (UINT)valueOffset <= size - (UINT)bufferSize)
{
memcpy(buffer, (uint8_t*)baseAddr + valueOffset, bufferSize);
Expand Down
9 changes: 3 additions & 6 deletions src/coreclr/vm/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,9 +2014,8 @@ PCODE MethodDesc::TryGetMultiCallableAddrOfCode(CORINFO_ACCESS_FLAGS accessFlags
if (IsWrapperStub() || IsEnCAddedMethod())
return GetStableEntryPoint();


// For EnC always just return the stable entrypoint so we can update the code
if (IsEnCMethod())
if (InEnCEnabledModule())
return GetStableEntryPoint();

// If the method has already been jitted, we can give out the direct address
Expand Down Expand Up @@ -2203,7 +2202,7 @@ void MethodDesc::Reset()
// different pieces of data non-atomically.
// Use this only if you can guarantee thread-safety somehow.

_ASSERTE(IsEnCMethod() || // The process is frozen by the debugger
_ASSERTE(InEnCEnabledModule() || // The process is frozen by the debugger
IsDynamicMethod() || // These are used in a very restricted way
GetLoaderModule()->IsReflection()); // Rental methods

Expand Down Expand Up @@ -2298,7 +2297,7 @@ BOOL MethodDesc::RequiresStableEntryPoint(BOOL fEstimateForChunk /*=FALSE*/)
return TRUE;

// Create precodes for edit and continue to make methods updateable
if (IsEnCMethod() || IsEnCAddedMethod())
if (InEnCEnabledModule() || IsEnCAddedMethod())
return TRUE;

// Precreate precodes for LCG methods so we do not leak memory when the method descs are recycled
Expand Down Expand Up @@ -2392,8 +2391,6 @@ void MethodDesc::CheckRestore(ClassLoadLevel level)
// it might be out-of-module
ClassLoader::EnsureLoaded(TypeHandle(GetMethodTable()), level);

pIMD->m_wFlags2 = pIMD->m_wFlags2 & ~InstantiatedMethodDesc::Unrestored;

if (ETW_PROVIDER_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER))
{
ETW::MethodLog::MethodRestored(this);
Expand Down
Loading