< prev index next >

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

*** 44,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)
--- 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.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 ***
      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());
      MemorySegment segment;
      byte[] base;
  
      ByteBuffer byteBuffer;
  
--- 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(sequenceElement());
      MemorySegment segment;
      byte[] base;
  
      ByteBuffer byteBuffer;
  

*** 77,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()));
              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);
              }
          }
  
          base = new byte[ALLOC_SIZE];
          for (int i = 0; i < ELEM_SIZE; i++) {
--- 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());
              for (int i = 0; i < ALLOC_SIZE; 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 ***
          }
          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
--- 134,14 ---
          }
          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
< prev index next >