A solution to detect the footprint of Java thread stack
David Holmes
david.holmes at oracle.com
Tue Dec 15 05:24:54 UTC 2020
Hi Yang Yi,
On 14/12/2020 3:03 pm, 杨易(青风) wrote:
> Hi all,
> We occasionally get stack overflow errors if the application has too many deep callings. The usual solution is to increase -Xss, but there is no guiding opinion telling us in advance that the thread stack space is not enough. This patch attempts to address this issue. It introduces a new stack zone(warning_zone) for Hotspot VM, which can be used to detect whether the footprint ratio of the thread stack has reached the watermark set by the user.
>
> The current stack layout is as follows:
> stack_base stack_end
> ---------------------------------------------------------------------------------------------------------------------------
> | | shadow zone | warning zone(added) | reserved zone | yellow zone | red zone |
> ---------------------------------------------------------------------------------------------------------------------------
> ^rsp |<-StackWarningRatio % of available stack->
>
> Users can set the option -XX:StackWarningRatio=0 to turn off this feature(which is also the default value) and there will be no warning zone, the stack layout is the same as usual.
> If the user sets -XX:StackWarningRatio to 50, the VM will protect 50% of the available stack space(let all = available+reserved+yellow+red;) as stack warning zone. When the footprint of available stack space reaches 50%, that is, when the application accesses the stack warning zone, the sigsegv signal will be triggered, and then the signal handler will warn this access in some ways(e.g. send the JFR event, logging) and resume current execution. As a prototype, this feature is only implemented on x86_posix, it can be implemented on more platforms as needed.
>
> Could anyone give some suggestions? If you think this is a useful feature, I will file an issue and support it on all platforms. Looking forward to your comments.
How do you actually envisage people using this? This seems more of a
tuning option, but you can tune just as readily by adjusting -Xss in the
same manner you would set the warning ratio. I.e. you'd like to shrink
your stack usage but are not sure how small you can make it safely so
you can either just reduce -Xss and see if it works, or you can set the
warning ratio to give the same effective -Xss and see if you get a warning.
The flag would need to be diagnostic rather than full product.
Cheers,
David
> Patch: https://github.com/kelthuzadx/jdk/commit/a145b2ebb4ac568e3bb090cbe3e7f091e1dc69ea
> Diff: https://github.com/kelthuzadx/jdk/compare/37dc675..a145b2e
>
> Best,
> Yang Yi
>
More information about the hotspot-dev
mailing list