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 CallOverheadVirtual {
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_v.invokeExact(func_addr);
55 }
56
57 @Benchmark
58 public void panama_blank_trivial() throws Throwable {
59 func_trivial_v.invokeExact(func_addr);
60 }
61
62 @Benchmark
63 public int jni_identity() throws Throwable {
64 return identity(10);
65 }
66
67 public MemorySegment panama_identity_struct_confined() throws Throwable {
68 return (MemorySegment) identity_struct_v.invokeExact(identity_struct_addr, recycling_allocator, confinedPoint);
69 }
70
71 @Benchmark
72 public MemorySegment panama_identity_struct_shared() throws Throwable {
73 return (MemorySegment) identity_struct_v.invokeExact(identity_struct_addr, recycling_allocator, sharedPoint);
74 }
75
76 @Benchmark
77 public MemorySegment panama_identity_struct_confined_3() throws Throwable {
78 return (MemorySegment) identity_struct_3_v.invokeExact(identity_struct_3_addr, recycling_allocator, confinedPoint, confinedPoint, confinedPoint);
79 }
92 public MemorySegment panama_identity_memory_address_confined() throws Throwable {
93 return (MemorySegment) identity_memory_address_v.invokeExact(identity_memory_address_addr, confinedPoint);
94 }
95
96 @Benchmark
97 public MemorySegment panama_identity_memory_address_shared_3() throws Throwable {
98 return (MemorySegment) identity_memory_address_3_v.invokeExact(identity_memory_address_3_addr, sharedPoint, sharedPoint, sharedPoint);
99 }
100
101 @Benchmark
102 public MemorySegment panama_identity_memory_address_confined_3() throws Throwable {
103 return (MemorySegment) identity_memory_address_3_v.invokeExact(identity_memory_address_3_addr, confinedPoint, confinedPoint, confinedPoint);
104 }
105
106 @Benchmark
107 public int panama_identity() throws Throwable {
108 return (int) identity_v.invokeExact(identity_addr, 10);
109 }
110
111 @Benchmark
112 public int panama_identity_trivial() throws Throwable {
113 return (int) identity_trivial_v.invokeExact(identity_addr, 10);
114 }
115
116 @Benchmark
117 public MemorySegment panama_identity_struct() throws Throwable {
118 return (MemorySegment) identity_struct_v.invokeExact(identity_struct_addr, recycling_allocator, point);
119 }
120
121 @Benchmark
122 public MemorySegment panama_identity_memory_address_null() throws Throwable {
123 return (MemorySegment) identity_memory_address_v.invokeExact(identity_memory_address_addr, MemorySegment.NULL);
124 }
125
126 @Benchmark
127 public void panama_args_01() throws Throwable {
128 args1_v.invokeExact(args1_addr, 10L);
129 }
130
131 @Benchmark
132 public void panama_args_02() throws Throwable {
133 args2_v.invokeExact(args2_addr, 10L, 11D);
|
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 CallOverheadVirtual {
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_v.invokeExact(func_addr);
55 }
56
57 @Benchmark
58 public void panama_blank_critical() throws Throwable {
59 func_critical_v.invokeExact(func_addr);
60 }
61
62 @Benchmark
63 public int jni_identity() throws Throwable {
64 return identity(10);
65 }
66
67 public MemorySegment panama_identity_struct_confined() throws Throwable {
68 return (MemorySegment) identity_struct_v.invokeExact(identity_struct_addr, recycling_allocator, confinedPoint);
69 }
70
71 @Benchmark
72 public MemorySegment panama_identity_struct_shared() throws Throwable {
73 return (MemorySegment) identity_struct_v.invokeExact(identity_struct_addr, recycling_allocator, sharedPoint);
74 }
75
76 @Benchmark
77 public MemorySegment panama_identity_struct_confined_3() throws Throwable {
78 return (MemorySegment) identity_struct_3_v.invokeExact(identity_struct_3_addr, recycling_allocator, confinedPoint, confinedPoint, confinedPoint);
79 }
92 public MemorySegment panama_identity_memory_address_confined() throws Throwable {
93 return (MemorySegment) identity_memory_address_v.invokeExact(identity_memory_address_addr, confinedPoint);
94 }
95
96 @Benchmark
97 public MemorySegment panama_identity_memory_address_shared_3() throws Throwable {
98 return (MemorySegment) identity_memory_address_3_v.invokeExact(identity_memory_address_3_addr, sharedPoint, sharedPoint, sharedPoint);
99 }
100
101 @Benchmark
102 public MemorySegment panama_identity_memory_address_confined_3() throws Throwable {
103 return (MemorySegment) identity_memory_address_3_v.invokeExact(identity_memory_address_3_addr, confinedPoint, confinedPoint, confinedPoint);
104 }
105
106 @Benchmark
107 public int panama_identity() throws Throwable {
108 return (int) identity_v.invokeExact(identity_addr, 10);
109 }
110
111 @Benchmark
112 public int panama_identity_critical() throws Throwable {
113 return (int) identity_critical_v.invokeExact(identity_addr, 10);
114 }
115
116 @Benchmark
117 public MemorySegment panama_identity_struct() throws Throwable {
118 return (MemorySegment) identity_struct_v.invokeExact(identity_struct_addr, recycling_allocator, point);
119 }
120
121 @Benchmark
122 public MemorySegment panama_identity_memory_address_null() throws Throwable {
123 return (MemorySegment) identity_memory_address_v.invokeExact(identity_memory_address_addr, MemorySegment.NULL);
124 }
125
126 @Benchmark
127 public void panama_args_01() throws Throwable {
128 args1_v.invokeExact(args1_addr, 10L);
129 }
130
131 @Benchmark
132 public void panama_args_02() throws Throwable {
133 args2_v.invokeExact(args2_addr, 10L, 11D);
|