Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333578

Fix uses of overaligned types induced by ZCACHE_ALIGNED

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 25
    • 23
    • hotspot
    • gc
    • master

      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.

            aboldtch Axel Boldt-Christmas
            kbarrett Kim Barrett
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: