RFR: 8370500: Change windows x64 implementation of os::current_stack_pointer()
David Holmes
dholmes at openjdk.org
Mon Oct 27 05:11:02 UTC 2025
On Thu, 23 Oct 2025 15:44:39 GMT, Erik Österlund <eosterlund at openjdk.org> wrote:
> The current implementation of os::current_stack_pointer() on windows x64 uses a code stub to read the stack pointer. This means that os::current_stack_pointer() may not be called early on in the bootstrapping. This prevents unhandled oops from being enabled early on.
>
> However, there is an MSVC intrinsic that provides the same functionality without the need to use stubs: _AddressOfReturnAddress() from intrin.h
> By changing this implementation on windows x64, we should be able to call os::current_stack_pointer() early on as it is seemingly the only implementation with such a bootstrapping dependency.
Always nice to get rid of stubs! A query and request below.
Thanks
src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp line 346:
> 344: __declspec(noinline)
> 345: address os::current_stack_pointer() {
> 346: return ((address)_AddressOfReturnAddress()) + sizeof(void*);
The document for this function explicitly states
> This address may not be used to access other memory locations (for example, the function's arguments).
yet here we seem to be using it to then get the SP?
A comment explaining why this yields the SP would also useful. Thanks.
-------------
PR Review: https://git.openjdk.org/jdk/pull/27956#pullrequestreview-3381818827
PR Review Comment: https://git.openjdk.org/jdk/pull/27956#discussion_r2464439494
More information about the hotspot-dev
mailing list