-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Implement stack probing using helpers #26807
Conversation
…PROBE in src/inc/readytorun.h src/inc/readytorunhelpers.h
/azp run coreclr-outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
@dotnet/jit-contrib @janvorli PTAL |
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, thank you!
@BruceForstall These are stack traces when StackOverflow happens in a funclet: win-x64
linux-x64
|
EH backtraces look great! |
I know you've got test for this. Would it be worthwhile adding this to the repo, even if it isn't built and run as part of the test tree? (I understand your test is somewhat manual in nature.) |
@BruceForstall Sure, I will add the test and T4 template that generates the tests |
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
end | ||
PAGE_SIZE equ 1000h | ||
|
||
LEAF_ENTRY JIT_StackProbe, _TEXT |
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'd like to see a line or two of comments in these asm helpers describing the purpose and function of the helper (what it does), in addition to the register "on entry" / "on exit" documentation (which is super useful).
It would also be useful to indicate what all the requirements are around each helper (as the requirements differ per platform). E.g., on Linux you can't probe beyond ESP/RSP.
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.
@BruceForstall I believe I have addressed all your suggestions - please take a look and let me know if I need to clarify anything else
src/vm/amd64/JitHelpers_Fast.asm
Outdated
|
||
ProbeLoop: | ||
test dword ptr [rax], eax | ||
sub rax, PAGE_SIZE |
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.
The probing math is a little tricky, to ensure exactly the right number of pages are probed. I would suggest a couple comments, e.g.:
or rax, (PAGE_SIZE - 1) ; rax points to the **highest address** on the first unprobed page
; This is done to make the loop end condition simpler.
...
sub rax, PAGE_SIZE ; rax points to the highest address of the next page to probe
...
cmp rax, r11 ; if rax >= r11, then we need to probe the page pointed to by rax.
@@ -955,5 +955,29 @@ endif ; _DEBUG | |||
|
|||
NESTED_END TailCallHelperStub, _TEXT | |||
|
|||
end | |||
PAGE_SIZE equ 1000h |
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.
An interesting side-effect here is that the page size (that we probe) is hard-coded to 0x1000, whereas in PAL builds, the page size is currently dynamic. For >4K pages, we might over-probe. But I suppose that is ok -- better perhaps than burning a register to pass in the page size, or creating extra page size specific helpers.
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 though about several options here:
- Have several versions of the helpers (e.g. JIT_StackProbe_0x1000 and JIT_StackProbe_0x10000) on platforms that can have different page sizes (e.g. arm64) and do selection when emitting a call to the helper from JIT.
- Burn a register and pass a page size from the JIT side (which feels weird to me since JIT asks EE for a page size). It's also going to be tough for find a spare register on x86.
- Use a stack for passing parameters and basically do the same as in 2).
- Hard-code the page size as I did
I chose 4 and as a contingency plan if there will be a strong requirement for using "true" page size we can add a logic that will patch the helper during the process startup and adjust the page size.
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.
A couple nits, but otherwise looks good.
Follow up to dotnet#26807.
Fixes #21061
This adds implementation of stack probing via helpers (similar to VC++
_chkstk()
function) on win-x86, win-x64, linux-x64 and linux-x86.The following are the stack traces collected on different OS and under different debuggers:
linux-x86 gdb
linux-x64 lldb
linux-x64 gdb - can not unwind the stack beyond
CallDescrWorkerInternal
win-x86 Visual Studio
win-x86 WinDbg
win-x64 Visual Studio
win-x64 WinDbg