< prev index next >

test/micro/org/openjdk/bench/jdk/incubator/foreign/UnrolledAccess.java

Print this page
*** 21,21 ***
   * questions.
   */
  
  package org.openjdk.bench.jdk.incubator.foreign;
  
- import static jdk.incubator.foreign.MemoryAccess.*;
  import jdk.incubator.foreign.*;
  import org.openjdk.jmh.annotations.*;
  import org.openjdk.jmh.runner.Runner;
  import org.openjdk.jmh.runner.options.Options;
  import org.openjdk.jmh.runner.options.OptionsBuilder;
  import sun.misc.Unsafe;
  import java.util.concurrent.TimeUnit;
  
  import java.lang.invoke.VarHandle;
  
  @BenchmarkMode(Mode.AverageTime)
  @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
  @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
  @State(org.openjdk.jmh.annotations.Scope.Thread)
  @OutputTimeUnit(TimeUnit.MICROSECONDS)
--- 21,22 ---
   * questions.
   */
  
  package org.openjdk.bench.jdk.incubator.foreign;
  
  import jdk.incubator.foreign.*;
  import org.openjdk.jmh.annotations.*;
  import org.openjdk.jmh.runner.Runner;
  import org.openjdk.jmh.runner.options.Options;
  import org.openjdk.jmh.runner.options.OptionsBuilder;
  import sun.misc.Unsafe;
  import java.util.concurrent.TimeUnit;
  
  import java.lang.invoke.VarHandle;
  
+ import static jdk.incubator.foreign.ValueLayout.JAVA_LONG;
+ 
  @BenchmarkMode(Mode.AverageTime)
  @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
  @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
  @State(org.openjdk.jmh.annotations.Scope.Thread)
  @OutputTimeUnit(TimeUnit.MICROSECONDS)

*** 44,12 ***
  
      static final Unsafe U = Utils.unsafe;
  
      final static int SIZE = 1024;
  
!     static final VarHandle LONG_HANDLE = MemoryLayout.sequenceLayout(SIZE, MemoryLayouts.JAVA_LONG)
!             .varHandle(long.class, MemoryLayout.PathElement.sequenceElement());
  
      @State(Scope.Benchmark)
      public static class Data {
  
          final double[] inputArray;
--- 45,12 ---
  
      static final Unsafe U = Utils.unsafe;
  
      final static int SIZE = 1024;
  
!     static final VarHandle LONG_HANDLE = MemoryLayout.sequenceLayout(SIZE, JAVA_LONG)
!             .varHandle(MemoryLayout.PathElement.sequenceElement());
  
      @State(Scope.Benchmark)
      public static class Data {
  
          final double[] inputArray;

*** 63,12 ***
          public Data() {
              this.inputArray = new double[SIZE];
              this.outputArray = new double[SIZE];
              this.inputAddress = U.allocateMemory(8 * SIZE);
              this.outputAddress = U.allocateMemory(8 * SIZE);
!             this.inputSegment = MemoryAddress.ofLong(inputAddress).asSegment(8*SIZE, ResourceScope.globalScope());
!             this.outputSegment = MemoryAddress.ofLong(outputAddress).asSegment(8*SIZE, ResourceScope.globalScope());
          }
      }
  
      @Benchmark
      public void unsafe_loop(Data state) {
--- 64,12 ---
          public Data() {
              this.inputArray = new double[SIZE];
              this.outputArray = new double[SIZE];
              this.inputAddress = U.allocateMemory(8 * SIZE);
              this.outputAddress = U.allocateMemory(8 * SIZE);
!             this.inputSegment = MemorySegment.ofAddressNative(MemoryAddress.ofLong(inputAddress), 8*SIZE, ResourceScope.globalScope());
!             this.outputSegment = MemorySegment.ofAddressNative(MemoryAddress.ofLong(outputAddress), 8*SIZE, ResourceScope.globalScope());
          }
      }
  
      @Benchmark
      public void unsafe_loop(Data state) {

*** 94,17 ***
              LONG_HANDLE.set(os, (long) (i+3), (long) LONG_HANDLE.get(is, (long) (i+3)) + (long) LONG_HANDLE.get(os, (long) (i+3)));
          }
      }
  
      @Benchmark
!     public void static_handle_loop(Data state) {
          final MemorySegment is = state.inputSegment;
          final MemorySegment os = state.outputSegment;
  
          for(int i = 0; i < SIZE; i+=4) {
!             setLongAtIndex(os, i,getLongAtIndex(is, i) + MemoryAccess.getLongAtIndex(os, i));
!             setLongAtIndex(os, i+1,getLongAtIndex(is, i+1) + getLongAtIndex(os, i+1));
!             setLongAtIndex(os, i+2,getLongAtIndex(is, i+2) + getLongAtIndex(os, i+2));
!             setLongAtIndex(os, i+3,getLongAtIndex(is, i+3) + getLongAtIndex(os, i+3));
          }
      }
  }
--- 95,17 ---
              LONG_HANDLE.set(os, (long) (i+3), (long) LONG_HANDLE.get(is, (long) (i+3)) + (long) LONG_HANDLE.get(os, (long) (i+3)));
          }
      }
  
      @Benchmark
!     public void handle_loop_instance(Data state) {
          final MemorySegment is = state.inputSegment;
          final MemorySegment os = state.outputSegment;
  
          for(int i = 0; i < SIZE; i+=4) {
!             os.setAtIndex(JAVA_LONG, i, is.getAtIndex(JAVA_LONG, i) + os.get(JAVA_LONG, i));
!             os.setAtIndex(JAVA_LONG, i+1, is.getAtIndex(JAVA_LONG, i+1) + os.get(JAVA_LONG, i+1));
!             os.setAtIndex(JAVA_LONG, i+2, is.getAtIndex(JAVA_LONG, i+2) + os.get(JAVA_LONG, i+2));
!             os.setAtIndex(JAVA_LONG, i+3, is.getAtIndex(JAVA_LONG, i+3) + os.get(JAVA_LONG, i+3));
          }
      }
  }
< prev index next >