On Mon, 4 May 2026 14:52:37 GMT, Anton Artemov <[email protected]> wrote:

> Hi, please consider the following changes:
> 
> This PR re-enables stringop-overflow warnings. 
> 
> It was assumed that the assert in `Thread::current()`, which calls the 
> `ATTRIBUTE_NORETURN` report function on failure, would be sufficient to 
> inform the GCC compiler that the current thread is always non-null. However, 
> it turns out that the assert is weakened by the `DebuggingContext`: 
> 
> Instead of having
> `assert(current != nullptr, "Thread::current() called on detached thread");`
> 
> in fact one gets this:
> `if ( !(DebuggingContext::is_enabled() || current != null) ) { 
> report_vm_error(...); }`
> 
> If `DebuggingContext` is enabled then the error will not be triggered 
> regardless of what `current` is. This makes GCC consider the virtually 
> impossible path and emit false positive warnings about atomics.
> 
> The same problem is found in the Shenandoah code.
> 
> The fix is to strengthen the assertion by 
> `DEBUG_ONLY(guarantee(current != nullptr, "...");)`
> which removes the assertion completely in product builds, but for debug 
> builds makes it clear for the compiler that the operand cannot be nullptr.
> 
> With this findings I conclude that it is not a compiler bug.
> 
> Tested in tiers 1-5 and GHA. 
> 
> Separate builds with Shenandoah done.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Hi, not a code review.
JDK release build on linux-aarch64 with GCC 13 fails with the following error.


 In file included from 
/tmp/jdk-src/src/hotspot/share/runtime/atomicAccess.hpp:859,
                  from /tmp/jdk-src/src/hotspot/share/runtime/atomic.hpp:31,
                  from 
/tmp/jdk-src/src/hotspot/share/utilities/exceptions.hpp:30,
                  from /tmp/jdk-src/src/hotspot/share/oops/metadata.hpp:28,
                  from /tmp/jdk-src/src/hotspot/share/oops/oop.hpp:34,
                  from /tmp/jdk-src/src/hotspot/share/runtime/handles.hpp:29,
                  from 
/tmp/jdk-src/src/hotspot/share/classfile/vmClasses.hpp:30,
                  from 
/tmp/jdk-src/src/hotspot/share/classfile/javaClasses.hpp:28,
                  from 
/tmp/jdk-src/src/hotspot/share/classfile/javaClasses.inline.hpp:28,
                  from 
/tmp/jdk-src/src/hotspot/share/precompiled/precompiled.hpp:32:
 In member function ‘T AtomicAccess::PlatformOrderedLoad<byte_size, 
X_ACQUIRE>::operator()(const volatile T*) const [with T = unsigned int; long 
unsigned int byte_size = 4]’,
     inlined from ‘T AtomicAccess::LoadImpl<T, PlatformOp, typename 
std::enable_if<(std::is_integral<_Tp>::value || std::is_pointer<_Tp>::value), 
void>::type>::operator()(const volatile T*) const [with T = unsigned int; 
PlatformOp = AtomicAccess::PlatformOrderedLoad<4, X_ACQUIRE>]’ at 
/tmp/jdk-src/src/hotspot/share/runtime/atomicAccess.hpp:515:24,
     inlined from ‘static T AtomicAccess::load_acquire(const volatile T*) [with 
T = unsigned int]’ at 
/tmp/jdk-src/src/hotspot/share/runtime/atomicAccess.hpp:884:67,
     inlined from ‘T AtomicImpl::CommonCore<T>::load_acquire() const [with T = 
unsigned int]’ at /tmp/jdk-src/src/hotspot/share/runtime/atomic.hpp:252:38,
     inlined from ‘T AtomicImpl::Atomic<T, 
AtomicImpl::Category::Translated>::load_acquire() const [with T = 
ShenandoahHeapRegion::RegionState]’ at 
/tmp/jdk-src/src/hotspot/share/runtime/atomic.hpp:470:19,
     inlined from ‘ShenandoahHeapRegion::RegionState 
ShenandoahHeapRegion::state() const’ at 
/tmp/jdk-src/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp:224:70,
     inlined from ‘bool ShenandoahHeapRegion::is_active() const’ at 
/tmp/jdk-src/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp:208:66,
     inlined from ‘void 
ShenandoahGenerationalUpdateHeapRefsTask<CONCURRENT>::update_references_in_remembered_set(uint,
 T&, const ShenandoahMarkingContext*, bool) [with T = 
ShenandoahConcUpdateRefsClosure; bool CONCURRENT = true]’ at 
/tmp/jdk-src/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp:817:23:
 
/tmp/jdk-src/src/hotspot/os_cpu/linux_aarch64/atomicAccess_linux_aarch64.hpp:206:66:
 error: ‘unsigned int __atomic_load_4(const volatile void*, int)’ writing 4 
bytes into a region of size 0 overflows the destination 
[-Werror=stringop-overflow=]
   206 |   T operator()(const volatile T* p) const { T data; 
__atomic_load(const_cast<T*>(p), &data, __ATOMIC_ACQUIRE); return data; }
       |                                                     
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 In member function ‘void 
ShenandoahGenerationalUpdateHeapRefsTask<CONCURRENT>::update_references_in_remembered_set(uint,
 T&, const ShenandoahMarkingContext*, bool) [with T = 
ShenandoahConcUpdateRefsClosure; bool CONCURRENT = true]’:
 cc1plus: note: destination object is likely at address zero
 In member function ‘T AtomicAccess::PlatformOrderedLoad<byte_size, 
X_ACQUIRE>::operator()(const volatile T*) const [with T = unsigned int; long 
unsigned int byte_size = 4]’,
     inlined from ‘T AtomicAccess::LoadImpl<T, PlatformOp, typename 
std::enable_if<(std::is_integral<_Tp>::value || std::is_pointer<_Tp>::value), 
void>::type>::operator()(const volatile T*) const [with T = unsigned int; 
PlatformOp = AtomicAccess::PlatformOrderedLoad<4, X_ACQUIRE>]’ at 
/tmp/jdk-src/src/hotspot/share/runtime/atomicAccess.hpp:515:24,
     inlined from ‘static T AtomicAccess::load_acquire(const volatile T*) [with 
T = unsigned int]’ at 
/tmp/jdk-src/src/hotspot/share/runtime/atomicAccess.hpp:884:67,
     inlined from ‘T AtomicImpl::CommonCore<T>::load_acquire() const [with T = 
unsigned int]’ at /tmp/jdk-src/src/hotspot/share/runtime/atomic.hpp:252:38,
     inlined from ‘T AtomicImpl::Atomic<T, 
AtomicImpl::Category::Translated>::load_acquire() const [with T = 
ShenandoahHeapRegion::RegionState]’ at 
/tmp/jdk-src/src/hotspot/share/runtime/atomic.hpp:470:19,
     inlined from ‘ShenandoahHeapRegion::RegionState 
ShenandoahHeapRegion::state() const’ at 
/tmp/jdk-src/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp:224:70,
     inlined from ‘bool ShenandoahHeapRegion::is_active() const’ at 
/tmp/jdk-src/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp:208:66,
     inlined from ‘void 
ShenandoahGenerationalUpdateHeapRefsTask<CONCURRENT>::update_references_in_remembered_set(uint,
 T&, const ShenandoahMarkingContext*, bool) [with T = 
ShenandoahNonConcUpdateRefsClosure; bool CONCURRENT = false]’ at 
/tmp/jdk-src/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp:817:23:
 
/tmp/jdk-src/src/hotspot/os_cpu/linux_aarch64/atomicAccess_linux_aarch64.hpp:206:66:
 error: ‘unsigned int __atomic_load_4(const volatile void*, int)’ writing 4 
bytes into a region of size 0 overflows the destination 
[-Werror=stringop-overflow=]
   206 |   T operator()(const volatile T* p) const { T data; 
__atomic_load(const_cast<T*>(p), &data, __ATOMIC_ACQUIRE); return data; }
       |                                                     
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 In member function ‘void 
ShenandoahGenerationalUpdateHeapRefsTask<CONCURRENT>::update_references_in_remembered_set(uint,
 T&, const ShenandoahMarkingContext*, bool) [with T = 
ShenandoahNonConcUpdateRefsClosure; bool CONCURRENT = false]’:


I suppose the previous issue https://bugs.openjdk.org/browse/JDK-8382395 is 
still triggering.

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

PR Comment: https://git.openjdk.org/jdk/pull/31025#issuecomment-4376491833

Reply via email to