1 package org.openjdk.bench.vm.gc.barriers.reads;
2
3 import org.openjdk.jmh.annotations.*;
4
5 import java.util.concurrent.TimeUnit;
6
7 @Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
8 @Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
9 @Fork(3)
10 @BenchmarkMode(Mode.AverageTime)
11 @OutputTimeUnit(TimeUnit.NANOSECONDS)
12 @State(Scope.Thread)
13 public class MultipleIntFields {
14
15 Target src;
16
17 @Setup
18 public void setup() {
19 src = new Target();
20 }
21
22 @Benchmark
23 @CompilerControl(CompilerControl.Mode.DONT_INLINE)
24 public int test_local() {
25 Target s = src;
26 return s.x1 + s.x2 + s.x3 + s.x4;
27 }
28
29 @Benchmark
30 @CompilerControl(CompilerControl.Mode.DONT_INLINE)
31 public int test_field() {
32 return src.x1 + src.x2 + src.x3 + src.x4;
33 }
34
35 static class Target {
36 int x1;
37 int x2;
38 int x3;
39 int x4;
40 }
41
42
43 }