strange behavior with stack overflow on windows

Roland Westrelin roland.westrelin at
Thu Jun 6 03:59:16 PDT 2013

Hi Andreas,

> IMO, the problem here is a conflict between the hotspot and stack overflow detection and the Windows internal SOF detection:
> Windows only uses reserved but only partially committed memory for its stacks. In order to detect when to commit more stack, it installs  a one-shot guard page (btw the same type of guard page that is used for the hotspot yellow and red zone) right at the edge of the currently commited stack zone. When a thread accesses this guard page an exception is thrown which Windows catches internally, commits more stack and re-establishes the one-shot guard page at the new edge of the commited zone. When Windows detects such an exception inside the _last 4 pages_ of a stack (I couldn't find any documentation for that on MSDN, I found this value from manually testing on several Windows machines with 4k stack pages) it throws a STACK_OVERFLOW_EXCEPTION.
> This implies:
> - If you only have 3 guard pages, a stack overflow will actually occur one page _ahead_ of the yellow zone the first time.
> - If you have more than 4 guard pages they will have no use because Windows will interpret them as it's normal guard pages used for stack committing and will not throw a STACK_OVERFLOW_EXCEPTION until again the stack has reached the last 4 pages of the stack.
> Does your problem also occur if you have 4 guard pages? Also, we'll have to test how Windows behaves for pages > 4k...

Thanks for your comments and insight.
It doesn't reproduce with StackYellowPages=3.


More information about the hotspot-runtime-dev mailing list