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

Fix GC overreporting with generics context + GS cookie #50544

Conversation

BruceForstall
Copy link
Member

@BruceForstall BruceForstall commented Apr 1, 2021

This is a case of a generics context in this where we need to keep
this alive (but aren't required to by the VM) with a GS cookie check
(due to "JitStress: STRESS_UNSAFE_BUFFER_CHECKS"), and maybe other
JitStress modes, where genEmitGSCookieCheck decides to use rcx
to load the cookie, even though it is alive. this is also mostly
in a register, but it reported live as a stack slot. When the GS
cookie label gets created, the "codegen" gc info hasn't been updated
with the killed register, so the emitter label gets the wrong GC info
and brings rcx back alive just for the nop. GC cookie checks kind
of do their own register allocation since they're part of the epilogs.

The GS cookie code checks for keep alive using "lvRegister", but that
isn't set, since the cookie is mostly alive in a stack slock, not
always in a register. Use lvIsInReg() instead, so GS cookie check
will use RDX to load the cookie instead.

No SuperPMI asm diffs.

Fixes #50404

This is a case of a generics context in `this` where we need to keep
`this` alive (but aren't required to by the VM) with a GS cookie check
(due to "JitStress: STRESS_UNSAFE_BUFFER_CHECKS"), and maybe other
JitStress modes, where `genEmitGSCookieCheck` decides to use `rcx`
to load the cookie, even though it is alive. `this` is also mostly
in a register, but it reported live as a stack slot. When the GS
cookie label gets created, the "codegen" gc info hasn�t been updated
with the killed register, so the emitter label gets the wrong GC info
and brings rcx back alive just for the `nop`. GC cookie checks kind
of do their own register allocation since they�re part of the epilogs.

The GS cookie code checks for keep alive using "lvRegister", but that
isn't set, since the cookie is mostly alive in a stack slock, not
always in a register. Use `lvIsInReg()` instead, so GS cookie check
will use RDX to load the cookie instead.

Fixes dotnet#50404
@BruceForstall
Copy link
Member Author

@AndyAyersMS @dotnet/jit-contrib PTAL
cc @AaronRobinsonMSFT

@AaronRobinsonMSFT
Copy link
Member

@BruceForstall Does this warrant a Pri1 test?

@BruceForstall
Copy link
Member Author

crossgen2smoke failures are #50539

No interop failures in gcstress-extra

@BruceForstall Does this warrant a Pri1 test?

Well, it already is a Pri1 test, just run in stress modes. We generally don't like to have gcstress tests in normal Pri-1 runs. What we really need is to more aggressively keep our stress modes (especially gcstress) clean.

@BruceForstall BruceForstall merged commit 60d169b into dotnet:main Apr 1, 2021
@BruceForstall BruceForstall deleted the PotentialFixGSCookieKeepAliveGCIssue branch April 1, 2021 16:36
@ghost ghost locked as resolved and limited conversation to collaborators May 1, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants