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

Add relaxed add_and_fetch for macos aarch64 atomics

XMLWordPrintable

    • b22

        Found this while micro benchmarking Generational ZGC.

        See how the following code uses __ATOMIC_RELEASE and FULL_MEM_BARRIER even when order == memory_order_relaxed:

        template<size_t byte_size>
        struct Atomic::PlatformAdd {
          template<typename D, typename I>
          D add_and_fetch(D volatile* dest, I add_value, atomic_memory_order order) const {
            D res = __atomic_add_fetch(dest, add_value, __ATOMIC_RELEASE);
            FULL_MEM_BARRIER;
            return res;
          }

        This causes a noticeable slowdown in parts of the Generational ZGC code that walks over large C++ arrays, and claim indices/chunks with fetch_and_add.

        If I change the code to be:
        if (order == memory_order_relaxed) {
          return __atomic_add_fetch(dest, add_value, __ATOMIC_RELAXED);
        } else {
          ... old code ...
        }

        then I see a significant enough speed up.

              stefank Stefan Karlsson
              stefank Stefan Karlsson
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: