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, jvmArgs = { "--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED" })
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 long UNSAFE_INT_OFFSET = unsafe.arrayBaseOffset(int[].class);
73
74 // large(ish) segments/buffers with same content, 0, for mismatch, non-multiple-of-8 sized
75 static final int SIZE_WITH_TAIL = (1024 * 1024) + 7;
76 final MemorySegment mismatchSegmentLarge1;
77
78 {
79 mismatchSegmentLarge1 = arena.allocate(SIZE_WITH_TAIL, 1);
80 }
81
82 final MemorySegment mismatchSegmentLarge2 = arena.allocate(SIZE_WITH_TAIL, 1);
83 final ByteBuffer mismatchBufferLarge1 = ByteBuffer.allocateDirect(SIZE_WITH_TAIL);
84 final ByteBuffer mismatchBufferLarge2 = ByteBuffer.allocateDirect(SIZE_WITH_TAIL);
85
86 // mismatch at first byte
87 final MemorySegment mismatchSegmentSmall1 = arena.allocate(7, 1);
88 final MemorySegment mismatchSegmentSmall2 = arena.allocate(7, 1);
89 final ByteBuffer mismatchBufferSmall1 = ByteBuffer.allocateDirect(7);
90 final ByteBuffer mismatchBufferSmall2 = ByteBuffer.allocateDirect(7);
|
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, jvmArgs = { "--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED" })
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 @SuppressWarnings("initialization")
72 final MemorySegment bytesSegment = MemorySegment.ofArray(ints);
73 final long UNSAFE_INT_OFFSET = unsafe.arrayBaseOffset(int[].class);
74
75 // large(ish) segments/buffers with same content, 0, for mismatch, non-multiple-of-8 sized
76 static final int SIZE_WITH_TAIL = (1024 * 1024) + 7;
77 final MemorySegment mismatchSegmentLarge1;
78
79 {
80 mismatchSegmentLarge1 = arena.allocate(SIZE_WITH_TAIL, 1);
81 }
82
83 final MemorySegment mismatchSegmentLarge2 = arena.allocate(SIZE_WITH_TAIL, 1);
84 final ByteBuffer mismatchBufferLarge1 = ByteBuffer.allocateDirect(SIZE_WITH_TAIL);
85 final ByteBuffer mismatchBufferLarge2 = ByteBuffer.allocateDirect(SIZE_WITH_TAIL);
86
87 // mismatch at first byte
88 final MemorySegment mismatchSegmentSmall1 = arena.allocate(7, 1);
89 final MemorySegment mismatchSegmentSmall2 = arena.allocate(7, 1);
90 final ByteBuffer mismatchBufferSmall1 = ByteBuffer.allocateDirect(7);
91 final ByteBuffer mismatchBufferSmall2 = ByteBuffer.allocateDirect(7);
|