< prev index next >

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

Print this page
@@ -20,11 +20,10 @@
   * 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;

@@ -44,11 +43,14 @@
  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;
+ import static jdk.incubator.foreign.ValueLayout.JAVA_BYTE;
+ import static jdk.incubator.foreign.ValueLayout.JAVA_DOUBLE;
+ 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)

@@ -61,11 +63,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 int UNSAFE_BYTE_BASE = unsafe.arrayBaseOffset(byte[].class);
  
-     static final VarHandle VH_int = MemoryLayout.sequenceLayout(JAVA_INT).varHandle(int.class, sequenceElement());
+     static final VarHandle VH_int = MemoryLayout.sequenceLayout(JAVA_INT).varHandle(sequenceElement());
      MemorySegment segment;
      byte[] base;
  
      ByteBuffer byteBuffer;
  

@@ -77,17 +79,17 @@
          if (polluteProfile) {
              MemorySegment intB = MemorySegment.ofArray(new byte[ALLOC_SIZE]);
              MemorySegment intI = MemorySegment.ofArray(new int[ALLOC_SIZE]);
              MemorySegment intD = MemorySegment.ofArray(new double[ALLOC_SIZE]);
              MemorySegment intF = MemorySegment.ofArray(new float[ALLOC_SIZE]);
-             MemorySegment s = MemorySegment.allocateNative(ALLOC_SIZE, 1, ResourceScope.newConfinedScope(Cleaner.create()));
+             MemorySegment s = MemorySegment.allocateNative(ALLOC_SIZE, 1, ResourceScope.newConfinedScope());
              for (int i = 0; i < ALLOC_SIZE; i++) {
-                 MemoryAccess.setByteAtOffset(intB, i, (byte)i);
-                 MemoryAccess.setIntAtIndex(intI, i, i);
-                 MemoryAccess.setDoubleAtIndex(intD, i, i);
-                 MemoryAccess.setFloatAtIndex(intF, i, i);
-                 MemoryAccess.setByteAtOffset(s, i, (byte) i);
+                 intB.set(JAVA_BYTE, i, (byte)i);
+                 intI.setAtIndex(JAVA_INT, i, i);
+                 intD.setAtIndex(JAVA_DOUBLE, i, i);
+                 intF.setAtIndex(JAVA_FLOAT, i, i);
+                 s.set(JAVA_BYTE, i, (byte) i);
              }
          }
  
          base = new byte[ALLOC_SIZE];
          for (int i = 0; i < ELEM_SIZE; i++) {

@@ -132,14 +134,23 @@
          }
          return sum;
      }
  
      @Benchmark
-     public int segment_loop_static() {
+     public int segment_loop_instance() {
          int res = 0;
          for (int i = 0; i < ELEM_SIZE; i ++) {
-             res += MemoryAccess.getIntAtIndex(segment, 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.address().get(JAVA_INT, i * CARRIER_SIZE);
          }
          return res;
      }
  
      @Benchmark
< prev index next >