RFR: 8072070: Improve interpreter stack banging

Aleksey Shipilev shade at openjdk.java.net
Sun Feb 6 07:28:08 UTC 2022


On Sat, 5 Feb 2022 09:18:17 GMT, Xin Liu <xliu at openjdk.org> wrote:

>> src/hotspot/share/runtime/stackOverflow.hpp line 166:
>> 
>>> 164:   //     into adjacent thread stack, or even into other readable memory. This would potentially
>>> 165:   //     pass the check by accident.
>>> 166:   //  c) Allow for incremental stack growth by handling traps from not yet committed thread
>> 
>> I failed to understand why we have to do "incremental stack growth" here.  Why can't use touch the last page? 
>> 
>> __ bang_stack_with_offset(n_shadow_pages*page_size);
>> 
>> 
>> The entire shadow zone is mapped. Touching it causes commit, page faults or SEGV. First 2 events are transparent for the userspace process.
>> 
>> Hotspot will trap into the signal handler if `bang_stack_shadow_pages` does cross shadow_zone_safe_limit().  `rsp + n_shadow_pages * page_size` falls into 2 possibilities: 
>> 1. red zone:  the program is about to die anyway. 
>> 2. yellow reserved zones, both are recoverable.
>> 
>> I feel it's not necessary to touch pages from 1 to n_shadow_pages-1. The side effect is same as touching the last page directly.
>> 
>> ps: I tried this [idea](https://github.com/navyxliu/jdk/runs/5075962312?check_suite_focus=true). 2 failures are found on Windows. I guess the premise that the shadow zone is mapped is false on Windows. 
>> 
>> compiler/interpreter/cr7116216/StackOverflow.java 
>> compiler/uncommontrap/UncommonTrapStackBang.java
>
> I read this blogpost and I need to take back my comment. 
> https://pangin.pro/posts/stack-overflow-handling
> 
> now I think interpreter has to do linear probing to make sure HotSpot executes Java programs correctly. reserve_zone has special meaning.  Further, if rsp is very close to the shadow_zone_safe_limit(), so-called last page may surpass red zone.

Yes, that's exactly what point "(c)" is about.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7247


More information about the hotspot-dev mailing list