From 738b8c71dbb6928bfcf8880ddbe64fc801d0322b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 25 Apr 2024 14:08:10 +0200 Subject: [PATCH 1/7] Avoid overwriting frame context in JIT_Patchpoint Hopefully will help with diagnosing #101060 once we get a new dump. --- src/coreclr/vm/jithelpers.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 7400708001589f..35d92c8791ba86 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -5144,7 +5144,7 @@ void JIT_Patchpoint(int* counter, int ilOffset) const int counterBump = g_pConfig->OSR_CounterBump(); *counter = counterBump; -#if _DEBUG +#ifdef _DEBUG const int ppId = ppInfo->m_patchpointId; #endif @@ -5316,9 +5316,18 @@ void JIT_Patchpoint(int* counter, int ilOffset) InitializeContext(pBuffer, contextFlags, &pFrameContext, &contextSize); _ASSERTE(success); #else // TARGET_WINDOWS && TARGET_AMD64 + +#ifdef _DEBUG + // Temporary change to avoid the frame context being overwritten after + // a crash after transition + pFrameContext = (CONTEXT*)_alloca(sizeof(CONTEXT) + 0x40000); +#else CONTEXT frameContext; - frameContext.ContextFlags = CONTEXT_FULL; pFrameContext = &frameContext; +#endif + + pFrameContext->ContextFlags = CONTEXT_FULL; + #endif // TARGET_WINDOWS && TARGET_AMD64 // Find context for the original method From 8032440b850965ec66e862ace60ce7dc67c0a488 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 25 Apr 2024 16:26:52 +0200 Subject: [PATCH 2/7] Just store it in a static --- src/coreclr/vm/jithelpers.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 35d92c8791ba86..9ea4da5c59cd03 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -5317,15 +5317,8 @@ void JIT_Patchpoint(int* counter, int ilOffset) _ASSERTE(success); #else // TARGET_WINDOWS && TARGET_AMD64 -#ifdef _DEBUG - // Temporary change to avoid the frame context being overwritten after - // a crash after transition - pFrameContext = (CONTEXT*)_alloca(sizeof(CONTEXT) + 0x40000); -#else CONTEXT frameContext; pFrameContext = &frameContext; -#endif - pFrameContext->ContextFlags = CONTEXT_FULL; #endif // TARGET_WINDOWS && TARGET_AMD64 @@ -5398,6 +5391,12 @@ void JIT_Patchpoint(int* counter, int ilOffset) // Install new entry point as IP SetIP(pFrameContext, osrMethodCode); +#ifdef _DEBUG + // Keep this context around to aid in debugging OSR transitions problems + static CONTEXT s_lastOSRTransitionContext; + s_lastOSRTransitionContext = *pFrameContext; +#endif + // Restore last error (since call below does not return) // END_PRESERVE_LAST_ERROR; ::SetLastError(dwLastError); From d9b0ab1e6118d60c0b2c601213310a6ecc07c0b0 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 25 Apr 2024 16:27:27 +0200 Subject: [PATCH 3/7] Revert unnecessary changes --- src/coreclr/vm/jithelpers.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 9ea4da5c59cd03..407bef8e2bc2c5 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -5316,10 +5316,9 @@ void JIT_Patchpoint(int* counter, int ilOffset) InitializeContext(pBuffer, contextFlags, &pFrameContext, &contextSize); _ASSERTE(success); #else // TARGET_WINDOWS && TARGET_AMD64 - CONTEXT frameContext; - pFrameContext = &frameContext; pFrameContext->ContextFlags = CONTEXT_FULL; + pFrameContext = &frameContext; #endif // TARGET_WINDOWS && TARGET_AMD64 From 54f64c7dcf4167594039b0659b0afdfafd6444b8 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 25 Apr 2024 16:27:54 +0200 Subject: [PATCH 4/7] Nit --- src/coreclr/vm/jithelpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 407bef8e2bc2c5..3153cc1dce56ba 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -5317,7 +5317,7 @@ void JIT_Patchpoint(int* counter, int ilOffset) _ASSERTE(success); #else // TARGET_WINDOWS && TARGET_AMD64 CONTEXT frameContext; - pFrameContext->ContextFlags = CONTEXT_FULL; + frameContext.ContextFlags = CONTEXT_FULL; pFrameContext = &frameContext; #endif // TARGET_WINDOWS && TARGET_AMD64 From cb544b4be58a3e45ac5e1c7fd0420b483b5b27c0 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 25 Apr 2024 16:28:07 +0200 Subject: [PATCH 5/7] Nit 2 --- src/coreclr/vm/jithelpers.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 3153cc1dce56ba..64b411d7e0e022 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -5319,7 +5319,6 @@ void JIT_Patchpoint(int* counter, int ilOffset) CONTEXT frameContext; frameContext.ContextFlags = CONTEXT_FULL; pFrameContext = &frameContext; - #endif // TARGET_WINDOWS && TARGET_AMD64 // Find context for the original method From f6865dd0ddc9812193fcc4af0010aa6b53e2f811 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 25 Apr 2024 16:46:43 +0200 Subject: [PATCH 6/7] Fix a couple more ifdef DEBUG --- src/coreclr/vm/jithelpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 64b411d7e0e022..8bf4f1dfcab94e 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -5431,7 +5431,7 @@ HCIMPL1(VOID, JIT_PartialCompilationPatchpoint, int ilOffset) // Patchpoint identity is the helper return address PCODE ip = (PCODE)_ReturnAddress(); -#if _DEBUG +#ifdef _DEBUG // Friendly ID number int ppId = 0; #endif @@ -5445,7 +5445,7 @@ HCIMPL1(VOID, JIT_PartialCompilationPatchpoint, int ilOffset) OnStackReplacementManager* manager = allocator->GetOnStackReplacementManager(); ppInfo = manager->GetPerPatchpointInfo(ip); -#if _DEBUG +#ifdef _DEBUG ppId = ppInfo->m_patchpointId; #endif From a857a6b65bc1cf584bb78cbd597efbe7e68e9f65 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 25 Apr 2024 16:47:12 +0200 Subject: [PATCH 7/7] Fix comment --- src/coreclr/vm/jithelpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 8bf4f1dfcab94e..98d6780258a6c6 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -5390,7 +5390,7 @@ void JIT_Patchpoint(int* counter, int ilOffset) SetIP(pFrameContext, osrMethodCode); #ifdef _DEBUG - // Keep this context around to aid in debugging OSR transitions problems + // Keep this context around to aid in debugging OSR transition problems static CONTEXT s_lastOSRTransitionContext; s_lastOSRTransitionContext = *pFrameContext; #endif