24
25 import java.lang.foreign.MemorySegment;
26 import org.openjdk.jmh.annotations.Benchmark;
27 import org.openjdk.jmh.annotations.BenchmarkMode;
28 import org.openjdk.jmh.annotations.Fork;
29 import org.openjdk.jmh.annotations.Measurement;
30 import org.openjdk.jmh.annotations.Mode;
31 import org.openjdk.jmh.annotations.OutputTimeUnit;
32 import org.openjdk.jmh.annotations.State;
33 import org.openjdk.jmh.annotations.Warmup;
34
35 import java.util.concurrent.TimeUnit;
36
37 import static org.openjdk.bench.java.lang.foreign.CallOverheadHelper.*;
38
39 @BenchmarkMode(Mode.AverageTime)
40 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
41 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
42 @State(org.openjdk.jmh.annotations.Scope.Thread)
43 @OutputTimeUnit(TimeUnit.NANOSECONDS)
44 @Fork(value = 3, jvmArgsAppend = { "--enable-native-access=ALL-UNNAMED", "--enable-preview" })
45 public class CallOverheadConstant {
46
47 @Benchmark
48 public void jni_blank() throws Throwable {
49 blank();
50 }
51
52 @Benchmark
53 public void panama_blank() throws Throwable {
54 func.invokeExact();
55 }
56
57 @Benchmark
58 public void panama_blank_trivial() throws Throwable {
59 func_trivial.invokeExact();
60 }
61
62 @Benchmark
63 public int jni_identity() throws Throwable {
64 return identity(10);
65 }
66
67 @Benchmark
68 public int panama_identity() throws Throwable {
69 return (int) identity.invokeExact(10);
70 }
71
72 @Benchmark
73 public int panama_identity_trivial() throws Throwable {
74 return (int) identity_trivial.invokeExact(10);
75 }
76
77 @Benchmark
78 public MemorySegment panama_identity_struct_confined() throws Throwable {
79 return (MemorySegment) identity_struct.invokeExact(recycling_allocator, confinedPoint);
80 }
81
82 @Benchmark
83 public MemorySegment panama_identity_struct_shared() throws Throwable {
84 return (MemorySegment) identity_struct.invokeExact(recycling_allocator, sharedPoint);
85 }
86
87 @Benchmark
88 public MemorySegment panama_identity_struct_confined_3() throws Throwable {
89 return (MemorySegment) identity_struct_3.invokeExact(recycling_allocator, confinedPoint, confinedPoint, confinedPoint);
90 }
91
92 @Benchmark
93 public MemorySegment panama_identity_struct_shared_3() throws Throwable {
94 return (MemorySegment) identity_struct_3.invokeExact(recycling_allocator, sharedPoint, sharedPoint, sharedPoint);
|
24
25 import java.lang.foreign.MemorySegment;
26 import org.openjdk.jmh.annotations.Benchmark;
27 import org.openjdk.jmh.annotations.BenchmarkMode;
28 import org.openjdk.jmh.annotations.Fork;
29 import org.openjdk.jmh.annotations.Measurement;
30 import org.openjdk.jmh.annotations.Mode;
31 import org.openjdk.jmh.annotations.OutputTimeUnit;
32 import org.openjdk.jmh.annotations.State;
33 import org.openjdk.jmh.annotations.Warmup;
34
35 import java.util.concurrent.TimeUnit;
36
37 import static org.openjdk.bench.java.lang.foreign.CallOverheadHelper.*;
38
39 @BenchmarkMode(Mode.AverageTime)
40 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
41 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
42 @State(org.openjdk.jmh.annotations.Scope.Thread)
43 @OutputTimeUnit(TimeUnit.NANOSECONDS)
44 @Fork(value = 3, jvmArgsAppend = { "--enable-native-access=ALL-UNNAMED" })
45 public class CallOverheadConstant {
46
47 @Benchmark
48 public void jni_blank() throws Throwable {
49 blank();
50 }
51
52 @Benchmark
53 public void panama_blank() throws Throwable {
54 func.invokeExact();
55 }
56
57 @Benchmark
58 public void panama_blank_critical() throws Throwable {
59 func_critical.invokeExact();
60 }
61
62 @Benchmark
63 public int jni_identity() throws Throwable {
64 return identity(10);
65 }
66
67 @Benchmark
68 public int panama_identity() throws Throwable {
69 return (int) identity.invokeExact(10);
70 }
71
72 @Benchmark
73 public int panama_identity_critical() throws Throwable {
74 return (int) identity_critical.invokeExact(10);
75 }
76
77 @Benchmark
78 public MemorySegment panama_identity_struct_confined() throws Throwable {
79 return (MemorySegment) identity_struct.invokeExact(recycling_allocator, confinedPoint);
80 }
81
82 @Benchmark
83 public MemorySegment panama_identity_struct_shared() throws Throwable {
84 return (MemorySegment) identity_struct.invokeExact(recycling_allocator, sharedPoint);
85 }
86
87 @Benchmark
88 public MemorySegment panama_identity_struct_confined_3() throws Throwable {
89 return (MemorySegment) identity_struct_3.invokeExact(recycling_allocator, confinedPoint, confinedPoint, confinedPoint);
90 }
91
92 @Benchmark
93 public MemorySegment panama_identity_struct_shared_3() throws Throwable {
94 return (MemorySegment) identity_struct_3.invokeExact(recycling_allocator, sharedPoint, sharedPoint, sharedPoint);
|