< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractVector.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -22,14 +22,14 @@
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  package jdk.incubator.vector;
  
+ import jdk.incubator.foreign.MemorySegment;
  import jdk.internal.vm.annotation.ForceInline;
  import jdk.internal.vm.vector.VectorSupport;
  
- import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  import java.util.function.IntUnaryOperator;
  
  import static jdk.incubator.vector.VectorOperators.*;
  

@@ -192,11 +192,11 @@
      abstract AbstractShuffle<E> shuffleFromArray(int[] indexes, int i);
  
      abstract AbstractShuffle<E> shuffleFromOp(IntUnaryOperator fn);
  
      /*package-private*/
-     abstract AbstractVector<E> fromByteArray0(byte[] a, int offset);
+     abstract AbstractVector<E> fromMemorySegment0(MemorySegment ms, long offset);
  
      /*package-private*/
      abstract AbstractVector<E> maybeSwap(ByteOrder bo);
  
      /*package-private*/

@@ -502,27 +502,27 @@
      @ForceInline
      final <F>
      AbstractVector<F> defaultReinterpret(AbstractSpecies<F> rsp) {
          int blen = Math.max(this.bitSize(), rsp.vectorBitSize()) / Byte.SIZE;
          ByteOrder bo = ByteOrder.nativeOrder();
-         ByteBuffer bb = ByteBuffer.allocate(blen);
-         this.intoByteBuffer(bb, 0, bo);
+         MemorySegment ms = MemorySegment.ofArray(new byte[blen]);
+         this.intoMemorySegment(ms, 0, bo);
          VectorMask<F> m = rsp.maskAll(true);
          // enum-switches don't optimize properly JDK-8161245
          switch (rsp.laneType.switchKey) {
          case LaneType.SK_BYTE:
-             return ByteVector.fromByteBuffer(rsp.check(byte.class), bb, 0, bo, m.check(byte.class)).check0(rsp);
+             return ByteVector.fromMemorySegment(rsp.check(byte.class), ms, 0, bo, m.check(byte.class)).check0(rsp);
          case LaneType.SK_SHORT:
-             return ShortVector.fromByteBuffer(rsp.check(short.class), bb, 0, bo, m.check(short.class)).check0(rsp);
+             return ShortVector.fromMemorySegment(rsp.check(short.class), ms, 0, bo, m.check(short.class)).check0(rsp);
          case LaneType.SK_INT:
-             return IntVector.fromByteBuffer(rsp.check(int.class), bb, 0, bo, m.check(int.class)).check0(rsp);
+             return IntVector.fromMemorySegment(rsp.check(int.class), ms, 0, bo, m.check(int.class)).check0(rsp);
          case LaneType.SK_LONG:
-             return LongVector.fromByteBuffer(rsp.check(long.class), bb, 0, bo, m.check(long.class)).check0(rsp);
+             return LongVector.fromMemorySegment(rsp.check(long.class), ms, 0, bo, m.check(long.class)).check0(rsp);
          case LaneType.SK_FLOAT:
-             return FloatVector.fromByteBuffer(rsp.check(float.class), bb, 0, bo, m.check(float.class)).check0(rsp);
+             return FloatVector.fromMemorySegment(rsp.check(float.class), ms, 0, bo, m.check(float.class)).check0(rsp);
          case LaneType.SK_DOUBLE:
-             return DoubleVector.fromByteBuffer(rsp.check(double.class), bb, 0, bo, m.check(double.class)).check0(rsp);
+             return DoubleVector.fromMemorySegment(rsp.check(double.class), ms, 0, bo, m.check(double.class)).check0(rsp);
          default:
              throw new AssertionError(rsp.toString());
          }
      }
  

@@ -728,19 +728,10 @@
                      AbstractVector::defaultReinterpret);
          }
          throw new AssertionError();
      }
  
-     // Byte buffer wrappers.
-     static ByteBuffer wrapper(ByteBuffer bb, ByteOrder bo) {
-         return bb.duplicate().order(bo);
-     }
- 
-     static ByteBuffer wrapper(byte[] a, ByteOrder bo) {
-         return ByteBuffer.wrap(a).order(bo);
-     }
- 
      static {
          // Recode uses of VectorSupport.reinterpret if this assertion fails:
          assert(REGISTER_ENDIAN == ByteOrder.LITTLE_ENDIAN);
      }
  }
< prev index next >