1 /*
  2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package org.openjdk.bench.valhalla.acmp.array;
 24 
 25 import org.openjdk.bench.valhalla.types.R64long;
 26 import org.openjdk.jmh.annotations.Benchmark;
 27 import org.openjdk.jmh.annotations.BenchmarkMode;
 28 import org.openjdk.jmh.annotations.CompilerControl;
 29 import org.openjdk.jmh.annotations.Fork;
 30 import org.openjdk.jmh.annotations.Measurement;
 31 import org.openjdk.jmh.annotations.Mode;
 32 import org.openjdk.jmh.annotations.OperationsPerInvocation;
 33 import org.openjdk.jmh.annotations.OutputTimeUnit;
 34 import org.openjdk.jmh.annotations.Scope;
 35 import org.openjdk.jmh.annotations.State;
 36 import org.openjdk.jmh.annotations.Warmup;
 37 
 38 import java.util.concurrent.TimeUnit;
 39 
 40 /*
 41  *  For proper results it should be executed:
 42  *  java -jar target/benchmarks.jar IdentityIsCmpBranch  -wmb IdentityIsCmpBranch.equals050
 43  */
 44 
 45 @Fork(3)
 46 @Warmup(iterations = 3, time = 1)
 47 @Measurement(iterations = 5, time = 1)
 48 @OutputTimeUnit(TimeUnit.NANOSECONDS)
 49 @BenchmarkMode(Mode.AverageTime)
 50 @State(Scope.Thread)
 51 public class IdentityIsCmpBranch extends StatesR64long {
 52 
 53     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 54     private static int cmp_Obj(Object[] objects1, Object[] objects2) {
 55         int s = 0;
 56         for (int i = 0; i < SIZE; i++) {
 57             if (objects1[i] == objects2[i]) {
 58                 s += 1;
 59             } else {
 60                 s -= 1;
 61             }
 62         }
 63         return s;
 64     }
 65 
 66     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 67     private static int cmp_Ref(R64long[] objects1, R64long[] objects2) {
 68         int s = 0;
 69         for (int i = 0; i < SIZE; i++) {
 70             if (objects1[i] == objects2[i]) {
 71                 s += 1;
 72             } else {
 73                 s -= 1;
 74             }
 75         }
 76         return s;
 77     }
 78 
 79     @Benchmark
 80     @OperationsPerInvocation(SIZE)
 81     @CompilerControl(CompilerControl.Mode.INLINE)
 82     public int Obj_equals000(ObjState00 st) {
 83         return cmp_Obj(st.arr1, st.arr2);
 84     }
 85 
 86     @Benchmark
 87     @OperationsPerInvocation(SIZE)
 88     @CompilerControl(CompilerControl.Mode.INLINE)
 89     public int Obj_equals025(ObjState25 st) {
 90         return cmp_Obj(st.arr1, st.arr2);
 91     }
 92 
 93     @Benchmark
 94     @OperationsPerInvocation(SIZE)
 95     @CompilerControl(CompilerControl.Mode.INLINE)
 96     public int Obj_equals050(ObjState50 st) {
 97         return cmp_Obj(st.arr1, st.arr2);
 98     }
 99 
100     @Benchmark
101     @OperationsPerInvocation(SIZE)
102     @CompilerControl(CompilerControl.Mode.INLINE)
103     public int Obj_equals075(ObjState75 st) {
104         return cmp_Obj(st.arr1, st.arr2);
105     }
106 
107     @Benchmark
108     @OperationsPerInvocation(SIZE)
109     @CompilerControl(CompilerControl.Mode.INLINE)
110     public int Obj_equals100(ObjState100 st) {
111         return cmp_Obj(st.arr1, st.arr2);
112     }
113 
114     @Benchmark
115     @OperationsPerInvocation(SIZE)
116     @CompilerControl(CompilerControl.Mode.INLINE)
117     public int Ref_equals000(RefState00 st) {
118         return cmp_Ref(st.arr1, st.arr2);
119     }
120 
121     @Benchmark
122     @OperationsPerInvocation(SIZE)
123     @CompilerControl(CompilerControl.Mode.INLINE)
124     public int Ref_equals025(RefState25 st) {
125         return cmp_Ref(st.arr1, st.arr2);
126     }
127 
128     @Benchmark
129     @OperationsPerInvocation(SIZE)
130     @CompilerControl(CompilerControl.Mode.INLINE)
131     public int Ref_equals050(RefState50 st) {
132         return cmp_Ref(st.arr1, st.arr2);
133     }
134 
135     @Benchmark
136     @OperationsPerInvocation(SIZE)
137     @CompilerControl(CompilerControl.Mode.INLINE)
138     public int Ref_equals075(RefState75 st) {
139         return cmp_Ref(st.arr1, st.arr2);
140     }
141 
142     @Benchmark
143     @OperationsPerInvocation(SIZE)
144     @CompilerControl(CompilerControl.Mode.INLINE)
145     public int Ref_equals100(RefState100 st) {
146         return cmp_Ref(st.arr1, st.arr2);
147     }
148 
149 }