On Mon, 9 Nov 2026 22:12:56 GMT, Dean Long <[email protected]> wrote:

>> 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.
>
> 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.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33729#discussion_r4518849092

Reply via email to