< prev index next >

test/micro/org/openjdk/bench/jdk/incubator/foreign/LoopOverNonConstantShared.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 ---

*** 42,11 ***
  import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  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)
--- 41,11 ---
  import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  import java.util.concurrent.TimeUnit;
  
  import static jdk.incubator.foreign.MemoryLayout.PathElement.sequenceElement;
! 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)

*** 58,11 ***
  
      static final int ELEM_SIZE = 1_000_000;
      static final int CARRIER_SIZE = (int)JAVA_INT.byteSize();
      static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
  
!     static final VarHandle VH_int = MemoryLayout.sequenceLayout(JAVA_INT).varHandle(int.class, sequenceElement());
      MemorySegment segment;
      long unsafe_addr;
  
      ByteBuffer byteBuffer;
  
--- 57,11 ---
  
      static final int ELEM_SIZE = 1_000_000;
      static final int CARRIER_SIZE = (int)JAVA_INT.byteSize();
      static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
  
!     static final VarHandle VH_int = MemoryLayout.sequenceLayout(JAVA_INT).varHandle(sequenceElement());
      MemorySegment segment;
      long unsafe_addr;
  
      ByteBuffer byteBuffer;
  

*** 70,11 ***
      public void setup() {
          unsafe_addr = unsafe.allocateMemory(ALLOC_SIZE);
          for (int i = 0; i < ELEM_SIZE; i++) {
              unsafe.putInt(unsafe_addr + (i * CARRIER_SIZE) , i);
          }
!         segment = MemorySegment.allocateNative(ALLOC_SIZE, CARRIER_SIZE, ResourceScope.newSharedScope());
          for (int i = 0; i < ELEM_SIZE; i++) {
              VH_int.set(segment, (long) i, i);
          }
          byteBuffer = ByteBuffer.allocateDirect(ALLOC_SIZE).order(ByteOrder.nativeOrder());
          for (int i = 0; i < ELEM_SIZE; i++) {
--- 69,11 ---
      public void setup() {
          unsafe_addr = unsafe.allocateMemory(ALLOC_SIZE);
          for (int i = 0; i < ELEM_SIZE; i++) {
              unsafe.putInt(unsafe_addr + (i * CARRIER_SIZE) , i);
          }
!         segment = MemorySegment.allocateNative(ALLOC_SIZE, CARRIER_SIZE, ResourceScope.newConfinedScope());
          for (int i = 0; i < ELEM_SIZE; i++) {
              VH_int.set(segment, (long) i, i);
          }
          byteBuffer = ByteBuffer.allocateDirect(ALLOC_SIZE).order(ByteOrder.nativeOrder());
          for (int i = 0; i < ELEM_SIZE; i++) {

*** 115,14 ***
          }
          return res;
      }
  
      @Benchmark
!     public int segment_loop_static() {
          int res = 0;
          for (int i = 0; i < ELEM_SIZE; i ++) {
!             res += MemoryAccess.getIntAtIndex(segment, i);
          }
          return res;
      }
  
      @Benchmark
--- 114,23 ---
          }
          return res;
      }
  
      @Benchmark
!     public int segment_loop_instance() {
          int res = 0;
          for (int i = 0; i < ELEM_SIZE; i ++) {
!             res += segment.get(JAVA_INT, i * CARRIER_SIZE);
+         }
+         return res;
+     }
+ 
+     @Benchmark
+     public int segment_loop_instance_address() {
+         int res = 0;
+         for (int i = 0; i < ELEM_SIZE; i ++) {
+             res += segment.get(JAVA_INT, i * CARRIER_SIZE);
          }
          return res;
      }
  
      @Benchmark
< prev index next >