On Mon, 9 Nov 2026 22:41:28 GMT, Ashay Rane <[email protected]> wrote:
>> src/hotspot/os/windows/os_windows.cpp line 2690:
>>
>>> 2688:
>>> 2689: static bool grow_windows_stack_to(address target) {
>>> 2690: const volatile PNT_TIB tib = (PNT_TIB)NtCurrentTeb();
>>
>> Isn't this applying "const volatile" only to the pointer, and not the fields?
>
> This trips me as well. If we put the `const volatile` after the type, that
> would make the pointer itself volatile. My understanding is that by saying
> `const volatile PNT_TIB`, we make the thing pointed-to by the pointer to be
> constant and volatile.
>
> Here's an example to demonstrate the difference:
>
> ```c++
> struct S {
> int value;
> };
>
> int volatile_pointee(volatile S* p) {
> volatile S* q = p;
> return q->value + q->value; // two volatile value loads
> }
>
> int volatile_pointer(S* volatile p) {
> S* q = p; // load from volatile pointer
> return q->value + q->value;
> }
>
>
> The assembly (via [CompilerExplorer](https://godbolt.org/z/5dra7aqfE)) shows:
>
>
> "volatile_pointee(S volatile*)":
> mov eax, DWORD PTR [rdi]
> add eax, DWORD PTR [rdi]
> ret
> "volatile_pointer(S*)":
> mov QWORD PTR [rsp-8], rdi
> mov rax, QWORD PTR [rsp-8]
> mov eax, DWORD PTR [rax]
> add eax, eax
> ret
>
>
> In the first case, the memory location pointed to by the pointer is read
> twice. In the second case, the pointer is read twice but the field is read
> just once.
Right, the difference shows up when there is a "*" in the declaration. The
problem is PNT_TIB is a typedef of a pointer type, so "const volatile PNT_TIB"
is the same as "PNT_TIB const volatile". I think what you need is "const
volatile TEB *" or an equivalent VOLATILE_PNT_TIB typedef.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/33729#discussion_r4518979843