34 import org.openjdk.jmh.annotations.Setup;
35 import org.openjdk.jmh.annotations.State;
36 import org.openjdk.jmh.annotations.TearDown;
37 import org.openjdk.jmh.annotations.Warmup;
38 import sun.misc.Unsafe;
39
40 import java.lang.foreign.Arena;
41 import java.lang.foreign.MemorySegment;
42 import java.nio.ByteBuffer;
43 import java.nio.IntBuffer;
44 import java.util.concurrent.TimeUnit;
45
46 import static java.lang.foreign.ValueLayout.JAVA_INT;
47 import static java.lang.foreign.ValueLayout.JAVA_INT_UNALIGNED;
48
49 @BenchmarkMode(Mode.AverageTime)
50 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
51 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
52 @State(org.openjdk.jmh.annotations.Scope.Thread)
53 @OutputTimeUnit(TimeUnit.MILLISECONDS)
54 @Fork(value = 3, jvmArgsAppend = "--enable-preview")
55 public class BulkOps {
56
57 static final Unsafe unsafe = Utils.unsafe;
58
59 static final int ELEM_SIZE = 1_000_000;
60 static final int CARRIER_SIZE = (int)JAVA_INT.byteSize();
61 static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
62
63 final Arena arena = Arena.ofShared();
64
65 final long unsafe_addr = unsafe.allocateMemory(ALLOC_SIZE);
66 final MemorySegment segment = arena.allocate(ALLOC_SIZE, 1);
67
68 final IntBuffer buffer = IntBuffer.allocate(ELEM_SIZE);
69
70 final int[] ints = new int[ELEM_SIZE];
71 final MemorySegment bytesSegment = MemorySegment.ofArray(ints);
72 final int UNSAFE_INT_OFFSET = unsafe.arrayBaseOffset(int[].class);
73
74 // large(ish) segments/buffers with same content, 0, for mismatch, non-multiple-of-8 sized
|
34 import org.openjdk.jmh.annotations.Setup;
35 import org.openjdk.jmh.annotations.State;
36 import org.openjdk.jmh.annotations.TearDown;
37 import org.openjdk.jmh.annotations.Warmup;
38 import sun.misc.Unsafe;
39
40 import java.lang.foreign.Arena;
41 import java.lang.foreign.MemorySegment;
42 import java.nio.ByteBuffer;
43 import java.nio.IntBuffer;
44 import java.util.concurrent.TimeUnit;
45
46 import static java.lang.foreign.ValueLayout.JAVA_INT;
47 import static java.lang.foreign.ValueLayout.JAVA_INT_UNALIGNED;
48
49 @BenchmarkMode(Mode.AverageTime)
50 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
51 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
52 @State(org.openjdk.jmh.annotations.Scope.Thread)
53 @OutputTimeUnit(TimeUnit.MILLISECONDS)
54 @Fork(3)
55 public class BulkOps {
56
57 static final Unsafe unsafe = Utils.unsafe;
58
59 static final int ELEM_SIZE = 1_000_000;
60 static final int CARRIER_SIZE = (int)JAVA_INT.byteSize();
61 static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
62
63 final Arena arena = Arena.ofShared();
64
65 final long unsafe_addr = unsafe.allocateMemory(ALLOC_SIZE);
66 final MemorySegment segment = arena.allocate(ALLOC_SIZE, 1);
67
68 final IntBuffer buffer = IntBuffer.allocate(ELEM_SIZE);
69
70 final int[] ints = new int[ELEM_SIZE];
71 final MemorySegment bytesSegment = MemorySegment.ofArray(ints);
72 final int UNSAFE_INT_OFFSET = unsafe.arrayBaseOffset(int[].class);
73
74 // large(ish) segments/buffers with same content, 0, for mismatch, non-multiple-of-8 sized
|