< prev index next >

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

Print this page
*** 20,11 ***
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  package org.openjdk.bench.jdk.incubator.foreign;
  
- import jdk.incubator.foreign.MemoryAccess;
  import jdk.incubator.foreign.MemoryLayout;
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import org.openjdk.jmh.annotations.Benchmark;
  import org.openjdk.jmh.annotations.BenchmarkMode;
--- 20,10 ---

*** 40,11 ***
  
  import java.lang.invoke.VarHandle;
  import java.util.concurrent.TimeUnit;
  
  import static jdk.incubator.foreign.MemoryLayout.PathElement.sequenceElement;
! import static jdk.incubator.foreign.MemoryLayouts.JAVA_INT;
  
  @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)
--- 39,12 ---
  
  import java.lang.invoke.VarHandle;
  import java.util.concurrent.TimeUnit;
  
  import static jdk.incubator.foreign.MemoryLayout.PathElement.sequenceElement;
! import static jdk.incubator.foreign.ValueLayout.JAVA_FLOAT;
+ import static jdk.incubator.foreign.ValueLayout.JAVA_INT;
  
  @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)

*** 60,11 ***
  
      MemorySegment nativeSegment, heapSegmentBytes, heapSegmentFloats;
      byte[] arr;
      long addr;
  
!     static final VarHandle intHandle = MemoryLayout.sequenceLayout(JAVA_INT).varHandle(int.class, MemoryLayout.PathElement.sequenceElement());
  
  
      @Setup
      public void setup() {
          addr = unsafe.allocateMemory(ALLOC_SIZE);
--- 60,11 ---
  
      MemorySegment nativeSegment, heapSegmentBytes, heapSegmentFloats;
      byte[] arr;
      long addr;
  
!     static final VarHandle intHandle = MemoryLayout.sequenceLayout(JAVA_INT).varHandle(MemoryLayout.PathElement.sequenceElement());
  
  
      @Setup
      public void setup() {
          addr = unsafe.allocateMemory(ALLOC_SIZE);

*** 77,18 ***
          heapSegmentFloats = MemorySegment.ofArray(new float[ELEM_SIZE]);
  
          for (int rep = 0 ; rep < 5 ; rep++) {
              for (int i = 0; i < ELEM_SIZE; i++) {
                  unsafe.putInt(arr, Unsafe.ARRAY_BYTE_BASE_OFFSET + (i * 4), i);
!                 MemoryAccess.setIntAtIndex(nativeSegment, i, i);
!                 MemoryAccess.setFloatAtIndex(nativeSegment, i, i);
                  intHandle.set(nativeSegment, (long)i, i);
!                 MemoryAccess.setIntAtIndex(heapSegmentBytes, i, i);
!                 MemoryAccess.setFloatAtIndex(heapSegmentBytes, i, i);
                  intHandle.set(heapSegmentBytes, (long)i, i);
!                 MemoryAccess.setIntAtIndex(heapSegmentFloats, i, i);
!                 MemoryAccess.setFloatAtIndex(heapSegmentFloats, i, i);
                  intHandle.set(heapSegmentFloats, (long)i, i);
              }
          }
      }
  
--- 77,18 ---
          heapSegmentFloats = MemorySegment.ofArray(new float[ELEM_SIZE]);
  
          for (int rep = 0 ; rep < 5 ; rep++) {
              for (int i = 0; i < ELEM_SIZE; i++) {
                  unsafe.putInt(arr, Unsafe.ARRAY_BYTE_BASE_OFFSET + (i * 4), i);
!                 nativeSegment.setAtIndex(JAVA_INT, i, i);
!                 nativeSegment.setAtIndex(JAVA_FLOAT, i, i);
                  intHandle.set(nativeSegment, (long)i, i);
!                 heapSegmentBytes.setAtIndex(JAVA_INT, i, i);
!                 heapSegmentBytes.setAtIndex(JAVA_FLOAT, i, i);
                  intHandle.set(heapSegmentBytes, (long)i, i);
!                 heapSegmentFloats.setAtIndex(JAVA_INT, i, i);
!                 heapSegmentFloats.setAtIndex(JAVA_FLOAT, i, i);
                  intHandle.set(heapSegmentFloats, (long)i, i);
              }
          }
      }
  

*** 111,15 ***
          }
          return sum;
      }
  
      @Benchmark
!     public int native_segment_static() {
          int sum = 0;
          for (int k = 0; k < ELEM_SIZE; k++) {
!             MemoryAccess.setIntAtOffset(nativeSegment, k, k + 1);
!             int v = MemoryAccess.getIntAtOffset(nativeSegment, k);
              sum += v;
          }
          return sum;
      }
  
--- 111,15 ---
          }
          return sum;
      }
  
      @Benchmark
!     public int native_segment_instance() {
          int sum = 0;
          for (int k = 0; k < ELEM_SIZE; k++) {
!             nativeSegment.setAtIndex(JAVA_INT, k, k + 1);
!             int v = nativeSegment.getAtIndex(JAVA_INT, k);
              sum += v;
          }
          return sum;
      }
  

*** 133,15 ***
          }
          return sum;
      }
  
      @Benchmark
!     public int heap_segment_ints_static() {
          int sum = 0;
          for (int k = 0; k < ELEM_SIZE; k++) {
!             MemoryAccess.setIntAtOffset(heapSegmentBytes, k, k + 1);
!             int v = MemoryAccess.getIntAtOffset(heapSegmentBytes, k);
              sum += v;
          }
          return sum;
      }
  
--- 133,15 ---
          }
          return sum;
      }
  
      @Benchmark
!     public int heap_segment_ints_instance() {
          int sum = 0;
          for (int k = 0; k < ELEM_SIZE; k++) {
!             heapSegmentBytes.setAtIndex(JAVA_INT, k, k + 1);
!             int v = heapSegmentBytes.getAtIndex(JAVA_INT, k);
              sum += v;
          }
          return sum;
      }
  

*** 155,15 ***
          }
          return sum;
      }
  
      @Benchmark
!     public int heap_segment_floats_static() {
          int sum = 0;
          for (int k = 0; k < ELEM_SIZE; k++) {
!             MemoryAccess.setIntAtOffset(heapSegmentFloats, k, k + 1);
!             int v = MemoryAccess.getIntAtOffset(heapSegmentFloats, k);
              sum += v;
          }
          return sum;
      }
  
--- 155,15 ---
          }
          return sum;
      }
  
      @Benchmark
!     public int heap_segment_floats_instance() {
          int sum = 0;
          for (int k = 0; k < ELEM_SIZE; k++) {
!             heapSegmentFloats.setAtIndex(JAVA_INT, k, k + 1);
!             int v = heapSegmentFloats.getAtIndex(JAVA_INT, k);
              sum += v;
          }
          return sum;
      }
  
< prev index next >