Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 01da3bd

Browse files
kouvelsergiy-k
authored andcommitted
Fix GCStress modes that do code instrumentation to work with code versioning (#25261)
- SOS changes are in dotnet/diagnostics#369 - Fixes https://github.com/dotnet/coreclr/issues/17646
1 parent f364536 commit 01da3bd

11 files changed

+224
-83
lines changed

src/debug/daccess/request.cpp

+42-35
Original file line numberDiff line numberDiff line change
@@ -889,19 +889,32 @@ HRESULT ClrDataAccess::GetMethodDescData(
889889
if (pcNeededRevertedRejitData != NULL)
890890
*pcNeededRevertedRejitData = 0;
891891

892+
NativeCodeVersion requestedNativeCodeVersion, activeNativeCodeVersion;
893+
if (ip != NULL)
894+
{
895+
requestedNativeCodeVersion = ExecutionManager::GetNativeCodeVersion(CLRDATA_ADDRESS_TO_TADDR(ip));
896+
}
897+
else
898+
{
899+
#ifdef FEATURE_CODE_VERSIONING
900+
activeNativeCodeVersion = pMD->GetCodeVersionManager()->GetActiveILCodeVersion(pMD).GetActiveNativeCodeVersion(pMD);
901+
#else
902+
activeNativeCodeVersion = NativeCodeVersion(pMD);
903+
#endif
904+
requestedNativeCodeVersion = activeNativeCodeVersion;
905+
}
906+
892907
methodDescData->requestedIP = ip;
893-
methodDescData->bHasNativeCode = pMD->HasNativeCode();
894908
methodDescData->bIsDynamic = (pMD->IsLCGMethod()) ? TRUE : FALSE;
895909
methodDescData->wSlotNumber = pMD->GetSlot();
896-
if (pMD->HasNativeCode())
910+
if (!requestedNativeCodeVersion.IsNull() && requestedNativeCodeVersion.GetNativeCode() != NULL)
897911
{
898-
methodDescData->NativeCodeAddr = TO_CDADDR(pMD->GetNativeCode());
899-
#ifdef DBG_TARGET_ARM
900-
methodDescData->NativeCodeAddr &= ~THUMB_CODE;
901-
#endif
912+
methodDescData->bHasNativeCode = TRUE;
913+
methodDescData->NativeCodeAddr = TO_CDADDR(PCODEToPINSTR(requestedNativeCodeVersion.GetNativeCode()));
902914
}
903915
else
904916
{
917+
methodDescData->bHasNativeCode = FALSE;
905918
methodDescData->NativeCodeAddr = (CLRDATA_ADDRESS)-1;
906919
}
907920
methodDescData->AddressOfNativeCodeSlot = pMD->HasNativeCodeSlot() ? TO_CDADDR(pMD->GetAddrOfNativeCodeSlot()) : NULL;
@@ -926,29 +939,24 @@ HRESULT ClrDataAccess::GetMethodDescData(
926939
CodeVersionManager *pCodeVersionManager = pMD->GetCodeVersionManager();
927940

928941
// Current ReJitInfo
929-
ILCodeVersion activeILCodeVersion = pCodeVersionManager->GetActiveILCodeVersion(pMD);
930-
NativeCodeVersion activeChild = activeILCodeVersion.GetActiveNativeCodeVersion(pMD);
931-
CopyNativeCodeVersionToReJitData(activeChild, activeChild, &methodDescData->rejitDataCurrent);
932-
933-
if (!activeChild.IsNull())
942+
if (activeNativeCodeVersion.IsNull())
934943
{
935-
// This was already set previously, but MethodDesc::GetNativeCode is potentially not aware of
936-
// a new native code version, so this is more accurate.
937-
methodDescData->NativeCodeAddr = activeChild.GetNativeCode();
944+
ILCodeVersion activeILCodeVersion = pCodeVersionManager->GetActiveILCodeVersion(pMD);
945+
activeNativeCodeVersion = activeILCodeVersion.GetActiveNativeCodeVersion(pMD);
938946
}
939-
947+
CopyNativeCodeVersionToReJitData(
948+
activeNativeCodeVersion,
949+
activeNativeCodeVersion,
950+
&methodDescData->rejitDataCurrent);
951+
940952
// Requested ReJitInfo
941953
_ASSERTE(methodDescData->rejitDataRequested.rejitID == 0);
942-
if (methodDescData->requestedIP != NULL)
954+
if (ip != NULL && !requestedNativeCodeVersion.IsNull())
943955
{
944-
NativeCodeVersion nativeCodeVersionRequested = pCodeVersionManager->GetNativeCodeVersion(
945-
pMD,
946-
CLRDATA_ADDRESS_TO_TADDR(methodDescData->requestedIP));
947-
948-
if (!nativeCodeVersionRequested.IsNull())
949-
{
950-
CopyNativeCodeVersionToReJitData(nativeCodeVersionRequested, activeChild, &methodDescData->rejitDataRequested);
951-
}
956+
CopyNativeCodeVersionToReJitData(
957+
requestedNativeCodeVersion,
958+
activeNativeCodeVersion,
959+
&methodDescData->rejitDataRequested);
952960
}
953961

954962
// Total number of jitted rejit versions
@@ -1000,7 +1008,10 @@ HRESULT ClrDataAccess::GetMethodDescData(
10001008
}
10011009

10021010
NativeCodeVersion activeRejitChild = ilCodeVersion.GetActiveNativeCodeVersion(pMD);
1003-
CopyNativeCodeVersionToReJitData(activeRejitChild, activeChild, &rgRevertedRejitData[iRejitDataReverted]);
1011+
CopyNativeCodeVersionToReJitData(
1012+
activeRejitChild,
1013+
activeNativeCodeVersion,
1014+
&rgRevertedRejitData[iRejitDataReverted]);
10041015
iRejitDataReverted++;
10051016
}
10061017
// pcNeededRevertedRejitData != NULL as per condition at top of function (cuz rgRevertedRejitData !=
@@ -1017,24 +1028,20 @@ HRESULT ClrDataAccess::GetMethodDescData(
10171028
}
10181029
EX_END_CATCH(SwallowAllExceptions)
10191030
hr = S_OK; // Failure to get rejitids is not fatal
1031+
10201032
#endif // FEATURE_REJIT
10211033

1022-
#if defined(HAVE_GCCOVER)
1023-
if (pMD->m_GcCover)
1034+
#ifdef HAVE_GCCOVER
1035+
if (!requestedNativeCodeVersion.IsNull())
10241036
{
1025-
EX_TRY
1037+
PTR_GCCoverageInfo gcCover = requestedNativeCodeVersion.GetGCCoverageInfo();
1038+
if (gcCover != NULL)
10261039
{
10271040
// In certain minidumps, we won't save the gccover information.
10281041
// (it would be unwise to do so, it is heavy and not a customer scenario).
1029-
methodDescData->GCStressCodeCopy = HOST_CDADDR(pMD->m_GcCover) + offsetof(GCCoverageInfo, savedCode);
1042+
methodDescData->GCStressCodeCopy = HOST_CDADDR(gcCover) + offsetof(GCCoverageInfo, savedCode);
10301043
}
1031-
EX_CATCH
1032-
{
1033-
methodDescData->GCStressCodeCopy = 0;
1034-
}
1035-
EX_END_CATCH(SwallowAllExceptions)
10361044
}
1037-
else
10381045
#endif // HAVE_GCCOVER
10391046

10401047
// Set this above Dario since you know how to tell if dynamic

src/vm/codeman.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -4206,6 +4206,21 @@ PCODE ExecutionManager::GetCodeStartAddress(PCODE currentPC)
42064206
return PINSTRToPCODE(codeInfo.GetStartAddress());
42074207
}
42084208

4209+
//**************************************************************************
4210+
NativeCodeVersion ExecutionManager::GetNativeCodeVersion(PCODE currentPC)
4211+
{
4212+
CONTRACTL
4213+
{
4214+
NOTHROW;
4215+
GC_NOTRIGGER;
4216+
FORBID_FAULT;
4217+
}
4218+
CONTRACTL_END;
4219+
4220+
EECodeInfo codeInfo(currentPC);
4221+
return codeInfo.IsValid() ? codeInfo.GetNativeCodeVersion() : NativeCodeVersion();
4222+
}
4223+
42094224
//**************************************************************************
42104225
MethodDesc * ExecutionManager::GetCodeMethodDesc(PCODE currentPC)
42114226
{

src/vm/codeman.h

+4
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,8 @@ class ExecutionManager
12511251
// Returns method's start address for a given PC
12521252
static PCODE GetCodeStartAddress(PCODE currentPC);
12531253

1254+
static NativeCodeVersion GetNativeCodeVersion(PCODE currentPC);
1255+
12541256
// Returns methodDesc for given PC
12551257
static MethodDesc * GetCodeMethodDesc(PCODE currentPC);
12561258

@@ -1805,6 +1807,8 @@ class EECodeInfo
18051807
return PCODEToPINSTR(m_codeAddress);
18061808
}
18071809

1810+
NativeCodeVersion GetNativeCodeVersion();
1811+
18081812
MethodDesc * GetMethodDesc()
18091813
{
18101814
LIMITED_METHOD_DAC_CONTRACT;

src/vm/codeversion.cpp

+70-3
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,29 @@
2525
// versioning information
2626
//
2727

28+
NativeCodeVersion::NativeCodeVersion() : m_pMethodDesc(PTR_NULL) {};
2829
NativeCodeVersion::NativeCodeVersion(const NativeCodeVersion & rhs) : m_pMethodDesc(rhs.m_pMethodDesc) {}
2930
NativeCodeVersion::NativeCodeVersion(PTR_MethodDesc pMethod) : m_pMethodDesc(pMethod) {}
3031
BOOL NativeCodeVersion::IsNull() const { return m_pMethodDesc == NULL; }
3132
PTR_MethodDesc NativeCodeVersion::GetMethodDesc() const { return m_pMethodDesc; }
32-
PCODE NativeCodeVersion::GetNativeCode() const { return m_pMethodDesc->GetNativeCode(); }
3333
NativeCodeVersionId NativeCodeVersion::GetVersionId() const { return 0; }
34-
// ReJITID NativeCodeVersion::GetILCodeVersionId() const; { return 0; }
35-
// ILCodeVersion NativeCodeVersion::GetILCodeVersion() const { return ILCodeVersion(m_pMethodDesc); }
34+
BOOL NativeCodeVersion::IsDefaultVersion() const { return TRUE; }
35+
PCODE NativeCodeVersion::GetNativeCode() const { return m_pMethodDesc->GetNativeCode(); }
36+
3637
#ifndef DACCESS_COMPILE
3738
BOOL NativeCodeVersion::SetNativeCodeInterlocked(PCODE pCode, PCODE pExpected) { return m_pMethodDesc->SetNativeCodeInterlocked(pCode, pExpected); }
3839
#endif
40+
41+
#ifdef HAVE_GCCOVER
42+
PTR_GCCoverageInfo NativeCodeVersion::GetGCCoverageInfo() const { return GetMethodDesc()->m_GcCover; }
43+
void NativeCodeVersion::SetGCCoverageInfo(PTR_GCCoverageInfo gcCover)
44+
{
45+
MethodDesc *pMD = GetMethodDesc();
46+
_ASSERTE(gcCover == NULL || pMD->m_GcCover == NULL);
47+
*EnsureWritablePages(&pMD->m_GcCover) = gcCover;
48+
}
49+
#endif
50+
3951
bool NativeCodeVersion::operator==(const NativeCodeVersion & rhs) const { return m_pMethodDesc == rhs.m_pMethodDesc; }
4052
bool NativeCodeVersion::operator!=(const NativeCodeVersion & rhs) const { return !operator==(rhs); }
4153

@@ -63,6 +75,9 @@ NativeCodeVersionNode::NativeCodeVersionNode(
6375
m_id(id),
6476
#ifdef FEATURE_TIERED_COMPILATION
6577
m_optTier(optimizationTier),
78+
#endif
79+
#ifdef HAVE_GCCOVER
80+
m_gcCover(PTR_NULL),
6681
#endif
6782
m_flags(0)
6883
{}
@@ -166,6 +181,24 @@ void NativeCodeVersionNode::SetOptimizationTier(NativeCodeVersion::OptimizationT
166181

167182
#endif // FEATURE_TIERED_COMPILATION
168183

184+
#ifdef HAVE_GCCOVER
185+
186+
PTR_GCCoverageInfo NativeCodeVersionNode::GetGCCoverageInfo() const
187+
{
188+
LIMITED_METHOD_CONTRACT;
189+
return m_gcCover;
190+
}
191+
192+
void NativeCodeVersionNode::SetGCCoverageInfo(PTR_GCCoverageInfo gcCover)
193+
{
194+
LIMITED_METHOD_CONTRACT;
195+
_ASSERTE(gcCover == NULL || m_gcCover == NULL);
196+
197+
m_gcCover = gcCover;
198+
}
199+
200+
#endif // HAVE_GCCOVER
201+
169202
NativeCodeVersion::NativeCodeVersion() :
170203
m_storageKind(StorageKind::Unknown)
171204
{}
@@ -371,6 +404,40 @@ void NativeCodeVersion::SetOptimizationTier(OptimizationTier tier)
371404

372405
#endif
373406

407+
#ifdef HAVE_GCCOVER
408+
409+
PTR_GCCoverageInfo NativeCodeVersion::GetGCCoverageInfo() const
410+
{
411+
WRAPPER_NO_CONTRACT;
412+
413+
if (m_storageKind == StorageKind::Explicit)
414+
{
415+
return AsNode()->GetGCCoverageInfo();
416+
}
417+
else
418+
{
419+
return GetMethodDesc()->m_GcCover;
420+
}
421+
}
422+
423+
void NativeCodeVersion::SetGCCoverageInfo(PTR_GCCoverageInfo gcCover)
424+
{
425+
WRAPPER_NO_CONTRACT;
426+
427+
if (m_storageKind == StorageKind::Explicit)
428+
{
429+
AsNode()->SetGCCoverageInfo(gcCover);
430+
}
431+
else
432+
{
433+
MethodDesc *pMD = GetMethodDesc();
434+
_ASSERTE(gcCover == NULL || pMD->m_GcCover == NULL);
435+
*EnsureWritablePages(&pMD->m_GcCover) = gcCover;
436+
}
437+
}
438+
439+
#endif // HAVE_GCCOVER
440+
374441
PTR_NativeCodeVersionNode NativeCodeVersion::AsNode() const
375442
{
376443
LIMITED_METHOD_DAC_CONTRACT;

src/vm/codeversion.h

+30-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ typedef DPTR(class CodeVersionManager) PTR_CodeVersionManager;
3737

3838
#endif
3939

40-
41-
40+
#ifdef HAVE_GCCOVER
41+
class GCCoverageInfo;
42+
typedef DPTR(class GCCoverageInfo) PTR_GCCoverageInfo;
43+
#endif
4244

4345
class NativeCodeVersion
4446
{
@@ -54,16 +56,22 @@ class NativeCodeVersion
5456
NativeCodeVersion(PTR_NativeCodeVersionNode pVersionNode);
5557
#endif
5658
explicit NativeCodeVersion(PTR_MethodDesc pMethod);
59+
5760
BOOL IsNull() const;
5861
PTR_MethodDesc GetMethodDesc() const;
5962
NativeCodeVersionId GetVersionId() const;
6063
BOOL IsDefaultVersion() const;
6164
PCODE GetNativeCode() const;
65+
66+
#ifdef FEATURE_CODE_VERSIONING
6267
ILCodeVersion GetILCodeVersion() const;
6368
ReJITID GetILCodeVersionId() const;
69+
#endif
70+
6471
#ifndef DACCESS_COMPILE
6572
BOOL SetNativeCodeInterlocked(PCODE pCode, PCODE pExpected = NULL);
6673
#endif
74+
6775
enum OptimizationTier
6876
{
6977
OptimizationTier0,
@@ -76,8 +84,15 @@ class NativeCodeVersion
7684
void SetOptimizationTier(OptimizationTier tier);
7785
#endif
7886
#endif // FEATURE_TIERED_COMPILATION
87+
88+
#ifdef HAVE_GCCOVER
89+
PTR_GCCoverageInfo GetGCCoverageInfo() const;
90+
void SetGCCoverageInfo(PTR_GCCoverageInfo gcCover);
91+
#endif
92+
7993
bool operator==(const NativeCodeVersion & rhs) const;
8094
bool operator!=(const NativeCodeVersion & rhs) const;
95+
8196
#if defined(DACCESS_COMPILE) && defined(FEATURE_CODE_VERSIONING)
8297
// The DAC is privy to the backing node abstraction
8398
PTR_NativeCodeVersionNode AsNode() const;
@@ -86,7 +101,7 @@ class NativeCodeVersion
86101
private:
87102

88103
#ifndef FEATURE_CODE_VERSIONING
89-
MethodDesc* m_pMethodDesc;
104+
PTR_MethodDesc m_pMethodDesc;
90105
#else // FEATURE_CODE_VERSIONING
91106

92107
#ifndef DACCESS_COMPILE
@@ -229,13 +244,16 @@ class NativeCodeVersionNode
229244
friend NativeCodeVersionIterator;
230245
friend MethodDescVersioningState;
231246
friend ILCodeVersionNode;
247+
232248
public:
233249
#ifndef DACCESS_COMPILE
234250
NativeCodeVersionNode(NativeCodeVersionId id, MethodDesc* pMethod, ReJITID parentId, NativeCodeVersion::OptimizationTier optimizationTier);
235251
#endif
252+
236253
#ifdef DEBUG
237254
BOOL LockOwnedByCurrentThread() const;
238255
#endif
256+
239257
PTR_MethodDesc GetMethodDesc() const;
240258
NativeCodeVersionId GetVersionId() const;
241259
PCODE GetNativeCode() const;
@@ -246,13 +264,19 @@ class NativeCodeVersionNode
246264
BOOL SetNativeCodeInterlocked(PCODE pCode, PCODE pExpected);
247265
void SetActiveChildFlag(BOOL isActive);
248266
#endif
267+
249268
#ifdef FEATURE_TIERED_COMPILATION
250269
NativeCodeVersion::OptimizationTier GetOptimizationTier() const;
251270
#ifndef DACCESS_COMPILE
252271
void SetOptimizationTier(NativeCodeVersion::OptimizationTier tier);
253272
#endif
254273
#endif // FEATURE_TIERED_COMPILATION
255274

275+
#ifdef HAVE_GCCOVER
276+
PTR_GCCoverageInfo GetGCCoverageInfo() const;
277+
void SetGCCoverageInfo(PTR_GCCoverageInfo gcCover);
278+
#endif
279+
256280
private:
257281
//union - could save a little memory?
258282
//{
@@ -266,6 +290,9 @@ class NativeCodeVersionNode
266290
#ifdef FEATURE_TIERED_COMPILATION
267291
NativeCodeVersion::OptimizationTier m_optTier;
268292
#endif
293+
#ifdef HAVE_GCCOVER
294+
PTR_GCCoverageInfo m_gcCover;
295+
#endif
269296

270297
enum NativeCodeVersionNodeFlags
271298
{

0 commit comments

Comments
 (0)