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

(bf) ByteBuffer::alignedSlice and alignmentOffset should not promise heap alignment

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 22
    • core-libs
    • None

      The following methods:

      - ByteBuffer::alignedSlice
      - ByteBuffer::alignmentOffset

      Make too many promises about the alignment of the underlying heap memory.

      The VM only guarantees that the elements of a Java array are aligned to their natural alignment. e.g for byte[] that is 1 byte (i.e. no alignment at all, really).

      However, these methods promise that accesses will be aligned for certain offsets, even though there is no hard guarantee for that.

      alignedSlice depends directly on alignmentOffset, and the latter purports to be able to guarantee alignment when accessing heap memory.

      The implementation currently tries to compute an alignment offset for heap buffers when the access size (unitSize) is > 1, which can not be guaranteed to be correct.

            jvernee Jorn Vernee
            jvernee Jorn Vernee
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: