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: Ensure EH clauses with same try region are reported contiguously to the VM #104531

Merged
merged 4 commits into from
Jul 8, 2024

Conversation

amanasifkhalid
Copy link
Member

@amanasifkhalid amanasifkhalid commented Jul 7, 2024

The CORINFO_EH_CLAUSE_SAMETRY flag indicates to the VM that a given EH clause maps to the same try region as the previous EH clause. However, the JIT's internal invariants may result in an EH table ordering such that clauses mapped to the same try region aren't contiguous, thus breaking the functionality of this flag. To address this without changing the JIT's EH invariants, ensure the JIT reports clauses with the same try region contiguously to the VM, and sets CORINFO_EH_CLAUSE_SAMETRY accordingly.

Fixes #101772.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 7, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@amanasifkhalid amanasifkhalid changed the title JIT: Report EH clauses to runtime in order of increasing try region index JIT: Ensure EH clauses with same try region are reported contiguously to the VM Jul 8, 2024
@amanasifkhalid amanasifkhalid marked this pull request as ready for review July 8, 2024 00:47
@amanasifkhalid
Copy link
Member Author

cc @janvorli @jkotas for visibility, @AndyAyersMS PTAL. Thanks!

This change has a bunch of zero-size diffs from changes in EH clause ordering -- looks like the JIT's internal ordering was breaking up clauses with the same try region with some frequency. TP cost is pretty minimal.

Are there any outerloop pipelines worth running? From my block layout work, I don't recall JitStress being all that useful for stressing EH semantics...

@jkotas
Copy link
Member

jkotas commented Jul 8, 2024

/azp run runtime-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@amanasifkhalid
Copy link
Member Author

The only failing outerloop test (report) is JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests, which isn't a new failure: #104337.

Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
}

return leftTryIndex < rightTryIndex;
});
Copy link
Member

Choose a reason for hiding this comment

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

We don't use any of the CORINFO_EH_CLAUSE data when sorting, so seems like it would be more efficient to just sort a table of EHblkDsc* and then report each clause like we did before?

Copy link
Member Author

@amanasifkhalid amanasifkhalid Jul 8, 2024

Choose a reason for hiding this comment

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

I initially tried doing this, and then iterating over the sorted table to build the clauses in the above loop, but changing the order in which we call Compiler::ehCodeOffset hit JIT asserts (in particular, assert(cookie != nullptr) in Compiler::ehEmitCookie) -- I think emitter::emitCodeOffset has some hard dependency on us calling ehCodeOffset in the order of the JIT's EH table. I can look into cleaning this up in a follow-up if you'd like, though the TP cost of the current approach doesn't seem too bad.

Copy link
Member

Choose a reason for hiding this comment

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

Thats fine. EH is relatively rare and lots of EH clauses even more so.

I don't see why there'd be such an order dependence in the emitter, so it is worth digging into more deeply.

// We have two clauses mapped to the same try region.
// Make sure we report the clause with the smaller index first.
const auto leftIndex = left.HBtab - this->compiler->compHndBBtab;
const auto rightIndex = right.HBtab - this->compiler->compHndBBtab;
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 we have used auto for anything but function types. Use ptrdiff_t?

@amanasifkhalid
Copy link
Member Author

SPMI replay failure is #104570.

@amanasifkhalid amanasifkhalid merged commit f99194c into dotnet:main Jul 8, 2024
99 of 107 checks passed
@amanasifkhalid amanasifkhalid deleted the fix-eh branch July 8, 2024 20:00
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change in exception handling in 9.0
4 participants