Skip to content

Commit

Permalink
[cDAC] Set RejitFlags to use a known underlying type (#109935)
Browse files Browse the repository at this point in the history
set RejitFlags enum to use uint32_t as backing type for use in cDAC
  • Loading branch information
max-charlamb authored Nov 19, 2024
1 parent d4516bf commit 161f346
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 71 deletions.
6 changes: 3 additions & 3 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7284,11 +7284,11 @@ HRESULT DacDbiInterfaceImpl::GetActiveRejitILCodeVersionNode(VMPTR_Module vmModu
// Be careful, there are two different definitions of 'active' being used here
// For the CodeVersionManager, the active IL version is whatever one should be used in the next invocation of the method
// 'rejit active' narrows that to only include rejit IL bodies where the profiler has already provided the definition
// for the new IL (ilCodeVersion.GetRejitState()==ILCodeVersion::kStateActive). It is possible that the code version
// for the new IL (ilCodeVersion.GetRejitState()==RejitFlags::kStateActive). It is possible that the code version
// manager's active IL version hasn't yet asked the profiler for the IL body to use, in which case we want to filter it
// out from the return in this method.
ILCodeVersion activeILVersion = pCodeVersionManager->GetActiveILCodeVersion(pModule, methodTk);
if (activeILVersion.IsNull() || activeILVersion.IsDefaultVersion() || activeILVersion.GetRejitState() != ILCodeVersion::kStateActive)
if (activeILVersion.IsNull() || activeILVersion.IsDefaultVersion() || activeILVersion.GetRejitState() != RejitFlags::kStateActive)
{
pVmILCodeVersionNode->SetDacTargetPtr(0);
}
Expand Down Expand Up @@ -7390,7 +7390,7 @@ HRESULT DacDbiInterfaceImpl::GetILCodeVersionNodeData(VMPTR_ILCodeVersionNode vm
DD_ENTER_MAY_THROW;
#ifdef FEATURE_REJIT
ILCodeVersion ilCode(vmILCodeVersionNode.GetDacPtr());
pData->m_state = ilCode.GetRejitState();
pData->m_state = static_cast<DWORD>(ilCode.GetRejitState());
pData->m_pbIL = PTR_TO_CORDB_ADDRESS(dac_cast<TADDR>(ilCode.GetIL()));
pData->m_dwCodegenFlags = ilCode.GetJitFlags();
const InstrumentedILOffsetMapping* pMapping = ilCode.GetInstrumentedILMap();
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,11 +921,11 @@ void CopyNativeCodeVersionToReJitData(NativeCodeVersion nativeCodeVersion, Nativ
pReJitData->flags = DacpReJitData::kUnknown;
break;

case ILCodeVersion::kStateRequested:
case RejitFlags::kStateRequested:
pReJitData->flags = DacpReJitData::kRequested;
break;

case ILCodeVersion::kStateActive:
case RejitFlags::kStateActive:
pReJitData->flags = DacpReJitData::kActive;
break;
}
Expand Down Expand Up @@ -4618,7 +4618,7 @@ HRESULT ClrDataAccess::GetPendingReJITID(CLRDATA_ADDRESS methodDesc, int *pRejit
{
hr = E_INVALIDARG;
}
else if (ilVersion.GetRejitState() == ILCodeVersion::kStateRequested)
else if (ilVersion.GetRejitState() == RejitFlags::kStateRequested)
{
*pRejitId = (int)ilVersion.GetVersionId();
}
Expand Down Expand Up @@ -4661,11 +4661,11 @@ HRESULT ClrDataAccess::GetReJITInformation(CLRDATA_ADDRESS methodDesc, int rejit
pReJitData->flags = DacpReJitData2::kUnknown;
break;

case ILCodeVersion::kStateRequested:
case RejitFlags::kStateRequested:
pReJitData->flags = DacpReJitData2::kRequested;
break;

case ILCodeVersion::kStateActive:
case RejitFlags::kStateActive:
pReJitData->flags = DacpReJitData2::kActive;
break;
}
Expand Down Expand Up @@ -4698,7 +4698,7 @@ HRESULT ClrDataAccess::GetProfilerModifiedILInformation(CLRDATA_ADDRESS methodDe
CodeVersionManager* pCodeVersionManager = pMD->GetCodeVersionManager();
CodeVersionManager::LockHolder codeVersioningLockHolder;
ILCodeVersion ilVersion = pCodeVersionManager->GetActiveILCodeVersion(pMD);
if (ilVersion.GetRejitState() != ILCodeVersion::kStateActive || !ilVersion.HasDefaultIL())
if (ilVersion.GetRejitState() != RejitFlags::kStateActive || !ilVersion.HasDefaultIL())
{
pILData->type = DacpProfilerILData::ReJITModified;
pILData->rejitID = static_cast<ULONG>(pCodeVersionManager->GetActiveILCodeVersion(pMD).GetVersionId());
Expand Down Expand Up @@ -4748,7 +4748,7 @@ HRESULT ClrDataAccess::GetMethodsWithProfilerModifiedIL(CLRDATA_ADDRESS mod, CLR

TADDR pDynamicIL = pModule->GetDynamicIL(pMD->GetMemberDef());
ILCodeVersion ilVersion = pCodeVersionManager->GetActiveILCodeVersion(pMD);
if (ilVersion.GetRejitState() != ILCodeVersion::kStateActive || !ilVersion.HasDefaultIL() || pDynamicIL != (TADDR)NULL)
if (ilVersion.GetRejitState() != RejitFlags::kStateActive || !ilVersion.HasDefaultIL() || pDynamicIL != (TADDR)NULL)
{
methodDescs[*pcMethodDescs] = PTR_CDADDR(pMD);
++(*pcMethodDescs);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/ee/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12251,7 +12251,7 @@ HRESULT Debugger::DeoptimizeMethodHelper(Module* pModule, mdMethodDef methodDef)
// call back in to anything so set it all here to match the original IL and debug codegen flags
ilCodeVersion.SetIL(ILCodeVersion(pModule, methodDef).GetIL());
ilCodeVersion.SetJitFlags(COR_PRF_CODEGEN_DISABLE_ALL_OPTIMIZATIONS | COR_PRF_CODEGEN_DEBUG_INFO);
ilCodeVersion.SetRejitState(ILCodeVersion::kStateActive);
ilCodeVersion.SetRejitState(RejitFlags::kStateActive);
ilCodeVersion.SetEnableReJITCallback(false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/ee/functioninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ void DebuggerJitInfo::SetBoundaries(ULONG32 cMap, ICorDebugInfo::OffsetMapping *
{
// Did the current rejit provide a map?
const InstrumentedILOffsetMapping *pReJitMap = NULL;
if (ilVersion.GetRejitState() == ILCodeVersion::kStateActive)
if (ilVersion.GetRejitState() == RejitFlags::kStateActive)
{
pReJitMap = ilVersion.GetInstrumentedILMap();
}
Expand Down
27 changes: 13 additions & 14 deletions src/coreclr/vm/codeversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ ILCodeVersionNode::ILCodeVersionNode() :
m_methodDef(0),
m_rejitId(0),
m_pNextILVersionNode(dac_cast<PTR_ILCodeVersionNode>(nullptr)),
m_rejitState(ILCodeVersion::kStateRequested),
m_rejitState(RejitFlags::kStateRequested),
m_pIL(),
m_jitFlags(0),
m_deoptimized(FALSE)
Expand All @@ -563,7 +563,7 @@ ILCodeVersionNode::ILCodeVersionNode(Module* pModule, mdMethodDef methodDef, ReJ
m_methodDef(methodDef),
m_rejitId(id),
m_pNextILVersionNode(dac_cast<PTR_ILCodeVersionNode>(nullptr)),
m_rejitState(ILCodeVersion::kStateRequested),
m_rejitState(RejitFlags::kStateRequested),
m_pIL(nullptr),
m_jitFlags(0),
m_deoptimized(isDeoptimized)
Expand All @@ -588,17 +588,17 @@ ReJITID ILCodeVersionNode::GetVersionId() const
return m_rejitId;
}

ILCodeVersion::RejitFlags ILCodeVersionNode::GetRejitState() const
RejitFlags ILCodeVersionNode::GetRejitState() const
{
LIMITED_METHOD_DAC_CONTRACT;
return static_cast<ILCodeVersion::RejitFlags>(m_rejitState.Load() & ILCodeVersion::kStateMask);
return m_rejitState.Load() & RejitFlags::kStateMask;
}

BOOL ILCodeVersionNode::GetEnableReJITCallback() const
{
LIMITED_METHOD_DAC_CONTRACT;

return (m_rejitState.Load() & ILCodeVersion::kSuppressParams) == ILCodeVersion::kSuppressParams;
return (m_rejitState.Load() & RejitFlags::kSuppressParams) == RejitFlags::kSuppressParams;
}

PTR_COR_ILMETHOD ILCodeVersionNode::GetIL() const
Expand Down Expand Up @@ -632,15 +632,14 @@ BOOL ILCodeVersionNode::IsDeoptimized() const
}

#ifndef DACCESS_COMPILE
void ILCodeVersionNode::SetRejitState(ILCodeVersion::RejitFlags newState)
void ILCodeVersionNode::SetRejitState(RejitFlags newState)
{
LIMITED_METHOD_CONTRACT;
// We're doing a non thread safe modification to m_rejitState
_ASSERTE(CodeVersionManager::IsLockOwnedByCurrentThread());

ILCodeVersion::RejitFlags oldNonMaskFlags =
static_cast<ILCodeVersion::RejitFlags>(m_rejitState.Load() & ~ILCodeVersion::kStateMask);
m_rejitState.Store(static_cast<ILCodeVersion::RejitFlags>(newState | oldNonMaskFlags));
RejitFlags oldNonMaskFlags = m_rejitState.Load() & ~RejitFlags::kStateMask;
m_rejitState.Store(static_cast<RejitFlags>(newState | oldNonMaskFlags));
}

void ILCodeVersionNode::SetEnableReJITCallback(BOOL state)
Expand All @@ -649,14 +648,14 @@ void ILCodeVersionNode::SetEnableReJITCallback(BOOL state)
// We're doing a non thread safe modification to m_rejitState
_ASSERTE(CodeVersionManager::IsLockOwnedByCurrentThread());

ILCodeVersion::RejitFlags oldFlags = m_rejitState.Load();
RejitFlags oldFlags = m_rejitState.Load();
if (state)
{
m_rejitState.Store(static_cast<ILCodeVersion::RejitFlags>(oldFlags | ILCodeVersion::kSuppressParams));
m_rejitState.Store(oldFlags | RejitFlags::kSuppressParams);
}
else
{
m_rejitState.Store(static_cast<ILCodeVersion::RejitFlags>(oldFlags & ~ILCodeVersion::kSuppressParams));
m_rejitState.Store(oldFlags & ~RejitFlags::kSuppressParams);
}
}

Expand Down Expand Up @@ -850,7 +849,7 @@ bool ILCodeVersion::HasAnyOptimizedNativeCodeVersion(NativeCodeVersion tier0Nati
}
#endif

ILCodeVersion::RejitFlags ILCodeVersion::GetRejitState() const
RejitFlags ILCodeVersion::GetRejitState() const
{
LIMITED_METHOD_DAC_CONTRACT;
if (m_storageKind == StorageKind::Explicit)
Expand All @@ -859,7 +858,7 @@ ILCodeVersion::RejitFlags ILCodeVersion::GetRejitState() const
}
else
{
return ILCodeVersion::kStateActive;
return RejitFlags::kStateActive;
}
}

Expand Down
62 changes: 31 additions & 31 deletions src/coreclr/vm/codeversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,34 @@ class NativeCodeVersion

#ifdef FEATURE_CODE_VERSIONING


enum class RejitFlags : uint32_t
{
// The profiler has requested a ReJit, so we've allocated stuff, but we haven't
// called back to the profiler to get any info or indicate that the ReJit has
// started. (This Info can be 'reused' for a new ReJit if the
// profiler calls RequestRejit again before we transition to the next state.)
kStateRequested = 0x00000000,

// The CLR has initiated the call to the profiler's GetReJITParameters() callback
// but it hasn't completed yet. At this point we have to assume the profiler has
// committed to a specific IL body, even if the CLR doesn't know what it is yet.
// If the profiler calls RequestRejit we need to allocate a new ILCodeVersion
// and call GetReJITParameters() again.
kStateGettingReJITParameters = 0x00000001,

// We have asked the profiler about this method via ICorProfilerFunctionControl,
// and have thus stored the IL and codegen flags the profiler specified.
kStateActive = 0x00000002,

kStateMask = 0x0000000F,

// Indicates that the method being ReJITted is an inliner of the actual
// ReJIT request and we should not issue the GetReJITParameters for this
// method.
kSuppressParams = 0x80000000,

support_use_as_flags // Enable the template functions in enum_class_flags.h
};

class ILCodeVersion
{
Expand Down Expand Up @@ -184,33 +211,6 @@ class ILCodeVersion
HRESULT SetActiveNativeCodeVersion(NativeCodeVersion activeNativeCodeVersion);
#endif //DACCESS_COMPILE

enum RejitFlags
{
// The profiler has requested a ReJit, so we've allocated stuff, but we haven't
// called back to the profiler to get any info or indicate that the ReJit has
// started. (This Info can be 'reused' for a new ReJit if the
// profiler calls RequestRejit again before we transition to the next state.)
kStateRequested = 0x00000000,

// The CLR has initiated the call to the profiler's GetReJITParameters() callback
// but it hasn't completed yet. At this point we have to assume the profiler has
// committed to a specific IL body, even if the CLR doesn't know what it is yet.
// If the profiler calls RequestRejit we need to allocate a new ILCodeVersion
// and call GetReJITParameters() again.
kStateGettingReJITParameters = 0x00000001,

// We have asked the profiler about this method via ICorProfilerFunctionControl,
// and have thus stored the IL and codegen flags the profiler specified.
kStateActive = 0x00000002,

kStateMask = 0x0000000F,

// Indicates that the method being ReJITted is an inliner of the actual
// ReJIT request and we should not issue the GetReJITParameters for this
// method.
kSuppressParams = 0x80000000
};

RejitFlags GetRejitState() const;
BOOL GetEnableReJITCallback() const;
BOOL IsDeoptimized() const;
Expand Down Expand Up @@ -388,15 +388,15 @@ class ILCodeVersionNode
PTR_COR_ILMETHOD GetIL() const;
DWORD GetJitFlags() const;
const InstrumentedILOffsetMapping* GetInstrumentedILMap() const;
ILCodeVersion::RejitFlags GetRejitState() const;
RejitFlags GetRejitState() const;
BOOL GetEnableReJITCallback() const;
PTR_ILCodeVersionNode GetNextILVersionNode() const;
BOOL IsDeoptimized() const;
#ifndef DACCESS_COMPILE
void SetIL(COR_ILMETHOD* pIL);
void SetJitFlags(DWORD flags);
void SetInstrumentedILMap(SIZE_T cMap, COR_IL_MAP * rgMap);
void SetRejitState(ILCodeVersion::RejitFlags newState);
void SetRejitState(RejitFlags newState);
void SetEnableReJITCallback(BOOL state);
void SetNextILVersionNode(ILCodeVersionNode* pNextVersionNode);
#endif
Expand All @@ -406,7 +406,7 @@ class ILCodeVersionNode
const mdMethodDef m_methodDef;
const ReJITID m_rejitId;
PTR_ILCodeVersionNode m_pNextILVersionNode; // Never modified after being added to the linked list
Volatile<ILCodeVersion::RejitFlags> m_rejitState;
Volatile<RejitFlags> m_rejitState;
VolatilePtr<COR_ILMETHOD, PTR_COR_ILMETHOD> m_pIL;
Volatile<DWORD> m_jitFlags;
InstrumentedILOffsetMapping m_instrumentedILMap;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7928,7 +7928,7 @@ CorInfoInline CEEInfo::canInline (CORINFO_METHOD_HANDLE hCaller,
CodeVersionManager* pCodeVersionManager = pCallee->GetCodeVersionManager();
CodeVersionManager::LockHolder codeVersioningLockHolder;
ILCodeVersion ilVersion = pCodeVersionManager->GetActiveILCodeVersion(pCallee);
if (ilVersion.GetRejitState() != ILCodeVersion::kStateActive || !ilVersion.HasDefaultIL())
if (ilVersion.GetRejitState() != RejitFlags::kStateActive || !ilVersion.HasDefaultIL())
{
result = INLINE_FAIL;
szFailReason = "ReJIT methods cannot be inlined.";
Expand Down Expand Up @@ -8131,7 +8131,7 @@ void CEEInfo::reportInliningDecision (CORINFO_METHOD_HANDLE inlinerHnd,
CodeVersionManager* pCodeVersionManager = pCallee->GetCodeVersionManager();
CodeVersionManager::LockHolder codeVersioningLockHolder;
ILCodeVersion ilVersion = pCodeVersionManager->GetActiveILCodeVersion(pCallee);
if (ilVersion.GetRejitState() != ILCodeVersion::kStateActive || !ilVersion.HasDefaultIL())
if (ilVersion.GetRejitState() != RejitFlags::kStateActive || !ilVersion.HasDefaultIL())
{
shouldCallReJIT = TRUE;
modId = reinterpret_cast<ModuleID>(pCaller->GetModule());
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/prestub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2113,11 +2113,11 @@ HRESULT VersionedPrepareCodeConfig::FinishConfiguration()
// Any code build stages that do just in time configuration should
// be configured now
#ifdef FEATURE_REJIT
if (m_ilCodeVersion.GetRejitState() != ILCodeVersion::kStateActive)
if (m_ilCodeVersion.GetRejitState() != RejitFlags::kStateActive)
{
ReJitManager::ConfigureILCodeVersion(m_ilCodeVersion);
}
_ASSERTE(m_ilCodeVersion.GetRejitState() == ILCodeVersion::kStateActive);
_ASSERTE(m_ilCodeVersion.GetRejitState() == RejitFlags::kStateActive);
#endif

return S_OK;
Expand Down
20 changes: 10 additions & 10 deletions src/coreclr/vm/rejit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ HRESULT ReJitManager::BindILVersion(
ILCodeVersion ilCodeVersion = pCodeVersionManager->GetActiveILCodeVersion(pModule, methodDef);
BOOL fDoCallback = (flags & COR_PRF_REJIT_INLINING_CALLBACKS) == COR_PRF_REJIT_INLINING_CALLBACKS;

if (ilCodeVersion.GetRejitState() == ILCodeVersion::kStateRequested)
if (ilCodeVersion.GetRejitState() == RejitFlags::kStateRequested)
{
// We can 'reuse' this instance because the profiler doesn't know about
// it yet. (This likely happened because a profiler called RequestReJIT
Expand Down Expand Up @@ -965,12 +965,12 @@ HRESULT ReJitManager::ConfigureILCodeVersion(ILCodeVersion ilCodeVersion)
CodeVersionManager::LockHolder codeVersioningLockHolder;
switch (ilCodeVersion.GetRejitState())
{
case ILCodeVersion::kStateRequested:
ilCodeVersion.SetRejitState(ILCodeVersion::kStateGettingReJITParameters);
case RejitFlags::kStateRequested:
ilCodeVersion.SetRejitState(RejitFlags::kStateGettingReJITParameters);
fNeedsParameters = TRUE;
break;

case ILCodeVersion::kStateGettingReJITParameters:
case RejitFlags::kStateGettingReJITParameters:
fWaitForParameters = TRUE;
break;

Expand Down Expand Up @@ -1026,9 +1026,9 @@ HRESULT ReJitManager::ConfigureILCodeVersion(ILCodeVersion ilCodeVersion)
// This code path also happens if the GetReJITParameters callback was suppressed due to
// the method being ReJITted as an inliner by the runtime (instead of by the user).
CodeVersionManager::LockHolder codeVersioningLockHolder;
if (ilCodeVersion.GetRejitState() == ILCodeVersion::kStateGettingReJITParameters)
if (ilCodeVersion.GetRejitState() == RejitFlags::kStateGettingReJITParameters)
{
ilCodeVersion.SetRejitState(ILCodeVersion::kStateActive);
ilCodeVersion.SetRejitState(RejitFlags::kStateActive);
ilCodeVersion.SetIL(ILCodeVersion(pModule, methodDef).GetIL());
}
}
Expand All @@ -1045,7 +1045,7 @@ HRESULT ReJitManager::ConfigureILCodeVersion(ILCodeVersion ilCodeVersion)
_ASSERTE(pFuncControl != NULL);

CodeVersionManager::LockHolder codeVersioningLockHolder;
if (ilCodeVersion.GetRejitState() == ILCodeVersion::kStateGettingReJITParameters)
if (ilCodeVersion.GetRejitState() == RejitFlags::kStateGettingReJITParameters)
{
// Inside the above call to ICorProfilerCallback4::GetReJITParameters, the profiler
// will have used the specified pFuncControl to provide its IL and codegen flags.
Expand All @@ -1055,7 +1055,7 @@ HRESULT ReJitManager::ConfigureILCodeVersion(ILCodeVersion ilCodeVersion)
// ilCodeVersion is now the owner of the memory for the IL buffer
ilCodeVersion.SetInstrumentedILMap(pFuncControl->GetInstrumentedMapEntryCount(),
pFuncControl->GetInstrumentedMapEntries());
ilCodeVersion.SetRejitState(ILCodeVersion::kStateActive);
ilCodeVersion.SetRejitState(RejitFlags::kStateActive);
}
}
}
Expand Down Expand Up @@ -1086,7 +1086,7 @@ HRESULT ReJitManager::ConfigureILCodeVersion(ILCodeVersion ilCodeVersion)
{
{
CodeVersionManager::LockHolder codeVersioningLockHolder;
if (ilCodeVersion.GetRejitState() == ILCodeVersion::kStateActive)
if (ilCodeVersion.GetRejitState() == RejitFlags::kStateActive)
{
break; // the other thread got the parameters successfully, go race to rejit
}
Expand Down Expand Up @@ -1188,7 +1188,7 @@ HRESULT ReJitManager::GetReJITIDs(PTR_MethodDesc pMD, ULONG cReJitIds, ULONG * p
{
ILCodeVersion curILVersion = *iter;

if (curILVersion.GetRejitState() == ILCodeVersion::kStateActive)
if (curILVersion.GetRejitState() == RejitFlags::kStateActive)
{
if (cnt < cReJitIds)
{
Expand Down

0 comments on commit 161f346

Please sign in to comment.