< prev index next >

test/micro/org/openjdk/bench/jdk/incubator/vector/TestLoadStoreShort.java

Print this page
*** 24,11 ***
  package org.openjdk.bench.jdk.incubator.vector;
  
  import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  import java.util.concurrent.TimeUnit;
! import jdk.incubator.foreign.CLinker;
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import jdk.incubator.vector.ShortVector;
  import jdk.incubator.vector.VectorOperators;
--- 24,11 ---
  package org.openjdk.bench.jdk.incubator.vector;
  
  import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  import java.util.concurrent.TimeUnit;
! 
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import jdk.incubator.vector.ShortVector;
  import jdk.incubator.vector.VectorOperators;

*** 110,34 ***
  
      srcBufferNative = ByteBuffer.allocateDirect(size);
      dstBufferNative = ByteBuffer.allocateDirect(size);
  
  
!     implicitScope = ResourceScope.newImplicitScope();
      srcSegmentImplicit = MemorySegment.allocateNative(size, SPECIES.vectorByteSize(), implicitScope);
      srcBufferSegmentImplicit = srcSegmentImplicit.asByteBuffer();
      dstSegmentImplicit = MemorySegment.allocateNative(size, SPECIES.vectorByteSize(), implicitScope);
      dstBufferSegmentImplicit = dstSegmentImplicit.asByteBuffer();
  
  
!     srcAddress = CLinker.allocateMemory(size);
!     dstAddress = CLinker.allocateMemory(size);
  
      this.longSize = longSize;
  
      a = new short[size];
      b = new short[size];
      c = new short[size];
  
    }
  
-   @TearDown
-   public void tearDown() {
-     CLinker.freeMemory(srcAddress);
-     CLinker.freeMemory(dstAddress);
-   }
- 
    @Benchmark
    @CompilerControl(CompilerControl.Mode.PRINT)
    public void array() {
      for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
        var v = ShortVector.fromArray(SPECIES, srcArray, i);
--- 110,28 ---
  
      srcBufferNative = ByteBuffer.allocateDirect(size);
      dstBufferNative = ByteBuffer.allocateDirect(size);
  
  
!     implicitScope = ResourceScope.newSharedScope();
      srcSegmentImplicit = MemorySegment.allocateNative(size, SPECIES.vectorByteSize(), implicitScope);
      srcBufferSegmentImplicit = srcSegmentImplicit.asByteBuffer();
      dstSegmentImplicit = MemorySegment.allocateNative(size, SPECIES.vectorByteSize(), implicitScope);
      dstBufferSegmentImplicit = dstSegmentImplicit.asByteBuffer();
  
  
!     srcAddress = MemorySegment.allocateNative(size, implicitScope).address();
!     dstAddress = MemorySegment.allocateNative(size, implicitScope).address();
  
      this.longSize = longSize;
  
      a = new short[size];
      b = new short[size];
      c = new short[size];
  
    }
  
    @Benchmark
    @CompilerControl(CompilerControl.Mode.PRINT)
    public void array() {
      for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
        var v = ShortVector.fromArray(SPECIES, srcArray, i);

*** 214,12 ***
    }
  
    @Benchmark
    public void bufferSegmentConfined() {
      try (final var scope = ResourceScope.newConfinedScope()) {
!       final var srcBufferSegmentConfined = srcAddress.asSegment(size, scope).asByteBuffer();
!       final var dstBufferSegmentConfined = dstAddress.asSegment(size, scope).asByteBuffer();
  
        for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
          var v = ShortVector.fromByteBuffer(SPECIES, srcBufferSegmentConfined, i, ByteOrder.nativeOrder());
          v.intoByteBuffer(dstBufferSegmentConfined, i, ByteOrder.nativeOrder());
        }
--- 208,12 ---
    }
  
    @Benchmark
    public void bufferSegmentConfined() {
      try (final var scope = ResourceScope.newConfinedScope()) {
!       final var srcBufferSegmentConfined = MemorySegment.ofAddressNative(srcAddress, size, scope).asByteBuffer();
!       final var dstBufferSegmentConfined = MemorySegment.ofAddressNative(dstAddress, size, scope).asByteBuffer();
  
        for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
          var v = ShortVector.fromByteBuffer(SPECIES, srcBufferSegmentConfined, i, ByteOrder.nativeOrder());
          v.intoByteBuffer(dstBufferSegmentConfined, i, ByteOrder.nativeOrder());
        }
< prev index next >