1 package org.openjdk.bench.vm.gc.barriers.reads;
2
3 import org.openjdk.jmh.annotations.*;
4 import org.openjdk.jmh.infra.Blackhole;
5
6 import java.util.concurrent.TimeUnit;
7
8 @Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
9 @Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
10 @Fork(3)
11 @BenchmarkMode(Mode.AverageTime)
12 @OutputTimeUnit(TimeUnit.NANOSECONDS)
13 @State(Scope.Thread)
14 public class IntenseLoadRefs {
15 public static class Node {
16 volatile Node child;
17 volatile byte[] payload;
18
19 Node(int size) {
20 payload = new byte[size];
21 }
22 }
23
24 @Param({"1024", "4096"})
25 public int treeDepth;
26
27 @Param({"1024", "4096"})
28 public int nodePayloadSize;
29
30 Node[] roots;
31
32 @Setup(Level.Iteration)
33 public void setup() {
34 roots = new Node[treeDepth];
35 for (int i = 0; i < treeDepth; i++) {
36 roots[i] = createTree(nodePayloadSize, 3);
37 }
38 }
39
40 private Node createTree(int payloadSize, int depth) {
41 if (depth == 0) return null;
42 Node n = new Node(payloadSize);
43 n.child = createTree(payloadSize, depth - 1);
44 return n;
45 }
46
47 @Benchmark
48 @BenchmarkMode(Mode.Throughput)
49 @OutputTimeUnit(TimeUnit.MILLISECONDS)
50 @Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
51 @Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
52 @Fork(1)
53 public int traverseLRBarrier() {
54 int sum = 0;
55 for (Node root : roots) {
56 Node n = root;
57 while (n != null) {
58 sum += n.payload[0];
59 n = n.child;
60 }
61 }
62 return sum;
63 }
64 }