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

Vector access on heap MemorySegments only works for byte[]

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 22
    • core-libs
    • None
    • behavioral
    • minimal
    • This is a permissive change. It is unreasonable to depend on an exception being thrown for certain backing arrays.
    • Java API
    • JDK

      Summary

      Remove the unnecessary constraint that Vector access to heap memory segments only works for segments backed by an array of bytes. Instead, arrays with a component type of byte, char, short, int float, long, and double are now supported.

      Problem

      Users may obtain memory segments from many different sources and the previous restriction prevented them from using certain heap segments. This created an unmotivatable asymmetry and reduced the versatility of the Vector API.

      Solution

      Remove the restrictions on heap memory segment sources and allow unaligned access to all primitive types supported by memory segments.

      Specification

      diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java
      index 3c9217fc9854..74b9461a5cb3 100644
      --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java
      +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java
           public abstract ByteVector withLane(int i, byte e);
      @@ -3281,8 +3281,6 @@ ByteVector fromBooleanArray(VectorSpecies<Byte> species,
            *         if {@code offset+N*1 < 0}
            *         or {@code offset+N*1 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      @@ -3333,8 +3331,6 @@ ByteVector fromMemorySegment(VectorSpecies<Byte> species,
            *         or {@code offset+N*1 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
            *         where the mask is set
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java
      index 39dc04cedb7b..f6e9b7b01ea3 100644
      --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java
      +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java
           public abstract DoubleVector withLane(int i, double e);
      @@ -2964,8 +2964,6 @@ DoubleVector fromArray(VectorSpecies<Double> species,
            *         if {@code offset+N*8 < 0}
            *         or {@code offset+N*8 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      @@ -3021,8 +3019,6 @@ DoubleVector fromMemorySegment(VectorSpecies<Double> species,
            *         or {@code offset+N*8 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
            *         where the mask is set
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java
      index 2095da4328c4..7265243b6b93 100644
      --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java
      +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java
           public abstract FloatVector withLane(int i, float e);
      @@ -2970,8 +2970,6 @@ FloatVector fromArray(VectorSpecies<Float> species,
            *         if {@code offset+N*4 < 0}
            *         or {@code offset+N*4 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      @@ -3027,8 +3025,6 @@ FloatVector fromMemorySegment(VectorSpecies<Float> species,
            *         or {@code offset+N*4 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
            *         where the mask is set
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java
      index 66f6bed91fd3..f9c913f823ca 100644
      --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java
      +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java
           public abstract IntVector withLane(int i, int e);
      @@ -3126,8 +3126,6 @@ IntVector fromArray(VectorSpecies<Integer> species,
            *         if {@code offset+N*4 < 0}
            *         or {@code offset+N*4 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      @@ -3183,8 +3181,6 @@ IntVector fromMemorySegment(VectorSpecies<Integer> species,
            *         or {@code offset+N*4 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
            *         where the mask is set
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java
      index 672f3ddc3f78..9339dc8616fc 100644
      --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java
      +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java
      @@ -3005,8 +3005,6 @@ LongVector fromArray(VectorSpecies<Long> species,
            *         if {@code offset+N*8 < 0}
            *         or {@code offset+N*8 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      @@ -3062,8 +3060,6 @@ LongVector fromMemorySegment(VectorSpecies<Long> species,
            *         or {@code offset+N*8 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
            *         where the mask is set
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java
      index ed74ce216534..cfe91f6e14e6 100644
      --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java
      +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java
           public abstract ShortVector withLane(int i, short e);
      @@ -3275,8 +3275,6 @@ ShortVector fromCharArray(VectorSpecies<Short> species,
            *         if {@code offset+N*2 < 0}
            *         or {@code offset+N*2 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      @@ -3332,8 +3330,6 @@ ShortVector fromMemorySegment(VectorSpecies<Short> species,
            *         or {@code offset+N*2 >= ms.byteSize()}
            *         for any lane {@code N} in the vector
            *         where the mask is set
      -     * @throws IllegalArgumentException if the memory segment is a heap segment that is
      -     *         not backed by a {@code byte[]} array.
            * @throws IllegalStateException if the memory segment's session is not alive,
            *         or if access occurs from a thread other than the thread owning the session.
            * @since 19
      

            pminborg Per-Ake Minborg
            psandoz Paul Sandoz
            Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: