ZCACHE_ALIGNED is used to attempt to align members of various classes. This is being done to isolate these members on their own cache line, to avoid false sharing.
However, this usage is problematic. The alignment value is large enough to make these overaligned types. Most of these members are ultimately in ZCollectedHeap, thereby affecting its alignment. But ZCollectedHeap is heap allocated, and heap allocation doesn't do anything special for overaligned types. Instead it gets allocated normally, e.g. the only guarantee is that it has std::max_align_t alignment.
This means that the actual alignment of these members is arbitrary within that constraint of std::max_align_t alignment. There may be alignment padding, but that doesn't guarantee complete isolation. Even worse, having objects that don't meet their alignment requirements is undefined behavior. So we should do something about this.
C++17 provides support for heap allocation of overaligned types. The `new` expression is extended to recognize an overaligned type and provides a different behavior in support of that. However, we aren't yet using C++17. And even if we were, providing NMT support overaligned types may be difficult, possibly imposing costs that are unacceptable given the infrequent usage.
The uses of ZCACHE_ALIGNED that I found were
ZMarkStripe < ZMarkStripeSet < ZMark < ZHeap < ZCollectedHeap
ZMarkStackAllocator < ZMark < ZHeap < ZCollectedHeap
ZMarkTerminate < ZMark < ZHeap < ZCollectedHeap
ZNMethodTableIteration < ZNMethodTable (AllStatic)
The ZCACHE_ALIGNED-induced overalignment of ZNMethodTableIteration in ZNMethodTable isn't a problem. The latter is AllStatic, so not heap allocated.
The others all affect the alignment requirements for ZCollectedHeap, so something should be done there.
One possibility would be to specially handle the allocation of the singleton ZCollectedHeap, to ensure it is properly aligned.
Another option would be to use padding (as from padding.hpp) to provide the isolation, rather than alignment. If padding is used, it might be desirable to define non-trivial copy and assignment operations (if needed) that avoid touching the padding.
However, this usage is problematic. The alignment value is large enough to make these overaligned types. Most of these members are ultimately in ZCollectedHeap, thereby affecting its alignment. But ZCollectedHeap is heap allocated, and heap allocation doesn't do anything special for overaligned types. Instead it gets allocated normally, e.g. the only guarantee is that it has std::max_align_t alignment.
This means that the actual alignment of these members is arbitrary within that constraint of std::max_align_t alignment. There may be alignment padding, but that doesn't guarantee complete isolation. Even worse, having objects that don't meet their alignment requirements is undefined behavior. So we should do something about this.
C++17 provides support for heap allocation of overaligned types. The `new` expression is extended to recognize an overaligned type and provides a different behavior in support of that. However, we aren't yet using C++17. And even if we were, providing NMT support overaligned types may be difficult, possibly imposing costs that are unacceptable given the infrequent usage.
The uses of ZCACHE_ALIGNED that I found were
ZMarkStripe < ZMarkStripeSet < ZMark < ZHeap < ZCollectedHeap
ZMarkStackAllocator < ZMark < ZHeap < ZCollectedHeap
ZMarkTerminate < ZMark < ZHeap < ZCollectedHeap
ZNMethodTableIteration < ZNMethodTable (AllStatic)
The ZCACHE_ALIGNED-induced overalignment of ZNMethodTableIteration in ZNMethodTable isn't a problem. The latter is AllStatic, so not heap allocated.
The others all affect the alignment requirements for ZCollectedHeap, so something should be done there.
One possibility would be to specially handle the allocation of the singleton ZCollectedHeap, to ensure it is properly aligned.
Another option would be to use padding (as from padding.hpp) to provide the isolation, rather than alignment. If padding is used, it might be desirable to define non-trivial copy and assignment operations (if needed) that avoid touching the padding.
- relates to
-
JDK-8351607 Test com/sun/jdi/JdbStopInNotificationThreadTest.java failing with missing "Breakpoint hit" for line 70
-
- Open
-
-
JDK-8300080 offset_of for GCC/Clang exhibits undefined behavior and is not always a compile-time constant
-
- Open
-
-
JDK-8330047 ASAN build error with gcc 13
-
- Resolved
-
- links to
-
Commit(master) openjdk/jdk/fb0efbe8
-
Review(master) openjdk/jdk/23885