On Sun, 15 Nov 2026 14:19:08 GMT, FuBangkun <[email protected]> wrote:

>> In debugging a crash that happens without this patch, I learnt of a 
>> situation where the existing implementation can subtly corrupt memory.  
>> Sometimes this has more visible effects like the crash, but it's possible 
>> that the execution can silently continue with corrupted memory.  Here's a 
>> reproduced paragraph from the document explaining the circumstances:
>> 
>>> Crucially, unlike the existing upstream implementation, we do not use 
>>> `VirtualAlloc()` with `MEM_COMMIT` to commit pages, because doing so would 
>>> forego updating `StackLimit`, leading to situations where the stack pointer 
>>> ends up being _below_ `StackLimit`, which is an invariant failure by 
>>> itself. As the code continues executing, the implicit calls to `__chkstk()` 
>>> in VM code [write zeros into pages starting from 
>>> `StackLimit`](https://devblogs.microsoft.com/oldnewthing/20260319-00/?p=112152/),
>>>  thus overwriting used pages in the stack memory! This can lead to abrupt 
>>> JVM crashes because return address and local variables are now corrupted.
>
> Hello @raneashay @dean-long,
> 
> Thank you for this monumental effort on Windows stack handling. I wanted to 
> share a concrete real-world production failure from the field that directly 
> validates the necessity of this PR.
> 
> In our runtime environment on **Windows x64 with JDK 27**, we hit this exact 
> failure during an asynchronous shader compilation pipeline driven by Project 
> Panama (FFM) downcalls and upcalls (`Shaderc` bindings via 
> `jdk.internal.foreign`):
> 
> ### The Crash Pattern
> - **Symptom:** Silent process termination with unhandled NTSTATUS 
> `0xC0000005` (Access Violation), without triggering `StackOverflowError` and 
> **without generating any `hs_err` log**.
> - **Context:** A newly spawned `ForkJoinWorkerThread` with only ~102 KB of 
> stack committed out of 1024 KB reserved.
> - **Faulting Instruction:** C2 JIT nmethod entry for 
> `jdk/internal/foreign/StringSupport$CharsetKind.of` (invoked via an FFM 
> upcall stub):
> 
> DowncallStub.invoke
> -> UpcallStub.invoke
> -> DirectMethodHandle$Interface.checkReceiver
> -> java.lang.Class.getName
> -> jdk.internal.foreign.StringSupport$CharsetKind.of <-- Faulting PC (C2 
> nmethod code entry)
> 
> - **Memory Analysis:** Minidump / ProcDump analysis confirmed that the C2 
> nmethod's far-access stack bang (`RSP - 0x8000`) jumped into an uncommitted 
> guard page. Because the Windows incremental stack commit mechanism was not 
> engaged sequentially, Windows dropped it as an untracked access violation, 
> crashing the JVM before SEH could recover it.
> 
> Our application-level workaround was to isolate the FFM pipeline onto 
> dedicated threads with a 16 MiB stack, but having this proper far-access 
> probe recovery merged into upstream HotSpot will be a massive stability boost 
> for real-world applications leveraging Project Panama on Windows.
> 
> Looking forward to seeing this integrated!

Hi @FuBangkun, thanks for sharing the problem that you're running into.  And 
thanks also for triaging the problem at your end!

There are a couple of scenarios that could explain the crash that you saw, one 
of which was addressed just last week in 
https://github.com/openjdk/jdk/pull/33729.  I have just now initiated 
backporting of that patch to JDK27 and CI builds are running at 
https://github.com/raneashay/jdk-27/actions/runs/43782257129.  If you were 
running into this scenario, then PR 33729's patch (and the JDK27 build from the 
link above) might work for you.

The other possible scenario is that the downcall stub allocated its frame 
without a stack bang, so at this point, the stack could already be in a bad 
state, which makes it hard to hypothesize what could have happened next.  That 
problem is addressed by this PR's changes (specifically, on Windows, the 
downcall stub first probes the allocation).  There are a few other fixes in 
this PR (like the default stack shadow pages being bumped to 20 pages to match 
other OSes) that could be relevant.

I have merged the master branch into this PR's branch, which should trigger the 
CI build.  If the JDK27 Windows/x64 build from above doesn't fix the issue, 
would you be willing to try the JDK tip (i.e. JDK28) build that's produced by 
this PR's CI (from 
https://github.com/raneashay/openjdk-jdk/actions/runs/43785113617) to see if 
that resolves the issue?

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

PR Comment: https://git.openjdk.org/jdk/pull/32365#issuecomment-6904640171

Reply via email to