Repository navigation
Closed
Labels
arch-x64arch-x86area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
Building Loader\classloader\StaticVirtualMethods\GenericContext\GenericContextTest in NativeAOT win-x86 Debug mode yields:
ILC: D:\runtime\src\coreclr\jit\scopeinfo.cpp:1566
ILC: D:\runtime\src\coreclr\jit\scopeinfo.cpp:1566
ILC: Assertion failed 'lastBlockILEndOffset < beginOffs' in 'TestEntrypoint:Test_Ldftn_NonGenericNonGenericValuetype_GenericOverString_GenericOverString_GenericMethodOverString[System.__Canon]()' during 'Generate code' (IL size 47; hash 0xab6c92eb; MinOpts)
ILC: Assertion failed 'lastBlockILEndOffset < beginOffs' in 'TestEntrypoint:Test_Ldftn_GenericOverReferenceType_ClassAGenericValuetype_GenericOverInt32_GenericOverObject_NormalMethod[System.__Canon]()' during 'Generate code' (IL size 47; hash 0x89d04558; MinOpts)
ILC: D:\runtime\src\coreclr\jit\scopeinfo.cpp:1566
ILC: Assertion failed 'lastBlockILEndOffset < beginOffs' in 'TestEntrypoint:Test_Ldftn_GenericOverReferenceType_ClassAGenericClass_GenericOverString_GenericOverString_NormalMethod[System.__Canon]()' during 'Generate code' (IL size 47; hash 0xa314cc02; MinOpts)
Native stack trace:
[0x0] KERNELBASE!wil::details::DebugBreak+0x2 0x3ba503b388 0x7ffd9f8eb9e9
[0x1] clrjit_win_aot_x86_x64!assertAbort+0x249 0x3ba503b390 0x7ffd9fb6c5c4
[0x2] clrjit_win_aot_x86_x64!CodeGen::siOpenScopesForNonTrackedVars+0xa4 0x3ba503d4c0 0x7ffd9fb6be2b
[0x3] clrjit_win_aot_x86_x64!CodeGen::siBeginBlock+0x15b 0x3ba503d510 0x7ffd9f8a2358
[0x4] clrjit_win_aot_x86_x64!CodeGen::genCodeForBBlist+0xaf8 0x3ba503d550 0x7ffd9f8969c3
[0x5] clrjit_win_aot_x86_x64!CodeGen::genGenerateMachineCode+0x683 0x3ba503da00 0x7ffd9f88a6cc
[0x6] clrjit_win_aot_x86_x64!CodeGenPhase::DoPhase+0x2c 0x3ba503da60 0x7ffd9fb3b157
[0x7] clrjit_win_aot_x86_x64!Phase::Run+0x87 0x3ba503daa0 0x7ffd9f88a688
[0x8] clrjit_win_aot_x86_x64!DoPhase+0x58 0x3ba503db20 0x7ffd9f89627b
JIT dump for TestEntrypoint:Test_Ldftn_GenericOverTypeParameterGenericValuetype_GenericOverString_CuriouslyRecurringGeneric_GenericMethodOverTypeParameter:
GenericContextTest.txt
Metadata
Metadata
Assignees
Labels
arch-x64arch-x86area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Activity
JulieLeeMSFT commentedon Mar 12, 2024
@TIHan PTAL.
TIHan commentedon Mar 12, 2024
Will do
TIHan commentedon Mar 12, 2024
For
Loader\classloader\StaticVirtualMethods\GenericContext\GenericContextTest, assertion also occurs in x64 debug:TIHan commentedon Mar 12, 2024
@filipnavara , your JIT dump link is giving a 404 - I guess GitHub got messed up?
TIHan commentedon Mar 13, 2024
This assertion occurs even in a December 2023 commit - so it's likely been this way for a while.
TIHan commentedon Mar 13, 2024
Dump from one of the x64 assertions:
dump.txt
Edit: Ok, so GitHub is showing 404 for 'dump.txt' even when uploading new files.
filipnavara commentedon Mar 13, 2024
I suspected it's not x86 specific. Thanks for looking into it.
AndyAyersMS commentedon Mar 13, 2024
@TIHan can you give a short description of what the problem is and where in the JIT it happens?
TIHan commentedon Mar 13, 2024
For JIT debug compilations, when code-gen'ing a basic block, if there was a previous block, we expect its ending IL offset to be less than the current block's beginning IL offset. These IL offsets and blocks themselves correspond to user code.
However, the JIT can create new basic blocks on its own that don't correspond to user code, in which case the new block needs to be marked with the
BBF_INTERNALflag. BecauseBBF_INTERNALblocks do not correspond to a user code block, their beginning and ending IL offsets must remain set atBAD_IL_OFFSET, which I believe is the max value of int32.The issue here is that some blocks that are marked with
BBF_INTERNALhave their ending IL offset not set toBAD_IL_OFFSET. The code below shows how this can occur:https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/fgbasic.cpp#L4810
IL_OFFSET splitPointILOffset = fgFindBlockILOffset(newBlock); curr->bbCodeOffsEnd = max(curr->bbCodeOffs, splitPointILOffset); newBlock->bbCodeOffs = min(splitPointILOffset, newBlock->bbCodeOffsEnd);splitPointILOffsetis not guaranteed to beBAD_IL_OFFSETifnewBlockisBBF_INTERNAL. So the line:causes
bbCodeOffsto not beBAD_IL_OFFSETfor aBBF_INTERNALsincesplitPointILOffsetwould be less thanBAD_IL_OFFSET.AndyAyersMS commentedon Mar 15, 2024
Can you share the dump?
For debug code if we have statements with IL offsets, it seems like the blocks they are in should also have IL offsets.
Seems like that means that
curris alsoBBF_INTERNALand has an IL offset, or at least has statements with IL offsets.TIHan commentedon Mar 15, 2024
You should be able to get the dump, GitHub is working again it looks like.
https://github.com/dotnet/runtime/files/14580404/dump.txt
curris aBBF_INTERNALand it has statements that have IL offsets which is whyfgFindBlockILOffsetreturns a valid offset.AndyAyersMS commentedon Mar 15, 2024
I am trying to determine what the right fix looks like.
It seems like the root cause is that we are putting IL-offset carrying statements into blocks that are marked as
BBF_INTERNALand not giving those blocks proper IL offsets. I suspect the IL offsets were set "correctly" this may cause us to lose debug information that we need to preserve.So one possible fix is to stop putting IL offset carrying statements into internal blocks, by making sure the blocks are not marked as internal, and getting the offsets right.
Another possible fix is to erase the debug info (at least from the block), which more or less what you're proposing. If we go this route, I think we should examine debug emission and make sure nothing is getting lost.
Whatever direction we go in we should update the post-phase diagnostic checker so it spots these problems right away.
Can you look at the first option? Things seem ok here:
but not just after (seemingly BB19 is the troublemaker, so something in this expansion is not treating debug offsets the way it should).
TIHan commentedon Mar 15, 2024
Sure, I can look.
TIHan commentedon Mar 19, 2024
The BFF_INTERNAL blocks are initially created in the
callindirecttransformer, specifically the fat-pointer transformer. It creates new basic blocks and marks them as BFF_INTERNAL - however, they contain statements that do contain valid IL offsets. These statements are copied from another statement that have valid IL offsets. Examples: https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/indirectcalltransformer.cpp#L399https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/indirectcalltransformer.cpp#L414
@AndyAyersMS Should we unmark BFF_INTERNAL from these new blocks since they will contain statements with valid IL offsets? It won't fix the issue if we do. Still looking into what is going on with the offsets.
AndyAyersMS commentedon Mar 19, 2024
If we are required to duplicate user statements (looks like we are) then some options are:
Whichever way we go we should clarify the behavior of the jit with respect to internal blocks. For instance, we might consider to enforcing the invariant that internal blocks and their statements do not have IL offsets, or (perhaps simpler) that internal blocks do not have IL offsets and we ignore any IL offsets for statements inside (for purposes of debug emission).
TIHan commentedon Mar 20, 2024
AFAIK, the debug format should allow to map multiple ranges, so I think it's fine that we copy user statements around.
I did a lot of investigation into this issue. I believe the problem really is how we are updating the IL offsets in
fgSplitBlockAfterStatement.I tweaked the original solution in #99662 where instead of checking for BBF_INTERNAL, it will check if the original block's ending offset was BAD_IL_OFFSET. If it was, then we do not update the IL offsets.
AndyAyersMS commentedon Mar 20, 2024
Does this mean we may lose a bit of debugging fidelity? Since this is for scopes then impact might be that at certain breakpoints or stepping, locals that should be visible suddenly are not?
Should we add a diagnostic check that no BBF_INTERNAL block has valid IL offsets?
TIHan commentedon Mar 20, 2024
If it is common to have blocks that have its ending offset set to BAD_IL_OFFSET and contain statements that have valid IL offsets, then maybe.
Another solution is to set the block's ending offset to BAD_IL_OFFSET only in expanding static init call. This would limit any risk to losing fidelity.
TIHan commentedon Mar 20, 2024
I made a compromise. I am now updating the IL offsets in
fgExpandStaticInitForCallwhich also solves the issue.Before:
After:
We actually gain some IL offsets here for few a few blocks. The only block that appears to lose fidelity is BB07 - which its internal statement gets modified in
fgExpandStaticInitForCallanyway - so I don't know what the implications are of that for debug fidelity.Before
fgExpandStaticInitForCall:After
fgExpandStaticInitForCall(BB02 is split and BB07 is created):