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 NullChecks {
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 boolean test_src() {
25         return (src != null);
26     }
27 
28     @Benchmark
29     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
30     public boolean test_src_ref() {
31         return (src != null) && (src.f_Object != null);
32     }
33 
34     static class Target {
35         Object f_Object;
36     }
37 
38 }