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 MultipleRefFields {
15 
16     Target src;
17 
18     @Setup
19     public void setup() {
20         src = new Target();
21     }
22 
23     @Benchmark
24     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
25     public void test_local(Blackhole bh) {
26         Target s = src;
27         bh.consume(s.x1);
28         bh.consume(s.x2);
29         bh.consume(s.x3);
30         bh.consume(s.x4);
31     }
32 
33     @Benchmark
34     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
35     public void test_field(Blackhole bh) {
36         bh.consume(src.x1);
37         bh.consume(src.x2);
38         bh.consume(src.x3);
39         bh.consume(src.x4);
40     }
41 
42     static class Target {
43         Object x1;
44         Object x2;
45         Object x3;
46         Object x4;
47     }
48 
49 
50 }