> Without this patch, HotSpot uses `VirtualAlloc()` with `MEM_COMMIT` to
> make Windows convert stack pages from "reserved" to "committed", but
> doing so does not update the `StackLimit` field in the Thread
> Environment Block (TEB) tracked by Windows.  Subsequent use of the stack
> by HotSpot can cause the stack pointer to be _below_ `StackLimit`, which
> breaks the invariant expected by the Win32 API functions like
> `__chkstk()`.
> 
> To fix this problem, this patch touches pages one by one, starting from
> `StackLimit` down to the target address.  This has the intended effect
> of commiting the pages, but it also correctly updates `StackLimit`.
> 
> The included test reliably fails without this patch, and it passes with
> this patch.  I validated this patch using Tier 1 through 3 tests in the
> JDK, HotSpot, and LangTools test groups.
> 
> ---------
> - [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 incrementally with one additional 
commit since the last revision:

  Address PR comments
  
  1. Mark TEB pointer as `volatile` so that read accesses of `StackLimit`
     are not optimized away.  Also mark it as constant since the function
     does not modify the TEB.
  
  2. Use the return value of `grow_windows_stack_to()` to decide whether
     to continue program execution or to show the unrecoverable handler
     error.
  
  3. Attach JBS issue identifier to the test.
  
  4. Allow access to native methods in the test.  Also set the stack size
     to 1MB, so that too small a stack size (e.g. 256KB) does not cause
     the JVM to crash when running the test.
  
  5. Update miscellaneous comments.

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/33729/files
  - new: https://git.openjdk.org/jdk/pull/33729/files/7fc92f5b..8a20a63f

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=33729&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=33729&range=00-01

  Stats: 8 lines in 2 files changed: 2 ins; 0 del; 6 mod
  Patch: https://git.openjdk.org/jdk/pull/33729.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/33729/head:pull/33729

PR: https://git.openjdk.org/jdk/pull/33729

Reply via email to