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

JIT: Fix emitter::emitSplit to not create zero-sized method fragment #107568

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Changes from 1 commit
Commits
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
17 changes: 15 additions & 2 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3071,8 +3071,21 @@ void emitter::emitSplit(emitLocation* startLoc,

} // end for loop

splitIfNecessary();
assert(curSize < UW_MAX_FRAGMENT_SIZE_BYTES);
if ((igLastCandidate != nullptr) && (curSize == candidateSize))
{
// TODO: This scenario may be possible (but very unlikely) when using the default fragment size.
// Fixing this would likely require padding out the last fragment to not be zero-sized, and doing the split.
// For now, assume this only occurs under stress modes, or when using DOTNET_JitSplitFunctionSize.
assert(maxSplitSize != UW_MAX_FRAGMENT_SIZE_BYTES);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is quite right. Yes, it is unlikely. But we're talking about a single empty fragment at the end. If there was a non-empty fragment, then curSize != candidateSize. So it seems like the fix works for any split size, including the default, and doesn't require this assert or TODO. (It might require other commenting/documentation, but that's a separate question.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we're talking about a single empty fragment at the end.

Yeah, on second thought, I think you're right. If we have a 512KB-sized IG, followed by an empty IG that happens to be zero-sized, then the last fragment should be exactly 512KB in size, which shouldn't break any unwind data invariants. I'll remove the TODO.

JITDUMP("emitSplit: can't split at last candidate IG%02u because it would create a zero-sized fragment\n",
igLastCandidate->igNum);
}
else
{
splitIfNecessary();
}

assert((curSize > 0) && (curSize < UW_MAX_FRAGMENT_SIZE_BYTES));
}

/*****************************************************************************
Expand Down
Loading