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

Atomic::add to pointer type may return wrong value

XMLWordPrintable

    • b21

        For all platforms, Atomic::PlatformAdd implements one of fetch_and_add and add_and_fetch in terms of the other, adding or subtracting (as appropriate) the result of the other operation and the addend.

        That's incorrect when the destination type is a pointer type. When the destination type is a pointer type, AddImpl scales the addend by the size of the pointee type, and passes that scaled value to the platform layer. (This is described in the comment documenting PlatformAdd.) If the pointee type has size > 1, this will double-scale the addend.

        Fortunately, at this time there are no uses of Atomic add operations with a pointer type whose pointee type's size > 1.

              kbarrett Kim Barrett
              kbarrett Kim Barrett
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: