< prev index next >

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

@@ -49,11 +48,11 @@
  import java.nio.file.Path;
  import java.nio.file.StandardOpenOption;
  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_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)

@@ -79,11 +78,11 @@
          } catch (IOException ex) {
              throw new ExceptionInInitializerError(ex);
          }
      }
  
-     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;
      long unsafe_addr;
  
      ByteBuffer byteBuffer;
  

@@ -141,14 +140,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 >