< prev index next >

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

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 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 ---

*** 49,18 ***
  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;
  
  @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.MILLISECONDS)
! @Fork(value = 3, jvmArgsAppend = { "--add-modules=jdk.incubator.foreign" })
  public class LoopOverNonConstantMapped {
  
      static final Unsafe unsafe = Utils.unsafe;
  
      static final int ELEM_SIZE = 1_000_000;
--- 48,18 ---
  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.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)
  @OutputTimeUnit(TimeUnit.MILLISECONDS)
! @Fork(value = 3, jvmArgsAppend = { "--add-modules=jdk.incubator.foreign", "--enable-native-access=ALL-UNNAMED" })
  public class LoopOverNonConstantMapped {
  
      static final Unsafe unsafe = Utils.unsafe;
  
      static final int ELEM_SIZE = 1_000_000;

*** 79,11 ***
          } catch (IOException ex) {
              throw new ExceptionInInitializerError(ex);
          }
      }
  
!     static final VarHandle VH_int = MemoryLayout.sequenceLayout(JAVA_INT).varHandle(int.class, sequenceElement());
      MemorySegment segment;
      long unsafe_addr;
  
      ByteBuffer byteBuffer;
  
--- 78,11 ---
          } catch (IOException ex) {
              throw new ExceptionInInitializerError(ex);
          }
      }
  
!     static final VarHandle VH_int = MemoryLayout.sequenceLayout(JAVA_INT).varHandle(sequenceElement());
      MemorySegment segment;
      long unsafe_addr;
  
      ByteBuffer byteBuffer;
  

*** 141,14 ***
          }
          return sum;
      }
  
      @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
--- 140,23 ---
          }
          return sum;
      }
  
      @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.address().get(JAVA_INT, i * CARRIER_SIZE);
          }
          return res;
      }
  
      @Benchmark
< prev index next >