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

SPMI: Capture EE API exceptions in getNewHelper, and simplify the API shape a bit #89852

Merged
merged 4 commits into from
Aug 6, 2023

Conversation

jakobbotsch
Copy link
Member

We have various tests where getNewHelper throws an EE exception, so
capture these and rethrow them as part of SPMI.

It would be nice with a more general approach to this (conceptually all
EE APIs could throw exceptions), but this at least handles it for our
own tests, and these situations are expected to be rare.

Contributes to #47540 and #47546.

Also clean up the API shape of getNewHelper slightly, since this requires
a JIT-EE GUID change anyway; the only used member of the token is the class,
so pass a class handle instead.

We have various tests where getNewHelper throws an EE exception, so
capture these and rethrow them as part of SPMI.

It would be nice with a more general approach to this (conceptually all
EE APIs could throw exceptions), but this at least handles it for our
own libraries.

Contributes to dotnet#47540 and dotnet#47546.
@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 Aug 2, 2023
@ghost ghost assigned jakobbotsch Aug 2, 2023
@ghost
Copy link

ghost commented Aug 2, 2023

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

Issue Details

We have various tests where getNewHelper throws an EE exception, so
capture these and rethrow them as part of SPMI.

It would be nice with a more general approach to this (conceptually all
EE APIs could throw exceptions), but this at least handles it for our
own tests, and these situations are expected to be rare.

Contributes to #47540 and #47546.

Also clean up the API shape of getNewHelper slightly, since this requires
a JIT-EE GUID change anyway; the only used member of the token is the class,
so pass a class handle instead.

Author: jakobbotsch
Assignees: jakobbotsch
Labels:

area-CodeGen-coreclr

Milestone: -

@@ -5772,7 +5772,7 @@ bool __stdcall TrackAllocationsEnabled()
}

/***********************************************************************/
CorInfoHelpFunc CEEInfo::getNewHelper(CORINFO_RESOLVED_TOKEN * pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, bool * pHasSideEffects)
CorInfoHelpFunc CEEInfo::getNewHelper(CORINFO_CLASS_HANDLE classHandle, CORINFO_METHOD_HANDLE callerHandle, bool* pHasSideEffects)
Copy link
Member

Choose a reason for hiding this comment

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

Can callerHandle be deleted? It looks unused.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used for diagnostics by crossgen2 – I initially actually was deleting it, until I ran into that use.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can replace the use by methodBeingCompiled -- it will have slightly different behavior when inlining, but maybe that's ok?

Copy link
Member Author

@jakobbotsch jakobbotsch Aug 2, 2023

Choose a reason for hiding this comment

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

Actually it shouldn't have any visible behavior difference since if crossgen2 throws the exception during inlining it will just result in the inlining attempt being aborted, and the exception won't be surfaced to the user. So let me make this change.

Copy link
Member

Choose a reason for hiding this comment

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

We can replace the use by methodBeingCompiled -- it will have slightly different behavior when inlining, but maybe that's ok?

I do not think it will have different observable behavior. We catch and ignore exceptions during inlining, so the only place where this error can show up is when we fail during compilation of the top level method. When we fail during compilation of the top-level method, we are going to print its name in front of the error message. It is not necessary to duplicate the name of the method that failed to compile in the error message.

@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @BruceForstall

I'll wait with merging until the weekend.

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

It would be nice with a more general approach to this (conceptually all
EE APIs could throw exceptions), but this at least handles it for our
own tests, and these situations are expected to be rare.

Seems like we should stop throwing exceptions across the JIT-EE API and instead use error codes. There are very few cases where we see exceptions today.

Comment on lines +2497 to +2498
CORINFO_CLASS_HANDLE classHandle,
bool* pHasSideEffects
Copy link
Member

Choose a reason for hiding this comment

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

Can you update the above documentation comment? It refers to "newCls", which doesn't exist (and didn't before, either), and doesn't describe pHasSideEffects.

@jakobbotsch
Copy link
Member Author

Seems like we should stop throwing exceptions across the JIT-EE API and instead use error codes. There are very few cases where we see exceptions today.

That sounds hard since these exceptions are meant to be surfaced to the user and not handled by the JIT, so the JIT would need to throw the proper exception itself based on the error returned by the EE API (with the same amount of details, presumably). Plus it would have additional throughput cost on calls to many hot JIT-EE APIs, like resolveToken.

IMO this is just an SPMI issue -- if we were auto generating (the majority of) the recording/replay layer of SPMI then it would be much easier to make a broad change like this. Our representation of exceptions in the collections is also unfortunate, requiring changes in the "value" struct that adds size overhead in the normal case and requires a JIT-EE GUID update in PRs like this one. An alternative to make it more pay-for-play would be to have separate packet IDs (or tag it in the upper bit) for the exceptions, and check both tables before reporting "missing".

@jakobbotsch jakobbotsch merged commit 242fc7d into dotnet:main Aug 6, 2023
@jakobbotsch jakobbotsch deleted the spmi-immediate-replay-fixes-3 branch August 6, 2023 21:09
@ghost ghost locked as resolved and limited conversation to collaborators Sep 6, 2023
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.

3 participants