Bad alignment check in MemorySegment.elements

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 20
    • Affects Version/s: 19, 20, repo-panama
    • Component/s: core-libs
    • None

      The change in this commit:

      https://github.com/openjdk/jdk/commit/9d43d25da8bcfff425a795dcc230914a384a5c82#diff-a311ae3c57c4204970424f03af3d0744a80f9ce43c2e4f6fdad8dc83bbfe515d

      Introduced a regression in few routines such as MemorySegment.elements which want to ensure that the size of the segments has to be a multiple of the layout.

      The check went from:

      byteSize() % elementLayout.byteSize() != 0

      To:

      (byteSize() & (elementLayout.byteSize() - 1)) == 0;

      The latter check only works for power of two (in fact we use it for alignment checks), so this change is incorrect.

            Assignee:
            Maurizio Cimadamore
            Reporter:
            Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: