Skip to content

Commit

Permalink
8318678: Vector access on heap MemorySegments only works for byte[]
Browse files Browse the repository at this point in the history
Reviewed-by: chegar, mcimadamore, psandoz
  • Loading branch information
minborg committed Nov 7, 2023
1 parent e1cae72 commit 74f1889
Show file tree
Hide file tree
Showing 12 changed files with 459 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,6 @@ public class ScopedMemoryAccess {
AbstractMemorySegmentImpl msp, long offset,
S s,
VectorSupport.LoadOperation<AbstractMemorySegmentImpl, V, S> defaultImpl) {
// @@@ Smarter alignment checking if accessing heap segment backing non-byte[] array
if (msp.maxAlignMask() > 1) {
throw new IllegalArgumentException();
}

try {
return loadFromMemorySegmentScopedInternal(
Expand Down Expand Up @@ -374,10 +370,6 @@ public class ScopedMemoryAccess {
V loadFromMemorySegmentMasked(Class<? extends V> vmClass, Class<M> maskClass, Class<E> e,
int length, AbstractMemorySegmentImpl msp, long offset, M m, S s, int offsetInRange,
VectorSupport.LoadVectorMaskedOperation<AbstractMemorySegmentImpl, V, S, M> defaultImpl) {
// @@@ Smarter alignment checking if accessing heap segment backing non-byte[] array
if (msp.maxAlignMask() > 1) {
throw new IllegalArgumentException();
}

try {
return loadFromMemorySegmentMaskedScopedInternal(
Expand Down Expand Up @@ -420,10 +412,6 @@ public class ScopedMemoryAccess {
V v,
AbstractMemorySegmentImpl msp, long offset,
VectorSupport.StoreVectorOperation<AbstractMemorySegmentImpl, V> defaultImpl) {
// @@@ Smarter alignment checking if accessing heap segment backing non-byte[] array
if (msp.maxAlignMask() > 1) {
throw new IllegalArgumentException();
}

try {
storeIntoMemorySegmentScopedInternal(
Expand Down Expand Up @@ -466,10 +454,6 @@ public class ScopedMemoryAccess {
int length, V v, M m,
AbstractMemorySegmentImpl msp, long offset,
VectorSupport.StoreVectorMaskedOperation<AbstractMemorySegmentImpl, V, M> defaultImpl) {
// @@@ Smarter alignment checking if accessing heap segment backing non-byte[] array
if (msp.maxAlignMask() > 1) {
throw new IllegalArgumentException();
}

try {
storeIntoMemorySegmentMaskedScopedInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@
package jdk.incubator.vector;

import java.lang.foreign.MemorySegment;

import jdk.internal.foreign.AbstractMemorySegmentImpl;
import jdk.internal.foreign.Utils;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;

import java.lang.foreign.ValueLayout;
import java.lang.reflect.Array;
import java.nio.ByteOrder;
import java.util.Objects;
import java.util.function.IntUnaryOperator;

import static jdk.incubator.vector.VectorOperators.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ private static ReductionOperation<ByteVector, VectorMask<Byte>> reductionOperati
*
* @param i the lane index
* @return the lane element at lane index {@code i}
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract byte lane(int i);
Expand All @@ -2863,7 +2863,7 @@ private static ReductionOperation<ByteVector, VectorMask<Byte>> reductionOperati
* @param e the value to be placed
* @return the result of replacing the lane element of this vector at lane
* index {@code i} with value {@code e}.
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract ByteVector withLane(int i, byte e);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2659,7 +2659,7 @@ private static ReductionOperation<DoubleVector, VectorMask<Double>> reductionOpe
*
* @param i the lane index
* @return the lane element at lane index {@code i}
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract double lane(int i);
Expand All @@ -2677,7 +2677,7 @@ private static ReductionOperation<DoubleVector, VectorMask<Double>> reductionOpe
* @param e the value to be placed
* @return the result of replacing the lane element of this vector at lane
* index {@code i} with value {@code e}.
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract DoubleVector withLane(int i, double e);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2679,7 +2679,7 @@ private static ReductionOperation<FloatVector, VectorMask<Float>> reductionOpera
*
* @param i the lane index
* @return the lane element at lane index {@code i}
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract float lane(int i);
Expand All @@ -2697,7 +2697,7 @@ private static ReductionOperation<FloatVector, VectorMask<Float>> reductionOpera
* @param e the value to be placed
* @return the result of replacing the lane element of this vector at lane
* index {@code i} with value {@code e}.
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract FloatVector withLane(int i, float e);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,7 @@ private static ReductionOperation<IntVector, VectorMask<Integer>> reductionOpera
*
* @param i the lane index
* @return the lane element at lane index {@code i}
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract int lane(int i);
Expand All @@ -2848,7 +2848,7 @@ private static ReductionOperation<IntVector, VectorMask<Integer>> reductionOpera
* @param e the value to be placed
* @return the result of replacing the lane element of this vector at lane
* index {@code i} with value {@code e}.
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract IntVector withLane(int i, int e);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ private static ReductionOperation<LongVector, VectorMask<Long>> reductionOperati
*
* @param i the lane index
* @return the lane element at lane index {@code i}
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract long lane(int i);
Expand All @@ -2714,7 +2714,7 @@ private static ReductionOperation<LongVector, VectorMask<Long>> reductionOperati
* @param e the value to be placed
* @return the result of replacing the lane element of this vector at lane
* index {@code i} with value {@code e}.
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract LongVector withLane(int i, long e);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2846,7 +2846,7 @@ private static ReductionOperation<ShortVector, VectorMask<Short>> reductionOpera
*
* @param i the lane index
* @return the lane element at lane index {@code i}
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract short lane(int i);
Expand All @@ -2864,7 +2864,7 @@ private static ReductionOperation<ShortVector, VectorMask<Short>> reductionOpera
* @param e the value to be placed
* @return the result of replacing the lane element of this vector at lane
* index {@code i} with value {@code e}.
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract ShortVector withLane(int i, short e);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3358,7 +3358,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
*
* @param i the lane index
* @return the lane element at lane index {@code i}
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract $type$ lane(int i);
Expand All @@ -3376,7 +3376,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
* @param e the value to be placed
* @return the result of replacing the lane element of this vector at lane
* index {@code i} with value {@code e}.
* @throws IllegalArgumentException if the index is is out of range
* @throws IllegalArgumentException if the index is out of range
* ({@code < 0 || >= length()})
*/
public abstract $abstractvectortype$ withLane(int i, $type$ e);
Expand Down Expand Up @@ -4077,8 +4077,6 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
* if {@code offset+N*$sizeInBytes$ < 0}
* or {@code offset+N*$sizeInBytes$ >= 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
Expand Down Expand Up @@ -4138,8 +4136,6 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
* or {@code offset+N*$sizeInBytes$ >= 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
Expand Down

1 comment on commit 74f1889

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.