On Mon, 16 Nov 2026 01:21:26 GMT, Ashay Rane <[email protected]> wrote:
>> This patch rewrites the code in the Windows port of HotSpot for detecting, >> handling, and reporting stack overflows. This patch is motivated by >> documented >> failures in JDK-8152598, JDK-8156538, JDK-8157521, JDK-8157924, JDK-8335362, >> and >> in JDK-8067946. >> >> The key result of this patch is that in addition to preventing the crashes >> that >> can be reproduced using the information in the above JBS issues, HotSpot on >> Windows now supports far-access stack bangs in compiled code while continuing >> to leverage Windows' incremental stack growth based on guard pages, ensuring >> that we don't sacrifice performance that would have been lost to page-by-page >> stack bangs. The Red and Yellow page counts now change the actual page >> permissions and HotSpot Guard Zone size, thus impacting the page that >> triggers >> the stack overflow error after stack banging. This patch also makes >> HotSpot's >> semantics for stack overflows for native and VM threads on Windows to match >> with >> those for Linux and macOS, in turn paving the way for supporting Reserved >> Stack >> pages on Windows. >> >> This is a non-trivial change, so I have documented the key ideas >> [here](https://cr.openjdk.org/~arane/windows-stack). The >> commits in this patch are organized (so far) to match the section headings in >> the document: >> >> - ed824007: [Section >> 4.1](https://cr.openjdk.org/~arane/windows-stack#growing-the-stack-on-demand) >> - f765e79d: [Section >> 4.2](https://cr.openjdk.org/~arane/windows-stack#matching-hotspots-guard-zone-with-windows-stack-guarantee) >> - 9d694f5c: [Section >> 4.3](https://cr.openjdk.org/~arane/windows-stack#handling-windows-stack-overflow-exceptions) >> - edf58c4f: [Section >> 4.4](https://cr.openjdk.org/~arane/windows-stack#handling-subsequent-stack-overflows) >> - ff9b65f6: [Section >> 4.5.1](https://cr.openjdk.org/~arane/windows-stack#miscellaneous-supporting-changes) >> - b3e146e9: [Section >> 4.5.2](https://cr.openjdk.org/~arane/windows-stack#miscellaneous-supporting-changes) >> - 8189a507: [Section >> 4.6](https://cr.openjdk.org/~arane/windows-stack#validation) >> >> I've validated this patch by running through all tier 1, 2, and 3 JDK, >> HotSpot, >> and LangTools tests on Windows/x64 and Windows/ARM64 in FastDebug config. >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Ashay Rane has updated the pull request with a new target base due to a merge > or a rebase. The pull request now contains 20 commits: > > - Merge branch 'master' into JDK-8067946-setthreadstackguarantee > - Merge branch 'master' into JDK-8067946-setthreadstackguarantee > - Bringing back the change to `DEFAULT_STACK_SHADOW_PAGES` > > This makes Windows use the same number of stack shadow pages by default > as other OSes. > - Merge branch 'master' into JDK-8067946-setthreadstackguarantee > - [Section 4.6] Add supporting tests > > - TestWindowsStackOverflow.java tests both recoverable and unrecoverable > overflows. > > - In particular, since recoverable overflow handling has two entry > points (first overflow using EXCEPTION_STACK_OVERFLOW and subsequent > overflows using EXCEPTION_ACCESS_VIOLATION), this test induces > multiple recoverable stack overflows. > > - The unrecoverable overflow test triggers a separate JVM execution that > executes native code that bangs into the red zone. The triggering JVM > then checks the return code and the output message. > > - TestWindowsStackPages.java makes the older TestWindowsStackYellowPages > test more broad, by checking the default and configurable values for > both Red and Yellow pages. > - [Section 4.5.2] Match default stack size across OSes on AArch64 > > Both Linux and macOS on AArch64 use a 2MB stack. Without this patch, > the SOEDeeplyNestedBlockTest.java test fails on Windows/ARM64. > - [Section 4.5.1] Include the allocated frame in the stack bang > - [Section 4.4] Handle Subsequent Stack Overflows > > Update handler for EXCEPTION_ACCESS_VIOLATION to report fatal versus > recoverable overflow errors depending on red zone or yellow zone memory > access > - [Section 4.3] Handle Windows' Stack Overflow Exceptions > > - Change protection of guard zone to use PAGE_NOACCESS instead of > PAGE_GUARD > > - Update handler for EXCEPTION_STACK_OVERFLOW to detect nested overflow > exceptions > > - Protect the red zone with PAGE_NOACCESS to detect runaway stack usage > > - If thread is executing Java code, report a StackOverflowError > exception; for native or VM threads, continue execution > - [Section 4.2] Match HotSpot's Guard Zone with Windows' Stack Guarantee > > - Set the (logical) yellow zone size to be the same for Windows as all > other OSes > > - Request the stack guarantee based on the red page count and the > logical yellow page count > > ... Closing this PR since it's too big and parts of it seem unnecessary. I think there's a way to break this change into smaller parts, and I'll create separate PRs for those changes. ------------- PR Comment: https://git.openjdk.org/jdk/pull/32365#issuecomment-7067340995
