Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose StressLog via CDAC and port StressLogAnalyzer to managed code #104999

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7d4a3e0
Start a StressLog contract for CDAC
jkoritzinsky Jun 20, 2024
2f03842
Start on StressLogAnalyzer port.
jkoritzinsky Jun 28, 2024
a904770
Load in and read the thread stress logs and the stress messages.
jkoritzinsky Jun 28, 2024
0edfc36
Add support for Ix, I64 specifiers
jkoritzinsky Jul 11, 2024
acbe6d5
Refactor into src/test directories and add tests for basic format str…
jkoritzinsky Jul 11, 2024
9d1f475
Add more tests and extend the signed integer test case to test a ton …
jkoritzinsky Jul 12, 2024
9b777ae
Add special pointer formatting hook and a default implementation for …
jkoritzinsky Jul 12, 2024
4ff56ba
Write the command line and start work on porting over logic (first on…
jkoritzinsky Jul 15, 2024
8864e5c
Add GC heap map memory and default string handling
jkoritzinsky Jul 15, 2024
5a192db
Implement GC heap map association
jkoritzinsky Jul 15, 2024
227ad83
Fill in more processing and start on sketching out the output handling.
jkoritzinsky Jul 16, 2024
d487523
Port over remaining features
jkoritzinsky Jul 16, 2024
3d92f5e
Remove native StressLogAnalyzer
jkoritzinsky Jul 16, 2024
5e20521
Get 'dump all messages' working correctly
jkoritzinsky Jul 16, 2024
8180c9f
Fix format offset calculation and update contract md to include refer…
jkoritzinsky Jul 16, 2024
1c5f08e
Merge branch 'main' of github.com:dotnet/runtime into cdac-stresslog-…
jkoritzinsky Jul 16, 2024
77669f3
Add a conceptual description of how to format a StressLog message
jkoritzinsky Jul 16, 2024
2c369c5
Implement escape sequence interpretation
jkoritzinsky Jul 16, 2024
7cb4dd3
Redefine maxMsgSize to make it C++11 constexpr-compliant even with ou…
jkoritzinsky Jul 16, 2024
0aad986
Merge branch 'main' of github.com:dotnet/runtime into cdac-stresslog-…
jkoritzinsky Jul 17, 2024
5e314f1
Add "is pointer in stresslog" contract function for SOS's GCHandleLea…
jkoritzinsky Jul 17, 2024
7fd20a0
Add some additional members to the contract to allow implementing all…
jkoritzinsky Jul 17, 2024
4c5ea16
Wire up ISOSDacInterface::GetStressLogAddress while I'm here
jkoritzinsky Jul 17, 2024
da3f56a
Merge branch 'main' of github.com:dotnet/runtime into cdac-stresslog-…
jkoritzinsky Jul 18, 2024
09ec3d2
Merge branch 'main' into cdac-stresslog-analyzer
jkoritzinsky Jul 19, 2024
0b28ab3
Merge branch 'main' into cdac-stresslog-analyzer
jkoritzinsky Jul 21, 2024
ee2f1f1
Update the StressLog contract to better describe and cross-link the c…
jkoritzinsky Jul 22, 2024
edebefa
Start adjusting output to match StressLogAnalyzer
jkoritzinsky Jul 22, 2024
914639a
Fix discovering the first message of a new chunk
jkoritzinsky Jul 22, 2024
23f9eaf
Fix remaining output nits that would cause the most confusion.
jkoritzinsky Jul 22, 2024
1bca8c2
Lots of perf improvements and some fixes
jkoritzinsky Jul 23, 2024
4145344
Rewrite GC time index searching for better perf
jkoritzinsky Jul 23, 2024
6d7a859
Make GC thread filtering more aggressive and fix non-GC thread filter…
jkoritzinsky Jul 23, 2024
9368bad
Hook into clr.tools and clr.toolstests subsets
jkoritzinsky Jul 23, 2024
277ca4b
Remove uncessary cast
jkoritzinsky Jul 23, 2024
96aaec7
Correctly implement the quit/retry commands
jkoritzinsky Jul 29, 2024
ee89343
Merge branch 'main' of github.com:dotnet/runtime into cdac-stresslog-…
jkoritzinsky Aug 20, 2024
208412b
Use string helpers from Target
jkoritzinsky Aug 20, 2024
ffd4fe1
Remove dead code now that StressLogAnalyzer is in C#
jkoritzinsky Sep 13, 2024
bdf5aca
Merge remote-tracking branch 'dotnet/main' into cdac-stresslog-analyzer
jkoritzinsky Oct 11, 2024
5543ee5
Update StressLogAnalyzer (not the tests) to the new refactoring.
jkoritzinsky Oct 11, 2024
5053a62
Fix tets and use Moq to mock the target instead of constructing a fak…
jkoritzinsky Oct 15, 2024
6c69ffd
Merge branch 'main' of github.com:dotnet/runtime into cdac-stresslog-…
jkoritzinsky Oct 15, 2024
48e0543
Merge branch 'main' into cdac-stresslog-analyzer
jkoritzinsky Oct 17, 2024
f194edf
Add support for padded strings as they're apparently used by the GC.
jkoritzinsky Oct 17, 2024
e45a636
Merge branch 'main' of https://github.com/dotnet/runtime into cdac-st…
jkoritzinsky Dec 11, 2024
2a4e153
PR feedback and allow a module table to be present or absent in v1/v2…
jkoritzinsky Dec 12, 2024
6093135
Fix typo
jkoritzinsky Dec 12, 2024
60bc596
Update IStressLog.cs
jkoritzinsky Dec 13, 2024
f8ef54f
Fix body and accessibility
jkoritzinsky Dec 13, 2024
f4cbfc4
Make the message filter internal
jkoritzinsky Dec 14, 2024
571d920
Merge branch 'main' of https://github.com/dotnet/runtime into cdac-st…
jkoritzinsky Jan 29, 2025
d854a6b
Move the formatter for stress messages into the Contracts assembly as…
jkoritzinsky Jan 29, 2025
1a9766f
Remove trailing references to StressLogAnalyzer.Tests
jkoritzinsky Jan 29, 2025
1d1c0c2
Use composition instead of inheritance
jkoritzinsky Feb 3, 2025
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
474 changes: 474 additions & 0 deletions docs/design/datacontracts/StressLog.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@
$(CoreClrProjectRoot)tools\aot\ILCompiler\repro\repro.csproj;
$(CoreClrProjectRoot)tools\r2rtest\R2RTest.csproj;
$(CoreClrProjectRoot)tools\PdbChecker\PdbChecker.csproj;
$(CoreClrProjectRoot)tools\AssemblyChecker\AssemblyChecker.csproj" Category="clr" Condition="'$(DotNetBuildSourceOnly)' != 'true'"/>
$(CoreClrProjectRoot)tools\AssemblyChecker\AssemblyChecker.csproj;
$(ToolsProjectRoot)StressLogAnalyzer\src\StressLogAnalyzer.csproj" Category="clr" Condition="'$(DotNetBuildSourceOnly)' != 'true'"/>
<!-- skip the architectures that don't have LKG runtime packs -->
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\crossgen2\crossgen2_publish.csproj" Condition="'$(NativeAotSupported)' == 'true'" Category="clr" />
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler.Build.Tasks\ILCompiler.Build.Tasks.csproj" Category="clr" Condition="'$(NativeAotSupported)' == 'true'" />
Expand All @@ -379,6 +380,8 @@
Test="true" Category="clr" Condition="'$(DotNetBuildSourceOnly)' != 'true' and '$(NativeAotSupported)' == 'true'"/>
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler.Trimming.Tests\ILCompiler.Trimming.Tests.csproj"
Test="true" Category="clr" Condition="'$(DotNetBuildSourceOnly)' != 'true' and '$(NativeAotSupported)' == 'true'"/>
<ProjectToBuild Include="$(ToolsProjectRoot)StressLogAnalyzer\tests\StressLogAnalyzer.Tests\StressLogAnalyzer.Tests.csproj"
Test="true" Category="clr" Condition="'$(DotNetBuildSourceOnly)' != 'true'" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+tools.cdacreadertests+'))">
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/debug/runtimeinfo/contracts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"Loader": 1,
"Object": 1,
"RuntimeTypeSystem": 1,
"Thread": 1
"Thread": 1,
"StressLog": 2
}
62 changes: 62 additions & 0 deletions src/coreclr/debug/runtimeinfo/datadescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,58 @@ CDAC_TYPE_FIELD(DynamicMetadata, /*uint32*/, Size, cdac_data<DynamicMetadata>::S
CDAC_TYPE_FIELD(DynamicMetadata, /*inline byte array*/, Data, cdac_data<DynamicMetadata>::Data)
CDAC_TYPE_END(DynamicMetadata)

#ifdef STRESS_LOG
CDAC_TYPE_BEGIN(StressLog)
CDAC_TYPE_SIZE(sizeof(StressLog))
CDAC_TYPE_FIELD(StressLog, /* uint32 */, LoggedFacilities, cdac_offsets<StressLog>::facilitiesToLog)
CDAC_TYPE_FIELD(StressLog, /* uint32 */, Level, cdac_offsets<StressLog>::levelToLog)
CDAC_TYPE_FIELD(StressLog, /* uint32 */, MaxSizePerThread, cdac_offsets<StressLog>::MaxSizePerThread)
CDAC_TYPE_FIELD(StressLog, /* uint32 */, MaxSizeTotal, cdac_offsets<StressLog>::MaxSizeTotal)
CDAC_TYPE_FIELD(StressLog, /* uint32 */, TotalChunks, cdac_offsets<StressLog>::totalChunk)
CDAC_TYPE_FIELD(StressLog, /* pointer */, Logs, cdac_offsets<StressLog>::logs)
CDAC_TYPE_FIELD(StressLog, /* uint64 */, TickFrequency, cdac_offsets<StressLog>::tickFrequency)
CDAC_TYPE_FIELD(StressLog, /* uint64 */, StartTimestamp, cdac_offsets<StressLog>::startTimeStamp)
CDAC_TYPE_FIELD(StressLog, /* nuint */, ModuleOffset, cdac_offsets<StressLog>::moduleOffset)
CDAC_TYPE_END(StressLog)

CDAC_TYPE_BEGIN(StressLogModuleDesc)
CDAC_TYPE_SIZE(cdac_offsets<StressLog>::ModuleDesc::type_size)
CDAC_TYPE_FIELD(StressLogModuleDesc, pointer, BaseAddress, cdac_offsets<StressLog>::ModuleDesc::baseAddress)
CDAC_TYPE_FIELD(StressLogModuleDesc, nuint, Size, cdac_offsets<StressLog>::ModuleDesc::size)
CDAC_TYPE_END(StressLogModuleDesc)

CDAC_TYPE_BEGIN(ThreadStressLog)
CDAC_TYPE_INDETERMINATE(ThreadStressLog)
CDAC_TYPE_FIELD(ThreadStressLog, /* pointer */, Next, cdac_offsets<ThreadStressLog>::next)
CDAC_TYPE_FIELD(ThreadStressLog, uint64, ThreadId, cdac_offsets<ThreadStressLog>::threadId)
CDAC_TYPE_FIELD(ThreadStressLog, uint8, WriteHasWrapped, cdac_offsets<ThreadStressLog>::writeHasWrapped)
CDAC_TYPE_FIELD(ThreadStressLog, pointer, CurrentPtr, cdac_offsets<ThreadStressLog>::curPtr)
CDAC_TYPE_FIELD(ThreadStressLog, /* pointer */, ChunkListHead, cdac_offsets<ThreadStressLog>::chunkListHead)
CDAC_TYPE_FIELD(ThreadStressLog, /* pointer */, ChunkListTail, cdac_offsets<ThreadStressLog>::chunkListTail)
CDAC_TYPE_FIELD(ThreadStressLog, /* pointer */, CurrentWriteChunk, cdac_offsets<ThreadStressLog>::curWriteChunk)
CDAC_TYPE_END(ThreadStressLog)

CDAC_TYPE_BEGIN(StressLogChunk)
CDAC_TYPE_SIZE(sizeof(StressLogChunk))
CDAC_TYPE_FIELD(StressLogChunk, /* pointer */, Prev, offsetof(StressLogChunk, prev))
CDAC_TYPE_FIELD(StressLogChunk, /* pointer */, Next, offsetof(StressLogChunk, next))
CDAC_TYPE_FIELD(StressLogChunk, /* uint8[STRESSLOG_CHUNK_SIZE] */, Buf, offsetof(StressLogChunk, buf))
CDAC_TYPE_FIELD(StressLogChunk, /* uint32 */, Sig1, offsetof(StressLogChunk, dwSig1))
CDAC_TYPE_FIELD(StressLogChunk, /* uint32 */, Sig2, offsetof(StressLogChunk, dwSig2))
CDAC_TYPE_END(StressLogChunk)

// The StressMsg Header is the fixed size portion of the StressMsg
CDAC_TYPE_BEGIN(StressMsgHeader)
CDAC_TYPE_SIZE(sizeof(StressMsg))
CDAC_TYPE_END(StressMsgHeader)

CDAC_TYPE_BEGIN(StressMsg)
CDAC_TYPE_INDETERMINATE(StressMsg)
CDAC_TYPE_FIELD(StressMsg, StressMsgHeader, Header, 0)
CDAC_TYPE_FIELD(StressMsg, /* pointer */, Args, offsetof(StressMsg, args))
CDAC_TYPE_END(StressMsg)
#endif

CDAC_TYPE_BEGIN(MethodDesc)
CDAC_TYPE_INDETERMINATE(MethodDesc)
CDAC_TYPE_FIELD(MethodDesc, /*uint8*/, ChunkIndex, cdac_data<MethodDesc>::ChunkIndex)
Expand Down Expand Up @@ -420,6 +472,16 @@ CDAC_GLOBAL_POINTER(StringMethodTable, &::g_pStringClass)
CDAC_GLOBAL_POINTER(SyncTableEntries, &::g_pSyncTable)
CDAC_GLOBAL_POINTER(MiniMetaDataBuffAddress, &::g_MiniMetaDataBuffAddress)
CDAC_GLOBAL_POINTER(MiniMetaDataBuffMaxSize, &::g_MiniMetaDataBuffMaxSize)
#ifdef STRESS_LOG
CDAC_GLOBAL(StressLogEnabled, uint8, 1)
CDAC_GLOBAL_POINTER(StressLog, &g_pStressLog)
CDAC_GLOBAL_POINTER(StressLogModuleTable, &g_pStressLog->modules)
CDAC_GLOBAL(StressLogMaxModules, uint64, cdac_offsets<StressLog>::MAX_MODULES)
CDAC_GLOBAL(StressLogChunkSize, uint32, STRESSLOG_CHUNK_SIZE)
CDAC_GLOBAL(StressLogMaxMessageSize, uint64, (uint64_t)StressMsg::maxMsgSize)
#else
CDAC_GLOBAL(StressLogEnabled, uint8, 0)
#endif
CDAC_GLOBAL_POINTER(ExecutionManagerCodeRangeMapAddress, cdac_data<ExecutionManager>::CodeRangeMapAddress)
CDAC_GLOBALS_END()

Expand Down
106 changes: 56 additions & 50 deletions src/coreclr/inc/stresslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "log.h"

#if defined(STRESS_LOG) && !defined(FEATURE_NO_STRESSLOG)
#ifndef STRESS_LOG_ANALYZER
#include "holder.h"
#include "staticcontract.h"
#include "mscoree.h"
Expand All @@ -46,9 +45,6 @@
#ifndef _ASSERTE
#define _ASSERTE(expr)
#endif
#else
#include <stddef.h> // offsetof
#endif // STRESS_LOG_ANALYZER

/* The STRESS_LOG* macros work like printf. In fact the use printf in their implementation
so all printf format specifications work. In addition the Stress log dumper knows
Expand Down Expand Up @@ -172,6 +168,9 @@

void ReplacePid(LPCWSTR original, LPWSTR replaced, size_t replacedLength);

template<typename T>
struct cdac_offsets;

class ThreadStressLog;

struct StressLogMsg;
Expand All @@ -180,12 +179,12 @@ struct StressLogMsg;
/* a log is a circular queue of messages */

class StressLog {
template<typename T> friend struct ::cdac_offsets;
public:
static void Initialize(unsigned facilities, unsigned level, unsigned maxBytesPerThread,
unsigned maxBytesTotal, void* moduleBase, LPWSTR logFilename = nullptr);
static void Terminate(BOOL fProcessDetach=FALSE);
static void ThreadDetach(); // call at DllMain THREAD_DETACH if you want to recycle thread logs
#ifndef STRESS_LOG_ANALYZER
static int NewChunk ()
{
return InterlockedIncrement (&theLog.totalChunk);
Expand All @@ -194,7 +193,6 @@ class StressLog {
{
return InterlockedDecrement (&theLog.totalChunk);
}
#endif //STRESS_LOG_ANALYZER

//the result is not 100% accurate. If multiple threads call this function at the same time,
//we could allow the total size be bigger than required. But the memory won't grow forever
Expand Down Expand Up @@ -246,28 +244,6 @@ class StressLog {
#endif
#endif

#ifdef STRESS_LOG_ANALYZER
static size_t writing_base_address;
static size_t reading_base_address;

template<typename T>
static T* TranslateMemoryMappedPointer(T* input)
{
if (input == nullptr)
{
return nullptr;
}

return ((T*)(((uint8_t*)input) - writing_base_address + reading_base_address));
}
#else
template<typename T>
static T* TranslateMemoryMappedPointer(T* input)
{
return input;
}
#endif

#ifdef MEMORY_MAPPED_STRESSLOG

//
Expand Down Expand Up @@ -399,9 +375,7 @@ inline void* StressLog::ConvertArgument(int64_t arg)
}
#endif

#ifndef STRESS_LOG_ANALYZER
typedef Holder<CRITSEC_COOKIE, StressLog::Enter, StressLog::Leave, 0, CompareDefault<CRITSEC_COOKIE>> StressLogLockHolder;
#endif //!STRESS_LOG_ANALYZER

#if defined(DACCESS_COMPILE)
inline BOOL StressLog::LogOn(unsigned facility, unsigned level)
Expand All @@ -414,6 +388,29 @@ inline BOOL StressLog::LogOn(unsigned facility, unsigned level)
}
#endif

template<>
struct cdac_offsets<StressLog>
{
static const size_t facilitiesToLog = offsetof(StressLog, facilitiesToLog);
static const size_t levelToLog = offsetof(StressLog, levelToLog);
static const size_t MaxSizePerThread = offsetof(StressLog, MaxSizePerThread);
static const size_t MaxSizeTotal = offsetof(StressLog, MaxSizeTotal);
static const size_t totalChunk = offsetof(StressLog, totalChunk);
static const size_t logs = offsetof(StressLog, logs);
static const size_t tickFrequency = offsetof(StressLog, tickFrequency);
static const size_t startTimeStamp = offsetof(StressLog, startTimeStamp);
static const size_t startTime = offsetof(StressLog, startTime);
static const size_t moduleOffset = offsetof(StressLog, moduleOffset);
static constexpr uint64_t MAX_MODULES = StressLog::MAX_MODULES;

struct ModuleDesc
{
static constexpr size_t type_size = sizeof(StressLog::ModuleDesc);
static const size_t baseAddress = offsetof(StressLog::ModuleDesc, baseAddress);
static const size_t size = offsetof(StressLog::ModuleDesc, size);
};
};

/*************************************************************************************/
/* private classes */

Expand Down Expand Up @@ -481,10 +478,9 @@ struct StressMsg
timeStamp = time;
}

static const size_t maxArgCnt = 63;
static constexpr size_t maxArgCnt = 63;
static const int64_t maxOffset = (int64_t)1 << (formatOffsetLowBits + formatOffsetHighBits);
static size_t maxMsgSize ()
{ return sizeof(StressMsg) + maxArgCnt*sizeof(void*); }
static constexpr size_t maxMsgSize = sizeof(uint64_t) * 2 + maxArgCnt * sizeof(void*);
};

static_assert(sizeof(StressMsg) == sizeof(uint64_t) * 2, "StressMsg bitfields aren't aligned correctly");
Expand Down Expand Up @@ -582,9 +578,7 @@ struct StressLogChunk
// readPtr / curPtr fields. thecaller is responsible for reading/writing
// to the corresponding field
class ThreadStressLog {
#ifdef STRESS_LOG_ANALYZER
public:
#endif
template<typename T> friend struct ::cdac_offsets;
ThreadStressLog* next; // we keep a linked list of these
uint64_t threadId; // the id for the thread using this buffer
uint8_t isDead; // Is this thread dead
Expand Down Expand Up @@ -613,7 +607,7 @@ class ThreadStressLog {
#endif //STRESS_LOG_READONLY
friend class StressLog;

#if !defined(STRESS_LOG_READONLY) && !defined(STRESS_LOG_ANALYZER)
#if !defined(STRESS_LOG_READONLY)
FORCEINLINE BOOL GrowChunkList ()
{
_ASSERTE (chunkListLength >= 1);
Expand All @@ -634,10 +628,10 @@ class ThreadStressLog {

return TRUE;
}
#endif //!STRESS_LOG_READONLY && !STRESS_LOG_ANALYZER
#endif //!STRESS_LOG_READONLY

public:
#if !defined(STRESS_LOG_READONLY) && !defined(STRESS_LOG_ANALYZER)
#if !defined(STRESS_LOG_READONLY)
ThreadStressLog ()
{
chunkListHead = chunkListTail = curWriteChunk = NULL;
Expand Down Expand Up @@ -665,9 +659,9 @@ class ThreadStressLog {
chunkListLength = 1;
}

#endif //!STRESS_LOG_READONLY && !STRESS_LOG_ANALYZER
#endif //!STRESS_LOG_READONLY

#if defined(MEMORY_MAPPED_STRESSLOG) && !defined(STRESS_LOG_ANALYZER)
#if defined(MEMORY_MAPPED_STRESSLOG)
void* __cdecl operator new(size_t n, const std::nothrow_t&) noexcept;
void __cdecl operator delete (void * chunk);
#endif
Expand All @@ -679,19 +673,19 @@ class ThreadStressLog {
{
return;
}
#if !defined(STRESS_LOG_READONLY) && !defined(STRESS_LOG_ANALYZER)
#if !defined(STRESS_LOG_READONLY)
_ASSERTE (chunkListLength >= 1 && chunkListLength <= StressLog::theLog.totalChunk);
#endif //!STRESS_LOG_READONLY && !STRESS_LOG_ANALYZER
#endif //!STRESS_LOG_READONLY
StressLogChunk * chunk = chunkListHead;

do
{
StressLogChunk * tmp = chunk;
chunk = chunk->next;
delete tmp;
#if !defined(STRESS_LOG_READONLY) && !defined(STRESS_LOG_ANALYZER)
#if !defined(STRESS_LOG_READONLY)
StressLog::ChunkDeleted ();
#endif //!STRESS_LOG_READONLY && !STRESS_LOG_ANALYZER
#endif //!STRESS_LOG_READONLY
} while (chunk != chunkListHead);
}

Expand All @@ -712,7 +706,7 @@ class ThreadStressLog {
// a previous record. Update curPtr to reflect the last safe beginning of a record,
// but curPtr shouldn't wrap around, otherwise it'll break our assumptions about stress
// log
curPtr = (StressMsg*)((char*)curPtr - StressMsg::maxMsgSize());
curPtr = (StressMsg*)((char*)curPtr - StressMsg::maxMsgSize);
if (curPtr < (StressMsg*)curWriteChunk->StartPtr())
{
curPtr = (StressMsg *)curWriteChunk->StartPtr();
Expand All @@ -727,7 +721,7 @@ class ThreadStressLog {

BOOL IsValid () const
{
return chunkListHead != NULL && (!curWriteChunk || StressLog::TranslateMemoryMappedPointer(curWriteChunk)->IsValid ());
return chunkListHead != NULL && (!curWriteChunk || curWriteChunk->IsValid ());
}

#ifdef STRESS_LOG_READONLY
Expand Down Expand Up @@ -759,6 +753,18 @@ class ThreadStressLog {
#endif //STRESS_LOG_READONLY
};

template<>
struct cdac_offsets<ThreadStressLog>
{
static const size_t next = offsetof(ThreadStressLog, next);
static const size_t threadId = offsetof(ThreadStressLog, threadId);
static const size_t writeHasWrapped = offsetof(ThreadStressLog, writeHasWrapped);
static const size_t curPtr = offsetof(ThreadStressLog, curPtr);
static const size_t chunkListHead = offsetof(ThreadStressLog, chunkListHead);
static const size_t chunkListTail = offsetof(ThreadStressLog, chunkListTail);
static const size_t curWriteChunk = offsetof(ThreadStressLog, curWriteChunk);
};

#ifdef STRESS_LOG_READONLY
/*********************************************************************************/
// Called when dumping the log (by StressLog::Dump())
Expand Down Expand Up @@ -794,7 +800,7 @@ inline StressMsg* ThreadStressLog::AdvReadPastBoundary() {
}
curReadChunk = curReadChunk->next;
void** p = (void**)curReadChunk->StartPtr();
while (*p == NULL && (size_t)(p-(void**)curReadChunk->StartPtr()) < (StressMsg::maxMsgSize() / sizeof(void*)))
while (*p == NULL && (size_t)(p-(void**)curReadChunk->StartPtr()) < (StressMsg::maxMsgSize / sizeof(void*)))
{
++p;
}
Expand Down Expand Up @@ -839,7 +845,7 @@ inline StressMsg* ThreadStressLog::AdvanceWrite(int cArgs) {
// In addition it writes NULLs b/w the startPtr and curPtr
inline StressMsg* ThreadStressLog::AdvWritePastBoundary(int cArgs) {
STATIC_CONTRACT_WRAPPER;
#if !defined(STRESS_LOG_READONLY) && !defined(STRESS_LOG_ANALYZER)
#if !defined(STRESS_LOG_READONLY)
//zeroed out remaining buffer
memset (curWriteChunk->StartPtr (), 0, (BYTE *)curPtr - (BYTE *)curWriteChunk->StartPtr ());

Expand All @@ -848,7 +854,7 @@ inline StressMsg* ThreadStressLog::AdvWritePastBoundary(int cArgs) {
{
GrowChunkList ();
}
#endif //!STRESS_LOG_READONLY && !STRESS_LOG_ANALYZER
#endif //!STRESS_LOG_READONLY

curWriteChunk = curWriteChunk->prev;
#ifndef STRESS_LOG_READONLY
Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/nativeaot/Runtime/inc/stressLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ struct StressMsg

static const size_t maxArgCnt = 63;
static const int64_t maxOffset = (int64_t)1 << (formatOffsetLowBits + formatOffsetHighBits);
static size_t maxMsgSize ()
{ return sizeof(StressMsg) + maxArgCnt*sizeof(void*); }
static constexpr size_t maxMsgSize = sizeof(uint64_t) * 2 + maxArgCnt * sizeof(void*);

friend void PopulateDebugHeaders();
};
Expand Down Expand Up @@ -623,7 +622,7 @@ inline StressMsg* ThreadStressLog::AdvReadPastBoundary() {
}
curReadChunk = curReadChunk->next;
void** p = (void**)curReadChunk->StartPtr();
while (*p == NULL && (size_t)(p-(void**)curReadChunk->StartPtr ()) < (StressMsg::maxMsgSize()/sizeof(void*)))
while (*p == NULL && (size_t)(p-(void**)curReadChunk->StartPtr ()) < (StressMsg::maxMsgSize/sizeof(void*)))
{
++p;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/stressLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ inline void ThreadStressLog::Activate (Thread * /*pThread*/)
// a previous record. Update curPtr to reflect the last safe beginning of a record,
// but curPtr shouldn't wrap around, otherwise it'll break our assumptions about stress
// log
curPtr = (StressMsg*)((char*)curPtr - StressMsg::maxMsgSize());
curPtr = (StressMsg*)((char*)curPtr - StressMsg::maxMsgSize);
if (curPtr < (StressMsg*)curWriteChunk->StartPtr())
{
curPtr = (StressMsg *)curWriteChunk->StartPtr();
Expand Down
Loading
Loading