< prev index next >

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

Print this page
@@ -20,12 +20,14 @@
   * 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.FunctionDescriptor;
+ import jdk.incubator.foreign.Addressable;
  import jdk.incubator.foreign.CLinker;
+ import jdk.incubator.foreign.FunctionDescriptor;
+ import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.SymbolLookup;
  import jdk.incubator.foreign.ResourceScope;
  import org.openjdk.jmh.annotations.Benchmark;
  import org.openjdk.jmh.annotations.BenchmarkMode;
  import org.openjdk.jmh.annotations.Fork;

@@ -34,43 +36,34 @@
  import org.openjdk.jmh.annotations.OutputTimeUnit;
  import org.openjdk.jmh.annotations.State;
  import org.openjdk.jmh.annotations.Warmup;
  
  import java.lang.invoke.MethodHandle;
- import java.lang.invoke.MethodType;
  import java.util.concurrent.TimeUnit;
  
- import static jdk.incubator.foreign.CLinker.C_DOUBLE;
- import static jdk.incubator.foreign.CLinker.C_INT;
- import static jdk.incubator.foreign.CLinker.C_LONG_LONG;
- import static jdk.incubator.foreign.CLinker.C_VA_LIST;
- import static jdk.incubator.foreign.CLinker.asVarArg;
- 
  @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.NANOSECONDS)
  @Fork(value = 3, jvmArgsAppend = { "--add-modules=jdk.incubator.foreign", "--enable-native-access=ALL-UNNAMED" })
- public class VaList {
+ public class VaList extends CLayouts {
  
-     static final CLinker linker = CLinker.getInstance();
+     static final CLinker linker = CLinker.systemCLinker();
      static {
          System.loadLibrary("VaList");
      }
  
      static final MethodHandle MH_ellipsis;
      static final MethodHandle MH_vaList;
  
      static {
          SymbolLookup lookup = SymbolLookup.loaderLookup();
          MH_ellipsis = linker.downcallHandle(lookup.lookup("ellipsis").get(),
-                 MethodType.methodType(void.class, int.class, int.class, double.class, long.class),
-                 FunctionDescriptor.ofVoid(C_INT, asVarArg(C_INT), asVarArg(C_DOUBLE), asVarArg(C_LONG_LONG)));
+                 FunctionDescriptor.ofVoid(C_INT).asVariadic(C_INT, C_DOUBLE, C_LONG_LONG));
          MH_vaList = linker.downcallHandle(lookup.lookup("vaList").get(),
-                 MethodType.methodType(void.class, int.class, CLinker.VaList.class),
-                 FunctionDescriptor.ofVoid(C_INT, C_VA_LIST));
+                 FunctionDescriptor.ofVoid(C_INT, C_POINTER));
      }
  
      @Benchmark
      public void ellipsis() throws Throwable {
          MH_ellipsis.invokeExact(3,

@@ -78,14 +71,14 @@
      }
  
      @Benchmark
      public void vaList() throws Throwable {
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-             CLinker.VaList vaList = CLinker.VaList.make(b ->
-                     b.vargFromInt(C_INT, 1)
-                             .vargFromDouble(C_DOUBLE, 2D)
-                             .vargFromLong(C_LONG_LONG, 3L), scope);
+             jdk.incubator.foreign.VaList vaList = jdk.incubator.foreign.VaList.make(b ->
+                     b.addVarg(C_INT, 1)
+                             .addVarg(C_DOUBLE, 2D)
+                             .addVarg(C_LONG_LONG, 3L), scope);
              MH_vaList.invokeExact(3,
-                     vaList);
+                     (Addressable)vaList);
          }
      }
  }
< prev index next >