-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: support OSR for synchronized methods #61712
Conversation
OSR methods share the "monitor acquired" flag with the original method. The monitor acquired flag is s bit of non-IL live state that must be tecorded in the patchpoint. Also, OSR methods only need to release the monitor as acquisition can only happen in the original method.
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsOSR methods share the "monitor acquired" flag with the original method. Also, OSR methods only need to release the monitor as acquisition can
|
@dotnet/jit-contrib PTAL |
|
||
for (int i = 0; i < 100_000; i++) | ||
{ | ||
s = z.F(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to verify Monitor.IsEntered(this)
inside the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will add this.
if (result == 100) { | ||
Console.WriteLine("SUCCESS"); | ||
} | ||
else { | ||
Console.WriteLine("FAILURE"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
if (result == 100) { | |
Console.WriteLine("SUCCESS"); | |
} | |
else { | |
Console.WriteLine("FAILURE"); | |
} | |
if (result == 100) | |
{ | |
Console.WriteLine("SUCCESS"); | |
} | |
else | |
{ | |
Console.WriteLine("FAILURE"); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise.
/azp run runtime-jit-experimental |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to ask how this works on x86, but I guess OSR isn't enabled for x86.
BasicBlock* tryBegBB = fgNewBBafter(BBJ_NONE, fgFirstBB, false); | ||
BasicBlock* tryNextBB = tryBegBB->bbNext; | ||
BasicBlock* tryLastBB = fgLastBB; | ||
BasicBlock* const tryBegBB = fgSplitBlockAtEnd(fgFirstBB); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the switch from fgNewBBafter
to fgSplitBlockAtEnd
required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in OSR methods fgFirstBB
may not be BBJ_NONE
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even after calling fgEnsureFirstBBisScratch()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because fgEnsureFirstBBisScratch
will just return if the first bb is already scratch.
For OSR we've already called this and messed with the resulting flow. See fgFixEntryFlowForOSR
.
Right, not yet enabled anywhere but x64. Arm64 support is next, then maybe I'll look at what we'd need to do for x86. |
Seeing a few unexpected OSR stress issues. Will need to investigate. |
Bug was that if you managed to remove all the EH table entries we'd null out the EH table. Then when we'd go to add a new entry for the synchronous try/fault we don't realize the table is gone and the jit goes boom. We could probably hit this with the right test case even without OSR (only dead EH in a synchronous method). |
/azp run runtime-jit-experimental |
Azure Pipelines successfully started running 1 pipeline(s). |
Back down to the "expected" set of failures, with one exception in osr + pc (likely unrelated). I'll track this one separately.
|
@BruceForstall want to take one last look? I had to make a change in jiteh.cpp to fix this issue. |
Looks like we only ever removed EH clauses after the code to add sync method EH, so it wouldn't hit before. The jiteh.cpp change makes sense: there's no reason to remove the table if |
OSR methods share the "monitor acquired" flag with the original method.
The monitor acquired flag is s bit of non-IL live state that must be
tecorded in the patchpoint.
Also, OSR methods only need to release the monitor as acquisition can
only happen in the original method.