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.field;
 24 
 25 import org.openjdk.jmh.annotations.Benchmark;
 26 import org.openjdk.jmh.annotations.BenchmarkMode;
 27 import org.openjdk.jmh.annotations.CompilerControl;
 28 import org.openjdk.jmh.annotations.Fork;
 29 import org.openjdk.jmh.annotations.Measurement;
 30 import org.openjdk.jmh.annotations.Mode;
 31 import org.openjdk.jmh.annotations.OperationsPerInvocation;
 32 import org.openjdk.jmh.annotations.OutputTimeUnit;
 33 import org.openjdk.jmh.annotations.Scope;
 34 import org.openjdk.jmh.annotations.State;
 35 import org.openjdk.jmh.annotations.Warmup;
 36 
 37 import java.util.concurrent.TimeUnit;
 38 
 39 /*
 40  *  For proper results it should be executed:
 41  *  java -jar target/benchmarks.jar baseline.acmp.IsCmpBranch  -wmb baseline.acmp.IsCmpBranch.equals050
 42  */
 43 
 44 @Fork(3)
 45 @Warmup(iterations = 3, time = 1)
 46 @Measurement(iterations = 5, time = 1)
 47 @OutputTimeUnit(TimeUnit.NANOSECONDS)
 48 @BenchmarkMode(Mode.AverageTime)
 49 @State(Scope.Thread)
 50 public class InlineIsCmpBranch64long extends StatesQ64long {
 51 
 52     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 53     private static int cmp_Obj(ObjWrapper[] objects1, ObjWrapper[] objects2) {
 54         int s = 0;
 55         for (int i = 0; i < SIZE; i++) {
 56             if (objects1[i].f == objects2[i].f) {
 57                 s += 1;
 58             } else {
 59                 s -= 1;
 60             }
 61         }
 62         return s;
 63     }
 64 
 65     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 66     private static int cmp_Int(IntWrapper[] objects1, IntWrapper[] objects2) {
 67         int s = 0;
 68         for (int i = 0; i < SIZE; i++) {
 69             if (objects1[i].f == objects2[i].f) {
 70                 s += 1;
 71             } else {
 72                 s -= 1;
 73             }
 74         }
 75         return s;
 76     }
 77 
 78     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 79     private static int cmp_Ref(RefWrapper[] objects1, RefWrapper[] objects2) {
 80         int s = 0;
 81         for (int i = 0; i < SIZE; i++) {
 82             if (objects1[i].f == objects2[i].f) {
 83                 s += 1;
 84             } else {
 85                 s -= 1;
 86             }
 87         }
 88         return s;
 89     }
 90 
 91     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 92     private static int cmp_Val(ValWrapper[] objects1, ValWrapper[] objects2) {
 93         int s = 0;
 94         for (int i = 0; i < SIZE; i++) {
 95             if (objects1[i].f == objects2[i].f) {
 96                 s += 1;
 97             } else {
 98                 s -= 1;
 99             }
100         }
101         return s;
102     }
103 
104 
105     @Benchmark
106     @OperationsPerInvocation(SIZE)
107     @CompilerControl(CompilerControl.Mode.INLINE)
108     public int Obj_equals000(ObjState00 st) {
109         return cmp_Obj(st.arr1, st.arr2);
110     }
111 
112     @Benchmark
113     @OperationsPerInvocation(SIZE)
114     @CompilerControl(CompilerControl.Mode.INLINE)
115     public int Obj_equals025(ObjState25 st) {
116         return cmp_Obj(st.arr1, st.arr2);
117     }
118 
119     @Benchmark
120     @OperationsPerInvocation(SIZE)
121     @CompilerControl(CompilerControl.Mode.INLINE)
122     public int Obj_equals050(ObjState50 st) {
123         return cmp_Obj(st.arr1, st.arr2);
124     }
125 
126     @Benchmark
127     @OperationsPerInvocation(SIZE)
128     @CompilerControl(CompilerControl.Mode.INLINE)
129     public int Obj_equals075(ObjState75 st) {
130         return cmp_Obj(st.arr1, st.arr2);
131     }
132 
133     @Benchmark
134     @OperationsPerInvocation(SIZE)
135     @CompilerControl(CompilerControl.Mode.INLINE)
136     public int Obj_equals100(ObjState100 st) {
137         return cmp_Obj(st.arr1, st.arr2);
138     }
139 
140     @Benchmark
141     @OperationsPerInvocation(SIZE)
142     @CompilerControl(CompilerControl.Mode.INLINE)
143     public int Int_equals000(IntState00 st) {
144         return cmp_Int(st.arr1, st.arr2);
145     }
146 
147     @Benchmark
148     @OperationsPerInvocation(SIZE)
149     @CompilerControl(CompilerControl.Mode.INLINE)
150     public int Int_equals025(IntState25 st) {
151         return cmp_Int(st.arr1, st.arr2);
152     }
153 
154     @Benchmark
155     @OperationsPerInvocation(SIZE)
156     @CompilerControl(CompilerControl.Mode.INLINE)
157     public int Int_equals050(IntState50 st) {
158         return cmp_Int(st.arr1, st.arr2);
159     }
160 
161     @Benchmark
162     @OperationsPerInvocation(SIZE)
163     @CompilerControl(CompilerControl.Mode.INLINE)
164     public int Int_equals075(IntState75 st) {
165         return cmp_Int(st.arr1, st.arr2);
166     }
167 
168     @Benchmark
169     @OperationsPerInvocation(SIZE)
170     @CompilerControl(CompilerControl.Mode.INLINE)
171     public int Int_equals100(IntState100 st) {
172         return cmp_Int(st.arr1, st.arr2);
173     }
174 
175     @Benchmark
176     @OperationsPerInvocation(SIZE)
177     @CompilerControl(CompilerControl.Mode.INLINE)
178     public int Ref_equals000(RefState00 st) {
179         return cmp_Ref(st.arr1, st.arr2);
180     }
181 
182     @Benchmark
183     @OperationsPerInvocation(SIZE)
184     @CompilerControl(CompilerControl.Mode.INLINE)
185     public int Ref_equals025(RefState25 st) {
186         return cmp_Ref(st.arr1, st.arr2);
187     }
188 
189     @Benchmark
190     @OperationsPerInvocation(SIZE)
191     @CompilerControl(CompilerControl.Mode.INLINE)
192     public int Ref_equals050(RefState50 st) {
193         return cmp_Ref(st.arr1, st.arr2);
194     }
195 
196     @Benchmark
197     @OperationsPerInvocation(SIZE)
198     @CompilerControl(CompilerControl.Mode.INLINE)
199     public int Ref_equals075(RefState75 st) {
200         return cmp_Ref(st.arr1, st.arr2);
201     }
202 
203     @Benchmark
204     @OperationsPerInvocation(SIZE)
205     @CompilerControl(CompilerControl.Mode.INLINE)
206     public int Ref_equals100(RefState100 st) {
207         return cmp_Ref(st.arr1, st.arr2);
208     }
209 
210     @Benchmark
211     @OperationsPerInvocation(SIZE)
212     @CompilerControl(CompilerControl.Mode.INLINE)
213     public int Val_equals000(ValState00 st) {
214         return cmp_Val(st.arr1, st.arr2);
215     }
216 
217     @Benchmark
218     @OperationsPerInvocation(SIZE)
219     @CompilerControl(CompilerControl.Mode.INLINE)
220     public int Val_equals025(ValState25 st) {
221         return cmp_Val(st.arr1, st.arr2);
222     }
223 
224     @Benchmark
225     @OperationsPerInvocation(SIZE)
226     @CompilerControl(CompilerControl.Mode.INLINE)
227     public int Val_equals050(ValState50 st) {
228         return cmp_Val(st.arr1, st.arr2);
229     }
230 
231     @Benchmark
232     @OperationsPerInvocation(SIZE)
233     @CompilerControl(CompilerControl.Mode.INLINE)
234     public int Val_equals075(ValState75 st) {
235         return cmp_Val(st.arr1, st.arr2);
236     }
237 
238     @Benchmark
239     @OperationsPerInvocation(SIZE)
240     @CompilerControl(CompilerControl.Mode.INLINE)
241     public int Val_equals100(ValState100 st) {
242         return cmp_Val(st.arr1, st.arr2);
243     }
244 
245 }